Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: fpdfsdk/fpdfformfill.cpp

Issue 2353303004: Make creation of CPDFSDK_Document clearer (Closed)
Patch Set: Review updates Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/cpdfsdk_environment.cpp ('k') | fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfformfill.cpp
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 7e4ce36f5f367889d7ec84087333f0c7d5a6de88..9baabc4de4632587a138958cfbc8cb6decfcdfc1 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -242,14 +242,22 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
if (!pDocument)
return nullptr;
+#ifdef PDF_ENABLE_XFA
+ // If the CPDFXFA_Document has a SDKDocument already then we've done this
+ // and can just return the old Env. Otherwise, we'll end up setting a new
+ // SDKDocument into the XFADocument and, that could get weird.
+ if (pDocument->GetSDKDoc())
+ return pDocument->GetSDKDoc()->GetEnv();
+#endif
+
CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo);
+
#ifdef PDF_ENABLE_XFA
- pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv));
- CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
- pApp->AddFormFillEnv(pEnv);
-#else // PDF_ENABLE_XFA
- pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv));
+ // Ownership of the SDKDocument is passed to the CPDFXFA_Document.
+ pDocument->SetSDKDoc(WrapUnique(pEnv->GetSDKDocument()));
+ CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv);
#endif // PDF_ENABLE_XFA
+
return pEnv;
}
@@ -257,16 +265,18 @@ DLLEXPORT void STDCALL
FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
if (!hHandle)
return;
+
CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle);
+
#ifdef PDF_ENABLE_XFA
- CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
- pApp->RemoveFormFillEnv(pEnv);
+ CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv);
#else // PDF_ENABLE_XFA
if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) {
pEnv->SetSDKDocument(nullptr);
delete pSDKDoc;
}
#endif // PDF_ENABLE_XFA
+
delete pEnv;
}
« no previous file with comments | « fpdfsdk/cpdfsdk_environment.cpp ('k') | fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698