Make pdfium::span<> templated on Extent and InternalPtrType.

First step in splitting raw_span off of span. Unlike base::span,
pdfium::span does not use Extent, but get these arguments in order
for the future.

Introduce raw_span as a distinct type that uses exactly the same
InternalPtrType as ordinary span for the moment.

-- Use it in one place.

Change-Id: Ic81baa23cf85a002b80b538f402edc9ab8623667
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117150
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/core/fpdfapi/page/cpdf_streamparser.h b/core/fpdfapi/page/cpdf_streamparser.h
index 7997494..50f7d65 100644
--- a/core/fpdfapi/page/cpdf_streamparser.h
+++ b/core/fpdfapi/page/cpdf_streamparser.h
@@ -7,6 +7,7 @@
 #ifndef CORE_FPDFAPI_PAGE_CPDF_STREAMPARSER_H_
 #define CORE_FPDFAPI_PAGE_CPDF_STREAMPARSER_H_
 
+#include "core/fxcrt/raw_span.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/span.h"
 #include "core/fxcrt/string_pool_template.h"
@@ -53,7 +54,7 @@
   uint32_t m_WordSize = 0;  // Current byte position within |m_WordBuffer|.
   WeakPtr<ByteStringPool> m_pPool;
   RetainPtr<CPDF_Object> m_pLastObj;
-  pdfium::span<const uint8_t> m_pBuf;
+  pdfium::raw_span<const uint8_t> m_pBuf;
   uint8_t m_WordBuffer[kMaxWordLength + 1] = {};  // Include space for NUL.
 };
 
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index 1531a7c..b7b8578 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -104,6 +104,7 @@
     "observed_ptr.h",
     "pauseindicator_iface.h",
     "ptr_util.h",
+    "raw_span.h",
     "retain_ptr.h",
     "scoped_set_insertion.h",
     "shared_copy_on_write.h",
diff --git a/core/fxcrt/raw_span.h b/core/fxcrt/raw_span.h
new file mode 100644
index 0000000..ff570e3
--- /dev/null
+++ b/core/fxcrt/raw_span.h
@@ -0,0 +1,31 @@
+// Copyright 2024 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CORE_FXCRT_RAW_SPAN_H_
+#define CORE_FXCRT_RAW_SPAN_H_
+
+#include "core/fxcrt/compiler_specific.h"
+#include "core/fxcrt/span.h"
+
+#if defined(PDF_USE_PARTITION_ALLOC)
+UNSAFE_BUFFERS_INCLUDE_BEGIN
+#include "partition_alloc/pointers/raw_ptr.h"
+UNSAFE_BUFFERS_INCLUDE_END
+#else
+#include "core/fxcrt/unowned_ptr_exclusion.h"
+#endif
+
+namespace pdfium {
+
+#if defined(PDF_USE_PARTITION_ALLOC)
+template <typename T>
+using raw_span = span<T, dynamic_extent, raw_ptr<T, AllowPtrArithmetic>>;
+#else
+template <typename T>
+using raw_span = span<T, dynamic_extent, UNOWNED_PTR_EXCLUSION T*>;
+#endif
+
+}  // namespace pdfium
+
+#endif  // CORE_FXCRT_RAW_SPAN_H_
diff --git a/core/fxcrt/span.h b/core/fxcrt/span.h
index 130af03..d7ecc9d 100644
--- a/core/fxcrt/span.h
+++ b/core/fxcrt/span.h
@@ -32,7 +32,17 @@
 
 constexpr size_t dynamic_extent = static_cast<size_t>(-1);
 
+#if defined(PDF_USE_PARTITION_ALLOC)
 template <typename T>
+using DefaultSpanInternalPtr = raw_ptr<T, AllowPtrArithmetic>;
+#else
+template <typename T>
+using DefaultSpanInternalPtr = UNOWNED_PTR_EXCLUSION T*;
+#endif
+
+template <typename T,
+          size_t Extent = dynamic_extent,
+          typename InternalPtr = DefaultSpanInternalPtr<T>>
 class span;
 
 namespace internal {
@@ -194,7 +204,7 @@
 // - byte_span_from_ref() function.
 
 // [span], class template span
-template <typename T>
+template <typename T, size_t Extent, typename InternalPtr>
 class TRIVIAL_ABI GSL_POINTER span {
  public:
   using value_type = typename std::remove_cv<T>::type;
@@ -323,11 +333,7 @@
   }
 
  private:
-#if defined(PDF_USE_PARTITION_ALLOC)
-  raw_ptr<T, AllowPtrArithmetic> data_ = nullptr;
-#else
-  UNOWNED_PTR_EXCLUSION T* data_ = nullptr;
-#endif
+  InternalPtr data_ = nullptr;
   size_t size_ = 0;
 };