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