Introduce CPDF_StreamAcc::KeyForCache()

This allows CPDF_StreamAcc to avoid handing out a reference to
its internal CPDF_Stream in a few places.

Change-Id: I4cb7bca0ba3a6435fb7158d98883b8bfc91f8afa
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/99091
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index ae0c257..cf8baf4 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -275,15 +275,13 @@
     pdfium::span<const uint8_t> pSrcSpan;
     if (m_pStreamAcc) {
       pSrcSpan = m_pStreamAcc->GetSpan();
-      if (m_pStreamAcc->GetStream())
-        nSrcKey = m_pStreamAcc->GetStream()->KeyForCache();
+      nSrcKey = m_pStreamAcc->KeyForCache();
     }
     uint64_t nGlobalKey = 0;
     pdfium::span<const uint8_t> pGlobalSpan;
     if (m_pGlobalAcc) {
       pGlobalSpan = m_pGlobalAcc->GetSpan();
-      if (m_pGlobalAcc->GetStream())
-        nGlobalKey = m_pGlobalAcc->GetStream()->KeyForCache();
+      nGlobalKey = m_pGlobalAcc->KeyForCache();
     }
     iDecodeStatus = Jbig2Decoder::StartDecode(
         m_pJbig2Context.get(), m_pDocument->GetOrCreateCodecContext(), m_Width,
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp
index 7ef79ff..e7eb6f4 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.cpp
+++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp
@@ -98,6 +98,10 @@
   return {GetData(), GetSize()};
 }
 
+uint64_t CPDF_StreamAcc::KeyForCache() const {
+  return m_pStream ? m_pStream->KeyForCache() : 0;
+}
+
 ByteString CPDF_StreamAcc::ComputeDigest() const {
   uint8_t digest[20];
   CRYPT_SHA1Generate(GetData(), GetSize(), digest);
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.h b/core/fpdfapi/parser/cpdf_stream_acc.h
index 7c1ca56..800adcf 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.h
+++ b/core/fpdfapi/parser/cpdf_stream_acc.h
@@ -37,6 +37,7 @@
 
   uint32_t GetSize() const;
   pdfium::span<const uint8_t> GetSpan() const;
+  uint64_t KeyForCache() const;
   ByteString ComputeDigest() const;
   ByteString GetImageDecoder() const { return m_ImageDecoder; }
   std::unique_ptr<uint8_t, FxFreeDeleter> DetachData();