Introduce the concept of CPDF_Page::Extension

Similar tp CPDF_Document::Extension, this is a base type for fpdfsdk/
to use to improve layering.

While we're at it, make pages point to documents to prove they don't
outlive them.

Another small step towards not passing XFA objects across FPDF.

Change-Id: Idcee9da3a18c06331fa56f3d6c188e4ce27d34f2
Reviewed-on: https://pdfium-review.googlesource.com/31631
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index d679766..eee6673 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -22,7 +22,9 @@
 CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
                      CPDF_Dictionary* pPageDict,
                      bool bPageCache)
-    : CPDF_PageObjectHolder(pDocument, pPageDict), m_PageSize(100, 100) {
+    : CPDF_PageObjectHolder(pDocument, pPageDict),
+      m_PageSize(100, 100),
+      m_pPDFDocument(pDocument) {
   if (bPageCache)
     m_pPageRender = pdfium::MakeUnique<CPDF_PageRenderCache>(this);
   if (!pPageDict)
diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h
index 0f401ea..4e8172d 100644
--- a/core/fpdfapi/page/cpdf_page.h
+++ b/core/fpdfapi/page/cpdf_page.h
@@ -12,6 +12,8 @@
 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/retain_ptr.h"
+#include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/optional.h"
 
 class CPDF_Dictionary;
@@ -23,6 +25,7 @@
 class CPDF_Page : public CPDF_PageObjectHolder {
  public:
   class View {};  // Caller implements as desired, empty here due to layering.
+  class Extension : public Retainable {};  // XFA page parent class, layering.
 
   CPDF_Page(CPDF_Document* pDocument,
             CPDF_Dictionary* pPageDict,
@@ -56,8 +59,11 @@
   }
   void SetRenderContext(std::unique_ptr<CPDF_PageRenderContext> pContext);
 
+  void* GetPDFDocument() const { return m_pPDFDocument.Get(); }
   View* GetView() const { return m_pView; }
   void SetView(View* pView) { m_pView = pView; }
+  Extension* GetPageExtension() const { return m_pPageExtension.Get(); }
+  void SetPageExtension(Extension* pExt) { m_pPageExtension = pExt; }
 
  private:
   void StartParse();
@@ -68,6 +74,8 @@
   CFX_SizeF m_PageSize;
   CFX_Matrix m_PageMatrix;
   View* m_pView = nullptr;
+  UnownedPtr<Extension> m_pPageExtension;
+  UnownedPtr<CPDF_Document> m_pPDFDocument;
   std::unique_ptr<CPDF_PageRenderCache> m_pPageRender;
   std::unique_ptr<CPDF_PageRenderContext> m_pRenderContext;
 };
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
index 0a5e3fc..030b068 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
@@ -9,24 +9,25 @@
 
 #include <memory>
 
+#include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/optional.h"
 
-class CPDFXFA_Context;
 class CPDF_Dictionary;
-class CPDF_Page;
+class CPDFXFA_Context;
 class CXFA_FFPageView;
 
-class CPDFXFA_Page : public Retainable {
+class CPDFXFA_Page : public CPDF_Page::Extension {
  public:
   template <typename T, typename... Args>
   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
 
   bool LoadPage();
   bool LoadPDFPage(CPDF_Dictionary* pageDict);
+
   CPDFXFA_Context* GetContext() const { return m_pContext.Get(); }
   int GetPageIndex() const { return m_iPageIndex; }
   CPDF_Page* GetPDFPage() const { return m_pPDFPage.get(); }