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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 m_bDelay(FALSE) {} | 156 m_bDelay(FALSE) {} |
157 | 157 |
158 Document::~Document() { | 158 Document::~Document() { |
159 } | 159 } |
160 | 160 |
161 // the total number of fileds in document. | 161 // the total number of fileds in document. |
162 FX_BOOL Document::numFields(IJS_Context* cc, | 162 FX_BOOL Document::numFields(IJS_Context* cc, |
163 CJS_PropValue& vp, | 163 CJS_PropValue& vp, |
164 CFX_WideString& sError) { | 164 CFX_WideString& sError) { |
165 if (vp.IsSetting()) { | 165 if (vp.IsSetting()) { |
166 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 166 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
167 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
168 return FALSE; | 167 return FALSE; |
169 } | 168 } |
170 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 169 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
171 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 170 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
172 vp << (int)pPDFForm->CountFields(); | 171 vp << (int)pPDFForm->CountFields(); |
173 return TRUE; | 172 return TRUE; |
174 } | 173 } |
175 | 174 |
176 FX_BOOL Document::dirty(IJS_Context* cc, | 175 FX_BOOL Document::dirty(IJS_Context* cc, |
177 CJS_PropValue& vp, | 176 CJS_PropValue& vp, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 270 |
272 // Maps a field object in PDF document to a JavaScript variable | 271 // Maps a field object in PDF document to a JavaScript variable |
273 // comment: | 272 // comment: |
274 // note: the paremter cName, this is clue how to treat if the cName is not a | 273 // note: the paremter cName, this is clue how to treat if the cName is not a |
275 // valiable filed name in this document | 274 // valiable filed name in this document |
276 | 275 |
277 FX_BOOL Document::getField(IJS_Context* cc, | 276 FX_BOOL Document::getField(IJS_Context* cc, |
278 const std::vector<CJS_Value>& params, | 277 const std::vector<CJS_Value>& params, |
279 CJS_Value& vRet, | 278 CJS_Value& vRet, |
280 CFX_WideString& sError) { | 279 CFX_WideString& sError) { |
281 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
282 | |
283 if (params.size() < 1) { | 280 if (params.size() < 1) { |
284 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 281 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
285 return FALSE; | 282 return FALSE; |
286 } | 283 } |
287 | 284 |
| 285 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
288 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 286 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
289 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 287 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
290 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 288 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
291 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 289 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
292 if (pPDFForm->CountFields(wideName) <= 0) { | 290 if (pPDFForm->CountFields(wideName) <= 0) { |
293 vRet.SetNull(pRuntime); | 291 vRet.SetNull(pRuntime); |
294 return TRUE; | 292 return TRUE; |
295 } | 293 } |
296 | 294 |
297 v8::Local<v8::Object> pFieldObj = | 295 v8::Local<v8::Object> pFieldObj = |
298 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); | 296 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
299 CJS_Field* pJSField = | 297 CJS_Field* pJSField = |
300 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); | 298 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
301 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); | 299 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
302 pField->AttachField(this, wideName); | 300 pField->AttachField(this, wideName); |
303 | 301 |
304 vRet = CJS_Value(pRuntime, pJSField); | 302 vRet = CJS_Value(pRuntime, pJSField); |
305 return TRUE; | 303 return TRUE; |
306 } | 304 } |
307 | 305 |
308 // Gets the name of the nth field in the document | 306 // Gets the name of the nth field in the document |
309 FX_BOOL Document::getNthFieldName(IJS_Context* cc, | 307 FX_BOOL Document::getNthFieldName(IJS_Context* cc, |
310 const std::vector<CJS_Value>& params, | 308 const std::vector<CJS_Value>& params, |
311 CJS_Value& vRet, | 309 CJS_Value& vRet, |
312 CFX_WideString& sError) { | 310 CFX_WideString& sError) { |
| 311 if (params.size() != 1) { |
| 312 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 313 return FALSE; |
| 314 } |
313 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 315 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
314 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 316 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
315 | 317 int nIndex = params[0].ToInt(pRuntime); |
316 if (params.size() != 1) { | 318 if (nIndex < 0) { |
317 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 319 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
318 return FALSE; | 320 return FALSE; |
319 } | 321 } |
320 int nIndex = params[0].ToInt(pRuntime); | |
321 if (nIndex < 0) { | |
322 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | |
323 return FALSE; | |
324 } | |
325 | |
326 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 322 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
327 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 323 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
328 CPDF_FormField* pField = pPDFForm->GetField(nIndex); | 324 CPDF_FormField* pField = pPDFForm->GetField(nIndex); |
329 if (!pField) | 325 if (!pField) |
330 return FALSE; | 326 return FALSE; |
331 | 327 |
332 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); | 328 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
333 return TRUE; | 329 return TRUE; |
334 } | 330 } |
335 | 331 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 459 |
464 // removes the specified field from the document. | 460 // removes the specified field from the document. |
465 // comment: | 461 // comment: |
466 // note: if the filed name is not rational, adobe is dumb for it. | 462 // note: if the filed name is not rational, adobe is dumb for it. |
467 | 463 |
468 FX_BOOL Document::removeField(IJS_Context* cc, | 464 FX_BOOL Document::removeField(IJS_Context* cc, |
469 const std::vector<CJS_Value>& params, | 465 const std::vector<CJS_Value>& params, |
470 CJS_Value& vRet, | 466 CJS_Value& vRet, |
471 CFX_WideString& sError) { | 467 CFX_WideString& sError) { |
472 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 468 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
473 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) | 469 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
474 return FALSE; | 470 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
475 | |
476 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
477 | |
478 if (params.size() != 1) { | |
479 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
480 return FALSE; | 471 return FALSE; |
481 } | 472 } |
482 | 473 if (params.size() != 1) { |
| 474 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 475 return FALSE; |
| 476 } |
| 477 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
483 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 478 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
484 | |
485 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); | 479 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
486 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 480 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
487 std::vector<CPDFSDK_Widget*> widgets; | 481 std::vector<CPDFSDK_Widget*> widgets; |
488 pInterForm->GetWidgets(sFieldName, &widgets); | 482 pInterForm->GetWidgets(sFieldName, &widgets); |
489 if (widgets.empty()) | 483 if (widgets.empty()) |
490 return TRUE; | 484 return TRUE; |
491 | 485 |
492 for (CPDFSDK_Widget* pWidget : widgets) { | 486 for (CPDFSDK_Widget* pWidget : widgets) { |
493 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 487 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
494 --rcAnnot.left; | 488 --rcAnnot.left; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 const std::vector<CJS_Value>& params, | 573 const std::vector<CJS_Value>& params, |
580 CJS_Value& vRet, | 574 CJS_Value& vRet, |
581 CFX_WideString& sError) { | 575 CFX_WideString& sError) { |
582 return TRUE; | 576 return TRUE; |
583 } | 577 } |
584 | 578 |
585 FX_BOOL Document::submitForm(IJS_Context* cc, | 579 FX_BOOL Document::submitForm(IJS_Context* cc, |
586 const std::vector<CJS_Value>& params, | 580 const std::vector<CJS_Value>& params, |
587 CJS_Value& vRet, | 581 CJS_Value& vRet, |
588 CFX_WideString& sError) { | 582 CFX_WideString& sError) { |
589 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
590 | 583 |
591 int nSize = params.size(); | 584 int nSize = params.size(); |
592 if (nSize < 1) { | 585 if (nSize < 1) { |
593 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 586 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
594 return FALSE; | 587 return FALSE; |
595 } | 588 } |
596 | 589 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 590 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
597 CJS_Array aFields; | 591 CJS_Array aFields; |
598 CFX_WideString strURL; | 592 CFX_WideString strURL; |
599 FX_BOOL bFDF = TRUE; | 593 FX_BOOL bFDF = TRUE; |
600 FX_BOOL bEmpty = FALSE; | 594 FX_BOOL bEmpty = FALSE; |
601 | |
602 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
603 | |
604 CJS_Value v = params[0]; | 595 CJS_Value v = params[0]; |
605 if (v.GetType() == CJS_Value::VT_string) { | 596 if (v.GetType() == CJS_Value::VT_string) { |
606 strURL = params[0].ToCFXWideString(pRuntime); | 597 strURL = params[0].ToCFXWideString(pRuntime); |
607 if (nSize > 1) | 598 if (nSize > 1) |
608 bFDF = params[1].ToBool(pRuntime); | 599 bFDF = params[1].ToBool(pRuntime); |
609 if (nSize > 2) | 600 if (nSize > 2) |
610 bEmpty = params[2].ToBool(pRuntime); | 601 bEmpty = params[2].ToBool(pRuntime); |
611 if (nSize > 3) | 602 if (nSize > 3) |
612 aFields.Attach(params[3].ToV8Array(pRuntime)); | 603 aFields.Attach(params[3].ToV8Array(pRuntime)); |
613 } else if (v.GetType() == CJS_Value::VT_object) { | 604 } else if (v.GetType() == CJS_Value::VT_object) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 FX_BOOL Document::author(IJS_Context* cc, | 730 FX_BOOL Document::author(IJS_Context* cc, |
740 CJS_PropValue& vp, | 731 CJS_PropValue& vp, |
741 CFX_WideString& sError) { | 732 CFX_WideString& sError) { |
742 return getPropertyInternal(cc, vp, "Author", sError); | 733 return getPropertyInternal(cc, vp, "Author", sError); |
743 } | 734 } |
744 | 735 |
745 FX_BOOL Document::info(IJS_Context* cc, | 736 FX_BOOL Document::info(IJS_Context* cc, |
746 CJS_PropValue& vp, | 737 CJS_PropValue& vp, |
747 CFX_WideString& sError) { | 738 CFX_WideString& sError) { |
748 if (vp.IsSetting()) { | 739 if (vp.IsSetting()) { |
749 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 740 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
750 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
751 return FALSE; | 741 return FALSE; |
752 } | 742 } |
753 | 743 |
754 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | 744 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
755 if (!pDictionary) | 745 if (!pDictionary) |
756 return FALSE; | 746 return FALSE; |
757 | 747 |
758 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); | 748 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); |
759 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); | 749 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); |
760 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); | 750 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) | 872 if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) |
883 return FALSE; | 873 return FALSE; |
884 | 874 |
885 return getPropertyInternal(cc, vp, "Title", sError); | 875 return getPropertyInternal(cc, vp, "Title", sError); |
886 } | 876 } |
887 | 877 |
888 FX_BOOL Document::numPages(IJS_Context* cc, | 878 FX_BOOL Document::numPages(IJS_Context* cc, |
889 CJS_PropValue& vp, | 879 CJS_PropValue& vp, |
890 CFX_WideString& sError) { | 880 CFX_WideString& sError) { |
891 if (vp.IsSetting()) { | 881 if (vp.IsSetting()) { |
892 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 882 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
893 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
894 return FALSE; | 883 return FALSE; |
895 } | 884 } |
896 vp << m_pDocument->GetPageCount(); | 885 vp << m_pDocument->GetPageCount(); |
897 return TRUE; | 886 return TRUE; |
898 } | 887 } |
899 | 888 |
900 FX_BOOL Document::external(IJS_Context* cc, | 889 FX_BOOL Document::external(IJS_Context* cc, |
901 CJS_PropValue& vp, | 890 CJS_PropValue& vp, |
902 CFX_WideString& sError) { | 891 CFX_WideString& sError) { |
903 // In Chrome case,should always return true. | 892 // In Chrome case, should always return true. |
904 if (vp.IsGetting()) { | 893 if (vp.IsGetting()) { |
905 vp << true; | 894 vp << true; |
906 } | 895 } |
907 return TRUE; | 896 return TRUE; |
908 } | 897 } |
909 | 898 |
910 FX_BOOL Document::filesize(IJS_Context* cc, | 899 FX_BOOL Document::filesize(IJS_Context* cc, |
911 CJS_PropValue& vp, | 900 CJS_PropValue& vp, |
912 CFX_WideString& sError) { | 901 CFX_WideString& sError) { |
913 if (vp.IsSetting()) { | 902 if (vp.IsSetting()) { |
914 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 903 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
915 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
916 return FALSE; | 904 return FALSE; |
917 } | 905 } |
918 vp << 0; | 906 vp << 0; |
919 return TRUE; | 907 return TRUE; |
920 } | 908 } |
921 | 909 |
922 FX_BOOL Document::mouseX(IJS_Context* cc, | 910 FX_BOOL Document::mouseX(IJS_Context* cc, |
923 CJS_PropValue& vp, | 911 CJS_PropValue& vp, |
924 CFX_WideString& sError) { | 912 CFX_WideString& sError) { |
925 return TRUE; | 913 return TRUE; |
926 } | 914 } |
927 | 915 |
928 FX_BOOL Document::mouseY(IJS_Context* cc, | 916 FX_BOOL Document::mouseY(IJS_Context* cc, |
929 CJS_PropValue& vp, | 917 CJS_PropValue& vp, |
930 CFX_WideString& sError) { | 918 CFX_WideString& sError) { |
931 return TRUE; | 919 return TRUE; |
932 } | 920 } |
933 | 921 |
934 FX_BOOL Document::URL(IJS_Context* cc, | 922 FX_BOOL Document::URL(IJS_Context* cc, |
935 CJS_PropValue& vp, | 923 CJS_PropValue& vp, |
936 CFX_WideString& sError) { | 924 CFX_WideString& sError) { |
937 if (vp.IsSetting()) { | 925 if (vp.IsSetting()) { |
938 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 926 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
939 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
940 return FALSE; | 927 return FALSE; |
941 } | 928 } |
942 vp << m_pDocument->GetPath(); | 929 vp << m_pDocument->GetPath(); |
943 return TRUE; | 930 return TRUE; |
944 } | 931 } |
945 | 932 |
946 FX_BOOL Document::baseURL(IJS_Context* cc, | 933 FX_BOOL Document::baseURL(IJS_Context* cc, |
947 CJS_PropValue& vp, | 934 CJS_PropValue& vp, |
948 CFX_WideString& sError) { | 935 CFX_WideString& sError) { |
949 if (vp.IsGetting()) { | 936 if (vp.IsGetting()) { |
(...skipping 20 matching lines...) Expand all Loading... |
970 pInterForm->EnableCalculate(bCalculate); | 957 pInterForm->EnableCalculate(bCalculate); |
971 } | 958 } |
972 | 959 |
973 return TRUE; | 960 return TRUE; |
974 } | 961 } |
975 | 962 |
976 FX_BOOL Document::documentFileName(IJS_Context* cc, | 963 FX_BOOL Document::documentFileName(IJS_Context* cc, |
977 CJS_PropValue& vp, | 964 CJS_PropValue& vp, |
978 CFX_WideString& sError) { | 965 CFX_WideString& sError) { |
979 if (vp.IsSetting()) { | 966 if (vp.IsSetting()) { |
980 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 967 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
981 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
982 return FALSE; | 968 return FALSE; |
983 } | 969 } |
984 CFX_WideString wsFilePath = m_pDocument->GetPath(); | 970 CFX_WideString wsFilePath = m_pDocument->GetPath(); |
985 int32_t i = wsFilePath.GetLength() - 1; | 971 int32_t i = wsFilePath.GetLength() - 1; |
986 for (; i >= 0; i--) { | 972 for (; i >= 0; i--) { |
987 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') | 973 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
988 break; | 974 break; |
989 } | 975 } |
990 if (i >= 0 && i < wsFilePath.GetLength() - 1) { | 976 if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
991 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); | 977 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
992 } else { | 978 } else { |
993 vp << L""; | 979 vp << L""; |
994 } | 980 } |
995 return TRUE; | 981 return TRUE; |
996 } | 982 } |
997 | 983 |
998 FX_BOOL Document::path(IJS_Context* cc, | 984 FX_BOOL Document::path(IJS_Context* cc, |
999 CJS_PropValue& vp, | 985 CJS_PropValue& vp, |
1000 CFX_WideString& sError) { | 986 CFX_WideString& sError) { |
1001 if (vp.IsSetting()) { | 987 if (vp.IsSetting()) { |
1002 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 988 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
1003 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1004 return FALSE; | 989 return FALSE; |
1005 } | 990 } |
1006 vp << app::SysPathToPDFPath(m_pDocument->GetPath()); | 991 vp << app::SysPathToPDFPath(m_pDocument->GetPath()); |
1007 return TRUE; | 992 return TRUE; |
1008 } | 993 } |
1009 | 994 |
1010 FX_BOOL Document::pageWindowRect(IJS_Context* cc, | 995 FX_BOOL Document::pageWindowRect(IJS_Context* cc, |
1011 CJS_PropValue& vp, | 996 CJS_PropValue& vp, |
1012 CFX_WideString& sError) { | 997 CFX_WideString& sError) { |
1013 return TRUE; | 998 return TRUE; |
(...skipping 23 matching lines...) Expand all Loading... |
1037 const std::vector<CJS_Value>& params, | 1022 const std::vector<CJS_Value>& params, |
1038 CJS_Value& vRet, | 1023 CJS_Value& vRet, |
1039 CFX_WideString& sError) { | 1024 CFX_WideString& sError) { |
1040 return TRUE; | 1025 return TRUE; |
1041 } | 1026 } |
1042 | 1027 |
1043 FX_BOOL Document::getAnnot(IJS_Context* cc, | 1028 FX_BOOL Document::getAnnot(IJS_Context* cc, |
1044 const std::vector<CJS_Value>& params, | 1029 const std::vector<CJS_Value>& params, |
1045 CJS_Value& vRet, | 1030 CJS_Value& vRet, |
1046 CFX_WideString& sError) { | 1031 CFX_WideString& sError) { |
1047 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1048 if (params.size() != 2) { | 1032 if (params.size() != 2) { |
1049 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1033 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1050 return FALSE; | 1034 return FALSE; |
1051 } | 1035 } |
1052 | 1036 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1053 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1037 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1054 int nPageNo = params[0].ToInt(pRuntime); | 1038 int nPageNo = params[0].ToInt(pRuntime); |
1055 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); | 1039 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); |
1056 | |
1057 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(nPageNo); | 1040 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(nPageNo); |
1058 if (!pPageView) | 1041 if (!pPageView) |
1059 return FALSE; | 1042 return FALSE; |
1060 | 1043 |
1061 CPDFSDK_AnnotIterator annotIterator(pPageView, false); | 1044 CPDFSDK_AnnotIterator annotIterator(pPageView, false); |
1062 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; | 1045 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; |
1063 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { | 1046 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { |
1064 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); | 1047 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); |
1065 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { | 1048 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { |
1066 pSDKBAAnnot = pBAAnnot; | 1049 pSDKBAAnnot = pBAAnnot; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 | 1154 |
1172 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { | 1155 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
1173 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && | 1156 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
1174 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); | 1157 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
1175 } | 1158 } |
1176 | 1159 |
1177 FX_BOOL Document::addIcon(IJS_Context* cc, | 1160 FX_BOOL Document::addIcon(IJS_Context* cc, |
1178 const std::vector<CJS_Value>& params, | 1161 const std::vector<CJS_Value>& params, |
1179 CJS_Value& vRet, | 1162 CJS_Value& vRet, |
1180 CFX_WideString& sError) { | 1163 CFX_WideString& sError) { |
1181 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1182 | 1164 |
1183 if (params.size() != 2) { | 1165 if (params.size() != 2) { |
1184 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1166 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1185 return FALSE; | 1167 return FALSE; |
1186 } | 1168 } |
1187 | 1169 |
| 1170 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1188 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1171 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1189 | |
1190 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1172 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
1191 | 1173 |
1192 if (params[1].GetType() != CJS_Value::VT_object) { | 1174 if (params[1].GetType() != CJS_Value::VT_object) { |
1193 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1175 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1194 return FALSE; | 1176 return FALSE; |
1195 } | 1177 } |
1196 | 1178 |
1197 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); | 1179 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
1198 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { | 1180 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
1199 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1181 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1200 return FALSE; | 1182 return FALSE; |
1201 } | 1183 } |
1202 | 1184 |
1203 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); | 1185 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
1204 if (!pEmbedObj) { | 1186 if (!pEmbedObj) { |
1205 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1187 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1206 return FALSE; | 1188 return FALSE; |
1207 } | 1189 } |
1208 | 1190 |
1209 m_IconList.push_back(std::unique_ptr<IconElement>( | 1191 m_IconList.push_back(std::unique_ptr<IconElement>( |
1210 new IconElement(swIconName, (Icon*)pEmbedObj))); | 1192 new IconElement(swIconName, (Icon*)pEmbedObj))); |
1211 return TRUE; | 1193 return TRUE; |
1212 } | 1194 } |
1213 | 1195 |
1214 FX_BOOL Document::icons(IJS_Context* cc, | 1196 FX_BOOL Document::icons(IJS_Context* cc, |
1215 CJS_PropValue& vp, | 1197 CJS_PropValue& vp, |
1216 CFX_WideString& sError) { | 1198 CFX_WideString& sError) { |
1217 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1218 if (vp.IsSetting()) { | 1199 if (vp.IsSetting()) { |
1219 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | 1200 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
1220 return FALSE; | 1201 return FALSE; |
1221 } | 1202 } |
1222 | 1203 |
1223 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1204 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1224 if (m_IconList.empty()) { | 1205 if (m_IconList.empty()) { |
1225 vp.GetJSValue()->SetNull(pRuntime); | 1206 vp.GetJSValue()->SetNull(pRuntime); |
1226 return TRUE; | 1207 return TRUE; |
1227 } | 1208 } |
1228 | 1209 |
1229 CJS_Array Icons; | 1210 CJS_Array Icons; |
(...skipping 20 matching lines...) Expand all Loading... |
1250 } | 1231 } |
1251 | 1232 |
1252 vp << Icons; | 1233 vp << Icons; |
1253 return TRUE; | 1234 return TRUE; |
1254 } | 1235 } |
1255 | 1236 |
1256 FX_BOOL Document::getIcon(IJS_Context* cc, | 1237 FX_BOOL Document::getIcon(IJS_Context* cc, |
1257 const std::vector<CJS_Value>& params, | 1238 const std::vector<CJS_Value>& params, |
1258 CJS_Value& vRet, | 1239 CJS_Value& vRet, |
1259 CFX_WideString& sError) { | 1240 CFX_WideString& sError) { |
1260 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1261 if (params.size() != 1) { | 1241 if (params.size() != 1) { |
1262 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1242 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1263 return FALSE; | 1243 return FALSE; |
1264 } | 1244 } |
1265 | 1245 |
1266 if (m_IconList.empty()) | 1246 if (m_IconList.empty()) |
1267 return FALSE; | 1247 return FALSE; |
1268 | 1248 |
1269 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1249 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1270 | |
1271 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1250 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
1272 | 1251 |
1273 for (const auto& pIconElement : m_IconList) { | 1252 for (const auto& pIconElement : m_IconList) { |
1274 if (pIconElement->IconName == swIconName) { | 1253 if (pIconElement->IconName == swIconName) { |
1275 Icon* pRetIcon = pIconElement->IconStream; | 1254 Icon* pRetIcon = pIconElement->IconStream; |
1276 | 1255 |
1277 v8::Local<v8::Object> pObj = | 1256 v8::Local<v8::Object> pObj = |
1278 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1257 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
1279 if (pObj.IsEmpty()) | 1258 if (pObj.IsEmpty()) |
1280 return FALSE; | 1259 return FALSE; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 FX_BOOL Document::Collab(IJS_Context* cc, | 1316 FX_BOOL Document::Collab(IJS_Context* cc, |
1338 CJS_PropValue& vp, | 1317 CJS_PropValue& vp, |
1339 CFX_WideString& sError) { | 1318 CFX_WideString& sError) { |
1340 return TRUE; | 1319 return TRUE; |
1341 } | 1320 } |
1342 | 1321 |
1343 FX_BOOL Document::getPageNthWord(IJS_Context* cc, | 1322 FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
1344 const std::vector<CJS_Value>& params, | 1323 const std::vector<CJS_Value>& params, |
1345 CJS_Value& vRet, | 1324 CJS_Value& vRet, |
1346 CFX_WideString& sError) { | 1325 CFX_WideString& sError) { |
1347 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1348 | |
1349 // TODO(tsepez): check maximum allowable params. | 1326 // TODO(tsepez): check maximum allowable params. |
1350 | 1327 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
1351 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1328 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
1352 return FALSE; | 1329 return FALSE; |
1353 | 1330 } |
1354 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1331 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1355 | |
1356 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1332 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
1357 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; | 1333 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
1358 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; | 1334 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
1359 | 1335 |
1360 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1336 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
1361 if (!pDocument) | 1337 if (!pDocument) |
1362 return FALSE; | 1338 return FALSE; |
1363 | 1339 |
1364 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1340 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
1365 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1341 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
1366 return FALSE; | 1342 return FALSE; |
1367 } | 1343 } |
1368 | 1344 |
1369 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1345 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
1370 if (!pPageDict) | 1346 if (!pPageDict) |
1371 return FALSE; | 1347 return FALSE; |
1372 | 1348 |
1373 CPDF_Page page(pDocument, pPageDict, true); | 1349 CPDF_Page page(pDocument, pPageDict, true); |
1374 page.ParseContent(); | 1350 page.ParseContent(); |
1375 | 1351 |
(...skipping 27 matching lines...) Expand all Loading... |
1403 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1379 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
1404 return FALSE; | 1380 return FALSE; |
1405 | 1381 |
1406 return FALSE; | 1382 return FALSE; |
1407 } | 1383 } |
1408 | 1384 |
1409 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | 1385 FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
1410 const std::vector<CJS_Value>& params, | 1386 const std::vector<CJS_Value>& params, |
1411 CJS_Value& vRet, | 1387 CJS_Value& vRet, |
1412 CFX_WideString& sError) { | 1388 CFX_WideString& sError) { |
1413 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1389 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
1414 | 1390 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
1415 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | |
1416 return FALSE; | 1391 return FALSE; |
1417 | 1392 } |
1418 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1393 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1419 | |
1420 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1394 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
1421 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1395 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
1422 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1396 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
1423 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1397 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
1424 return FALSE; | 1398 return FALSE; |
1425 } | 1399 } |
1426 | 1400 |
1427 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1401 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
1428 if (!pPageDict) | 1402 if (!pPageDict) |
1429 return FALSE; | 1403 return FALSE; |
1430 | 1404 |
1431 CPDF_Page page(pDocument, pPageDict, true); | 1405 CPDF_Page page(pDocument, pPageDict, true); |
1432 page.ParseContent(); | 1406 page.ParseContent(); |
1433 | 1407 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 CJS_Value& vRet, | 1561 CJS_Value& vRet, |
1588 CFX_WideString& sError) { | 1562 CFX_WideString& sError) { |
1589 // Unsafe, not supported. | 1563 // Unsafe, not supported. |
1590 return TRUE; | 1564 return TRUE; |
1591 } | 1565 } |
1592 | 1566 |
1593 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, | 1567 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, |
1594 const std::vector<CJS_Value>& params, | 1568 const std::vector<CJS_Value>& params, |
1595 CJS_Value& vRet, | 1569 CJS_Value& vRet, |
1596 CFX_WideString& sError) { | 1570 CFX_WideString& sError) { |
1597 CJS_Context* context = (CJS_Context*)cc; | |
1598 | |
1599 if (params.size() != 1) { | 1571 if (params.size() != 1) { |
1600 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR); | 1572 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1601 return FALSE; | 1573 return FALSE; |
1602 } | 1574 } |
1603 | 1575 |
1604 CJS_Runtime* pRuntime = context->GetJSRuntime(); | 1576 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1605 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 1577 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
1606 CFX_ByteString utf8Name = wideName.UTF8Encode(); | 1578 CFX_ByteString utf8Name = wideName.UTF8Encode(); |
1607 | |
1608 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1579 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
1609 if (!pDocument) | 1580 if (!pDocument) |
1610 return FALSE; | 1581 return FALSE; |
1611 | 1582 |
1612 CPDF_NameTree nameTree(pDocument, "Dests"); | 1583 CPDF_NameTree nameTree(pDocument, "Dests"); |
1613 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); | 1584 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
1614 if (!destArray) | 1585 if (!destArray) |
1615 return FALSE; | 1586 return FALSE; |
1616 | 1587 |
1617 CPDF_Dest dest(destArray); | 1588 CPDF_Dest dest(destArray); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 } | 1625 } |
1655 } | 1626 } |
1656 | 1627 |
1657 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1628 for (const auto& pData : DelayDataForFieldAndControlIndex) |
1658 Field::DoDelay(m_pDocument, pData.get()); | 1629 Field::DoDelay(m_pDocument, pData.get()); |
1659 } | 1630 } |
1660 | 1631 |
1661 CJS_Document* Document::GetCJSDoc() const { | 1632 CJS_Document* Document::GetCJSDoc() const { |
1662 return static_cast<CJS_Document*>(m_pJSObject); | 1633 return static_cast<CJS_Document*>(m_pJSObject); |
1663 } | 1634 } |
OLD | NEW |