| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "core/fpdfapi/font/cpdf_font.h" | 12 #include "core/fpdfapi/font/cpdf_font.h" |
| 13 #include "core/fpdfapi/page/cpdf_page.h" | 13 #include "core/fpdfapi/page/cpdf_page.h" |
| 14 #include "core/fpdfapi/parser/cpdf_array.h" | 14 #include "core/fpdfapi/parser/cpdf_array.h" |
| 15 #include "core/fpdfapi/parser/cpdf_document.h" | 15 #include "core/fpdfapi/parser/cpdf_document.h" |
| 16 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 16 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 17 #include "core/fpdfdoc/cpdf_interform.h" | 17 #include "core/fpdfdoc/cpdf_interform.h" |
| 18 #include "core/fpdfdoc/cpdf_nametree.h" | 18 #include "core/fpdfdoc/cpdf_nametree.h" |
| 19 #include "fpdfsdk/cpdfsdk_annotiterator.h" | 19 #include "fpdfsdk/cpdfsdk_annotiterator.h" |
| 20 #include "fpdfsdk/cpdfsdk_document.h" | |
| 21 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 20 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 22 #include "fpdfsdk/cpdfsdk_interform.h" | 21 #include "fpdfsdk/cpdfsdk_interform.h" |
| 23 #include "fpdfsdk/cpdfsdk_pageview.h" | 22 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 24 #include "fpdfsdk/cpdfsdk_widget.h" | 23 #include "fpdfsdk/cpdfsdk_widget.h" |
| 25 #include "fpdfsdk/javascript/Annot.h" | 24 #include "fpdfsdk/javascript/Annot.h" |
| 26 #include "fpdfsdk/javascript/Field.h" | 25 #include "fpdfsdk/javascript/Field.h" |
| 27 #include "fpdfsdk/javascript/Icon.h" | 26 #include "fpdfsdk/javascript/Icon.h" |
| 28 #include "fpdfsdk/javascript/JS_Define.h" | 27 #include "fpdfsdk/javascript/JS_Define.h" |
| 29 #include "fpdfsdk/javascript/JS_EventHandler.h" | 28 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 30 #include "fpdfsdk/javascript/JS_Object.h" | 29 #include "fpdfsdk/javascript/JS_Object.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 CJS_PropValue& vp, | 165 CJS_PropValue& vp, |
| 167 CFX_WideString& sError) { | 166 CFX_WideString& sError) { |
| 168 if (vp.IsSetting()) { | 167 if (vp.IsSetting()) { |
| 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 168 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 170 return FALSE; | 169 return FALSE; |
| 171 } | 170 } |
| 172 if (!m_pFormFillEnv) { | 171 if (!m_pFormFillEnv) { |
| 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 172 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 174 return FALSE; | 173 return FALSE; |
| 175 } | 174 } |
| 176 CPDFSDK_InterForm* pInterForm = | 175 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 177 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 178 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 176 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 179 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); | 177 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); |
| 180 return TRUE; | 178 return TRUE; |
| 181 } | 179 } |
| 182 | 180 |
| 183 FX_BOOL Document::dirty(IJS_Context* cc, | 181 FX_BOOL Document::dirty(IJS_Context* cc, |
| 184 CJS_PropValue& vp, | 182 CJS_PropValue& vp, |
| 185 CFX_WideString& sError) { | 183 CFX_WideString& sError) { |
| 186 if (!m_pFormFillEnv) { | 184 if (!m_pFormFillEnv) { |
| 187 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 185 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 188 return FALSE; | 186 return FALSE; |
| 189 } | 187 } |
| 190 if (vp.IsGetting()) { | 188 if (vp.IsGetting()) { |
| 191 vp << !!m_pFormFillEnv->GetSDKDocument()->GetChangeMark(); | 189 vp << !!m_pFormFillEnv->GetChangeMark(); |
| 192 } else { | 190 } else { |
| 193 bool bChanged = false; | 191 bool bChanged = false; |
| 194 vp >> bChanged; | 192 vp >> bChanged; |
| 195 | 193 |
| 196 if (bChanged) | 194 if (bChanged) |
| 197 m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 195 m_pFormFillEnv->SetChangeMark(); |
| 198 else | 196 else |
| 199 m_pFormFillEnv->GetSDKDocument()->ClearChangeMark(); | 197 m_pFormFillEnv->ClearChangeMark(); |
| 200 } | 198 } |
| 201 return TRUE; | 199 return TRUE; |
| 202 } | 200 } |
| 203 | 201 |
| 204 FX_BOOL Document::ADBE(IJS_Context* cc, | 202 FX_BOOL Document::ADBE(IJS_Context* cc, |
| 205 CJS_PropValue& vp, | 203 CJS_PropValue& vp, |
| 206 CFX_WideString& sError) { | 204 CFX_WideString& sError) { |
| 207 if (vp.IsGetting()) | 205 if (vp.IsGetting()) |
| 208 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); | 206 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); |
| 209 | 207 |
| 210 return TRUE; | 208 return TRUE; |
| 211 } | 209 } |
| 212 | 210 |
| 213 FX_BOOL Document::pageNum(IJS_Context* cc, | 211 FX_BOOL Document::pageNum(IJS_Context* cc, |
| 214 CJS_PropValue& vp, | 212 CJS_PropValue& vp, |
| 215 CFX_WideString& sError) { | 213 CFX_WideString& sError) { |
| 216 if (!m_pFormFillEnv) { | 214 if (!m_pFormFillEnv) { |
| 217 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 215 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 218 return FALSE; | 216 return FALSE; |
| 219 } | 217 } |
| 220 if (vp.IsGetting()) { | 218 if (vp.IsGetting()) { |
| 221 if (CPDFSDK_PageView* pPageView = | 219 if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { |
| 222 m_pFormFillEnv->GetSDKDocument()->GetCurrentView()) { | |
| 223 vp << pPageView->GetPageIndex(); | 220 vp << pPageView->GetPageIndex(); |
| 224 } | 221 } |
| 225 } else { | 222 } else { |
| 226 int iPageCount = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); | 223 int iPageCount = m_pFormFillEnv->GetPageCount(); |
| 227 int iPageNum = 0; | 224 int iPageNum = 0; |
| 228 vp >> iPageNum; | 225 vp >> iPageNum; |
| 229 | 226 |
| 230 if (iPageNum >= 0 && iPageNum < iPageCount) { | 227 if (iPageNum >= 0 && iPageNum < iPageCount) { |
| 231 m_pFormFillEnv->JS_docgotoPage(iPageNum); | 228 m_pFormFillEnv->JS_docgotoPage(iPageNum); |
| 232 } else if (iPageNum >= iPageCount) { | 229 } else if (iPageNum >= iPageCount) { |
| 233 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); | 230 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); |
| 234 } else if (iPageNum < 0) { | 231 } else if (iPageNum < 0) { |
| 235 m_pFormFillEnv->JS_docgotoPage(0); | 232 m_pFormFillEnv->JS_docgotoPage(0); |
| 236 } | 233 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 289 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 293 return FALSE; | 290 return FALSE; |
| 294 } | 291 } |
| 295 if (!m_pFormFillEnv) { | 292 if (!m_pFormFillEnv) { |
| 296 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 293 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 297 return FALSE; | 294 return FALSE; |
| 298 } | 295 } |
| 299 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 296 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 300 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 297 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 301 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 298 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 302 CPDFSDK_InterForm* pInterForm = | 299 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 303 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 304 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 300 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 305 if (pPDFForm->CountFields(wideName) <= 0) { | 301 if (pPDFForm->CountFields(wideName) <= 0) { |
| 306 vRet.SetNull(pRuntime); | 302 vRet.SetNull(pRuntime); |
| 307 return TRUE; | 303 return TRUE; |
| 308 } | 304 } |
| 309 | 305 |
| 310 v8::Local<v8::Object> pFieldObj = | 306 v8::Local<v8::Object> pFieldObj = |
| 311 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); | 307 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
| 312 CJS_Field* pJSField = | 308 CJS_Field* pJSField = |
| 313 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); | 309 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 331 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 327 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 332 return FALSE; | 328 return FALSE; |
| 333 } | 329 } |
| 334 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 330 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 335 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 331 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 336 int nIndex = params[0].ToInt(pRuntime); | 332 int nIndex = params[0].ToInt(pRuntime); |
| 337 if (nIndex < 0) { | 333 if (nIndex < 0) { |
| 338 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 334 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 339 return FALSE; | 335 return FALSE; |
| 340 } | 336 } |
| 341 CPDFSDK_InterForm* pInterForm = | 337 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 342 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 343 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 338 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 344 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); | 339 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); |
| 345 if (!pField) | 340 if (!pField) |
| 346 return FALSE; | 341 return FALSE; |
| 347 | 342 |
| 348 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); | 343 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
| 349 return TRUE; | 344 return TRUE; |
| 350 } | 345 } |
| 351 | 346 |
| 352 FX_BOOL Document::importAnFDF(IJS_Context* cc, | 347 FX_BOOL Document::importAnFDF(IJS_Context* cc, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 377 // all recipients. | 372 // all recipients. |
| 378 // comment: need reader supports | 373 // comment: need reader supports |
| 379 FX_BOOL Document::mailForm(IJS_Context* cc, | 374 FX_BOOL Document::mailForm(IJS_Context* cc, |
| 380 const std::vector<CJS_Value>& params, | 375 const std::vector<CJS_Value>& params, |
| 381 CJS_Value& vRet, | 376 CJS_Value& vRet, |
| 382 CFX_WideString& sError) { | 377 CFX_WideString& sError) { |
| 383 if (!m_pFormFillEnv) { | 378 if (!m_pFormFillEnv) { |
| 384 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 379 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 385 return FALSE; | 380 return FALSE; |
| 386 } | 381 } |
| 387 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( | 382 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 388 FPDFPERM_EXTRACT_ACCESS)) { | |
| 389 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 383 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 390 return FALSE; | 384 return FALSE; |
| 391 } | 385 } |
| 392 | 386 |
| 393 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 387 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 394 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 388 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 395 | 389 |
| 396 int iLength = params.size(); | 390 int iLength = params.size(); |
| 397 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; | 391 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; |
| 398 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; | 392 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 399 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; | 393 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 400 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; | 394 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
| 401 CFX_WideString cSubject = | 395 CFX_WideString cSubject = |
| 402 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; | 396 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 403 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; | 397 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
| 404 | 398 |
| 405 CPDFSDK_InterForm* pInterForm = | 399 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 406 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 407 CFX_ByteTextBuf textBuf; | 400 CFX_ByteTextBuf textBuf; |
| 408 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | 401 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 409 return FALSE; | 402 return FALSE; |
| 410 | 403 |
| 411 pRuntime->BeginBlock(); | 404 pRuntime->BeginBlock(); |
| 412 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetFormFillEnv(); | 405 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetFormFillEnv(); |
| 413 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | 406 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 414 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), | 407 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 415 cMsg.c_str()); | 408 cMsg.c_str()); |
| 416 pRuntime->EndBlock(); | 409 pRuntime->EndBlock(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 CJS_Value& vRet, | 488 CJS_Value& vRet, |
| 496 CFX_WideString& sError) { | 489 CFX_WideString& sError) { |
| 497 if (params.size() != 1) { | 490 if (params.size() != 1) { |
| 498 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 491 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 499 return FALSE; | 492 return FALSE; |
| 500 } | 493 } |
| 501 if (!m_pFormFillEnv) { | 494 if (!m_pFormFillEnv) { |
| 502 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 495 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 503 return FALSE; | 496 return FALSE; |
| 504 } | 497 } |
| 505 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || | 498 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 506 m_pFormFillEnv->GetSDKDocument()->GetPermissions( | 499 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
| 507 FPDFPERM_ANNOT_FORM))) { | |
| 508 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 500 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 509 return FALSE; | 501 return FALSE; |
| 510 } | 502 } |
| 511 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 503 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 512 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 504 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 513 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); | 505 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
| 514 CPDFSDK_InterForm* pInterForm = | 506 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 515 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 516 std::vector<CPDFSDK_Widget*> widgets; | 507 std::vector<CPDFSDK_Widget*> widgets; |
| 517 pInterForm->GetWidgets(sFieldName, &widgets); | 508 pInterForm->GetWidgets(sFieldName, &widgets); |
| 518 if (widgets.empty()) | 509 if (widgets.empty()) |
| 519 return TRUE; | 510 return TRUE; |
| 520 | 511 |
| 521 for (CPDFSDK_Widget* pWidget : widgets) { | 512 for (CPDFSDK_Widget* pWidget : widgets) { |
| 522 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 513 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
| 523 --rcAnnot.left; | 514 --rcAnnot.left; |
| 524 --rcAnnot.bottom; | 515 --rcAnnot.bottom; |
| 525 ++rcAnnot.right; | 516 ++rcAnnot.right; |
| 526 ++rcAnnot.top; | 517 ++rcAnnot.top; |
| 527 | 518 |
| 528 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); | 519 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); |
| 529 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 520 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
| 530 ASSERT(pPage); | 521 ASSERT(pPage); |
| 531 | 522 |
| 532 // If there is currently no pageview associated with the page being used | 523 // If there is currently no pageview associated with the page being used |
| 533 // do not create one. We may be in the process of tearing down the document | 524 // do not create one. We may be in the process of tearing down the document |
| 534 // and creating a new pageview at this point will cause bad things. | 525 // and creating a new pageview at this point will cause bad things. |
| 535 CPDFSDK_PageView* pPageView = | 526 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); |
| 536 m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); | |
| 537 if (pPageView) { | 527 if (pPageView) { |
| 538 #if PDF_ENABLE_XFA | 528 #if PDF_ENABLE_XFA |
| 539 pPageView->DeleteAnnot(pWidget); | 529 pPageView->DeleteAnnot(pWidget); |
| 540 #endif // PDF_ENABLE_XFA | 530 #endif // PDF_ENABLE_XFA |
| 541 pPageView->UpdateRects(aRefresh); | 531 pPageView->UpdateRects(aRefresh); |
| 542 } | 532 } |
| 543 } | 533 } |
| 544 m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 534 m_pFormFillEnv->SetChangeMark(); |
| 545 | 535 |
| 546 return TRUE; | 536 return TRUE; |
| 547 } | 537 } |
| 548 | 538 |
| 549 // reset filed values within a document. | 539 // reset filed values within a document. |
| 550 // comment: | 540 // comment: |
| 551 // note: if the fields names r not rational, aodbe is dumb for it. | 541 // note: if the fields names r not rational, aodbe is dumb for it. |
| 552 | 542 |
| 553 FX_BOOL Document::resetForm(IJS_Context* cc, | 543 FX_BOOL Document::resetForm(IJS_Context* cc, |
| 554 const std::vector<CJS_Value>& params, | 544 const std::vector<CJS_Value>& params, |
| 555 CJS_Value& vRet, | 545 CJS_Value& vRet, |
| 556 CFX_WideString& sError) { | 546 CFX_WideString& sError) { |
| 557 if (!m_pFormFillEnv) { | 547 if (!m_pFormFillEnv) { |
| 558 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 548 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 559 return FALSE; | 549 return FALSE; |
| 560 } | 550 } |
| 561 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || | 551 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 562 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || | 552 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 563 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { | 553 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 564 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 554 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 565 return FALSE; | 555 return FALSE; |
| 566 } | 556 } |
| 567 | 557 |
| 568 CPDFSDK_InterForm* pInterForm = | 558 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 569 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 570 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 559 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 571 CJS_Array aName; | 560 CJS_Array aName; |
| 572 | 561 |
| 573 if (params.empty()) { | 562 if (params.empty()) { |
| 574 pPDFForm->ResetForm(TRUE); | 563 pPDFForm->ResetForm(TRUE); |
| 575 m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 564 m_pFormFillEnv->SetChangeMark(); |
| 576 return TRUE; | 565 return TRUE; |
| 577 } | 566 } |
| 578 | 567 |
| 579 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 568 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 580 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 569 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 581 | 570 |
| 582 switch (params[0].GetType()) { | 571 switch (params[0].GetType()) { |
| 583 default: | 572 default: |
| 584 aName.Attach(params[0].ToV8Array(pRuntime)); | 573 aName.Attach(params[0].ToV8Array(pRuntime)); |
| 585 break; | 574 break; |
| 586 case CJS_Value::VT_string: | 575 case CJS_Value::VT_string: |
| 587 aName.SetElement(pRuntime, 0, params[0]); | 576 aName.SetElement(pRuntime, 0, params[0]); |
| 588 break; | 577 break; |
| 589 } | 578 } |
| 590 | 579 |
| 591 std::vector<CPDF_FormField*> aFields; | 580 std::vector<CPDF_FormField*> aFields; |
| 592 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { | 581 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { |
| 593 CJS_Value valElement(pRuntime); | 582 CJS_Value valElement(pRuntime); |
| 594 aName.GetElement(pRuntime, i, valElement); | 583 aName.GetElement(pRuntime, i, valElement); |
| 595 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); | 584 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); |
| 596 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) | 585 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 597 aFields.push_back(pPDFForm->GetField(j, swVal)); | 586 aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 598 } | 587 } |
| 599 | 588 |
| 600 if (!aFields.empty()) { | 589 if (!aFields.empty()) { |
| 601 pPDFForm->ResetForm(aFields, TRUE, TRUE); | 590 pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 602 m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 591 m_pFormFillEnv->SetChangeMark(); |
| 603 } | 592 } |
| 604 | 593 |
| 605 return TRUE; | 594 return TRUE; |
| 606 } | 595 } |
| 607 | 596 |
| 608 FX_BOOL Document::saveAs(IJS_Context* cc, | 597 FX_BOOL Document::saveAs(IJS_Context* cc, |
| 609 const std::vector<CJS_Value>& params, | 598 const std::vector<CJS_Value>& params, |
| 610 CJS_Value& vRet, | 599 CJS_Value& vRet, |
| 611 CFX_WideString& sError) { | 600 CFX_WideString& sError) { |
| 612 // Unsafe, not supported. | 601 // Unsafe, not supported. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); | 646 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); |
| 658 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); | 647 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 659 | 648 |
| 660 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); | 649 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); |
| 661 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); | 650 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 662 | 651 |
| 663 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); | 652 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); |
| 664 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); | 653 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); |
| 665 } | 654 } |
| 666 | 655 |
| 667 CPDFSDK_InterForm* pInterForm = | 656 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 668 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 669 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 657 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 670 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { | 658 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { |
| 671 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | 659 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 672 pRuntime->BeginBlock(); | 660 pRuntime->BeginBlock(); |
| 673 pInterForm->SubmitForm(strURL, FALSE); | 661 pInterForm->SubmitForm(strURL, FALSE); |
| 674 pRuntime->EndBlock(); | 662 pRuntime->EndBlock(); |
| 675 } | 663 } |
| 676 return TRUE; | 664 return TRUE; |
| 677 } | 665 } |
| 678 | 666 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 CJS_PropValue& vp, | 769 CJS_PropValue& vp, |
| 782 CFX_WideString& sError) { | 770 CFX_WideString& sError) { |
| 783 if (vp.IsSetting()) { | 771 if (vp.IsSetting()) { |
| 784 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 772 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 785 return FALSE; | 773 return FALSE; |
| 786 } | 774 } |
| 787 if (!m_pFormFillEnv) { | 775 if (!m_pFormFillEnv) { |
| 788 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 776 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 789 return FALSE; | 777 return FALSE; |
| 790 } | 778 } |
| 791 CPDF_Dictionary* pDictionary = | 779 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
| 792 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); | |
| 793 if (!pDictionary) | 780 if (!pDictionary) |
| 794 return FALSE; | 781 return FALSE; |
| 795 | 782 |
| 796 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); | 783 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); |
| 797 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); | 784 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); |
| 798 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); | 785 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); |
| 799 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); | 786 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); |
| 800 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); | 787 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); |
| 801 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); | 788 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); |
| 802 CFX_WideString cwCreationDate = | 789 CFX_WideString cwCreationDate = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 } | 823 } |
| 837 | 824 |
| 838 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, | 825 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, |
| 839 CJS_PropValue& vp, | 826 CJS_PropValue& vp, |
| 840 const CFX_ByteString& propName, | 827 const CFX_ByteString& propName, |
| 841 CFX_WideString& sError) { | 828 CFX_WideString& sError) { |
| 842 if (!m_pFormFillEnv) { | 829 if (!m_pFormFillEnv) { |
| 843 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 830 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 844 return FALSE; | 831 return FALSE; |
| 845 } | 832 } |
| 846 CPDF_Dictionary* pDictionary = | 833 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
| 847 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); | |
| 848 if (!pDictionary) | 834 if (!pDictionary) |
| 849 return FALSE; | 835 return FALSE; |
| 850 | 836 |
| 851 if (vp.IsGetting()) { | 837 if (vp.IsGetting()) { |
| 852 vp << pDictionary->GetUnicodeTextFor(propName); | 838 vp << pDictionary->GetUnicodeTextFor(propName); |
| 853 } else { | 839 } else { |
| 854 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { | 840 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
| 855 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 841 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 856 return FALSE; | 842 return FALSE; |
| 857 } | 843 } |
| 858 CFX_WideString csProperty; | 844 CFX_WideString csProperty; |
| 859 vp >> csProperty; | 845 vp >> csProperty; |
| 860 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); | 846 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); |
| 861 m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 847 m_pFormFillEnv->SetChangeMark(); |
| 862 } | 848 } |
| 863 return TRUE; | 849 return TRUE; |
| 864 } | 850 } |
| 865 | 851 |
| 866 FX_BOOL Document::creationDate(IJS_Context* cc, | 852 FX_BOOL Document::creationDate(IJS_Context* cc, |
| 867 CJS_PropValue& vp, | 853 CJS_PropValue& vp, |
| 868 CFX_WideString& sError) { | 854 CFX_WideString& sError) { |
| 869 return getPropertyInternal(cc, vp, "CreationDate", sError); | 855 return getPropertyInternal(cc, vp, "CreationDate", sError); |
| 870 } | 856 } |
| 871 | 857 |
| 872 FX_BOOL Document::creator(IJS_Context* cc, | 858 FX_BOOL Document::creator(IJS_Context* cc, |
| 873 CJS_PropValue& vp, | 859 CJS_PropValue& vp, |
| 874 CFX_WideString& sError) { | 860 CFX_WideString& sError) { |
| 875 return getPropertyInternal(cc, vp, "Creator", sError); | 861 return getPropertyInternal(cc, vp, "Creator", sError); |
| 876 } | 862 } |
| 877 | 863 |
| 878 FX_BOOL Document::delay(IJS_Context* cc, | 864 FX_BOOL Document::delay(IJS_Context* cc, |
| 879 CJS_PropValue& vp, | 865 CJS_PropValue& vp, |
| 880 CFX_WideString& sError) { | 866 CFX_WideString& sError) { |
| 881 if (!m_pFormFillEnv) { | 867 if (!m_pFormFillEnv) { |
| 882 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 868 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 883 return FALSE; | 869 return FALSE; |
| 884 } | 870 } |
| 885 if (vp.IsGetting()) { | 871 if (vp.IsGetting()) { |
| 886 vp << m_bDelay; | 872 vp << m_bDelay; |
| 887 } else { | 873 } else { |
| 888 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { | 874 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
| 889 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 875 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 890 return FALSE; | 876 return FALSE; |
| 891 } | 877 } |
| 892 vp >> m_bDelay; | 878 vp >> m_bDelay; |
| 893 if (m_bDelay) { | 879 if (m_bDelay) { |
| 894 m_DelayData.clear(); | 880 m_DelayData.clear(); |
| 895 } else { | 881 } else { |
| 896 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; | 882 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
| 897 DelayDataToProcess.swap(m_DelayData); | 883 DelayDataToProcess.swap(m_DelayData); |
| 898 for (const auto& pData : DelayDataToProcess) | 884 for (const auto& pData : DelayDataToProcess) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 CJS_PropValue& vp, | 926 CJS_PropValue& vp, |
| 941 CFX_WideString& sError) { | 927 CFX_WideString& sError) { |
| 942 if (vp.IsSetting()) { | 928 if (vp.IsSetting()) { |
| 943 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 929 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 944 return FALSE; | 930 return FALSE; |
| 945 } | 931 } |
| 946 if (!m_pFormFillEnv) { | 932 if (!m_pFormFillEnv) { |
| 947 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 933 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 948 return FALSE; | 934 return FALSE; |
| 949 } | 935 } |
| 950 vp << m_pFormFillEnv->GetSDKDocument()->GetPageCount(); | 936 vp << m_pFormFillEnv->GetPageCount(); |
| 951 return TRUE; | 937 return TRUE; |
| 952 } | 938 } |
| 953 | 939 |
| 954 FX_BOOL Document::external(IJS_Context* cc, | 940 FX_BOOL Document::external(IJS_Context* cc, |
| 955 CJS_PropValue& vp, | 941 CJS_PropValue& vp, |
| 956 CFX_WideString& sError) { | 942 CFX_WideString& sError) { |
| 957 // In Chrome case, should always return true. | 943 // In Chrome case, should always return true. |
| 958 if (vp.IsGetting()) { | 944 if (vp.IsGetting()) { |
| 959 vp << true; | 945 vp << true; |
| 960 } | 946 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 988 CJS_PropValue& vp, | 974 CJS_PropValue& vp, |
| 989 CFX_WideString& sError) { | 975 CFX_WideString& sError) { |
| 990 if (vp.IsSetting()) { | 976 if (vp.IsSetting()) { |
| 991 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 977 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 992 return FALSE; | 978 return FALSE; |
| 993 } | 979 } |
| 994 if (!m_pFormFillEnv) { | 980 if (!m_pFormFillEnv) { |
| 995 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 981 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 996 return FALSE; | 982 return FALSE; |
| 997 } | 983 } |
| 998 vp << m_pFormFillEnv->GetSDKDocument()->GetPath(); | 984 vp << m_pFormFillEnv->JS_docGetFilePath(); |
| 999 return TRUE; | 985 return TRUE; |
| 1000 } | 986 } |
| 1001 | 987 |
| 1002 FX_BOOL Document::baseURL(IJS_Context* cc, | 988 FX_BOOL Document::baseURL(IJS_Context* cc, |
| 1003 CJS_PropValue& vp, | 989 CJS_PropValue& vp, |
| 1004 CFX_WideString& sError) { | 990 CFX_WideString& sError) { |
| 1005 if (vp.IsGetting()) { | 991 if (vp.IsGetting()) { |
| 1006 vp << m_cwBaseURL; | 992 vp << m_cwBaseURL; |
| 1007 } else { | 993 } else { |
| 1008 vp >> m_cwBaseURL; | 994 vp >> m_cwBaseURL; |
| 1009 } | 995 } |
| 1010 return TRUE; | 996 return TRUE; |
| 1011 } | 997 } |
| 1012 | 998 |
| 1013 FX_BOOL Document::calculate(IJS_Context* cc, | 999 FX_BOOL Document::calculate(IJS_Context* cc, |
| 1014 CJS_PropValue& vp, | 1000 CJS_PropValue& vp, |
| 1015 CFX_WideString& sError) { | 1001 CFX_WideString& sError) { |
| 1016 if (!m_pFormFillEnv) { | 1002 if (!m_pFormFillEnv) { |
| 1017 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1003 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1018 return FALSE; | 1004 return FALSE; |
| 1019 } | 1005 } |
| 1020 CPDFSDK_InterForm* pInterForm = | 1006 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1021 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1022 if (vp.IsGetting()) { | 1007 if (vp.IsGetting()) { |
| 1023 vp << !!pInterForm->IsCalculateEnabled(); | 1008 vp << !!pInterForm->IsCalculateEnabled(); |
| 1024 } else { | 1009 } else { |
| 1025 bool bCalculate; | 1010 bool bCalculate; |
| 1026 vp >> bCalculate; | 1011 vp >> bCalculate; |
| 1027 pInterForm->EnableCalculate(bCalculate); | 1012 pInterForm->EnableCalculate(bCalculate); |
| 1028 } | 1013 } |
| 1029 return TRUE; | 1014 return TRUE; |
| 1030 } | 1015 } |
| 1031 | 1016 |
| 1032 FX_BOOL Document::documentFileName(IJS_Context* cc, | 1017 FX_BOOL Document::documentFileName(IJS_Context* cc, |
| 1033 CJS_PropValue& vp, | 1018 CJS_PropValue& vp, |
| 1034 CFX_WideString& sError) { | 1019 CFX_WideString& sError) { |
| 1035 if (vp.IsSetting()) { | 1020 if (vp.IsSetting()) { |
| 1036 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1021 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 1037 return FALSE; | 1022 return FALSE; |
| 1038 } | 1023 } |
| 1039 if (!m_pFormFillEnv) { | 1024 if (!m_pFormFillEnv) { |
| 1040 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1025 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1041 return FALSE; | 1026 return FALSE; |
| 1042 } | 1027 } |
| 1043 CFX_WideString wsFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); | 1028 CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
| 1044 int32_t i = wsFilePath.GetLength() - 1; | 1029 int32_t i = wsFilePath.GetLength() - 1; |
| 1045 for (; i >= 0; i--) { | 1030 for (; i >= 0; i--) { |
| 1046 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') | 1031 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1047 break; | 1032 break; |
| 1048 } | 1033 } |
| 1049 if (i >= 0 && i < wsFilePath.GetLength() - 1) { | 1034 if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1050 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); | 1035 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1051 } else { | 1036 } else { |
| 1052 vp << L""; | 1037 vp << L""; |
| 1053 } | 1038 } |
| 1054 return TRUE; | 1039 return TRUE; |
| 1055 } | 1040 } |
| 1056 | 1041 |
| 1057 FX_BOOL Document::path(IJS_Context* cc, | 1042 FX_BOOL Document::path(IJS_Context* cc, |
| 1058 CJS_PropValue& vp, | 1043 CJS_PropValue& vp, |
| 1059 CFX_WideString& sError) { | 1044 CFX_WideString& sError) { |
| 1060 if (vp.IsSetting()) { | 1045 if (vp.IsSetting()) { |
| 1061 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1046 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 1062 return FALSE; | 1047 return FALSE; |
| 1063 } | 1048 } |
| 1064 if (!m_pFormFillEnv) { | 1049 if (!m_pFormFillEnv) { |
| 1065 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1050 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1066 return FALSE; | 1051 return FALSE; |
| 1067 } | 1052 } |
| 1068 vp << app::SysPathToPDFPath(m_pFormFillEnv->GetSDKDocument()->GetPath()); | 1053 vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); |
| 1069 return TRUE; | 1054 return TRUE; |
| 1070 } | 1055 } |
| 1071 | 1056 |
| 1072 FX_BOOL Document::pageWindowRect(IJS_Context* cc, | 1057 FX_BOOL Document::pageWindowRect(IJS_Context* cc, |
| 1073 CJS_PropValue& vp, | 1058 CJS_PropValue& vp, |
| 1074 CFX_WideString& sError) { | 1059 CFX_WideString& sError) { |
| 1075 return TRUE; | 1060 return TRUE; |
| 1076 } | 1061 } |
| 1077 | 1062 |
| 1078 FX_BOOL Document::layout(IJS_Context* cc, | 1063 FX_BOOL Document::layout(IJS_Context* cc, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 return FALSE; | 1096 return FALSE; |
| 1112 } | 1097 } |
| 1113 if (!m_pFormFillEnv) { | 1098 if (!m_pFormFillEnv) { |
| 1114 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1099 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1115 return FALSE; | 1100 return FALSE; |
| 1116 } | 1101 } |
| 1117 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1102 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1118 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1103 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1119 int nPageNo = params[0].ToInt(pRuntime); | 1104 int nPageNo = params[0].ToInt(pRuntime); |
| 1120 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); | 1105 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); |
| 1121 CPDFSDK_PageView* pPageView = | 1106 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); |
| 1122 m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageNo); | |
| 1123 if (!pPageView) | 1107 if (!pPageView) |
| 1124 return FALSE; | 1108 return FALSE; |
| 1125 | 1109 |
| 1126 CPDFSDK_AnnotIterator annotIterator(pPageView, false); | 1110 CPDFSDK_AnnotIterator annotIterator(pPageView, false); |
| 1127 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; | 1111 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; |
| 1128 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { | 1112 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { |
| 1129 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); | 1113 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); |
| 1130 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { | 1114 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { |
| 1131 pSDKBAAnnot = pBAAnnot; | 1115 pSDKBAAnnot = pBAAnnot; |
| 1132 break; | 1116 break; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1163 if (!m_pFormFillEnv) { | 1147 if (!m_pFormFillEnv) { |
| 1164 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1148 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1165 return FALSE; | 1149 return FALSE; |
| 1166 } | 1150 } |
| 1167 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1151 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1168 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1152 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1169 | 1153 |
| 1170 // TODO(tonikitoo): Add support supported parameters as per | 1154 // TODO(tonikitoo): Add support supported parameters as per |
| 1171 // the PDF spec. | 1155 // the PDF spec. |
| 1172 | 1156 |
| 1173 int nPageNo = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); | 1157 int nPageNo = m_pFormFillEnv->GetPageCount(); |
| 1174 CJS_Array annots; | 1158 CJS_Array annots; |
| 1175 | 1159 |
| 1176 for (int i = 0; i < nPageNo; ++i) { | 1160 for (int i = 0; i < nPageNo; ++i) { |
| 1177 CPDFSDK_PageView* pPageView = | 1161 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); |
| 1178 m_pFormFillEnv->GetSDKDocument()->GetPageView(i); | |
| 1179 if (!pPageView) | 1162 if (!pPageView) |
| 1180 return FALSE; | 1163 return FALSE; |
| 1181 | 1164 |
| 1182 CPDFSDK_AnnotIterator annotIterator(pPageView, false); | 1165 CPDFSDK_AnnotIterator annotIterator(pPageView, false); |
| 1183 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { | 1166 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { |
| 1184 CPDFSDK_BAAnnot* pSDKBAAnnot = | 1167 CPDFSDK_BAAnnot* pSDKBAAnnot = |
| 1185 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); | 1168 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); |
| 1186 if (!pSDKBAAnnot) | 1169 if (!pSDKBAAnnot) |
| 1187 return FALSE; | 1170 return FALSE; |
| 1188 | 1171 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 } | 1368 } |
| 1386 | 1369 |
| 1387 FX_BOOL Document::calculateNow(IJS_Context* cc, | 1370 FX_BOOL Document::calculateNow(IJS_Context* cc, |
| 1388 const std::vector<CJS_Value>& params, | 1371 const std::vector<CJS_Value>& params, |
| 1389 CJS_Value& vRet, | 1372 CJS_Value& vRet, |
| 1390 CFX_WideString& sError) { | 1373 CFX_WideString& sError) { |
| 1391 if (!m_pFormFillEnv) { | 1374 if (!m_pFormFillEnv) { |
| 1392 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1375 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1393 return FALSE; | 1376 return FALSE; |
| 1394 } | 1377 } |
| 1395 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || | 1378 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 1396 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || | 1379 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1397 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { | 1380 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 1398 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1381 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1399 return FALSE; | 1382 return FALSE; |
| 1400 } | 1383 } |
| 1401 m_pFormFillEnv->GetSDKDocument()->GetInterForm()->OnCalculate(); | 1384 m_pFormFillEnv->GetInterForm()->OnCalculate(); |
| 1402 return TRUE; | 1385 return TRUE; |
| 1403 } | 1386 } |
| 1404 | 1387 |
| 1405 FX_BOOL Document::Collab(IJS_Context* cc, | 1388 FX_BOOL Document::Collab(IJS_Context* cc, |
| 1406 CJS_PropValue& vp, | 1389 CJS_PropValue& vp, |
| 1407 CFX_WideString& sError) { | 1390 CFX_WideString& sError) { |
| 1408 return TRUE; | 1391 return TRUE; |
| 1409 } | 1392 } |
| 1410 | 1393 |
| 1411 FX_BOOL Document::getPageNthWord(IJS_Context* cc, | 1394 FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
| 1412 const std::vector<CJS_Value>& params, | 1395 const std::vector<CJS_Value>& params, |
| 1413 CJS_Value& vRet, | 1396 CJS_Value& vRet, |
| 1414 CFX_WideString& sError) { | 1397 CFX_WideString& sError) { |
| 1415 if (!m_pFormFillEnv) { | 1398 if (!m_pFormFillEnv) { |
| 1416 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1399 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1417 return FALSE; | 1400 return FALSE; |
| 1418 } | 1401 } |
| 1419 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( | 1402 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1420 FPDFPERM_EXTRACT_ACCESS)) { | |
| 1421 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1403 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1422 return FALSE; | 1404 return FALSE; |
| 1423 } | 1405 } |
| 1424 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1406 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1425 | 1407 |
| 1426 // TODO(tsepez): check maximum allowable params. | 1408 // TODO(tsepez): check maximum allowable params. |
| 1427 | 1409 |
| 1428 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1410 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1429 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; | 1411 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1430 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; | 1412 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
| 1431 | 1413 |
| 1432 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 1414 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1433 if (!pDocument) | 1415 if (!pDocument) |
| 1434 return FALSE; | 1416 return FALSE; |
| 1435 | 1417 |
| 1436 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1418 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1437 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 1419 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 1438 return FALSE; | 1420 return FALSE; |
| 1439 } | 1421 } |
| 1440 | 1422 |
| 1441 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1423 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1442 if (!pPageDict) | 1424 if (!pPageDict) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1469 } | 1451 } |
| 1470 | 1452 |
| 1471 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, | 1453 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, |
| 1472 const std::vector<CJS_Value>& params, | 1454 const std::vector<CJS_Value>& params, |
| 1473 CJS_Value& vRet, | 1455 CJS_Value& vRet, |
| 1474 CFX_WideString& sError) { | 1456 CFX_WideString& sError) { |
| 1475 if (!m_pFormFillEnv) { | 1457 if (!m_pFormFillEnv) { |
| 1476 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1458 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1477 return FALSE; | 1459 return FALSE; |
| 1478 } | 1460 } |
| 1479 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( | 1461 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1480 FPDFPERM_EXTRACT_ACCESS)) { | |
| 1481 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1462 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1482 return FALSE; | 1463 return FALSE; |
| 1483 } | 1464 } |
| 1484 return FALSE; | 1465 return FALSE; |
| 1485 } | 1466 } |
| 1486 | 1467 |
| 1487 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | 1468 FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
| 1488 const std::vector<CJS_Value>& params, | 1469 const std::vector<CJS_Value>& params, |
| 1489 CJS_Value& vRet, | 1470 CJS_Value& vRet, |
| 1490 CFX_WideString& sError) { | 1471 CFX_WideString& sError) { |
| 1491 if (!m_pFormFillEnv) { | 1472 if (!m_pFormFillEnv) { |
| 1492 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1473 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1493 return FALSE; | 1474 return FALSE; |
| 1494 } | 1475 } |
| 1495 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( | 1476 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1496 FPDFPERM_EXTRACT_ACCESS)) { | |
| 1497 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1477 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1498 return FALSE; | 1478 return FALSE; |
| 1499 } | 1479 } |
| 1500 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1480 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1501 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1481 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1502 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 1482 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1503 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1483 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1504 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 1484 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 1505 return FALSE; | 1485 return FALSE; |
| 1506 } | 1486 } |
| 1507 | 1487 |
| 1508 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1488 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1509 if (!pPageDict) | 1489 if (!pPageDict) |
| 1510 return FALSE; | 1490 return FALSE; |
| 1511 | 1491 |
| 1512 CPDF_Page page(pDocument, pPageDict, true); | 1492 CPDF_Page page(pDocument, pPageDict, true); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1659 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1680 return FALSE; | 1660 return FALSE; |
| 1681 } | 1661 } |
| 1682 if (!m_pFormFillEnv) { | 1662 if (!m_pFormFillEnv) { |
| 1683 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1663 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1684 return FALSE; | 1664 return FALSE; |
| 1685 } | 1665 } |
| 1686 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1666 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1687 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 1667 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 1688 CFX_ByteString utf8Name = wideName.UTF8Encode(); | 1668 CFX_ByteString utf8Name = wideName.UTF8Encode(); |
| 1689 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 1669 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1690 if (!pDocument) | 1670 if (!pDocument) |
| 1691 return FALSE; | 1671 return FALSE; |
| 1692 | 1672 |
| 1693 CPDF_NameTree nameTree(pDocument, "Dests"); | 1673 CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1694 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); | 1674 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1695 if (!destArray) | 1675 if (!destArray) |
| 1696 return FALSE; | 1676 return FALSE; |
| 1697 | 1677 |
| 1698 CPDF_Dest dest(destArray); | 1678 CPDF_Dest dest(destArray); |
| 1699 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); | 1679 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 } | 1715 } |
| 1736 } | 1716 } |
| 1737 | 1717 |
| 1738 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1718 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1739 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); | 1719 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
| 1740 } | 1720 } |
| 1741 | 1721 |
| 1742 CJS_Document* Document::GetCJSDoc() const { | 1722 CJS_Document* Document::GetCJSDoc() const { |
| 1743 return static_cast<CJS_Document*>(m_pJSObject); | 1723 return static_cast<CJS_Document*>(m_pJSObject); |
| 1744 } | 1724 } |
| OLD | NEW |