diff options
author | dsinclair <dsinclair@chromium.org> | 2016-10-12 11:56:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-12 11:56:23 -0700 |
commit | 7cbe68e34257b460bfa3baf0ea68fd6d50e1bc77 (patch) | |
tree | cc439488801d7a3e72a56ecd88df600e12b8a948 /fpdfsdk/javascript/Document.cpp | |
parent | 7cc6a32693a07210e036a8d7131232231ec0fdb3 (diff) | |
download | pdfium-7cbe68e34257b460bfa3baf0ea68fd6d50e1bc77.tar.xz |
Merge CPDFSDK_Document into CPDFSDK_FormFillEnvironment
This CL merges the CPDFSDK_Document and CPDFSDK_FormFillEnvironment classes
as they always existed and always pointed at each other.
Review-Url: https://codereview.chromium.org/2410893002
Diffstat (limited to 'fpdfsdk/javascript/Document.cpp')
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 110 |
1 files changed, 45 insertions, 65 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index ed87c2dbba..6b795a02ec 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -17,7 +17,6 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fpdfdoc/cpdf_nametree.h" #include "fpdfsdk/cpdfsdk_annotiterator.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -173,8 +172,7 @@ FX_BOOL Document::numFields(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); return TRUE; @@ -188,15 +186,15 @@ FX_BOOL Document::dirty(IJS_Context* cc, return FALSE; } if (vp.IsGetting()) { - vp << !!m_pFormFillEnv->GetSDKDocument()->GetChangeMark(); + vp << !!m_pFormFillEnv->GetChangeMark(); } else { bool bChanged = false; vp >> bChanged; if (bChanged) - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); else - m_pFormFillEnv->GetSDKDocument()->ClearChangeMark(); + m_pFormFillEnv->ClearChangeMark(); } return TRUE; } @@ -218,12 +216,11 @@ FX_BOOL Document::pageNum(IJS_Context* cc, return FALSE; } if (vp.IsGetting()) { - if (CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetCurrentView()) { + if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { vp << pPageView->GetPageIndex(); } } else { - int iPageCount = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + int iPageCount = m_pFormFillEnv->GetPageCount(); int iPageNum = 0; vp >> iPageNum; @@ -299,8 +296,7 @@ FX_BOOL Document::getField(IJS_Context* cc, CJS_Context* pContext = static_cast<CJS_Context*>(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { vRet.SetNull(pRuntime); @@ -338,8 +334,7 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); if (!pField) @@ -384,8 +379,7 @@ FX_BOOL Document::mailForm(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -402,8 +396,7 @@ FX_BOOL Document::mailForm(IJS_Context* cc, iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CFX_ByteTextBuf textBuf; if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) return FALSE; @@ -502,17 +495,15 @@ FX_BOOL Document::removeField(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_ANNOT_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CJS_Context* pContext = static_cast<CJS_Context*>(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector<CPDFSDK_Widget*> widgets; pInterForm->GetWidgets(sFieldName, &widgets); if (widgets.empty()) @@ -532,8 +523,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, // If there is currently no pageview associated with the page being used // do not create one. We may be in the process of tearing down the document // and creating a new pageview at this point will cause bad things. - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); if (pPageView) { #if PDF_ENABLE_XFA pPageView->DeleteAnnot(pWidget); @@ -541,7 +531,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, pPageView->UpdateRects(aRefresh); } } - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); return TRUE; } @@ -558,21 +548,20 @@ FX_BOOL Document::resetForm(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CJS_Array aName; if (params.empty()) { pPDFForm->ResetForm(TRUE); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); return TRUE; } @@ -599,7 +588,7 @@ FX_BOOL Document::resetForm(IJS_Context* cc, if (!aFields.empty()) { pPDFForm->ResetForm(aFields, TRUE, TRUE); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); } return TRUE; @@ -664,8 +653,7 @@ FX_BOOL Document::submitForm(IJS_Context* cc, aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); if (aFields.GetLength(pRuntime) == 0 && bEmpty) { if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { @@ -788,8 +776,7 @@ FX_BOOL Document::info(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = - m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -843,22 +830,21 @@ FX_BOOL Document::getPropertyInternal(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = - m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; if (vp.IsGetting()) { vp << pDictionary->GetUnicodeTextFor(propName); } else { - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CFX_WideString csProperty; vp >> csProperty; pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); } return TRUE; } @@ -885,7 +871,7 @@ FX_BOOL Document::delay(IJS_Context* cc, if (vp.IsGetting()) { vp << m_bDelay; } else { - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -947,7 +933,7 @@ FX_BOOL Document::numPages(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + vp << m_pFormFillEnv->GetPageCount(); return TRUE; } @@ -995,7 +981,7 @@ FX_BOOL Document::URL(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pFormFillEnv->GetSDKDocument()->GetPath(); + vp << m_pFormFillEnv->JS_docGetFilePath(); return TRUE; } @@ -1017,8 +1003,7 @@ FX_BOOL Document::calculate(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); if (vp.IsGetting()) { vp << !!pInterForm->IsCalculateEnabled(); } else { @@ -1040,7 +1025,7 @@ FX_BOOL Document::documentFileName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CFX_WideString wsFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); + CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); int32_t i = wsFilePath.GetLength() - 1; for (; i >= 0; i--) { if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') @@ -1065,7 +1050,7 @@ FX_BOOL Document::path(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << app::SysPathToPDFPath(m_pFormFillEnv->GetSDKDocument()->GetPath()); + vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); return TRUE; } @@ -1118,8 +1103,7 @@ FX_BOOL Document::getAnnot(IJS_Context* cc, CJS_Runtime* pRuntime = pContext->GetJSRuntime(); int nPageNo = params[0].ToInt(pRuntime); CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageNo); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); if (!pPageView) return FALSE; @@ -1170,12 +1154,11 @@ FX_BOOL Document::getAnnots(IJS_Context* cc, // TODO(tonikitoo): Add support supported parameters as per // the PDF spec. - int nPageNo = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + int nPageNo = m_pFormFillEnv->GetPageCount(); CJS_Array annots; for (int i = 0; i < nPageNo; ++i) { - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(i); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); if (!pPageView) return FALSE; @@ -1392,13 +1375,13 @@ FX_BOOL Document::calculateNow(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - m_pFormFillEnv->GetSDKDocument()->GetInterForm()->OnCalculate(); + m_pFormFillEnv->GetInterForm()->OnCalculate(); return TRUE; } @@ -1416,8 +1399,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -1429,7 +1411,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return FALSE; @@ -1476,8 +1458,7 @@ FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -1492,14 +1473,13 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; @@ -1686,7 +1666,7 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CFX_ByteString utf8Name = wideName.UTF8Encode(); - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return FALSE; |