| 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 "Document.h" | 7 #include "Document.h" |
| 8 | 8 |
| 9 #include "../../../third_party/base/numerics/safe_math.h" | 9 #include "../../../third_party/base/numerics/safe_math.h" |
| 10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | 10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), | 778 pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), |
| 779 cBcc.c_str(), cMsg.c_str()); | 779 cBcc.c_str(), cMsg.c_str()); |
| 780 pRuntime->EndBlock(); | 780 pRuntime->EndBlock(); |
| 781 | 781 |
| 782 return TRUE; | 782 return TRUE; |
| 783 } | 783 } |
| 784 | 784 |
| 785 FX_BOOL Document::author(IJS_Context* cc, | 785 FX_BOOL Document::author(IJS_Context* cc, |
| 786 CJS_PropValue& vp, | 786 CJS_PropValue& vp, |
| 787 CFX_WideString& sError) { | 787 CFX_WideString& sError) { |
| 788 ASSERT(m_pDocument != NULL); | 788 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 789 | |
| 790 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | |
| 791 if (!pDictionary) | 789 if (!pDictionary) |
| 792 return FALSE; | 790 return FALSE; |
| 793 | 791 |
| 794 if (vp.IsGetting()) { | 792 if (vp.IsGetting()) { |
| 795 vp << pDictionary->GetUnicodeText("Author"); | 793 vp << pDictionary->GetUnicodeText("Author"); |
| 796 return TRUE; | 794 return TRUE; |
| 797 } else { | 795 } else { |
| 798 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 796 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 799 return FALSE; | 797 return FALSE; |
| 800 | 798 |
| 801 CFX_WideString csAuthor; | 799 CFX_WideString csAuthor; |
| 802 vp >> csAuthor; | 800 vp >> csAuthor; |
| 803 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); | 801 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); |
| 804 m_pDocument->SetChangeMark(); | 802 m_pDocument->SetChangeMark(); |
| 805 return TRUE; | 803 return TRUE; |
| 806 } | 804 } |
| 807 } | 805 } |
| 808 | 806 |
| 809 FX_BOOL Document::info(IJS_Context* cc, | 807 FX_BOOL Document::info(IJS_Context* cc, |
| 810 CJS_PropValue& vp, | 808 CJS_PropValue& vp, |
| 811 CFX_WideString& sError) { | 809 CFX_WideString& sError) { |
| 812 ASSERT(m_pDocument != NULL); | 810 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 813 | |
| 814 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | |
| 815 if (!pDictionary) | 811 if (!pDictionary) |
| 816 return FALSE; | 812 return FALSE; |
| 817 | 813 |
| 818 CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author"); | 814 CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author"); |
| 819 CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title"); | 815 CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title"); |
| 820 CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject"); | 816 CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject"); |
| 821 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords"); | 817 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords"); |
| 822 CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator"); | 818 CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator"); |
| 823 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); | 819 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); |
| 824 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); | 820 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 } | 857 } |
| 862 } | 858 } |
| 863 vp << pObj; | 859 vp << pObj; |
| 864 } | 860 } |
| 865 return TRUE; | 861 return TRUE; |
| 866 } | 862 } |
| 867 | 863 |
| 868 FX_BOOL Document::creationDate(IJS_Context* cc, | 864 FX_BOOL Document::creationDate(IJS_Context* cc, |
| 869 CJS_PropValue& vp, | 865 CJS_PropValue& vp, |
| 870 CFX_WideString& sError) { | 866 CFX_WideString& sError) { |
| 871 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 867 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 872 if (!pDictionary) | 868 if (!pDictionary) |
| 873 return FALSE; | 869 return FALSE; |
| 874 | 870 |
| 875 if (vp.IsGetting()) { | 871 if (vp.IsGetting()) { |
| 876 vp << pDictionary->GetUnicodeText("CreationDate"); | 872 vp << pDictionary->GetUnicodeText("CreationDate"); |
| 877 } else { | 873 } else { |
| 878 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 874 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 879 return FALSE; | 875 return FALSE; |
| 880 | 876 |
| 881 CFX_WideString csCreationDate; | 877 CFX_WideString csCreationDate; |
| 882 vp >> csCreationDate; | 878 vp >> csCreationDate; |
| 883 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); | 879 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); |
| 884 m_pDocument->SetChangeMark(); | 880 m_pDocument->SetChangeMark(); |
| 885 } | 881 } |
| 886 return TRUE; | 882 return TRUE; |
| 887 } | 883 } |
| 888 | 884 |
| 889 FX_BOOL Document::creator(IJS_Context* cc, | 885 FX_BOOL Document::creator(IJS_Context* cc, |
| 890 CJS_PropValue& vp, | 886 CJS_PropValue& vp, |
| 891 CFX_WideString& sError) { | 887 CFX_WideString& sError) { |
| 892 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 888 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 893 if (!pDictionary) | 889 if (!pDictionary) |
| 894 return FALSE; | 890 return FALSE; |
| 895 | 891 |
| 896 if (vp.IsGetting()) { | 892 if (vp.IsGetting()) { |
| 897 vp << pDictionary->GetUnicodeText("Creator"); | 893 vp << pDictionary->GetUnicodeText("Creator"); |
| 898 } else { | 894 } else { |
| 899 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 895 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 900 return FALSE; | 896 return FALSE; |
| 901 | 897 |
| 902 CFX_WideString csCreator; | 898 CFX_WideString csCreator; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 delete pData; | 934 delete pData; |
| 939 } | 935 } |
| 940 } | 936 } |
| 941 } | 937 } |
| 942 return TRUE; | 938 return TRUE; |
| 943 } | 939 } |
| 944 | 940 |
| 945 FX_BOOL Document::keywords(IJS_Context* cc, | 941 FX_BOOL Document::keywords(IJS_Context* cc, |
| 946 CJS_PropValue& vp, | 942 CJS_PropValue& vp, |
| 947 CFX_WideString& sError) { | 943 CFX_WideString& sError) { |
| 948 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 944 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 949 if (!pDictionary) | 945 if (!pDictionary) |
| 950 return FALSE; | 946 return FALSE; |
| 951 | 947 |
| 952 if (vp.IsGetting()) { | 948 if (vp.IsGetting()) { |
| 953 vp << pDictionary->GetUnicodeText("Keywords"); | 949 vp << pDictionary->GetUnicodeText("Keywords"); |
| 954 } else { | 950 } else { |
| 955 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 951 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 956 return FALSE; | 952 return FALSE; |
| 957 | 953 |
| 958 CFX_WideString csKeywords; | 954 CFX_WideString csKeywords; |
| 959 vp >> csKeywords; | 955 vp >> csKeywords; |
| 960 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); | 956 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); |
| 961 m_pDocument->SetChangeMark(); | 957 m_pDocument->SetChangeMark(); |
| 962 } | 958 } |
| 963 return TRUE; | 959 return TRUE; |
| 964 } | 960 } |
| 965 | 961 |
| 966 FX_BOOL Document::modDate(IJS_Context* cc, | 962 FX_BOOL Document::modDate(IJS_Context* cc, |
| 967 CJS_PropValue& vp, | 963 CJS_PropValue& vp, |
| 968 CFX_WideString& sError) { | 964 CFX_WideString& sError) { |
| 969 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 965 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 970 if (!pDictionary) | 966 if (!pDictionary) |
| 971 return FALSE; | 967 return FALSE; |
| 972 | 968 |
| 973 if (vp.IsGetting()) { | 969 if (vp.IsGetting()) { |
| 974 vp << pDictionary->GetUnicodeText("ModDate"); | 970 vp << pDictionary->GetUnicodeText("ModDate"); |
| 975 } else { | 971 } else { |
| 976 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 972 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 977 return FALSE; | 973 return FALSE; |
| 978 | 974 |
| 979 CFX_WideString csmodDate; | 975 CFX_WideString csmodDate; |
| 980 vp >> csmodDate; | 976 vp >> csmodDate; |
| 981 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); | 977 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); |
| 982 m_pDocument->SetChangeMark(); | 978 m_pDocument->SetChangeMark(); |
| 983 } | 979 } |
| 984 return TRUE; | 980 return TRUE; |
| 985 } | 981 } |
| 986 | 982 |
| 987 FX_BOOL Document::producer(IJS_Context* cc, | 983 FX_BOOL Document::producer(IJS_Context* cc, |
| 988 CJS_PropValue& vp, | 984 CJS_PropValue& vp, |
| 989 CFX_WideString& sError) { | 985 CFX_WideString& sError) { |
| 990 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 986 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 991 if (!pDictionary) | 987 if (!pDictionary) |
| 992 return FALSE; | 988 return FALSE; |
| 993 | 989 |
| 994 if (vp.IsGetting()) { | 990 if (vp.IsGetting()) { |
| 995 vp << pDictionary->GetUnicodeText("Producer"); | 991 vp << pDictionary->GetUnicodeText("Producer"); |
| 996 } else { | 992 } else { |
| 997 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 993 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 998 return FALSE; | 994 return FALSE; |
| 999 | 995 |
| 1000 CFX_WideString csproducer; | 996 CFX_WideString csproducer; |
| 1001 vp >> csproducer; | 997 vp >> csproducer; |
| 1002 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); | 998 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); |
| 1003 m_pDocument->SetChangeMark(); | 999 m_pDocument->SetChangeMark(); |
| 1004 } | 1000 } |
| 1005 return TRUE; | 1001 return TRUE; |
| 1006 } | 1002 } |
| 1007 | 1003 |
| 1008 FX_BOOL Document::subject(IJS_Context* cc, | 1004 FX_BOOL Document::subject(IJS_Context* cc, |
| 1009 CJS_PropValue& vp, | 1005 CJS_PropValue& vp, |
| 1010 CFX_WideString& sError) { | 1006 CFX_WideString& sError) { |
| 1011 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 1007 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 1012 if (!pDictionary) | 1008 if (!pDictionary) |
| 1013 return FALSE; | 1009 return FALSE; |
| 1014 | 1010 |
| 1015 if (vp.IsGetting()) { | 1011 if (vp.IsGetting()) { |
| 1016 vp << pDictionary->GetUnicodeText("Subject"); | 1012 vp << pDictionary->GetUnicodeText("Subject"); |
| 1017 } else { | 1013 } else { |
| 1018 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 1014 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 1019 return FALSE; | 1015 return FALSE; |
| 1020 | 1016 |
| 1021 CFX_WideString cssubject; | 1017 CFX_WideString cssubject; |
| 1022 vp >> cssubject; | 1018 vp >> cssubject; |
| 1023 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); | 1019 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); |
| 1024 m_pDocument->SetChangeMark(); | 1020 m_pDocument->SetChangeMark(); |
| 1025 } | 1021 } |
| 1026 return TRUE; | 1022 return TRUE; |
| 1027 } | 1023 } |
| 1028 | 1024 |
| 1029 FX_BOOL Document::title(IJS_Context* cc, | 1025 FX_BOOL Document::title(IJS_Context* cc, |
| 1030 CJS_PropValue& vp, | 1026 CJS_PropValue& vp, |
| 1031 CFX_WideString& sError) { | 1027 CFX_WideString& sError) { |
| 1032 if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) | 1028 if (m_pDocument == NULL || m_pDocument->GetPDFDocument() == NULL) |
| 1033 return FALSE; | 1029 return FALSE; |
| 1034 | 1030 |
| 1035 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); | 1031 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 1036 if (!pDictionary) | 1032 if (!pDictionary) |
| 1037 return FALSE; | 1033 return FALSE; |
| 1038 | 1034 |
| 1039 if (vp.IsGetting()) { | 1035 if (vp.IsGetting()) { |
| 1040 vp << pDictionary->GetUnicodeText("Title"); | 1036 vp << pDictionary->GetUnicodeText("Title"); |
| 1041 } else { | 1037 } else { |
| 1042 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 1038 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 1043 return FALSE; | 1039 return FALSE; |
| 1044 | 1040 |
| 1045 CFX_WideString cstitle; | 1041 CFX_WideString cstitle; |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 CFX_WideString& sError) { | 1511 CFX_WideString& sError) { |
| 1516 ASSERT(m_pDocument != NULL); | 1512 ASSERT(m_pDocument != NULL); |
| 1517 | 1513 |
| 1518 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1514 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1519 return FALSE; | 1515 return FALSE; |
| 1520 | 1516 |
| 1521 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; | 1517 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; |
| 1522 int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; | 1518 int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; |
| 1523 bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; | 1519 bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; |
| 1524 | 1520 |
| 1525 CPDF_Document* pDocument = m_pDocument->GetDocument(); | 1521 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1526 if (!pDocument) | 1522 if (!pDocument) |
| 1527 return FALSE; | 1523 return FALSE; |
| 1528 | 1524 |
| 1529 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1525 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1530 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1526 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1531 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1527 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1532 return FALSE; | 1528 return FALSE; |
| 1533 } | 1529 } |
| 1534 | 1530 |
| 1535 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1531 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 const CJS_Parameters& params, | 1583 const CJS_Parameters& params, |
| 1588 CJS_Value& vRet, | 1584 CJS_Value& vRet, |
| 1589 CFX_WideString& sError) { | 1585 CFX_WideString& sError) { |
| 1590 ASSERT(m_pDocument != NULL); | 1586 ASSERT(m_pDocument != NULL); |
| 1591 | 1587 |
| 1592 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1588 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1593 return FALSE; | 1589 return FALSE; |
| 1594 | 1590 |
| 1595 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; | 1591 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; |
| 1596 | 1592 |
| 1597 CPDF_Document* pDocument = m_pDocument->GetDocument(); | 1593 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1598 ASSERT(pDocument != NULL); | 1594 ASSERT(pDocument != NULL); |
| 1599 | 1595 |
| 1600 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1596 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1601 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1597 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1602 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1598 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1603 return FALSE; | 1599 return FALSE; |
| 1604 } | 1600 } |
| 1605 | 1601 |
| 1606 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1602 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1607 if (!pPageDict) | 1603 if (!pPageDict) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 CFX_DWordArray DelArray; | 1818 CFX_DWordArray DelArray; |
| 1823 | 1819 |
| 1824 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1820 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
| 1825 m_DelayData.RemoveAt(DelArray[j]); | 1821 m_DelayData.RemoveAt(DelArray[j]); |
| 1826 } | 1822 } |
| 1827 } | 1823 } |
| 1828 | 1824 |
| 1829 CJS_Document* Document::GetCJSDoc() const { | 1825 CJS_Document* Document::GetCJSDoc() const { |
| 1830 return static_cast<CJS_Document*>(m_pJSObject); | 1826 return static_cast<CJS_Document*>(m_pJSObject); |
| 1831 } | 1827 } |
| OLD | NEW |