diff options
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 202 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.h | 10 | ||||
-rw-r--r-- | fpdfsdk/javascript/Field.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_EventHandler.cpp | 12 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Runtime_Stub.cpp | 14 | ||||
-rw-r--r-- | fpdfsdk/javascript/app.cpp | 78 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_context.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_runtime.cpp | 31 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_runtime.h | 13 | ||||
-rw-r--r-- | fpdfsdk/javascript/global.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/ijs_runtime.h | 8 |
11 files changed, 185 insertions, 189 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index f8edf97247..ac94e10303 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -149,12 +149,12 @@ IMPLEMENT_JS_CLASS(CJS_Document, Document) void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); Document* pDoc = static_cast<Document*>(GetEmbedObject()); - pDoc->AttachDoc(pRuntime->GetReaderDocument()); + pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv()); } Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), - m_pDocument(nullptr), + m_pFormFillEnv(nullptr), m_cwBaseURL(L""), m_bDelay(FALSE) {} @@ -169,11 +169,12 @@ FX_BOOL Document::numFields(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); return TRUE; @@ -182,20 +183,20 @@ FX_BOOL Document::numFields(IJS_Context* cc, FX_BOOL Document::dirty(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } if (vp.IsGetting()) { - vp << !!m_pDocument->GetChangeMark(); + vp << !!m_pFormFillEnv->GetSDKDocument()->GetChangeMark(); } else { bool bChanged = false; vp >> bChanged; if (bChanged) - m_pDocument->SetChangeMark(); + m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); else - m_pDocument->ClearChangeMark(); + m_pFormFillEnv->GetSDKDocument()->ClearChangeMark(); } return TRUE; } @@ -212,26 +213,26 @@ FX_BOOL Document::ADBE(IJS_Context* cc, FX_BOOL Document::pageNum(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } if (vp.IsGetting()) { - if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { + if (CPDFSDK_PageView* pPageView = + m_pFormFillEnv->GetSDKDocument()->GetCurrentView()) { vp << pPageView->GetPageIndex(); } } else { - int iPageCount = m_pDocument->GetPageCount(); + int iPageCount = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); int iPageNum = 0; vp >> iPageNum; - CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv(); if (iPageNum >= 0 && iPageNum < iPageCount) { - pEnv->JS_docgotoPage(iPageNum); + m_pFormFillEnv->JS_docgotoPage(iPageNum); } else if (iPageNum >= iPageCount) { - pEnv->JS_docgotoPage(iPageCount - 1); + m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); } else if (iPageNum < 0) { - pEnv->JS_docgotoPage(0); + m_pFormFillEnv->JS_docgotoPage(0); } } @@ -291,14 +292,15 @@ FX_BOOL Document::getField(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } CJS_Context* pContext = static_cast<CJS_Context*>(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { vRet.SetNull(pRuntime); @@ -325,7 +327,7 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -336,7 +338,8 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); if (!pField) @@ -381,11 +384,12 @@ FX_BOOL Document::mailForm(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( + FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -402,7 +406,8 @@ 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_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CFX_ByteTextBuf textBuf; if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) return FALSE; @@ -420,7 +425,7 @@ FX_BOOL Document::print(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -477,9 +482,9 @@ FX_BOOL Document::print(IJS_Context* cc, bAnnotations = params[7].ToBool(pRuntime); } - if (CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv()) { - pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, - bReverse, bAnnotations); + if (m_pFormFillEnv) { + m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, + bPrintAsImage, bReverse, bAnnotations); return TRUE; } return FALSE; @@ -497,19 +502,21 @@ FX_BOOL Document::removeField(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { + if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetSDKDocument()->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_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); std::vector<CPDFSDK_Widget*> widgets; pInterForm->GetWidgets(sFieldName, &widgets); if (widgets.empty()) @@ -529,7 +536,8 @@ 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_pDocument->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = + m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); if (pPageView) { #if PDF_ENABLE_XFA pPageView->DeleteAnnot(pWidget); @@ -537,7 +545,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, pPageView->UpdateRects(aRefresh); } } - m_pDocument->SetChangeMark(); + m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); return TRUE; } @@ -550,24 +558,25 @@ FX_BOOL Document::resetForm(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CJS_Array aName; if (params.empty()) { pPDFForm->ResetForm(TRUE); - m_pDocument->SetChangeMark(); + m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); return TRUE; } @@ -594,7 +603,7 @@ FX_BOOL Document::resetForm(IJS_Context* cc, if (!aFields.empty()) { pPDFForm->ResetForm(aFields, TRUE, TRUE); - m_pDocument->SetChangeMark(); + m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); } return TRUE; @@ -624,7 +633,7 @@ FX_BOOL Document::submitForm(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -659,7 +668,8 @@ FX_BOOL Document::submitForm(IJS_Context* cc, aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); if (aFields.GetLength(pRuntime) == 0 && bEmpty) { if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { @@ -694,8 +704,8 @@ FX_BOOL Document::submitForm(IJS_Context* cc, return TRUE; } -void Document::AttachDoc(CPDFSDK_Document* pDoc) { - m_pDocument.Reset(pDoc); +void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { + m_pFormFillEnv.Reset(pFormFillEnv); } FX_BOOL Document::bookmarkRoot(IJS_Context* cc, @@ -757,7 +767,7 @@ FX_BOOL Document::mailDoc(IJS_Context* cc, } pRuntime->BeginBlock(); - CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); + CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetFormFillEnv(); pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); pRuntime->EndBlock(); @@ -778,11 +788,12 @@ FX_BOOL Document::info(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = + m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -832,25 +843,26 @@ FX_BOOL Document::getPropertyInternal(IJS_Context* cc, CJS_PropValue& vp, const CFX_ByteString& propName, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = + m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; if (vp.IsGetting()) { vp << pDictionary->GetUnicodeTextFor(propName); } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CFX_WideString csProperty; vp >> csProperty; pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); - m_pDocument->SetChangeMark(); + m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); } return TRUE; } @@ -870,14 +882,14 @@ FX_BOOL Document::creator(IJS_Context* cc, FX_BOOL Document::delay(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } if (vp.IsGetting()) { vp << m_bDelay; } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -887,10 +899,8 @@ FX_BOOL Document::delay(IJS_Context* cc, } else { std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; DelayDataToProcess.swap(m_DelayData); - for (const auto& pData : DelayDataToProcess) { - if (m_pDocument.Get()) - Field::DoDelay(m_pDocument->GetEnv(), pData.get()); - } + for (const auto& pData : DelayDataToProcess) + Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); } } return TRUE; @@ -923,7 +933,7 @@ FX_BOOL Document::subject(IJS_Context* cc, FX_BOOL Document::title(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) { + if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -937,11 +947,11 @@ FX_BOOL Document::numPages(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pDocument->GetPageCount(); + vp << m_pFormFillEnv->GetSDKDocument()->GetPageCount(); return TRUE; } @@ -985,11 +995,11 @@ FX_BOOL Document::URL(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pDocument->GetPath(); + vp << m_pFormFillEnv->GetSDKDocument()->GetPath(); return TRUE; } @@ -1007,11 +1017,12 @@ FX_BOOL Document::baseURL(IJS_Context* cc, FX_BOOL Document::calculate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + m_pFormFillEnv->GetSDKDocument()->GetInterForm(); if (vp.IsGetting()) { vp << !!pInterForm->IsCalculateEnabled(); } else { @@ -1029,11 +1040,11 @@ FX_BOOL Document::documentFileName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CFX_WideString wsFilePath = m_pDocument->GetPath(); + CFX_WideString wsFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); int32_t i = wsFilePath.GetLength() - 1; for (; i >= 0; i--) { if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') @@ -1054,11 +1065,11 @@ FX_BOOL Document::path(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << app::SysPathToPDFPath(m_pDocument->GetPath()); + vp << app::SysPathToPDFPath(m_pFormFillEnv->GetSDKDocument()->GetPath()); return TRUE; } @@ -1103,7 +1114,7 @@ FX_BOOL Document::getAnnot(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -1111,7 +1122,8 @@ 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_pDocument->GetPageView(nPageNo); + CPDFSDK_PageView* pPageView = + m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageNo); if (!pPageView) return FALSE; @@ -1152,7 +1164,7 @@ FX_BOOL Document::getAnnots(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -1162,11 +1174,12 @@ FX_BOOL Document::getAnnots(IJS_Context* cc, // TODO(tonikitoo): Add support supported parameters as per // the PDF spec. - int nPageNo = m_pDocument->GetPageCount(); + int nPageNo = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); CJS_Array annots; for (int i = 0; i < nPageNo; ++i) { - CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(i); + CPDFSDK_PageView* pPageView = + m_pFormFillEnv->GetSDKDocument()->GetPageView(i); if (!pPageView) return FALSE; @@ -1379,17 +1392,17 @@ FX_BOOL Document::calculateNow(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - m_pDocument->GetInterForm()->OnCalculate(); + m_pFormFillEnv->GetSDKDocument()->GetInterForm()->OnCalculate(); return TRUE; } @@ -1403,11 +1416,12 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( + FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -1419,7 +1433,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_pDocument->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); if (!pDocument) return FALSE; @@ -1462,11 +1476,12 @@ FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( + FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -1477,17 +1492,18 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetSDKDocument()->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_pDocument->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; @@ -1667,14 +1683,14 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; } - if (!m_pDocument) { + if (!m_pFormFillEnv) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CFX_ByteString utf8Name = wideName.UTF8Encode(); - CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); if (!pDocument) return FALSE; @@ -1698,9 +1714,9 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, } pRuntime->BeginBlock(); - CPDFSDK_FormFillEnvironment* pApp = m_pDocument->GetEnv(); - pApp->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), - scrollPositionArray.get(), scrollPositionArraySize); + m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), + scrollPositionArray.get(), + scrollPositionArraySize); pRuntime->EndBlock(); return TRUE; @@ -1723,10 +1739,8 @@ void Document::DoFieldDelay(const CFX_WideString& sFieldName, } } - for (const auto& pData : DelayDataForFieldAndControlIndex) { - if (m_pDocument.Get()) - Field::DoDelay(m_pDocument->GetEnv(), pData.get()); - } + for (const auto& pData : DelayDataForFieldAndControlIndex) + Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); } CJS_Document* Document::GetCJSDoc() const { diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 5f33cf1f69..a72316c3d1 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -13,7 +13,7 @@ #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fpdfapi/page/cpdf_textobject.h" -#include "fpdfsdk/cpdfsdk_document.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" class PrintParamsObj : public CJS_EmbedObj { @@ -270,8 +270,10 @@ class Document : public CJS_EmbedObj { CFX_WideString& sError); FX_BOOL URL(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); - void AttachDoc(CPDFSDK_Document* pDoc); - CPDFSDK_Document* GetReaderDoc() const { return m_pDocument.Get(); } + void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); + CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { + return m_pFormFillEnv.Get(); + } void AddDelayData(CJS_DelayData* pData); void DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex); CJS_Document* GetCJSDoc() const; @@ -286,7 +288,7 @@ class Document : public CJS_EmbedObj { const CFX_ByteString& propName, CFX_WideString& sError); - CPDFSDK_Document::ObservedPtr m_pDocument; + CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; CFX_WideString m_cwBaseURL; std::list<std::unique_ptr<CJS_DelayData>> m_DelayData; std::list<std::unique_ptr<IconElement>> m_IconList; diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 51724c450f..652f1e640d 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -212,7 +212,7 @@ void Field::ParseFieldName(const std::wstring& strFieldNameParsed, FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName) { m_pJSDoc = pDocument; - m_pFormFillEnv.Reset(pDocument->GetReaderDoc()->GetEnv()); + m_pFormFillEnv.Reset(pDocument->GetFormFillEnv()); m_bCanSet = m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM) || m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || diff --git a/fpdfsdk/javascript/JS_EventHandler.cpp b/fpdfsdk/javascript/JS_EventHandler.cpp index 731d803d2c..27223cfccb 100644 --- a/fpdfsdk/javascript/JS_EventHandler.cpp +++ b/fpdfsdk/javascript/JS_EventHandler.cpp @@ -602,9 +602,9 @@ Field* CJS_EventHandler::Source() { CJS_Document* pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj)); Document* pDocument = (Document*)pJSDocument->GetEmbedObject(); - pDocument->AttachDoc(m_pTargetFormFillEnv - ? m_pTargetFormFillEnv->GetSDKDocument() - : m_pJSContext->GetFormFillEnv()->GetSDKDocument()); + pDocument->SetFormFillEnv(m_pTargetFormFillEnv + ? m_pTargetFormFillEnv + : m_pJSContext->GetFormFillEnv()); CJS_Field* pJSField = static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); @@ -626,9 +626,9 @@ Field* CJS_EventHandler::Target_Field() { CJS_Document* pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj)); Document* pDocument = (Document*)pJSDocument->GetEmbedObject(); - pDocument->AttachDoc(m_pTargetFormFillEnv - ? m_pTargetFormFillEnv->GetSDKDocument() - : m_pJSContext->GetFormFillEnv()->GetSDKDocument()); + pDocument->SetFormFillEnv(m_pTargetFormFillEnv + ? m_pTargetFormFillEnv + : m_pJSContext->GetFormFillEnv()); CJS_Field* pJSField = static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); diff --git a/fpdfsdk/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/javascript/JS_Runtime_Stub.cpp index 904ee12cca..e7853fba7a 100644 --- a/fpdfsdk/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/javascript/JS_Runtime_Stub.cpp @@ -121,7 +121,8 @@ class CJS_ContextStub final : public IJS_Context { class CJS_RuntimeStub final : public IJS_Runtime { public: - CJS_RuntimeStub() : m_pDoc(nullptr) {} + CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv) + : m_pFormFillEnv(pFormFillEnv) {} ~CJS_RuntimeStub() override {} IJS_Context* NewContext() override { @@ -133,10 +134,9 @@ class CJS_RuntimeStub final : public IJS_Runtime { IJS_Context* GetCurrentContext() override { return m_pContext.get(); } void ReleaseContext(IJS_Context* pContext) override {} - void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override { - m_pDoc = pReaderDoc; + CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override { + return m_pFormFillEnv; } - CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; } #ifdef PDF_ENABLE_XFA FX_BOOL GetValueByName(const CFX_ByteStringC&, CFXJSE_Value*) override { @@ -154,7 +154,7 @@ class CJS_RuntimeStub final : public IJS_Runtime { } protected: - CPDFSDK_Document* m_pDoc; + CPDFSDK_FormFillEnvironment* m_pFormFillEnv; std::unique_ptr<CJS_ContextStub> m_pContext; }; @@ -165,6 +165,6 @@ void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {} void IJS_Runtime::Destroy() {} // static -IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pEnv) { - return new CJS_RuntimeStub; +IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pFormFillEnv) { + return new CJS_RuntimeStub(pFormFillEnv); } diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 048bea73c6..b41b8727ab 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -25,7 +25,7 @@ class GlobalTimer { public: GlobalTimer(app* pObj, - CPDFSDK_FormFillEnvironment* pEnv, + CPDFSDK_FormFillEnvironment* pFormFillEnv, CJS_Runtime* pRuntime, int nType, const CFX_WideString& script, @@ -55,11 +55,11 @@ class GlobalTimer { const uint32_t m_dwTimeOut; const CFX_WideString m_swJScript; CJS_Runtime::ObservedPtr m_pRuntime; - CPDFSDK_FormFillEnvironment* const m_pEnv; + CPDFSDK_FormFillEnvironment* const m_pFormFillEnv; }; GlobalTimer::GlobalTimer(app* pObj, - CPDFSDK_FormFillEnvironment* pEnv, + CPDFSDK_FormFillEnvironment* pFormFillEnv, CJS_Runtime* pRuntime, int nType, const CFX_WideString& script, @@ -72,8 +72,8 @@ GlobalTimer::GlobalTimer(app* pObj, m_dwTimeOut(dwTimeOut), m_swJScript(script), m_pRuntime(pRuntime), - m_pEnv(pEnv) { - CFX_SystemHandler* pHandler = m_pEnv->GetSysHandler(); + m_pFormFillEnv(pFormFillEnv) { + CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler(); m_nTimerID = pHandler->SetTimer(dwElapse, Trigger); (*GetGlobalTimerMap())[m_nTimerID] = this; } @@ -83,7 +83,7 @@ GlobalTimer::~GlobalTimer() { return; if (GetRuntime()) - m_pEnv->GetSysHandler()->KillTimer(m_nTimerID); + m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID); GetGlobalTimerMap()->erase(m_nTimerID); } @@ -217,27 +217,16 @@ FX_BOOL app::activeDocs(IJS_Context* cc, return FALSE; CJS_Context* pContext = (CJS_Context*)cc; - CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CPDFSDK_Document* pCurDoc = pContext->GetJSRuntime()->GetReaderDocument(); - CJS_Array aDocs; - if (CPDFSDK_Document* pDoc = pFormFillEnv->GetSDKDocument()) { - CJS_Document* pJSDocument = nullptr; - if (pDoc == pCurDoc) { - v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); - if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { - pJSDocument = - static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); - } - } else { - v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID); - pJSDocument = - static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); - ASSERT(pJSDocument); - } - aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); + CJS_Document* pJSDocument = nullptr; + v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); + if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { + pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); } + + CJS_Array aDocs; + aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); + if (aDocs.GetLength(pRuntime) > 0) vp << aDocs; else @@ -322,11 +311,11 @@ FX_BOOL app::platform(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; #ifdef PDF_ENABLE_XFA - CPDFSDK_FormFillEnvironment* pEnv = - static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderEnv(); - if (!pEnv) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); + if (!pFormFillEnv) return FALSE; - CFX_WideString platfrom = pEnv->GetPlatform(); + CFX_WideString platfrom = pFormFillEnv->GetPlatform(); if (!platfrom.IsEmpty()) { vp << platfrom; return TRUE; @@ -342,11 +331,11 @@ FX_BOOL app::language(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; #ifdef PDF_ENABLE_XFA - CPDFSDK_FormFillEnvironment* pEnv = - static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderEnv(); - if (!pEnv) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); + if (!pFormFillEnv) return FALSE; - CFX_WideString language = pEnv->GetLanguage(); + CFX_WideString language = pFormFillEnv->GetLanguage(); if (!language.IsEmpty()) { vp << language; return TRUE; @@ -393,8 +382,8 @@ FX_BOOL app::alert(IJS_Context* cc, return FALSE; } - CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); - if (!pEnv) { + CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); + if (!pFormFillEnv) { vRet = CJS_Value(pRuntime, 0); return TRUE; } @@ -434,10 +423,10 @@ FX_BOOL app::alert(IJS_Context* cc, swTitle = JSGetStringFromID(IDS_STRING_JSALERT); pRuntime->BeginBlock(); - pEnv->GetSDKDocument()->KillFocusAnnot(0); + pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); - vRet = CJS_Value(pRuntime, pEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), - iType, iIcon)); + vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert( + swMsg.c_str(), swTitle.c_str(), iType, iIcon)); pRuntime->EndBlock(); return TRUE; } @@ -448,8 +437,7 @@ FX_BOOL app::beep(IJS_Context* cc, CFX_WideString& sError) { if (params.size() == 1) { CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); - pEnv->JS_appBeep(params[0].ToInt(pRuntime)); + pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); return TRUE; } @@ -493,10 +481,9 @@ FX_BOOL app::setInterval(IJS_Context* cc, } uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; - CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); - GlobalTimer* timerRef = - new GlobalTimer(this, pEnv, pRuntime, 0, script, dwInterval, 0); + GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), + pRuntime, 0, script, dwInterval, 0); m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); v8::Local<v8::Object> pRetObj = @@ -527,10 +514,9 @@ FX_BOOL app::setTimeOut(IJS_Context* cc, } uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; - CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); - GlobalTimer* timerRef = - new GlobalTimer(this, pEnv, pRuntime, 1, script, dwTimeOut, dwTimeOut); + new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, + dwTimeOut, dwTimeOut); m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); v8::Local<v8::Object> pRetObj = diff --git a/fpdfsdk/javascript/cjs_context.cpp b/fpdfsdk/javascript/cjs_context.cpp index d50bc1dd16..0a34b353b5 100644 --- a/fpdfsdk/javascript/cjs_context.cpp +++ b/fpdfsdk/javascript/cjs_context.cpp @@ -18,7 +18,7 @@ CJS_Context::CJS_Context(CJS_Runtime* pRuntime) CJS_Context::~CJS_Context() {} CPDFSDK_FormFillEnvironment* CJS_Context::GetFormFillEnv() { - return m_pRuntime->GetReaderEnv(); + return m_pRuntime->GetFormFillEnv(); } FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index af70dd17cc..d41726b315 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -47,8 +47,8 @@ void IJS_Runtime::Destroy() { } // static -IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pEnv) { - return new CJS_Runtime(pEnv); +IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pFormFillEnv) { + return new CJS_Runtime(pFormFillEnv); } // static @@ -63,14 +63,13 @@ CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) { CFXJS_Engine::CurrentEngineFromIsolate(pIsolate)); } -CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pEnv) - : m_pEnv(pEnv), - m_pDocument(nullptr), +CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) + : m_pFormFillEnv(pFormFillEnv), m_bBlocking(false), m_isolateManaged(false) { v8::Isolate* pIsolate = nullptr; #ifndef PDF_ENABLE_XFA - IPDF_JSPLATFORM* pPlatform = m_pEnv->GetFormFillInfo()->m_pJsPlatform; + IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; @@ -88,7 +87,8 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pEnv) pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime(); SetIsolate(pIsolate); } else { - IPDF_JSPLATFORM* pPlatform = m_pEnv->GetFormFillInfo()->m_pJsPlatform; + IPDF_JSPLATFORM* pPlatform = + m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; @@ -122,6 +122,8 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pEnv) CJS_Context* pContext = (CJS_Context*)NewContext(); InitializeEngine(); ReleaseContext(pContext); + + SetFormFillEnvToDocument(); } CJS_Runtime::~CJS_Runtime() { @@ -199,19 +201,12 @@ IJS_Context* CJS_Runtime::GetCurrentContext() { return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get(); } -void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { - if (m_pDocument == pReaderDoc) - return; - +void CJS_Runtime::SetFormFillEnvToDocument() { v8::Isolate::Scope isolate_scope(GetIsolate()); v8::HandleScope handle_scope(GetIsolate()); v8::Local<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - m_pDocument = pReaderDoc; - if (!pReaderDoc) - return; - v8::Local<v8::Object> pThis = GetThisObj(); if (pThis.IsEmpty()) return; @@ -228,11 +223,11 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { if (!pDocument) return; - pDocument->AttachDoc(pReaderDoc); + pDocument->SetFormFillEnv(m_pFormFillEnv); } -CPDFSDK_Document* CJS_Runtime::GetReaderDocument() { - return m_pDocument; +CPDFSDK_FormFillEnvironment* CJS_Runtime::GetFormFillEnv() const { + return m_pFormFillEnv; } int CJS_Runtime::ExecuteScript(const CFX_WideString& script, diff --git a/fpdfsdk/javascript/cjs_runtime.h b/fpdfsdk/javascript/cjs_runtime.h index 2b075afa01..1b004ded89 100644 --- a/fpdfsdk/javascript/cjs_runtime.h +++ b/fpdfsdk/javascript/cjs_runtime.h @@ -30,20 +30,19 @@ class CJS_Runtime : public IJS_Runtime, static CJS_Runtime* FromContext(const IJS_Context* cc); static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); - explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pApp); + explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv); ~CJS_Runtime() override; // IJS_Runtime IJS_Context* NewContext() override; void ReleaseContext(IJS_Context* pContext) override; IJS_Context* GetCurrentContext() override; - void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; - CPDFSDK_Document* GetReaderDocument() override; + + CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override; + int ExecuteScript(const CFX_WideString& script, CFX_WideString* info) override; - CPDFSDK_FormFillEnvironment* GetReaderEnv() const { return m_pEnv; } - // Returns true if the event isn't already found in the set. bool AddEventToSet(const FieldEvent& event); void RemoveEventFromSet(const FieldEvent& event); @@ -61,10 +60,10 @@ class CJS_Runtime : public IJS_Runtime, private: void DefineJSObjects(); + void SetFormFillEnvToDocument(); std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; - CPDFSDK_FormFillEnvironment* const m_pEnv; - CPDFSDK_Document* m_pDocument; + CPDFSDK_FormFillEnvironment* const m_pFormFillEnv; bool m_bBlocking; bool m_isolateManaged; std::set<FieldEvent> m_FieldEventSet; diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 78da7038b8..3ac8c40384 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -33,7 +33,7 @@ void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) { CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); JSGlobalAlternate* pGlobal = static_cast<JSGlobalAlternate*>(GetEmbedObject()); - pGlobal->Initial(pRuntime->GetReaderEnv()); + pGlobal->Initial(pRuntime->GetFormFillEnv()); } JSGlobalData::JSGlobalData() diff --git a/fpdfsdk/javascript/ijs_runtime.h b/fpdfsdk/javascript/ijs_runtime.h index e656545b56..c14ed7e623 100644 --- a/fpdfsdk/javascript/ijs_runtime.h +++ b/fpdfsdk/javascript/ijs_runtime.h @@ -15,7 +15,6 @@ #endif // PDF_ENABLE_XFA class CPDFSDK_FormFillEnvironment; -class CPDFSDK_Document; class IJS_Context; // Owns the FJXS objects needed to actually execute JS. @@ -23,14 +22,15 @@ class IJS_Runtime { public: static void Initialize(unsigned int slot, void* isolate); static void Destroy(); - static IJS_Runtime* Create(CPDFSDK_FormFillEnvironment* pEnv); + static IJS_Runtime* Create(CPDFSDK_FormFillEnvironment* pFormFillEnv); virtual ~IJS_Runtime() {} virtual IJS_Context* NewContext() = 0; virtual void ReleaseContext(IJS_Context* pContext) = 0; virtual IJS_Context* GetCurrentContext() = 0; - virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0; - virtual CPDFSDK_Document* GetReaderDocument() = 0; + + virtual CPDFSDK_FormFillEnvironment* GetFormFillEnv() const = 0; + virtual int ExecuteScript(const CFX_WideString& script, CFX_WideString* info) = 0; |