diff options
author | dsinclair <dsinclair@chromium.org> | 2016-09-22 13:18:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-22 13:18:45 -0700 |
commit | a939bfe3e102bfb28b4e8a5d951333d16badf80b (patch) | |
tree | d9dc20fc9dbf6649a460f3aa10be7124b51caa7d /fpdfsdk/fpdfformfill.cpp | |
parent | 62356867b331bc9f71f9a0c8fce0cff9927d3356 (diff) | |
download | pdfium-a939bfe3e102bfb28b4e8a5d951333d16badf80b.tar.xz |
Make creation of CPDFSDK_Document clearer
Move the creation of the CPDFSDK_Document into FPDFDOC_InitFormFillEnvironment
instead of hidden inside a Get method in CDPFXFA_Document.
Review-Url: https://codereview.chromium.org/2353303004
Diffstat (limited to 'fpdfsdk/fpdfformfill.cpp')
-rw-r--r-- | fpdfsdk/fpdfformfill.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 7e4ce36f5f..9baabc4de4 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; } |