| 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 742 |
| 743 FX_BOOL Document::author(IJS_Context* cc, | 743 FX_BOOL Document::author(IJS_Context* cc, |
| 744 CJS_PropValue& vp, | 744 CJS_PropValue& vp, |
| 745 CFX_WideString& sError) { | 745 CFX_WideString& sError) { |
| 746 return getPropertyInternal(cc, vp, "Author", sError); | 746 return getPropertyInternal(cc, vp, "Author", sError); |
| 747 } | 747 } |
| 748 | 748 |
| 749 FX_BOOL Document::info(IJS_Context* cc, | 749 FX_BOOL Document::info(IJS_Context* cc, |
| 750 CJS_PropValue& vp, | 750 CJS_PropValue& vp, |
| 751 CFX_WideString& sError) { | 751 CFX_WideString& sError) { |
| 752 if (vp.IsSetting()) { |
| 753 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 754 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 755 return FALSE; |
| 756 } |
| 757 |
| 752 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | 758 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 753 if (!pDictionary) | 759 if (!pDictionary) |
| 754 return FALSE; | 760 return FALSE; |
| 755 | 761 |
| 756 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); | 762 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); |
| 757 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); | 763 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); |
| 758 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); | 764 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); |
| 759 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); | 765 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); |
| 760 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); | 766 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); |
| 761 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); | 767 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); |
| 762 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); | 768 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); |
| 763 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); | 769 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); |
| 764 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); | 770 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); |
| 765 | 771 |
| 772 CJS_Context* pContext = (CJS_Context*)cc; |
| 773 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 774 v8::Local<v8::Object> pObj = |
| 775 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); |
| 776 |
| 766 v8::Isolate* isolate = GetIsolate(cc); | 777 v8::Isolate* isolate = GetIsolate(cc); |
| 767 if (vp.IsGetting()) { | 778 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor); |
| 768 CJS_Context* pContext = (CJS_Context*)cc; | 779 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle); |
| 769 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 780 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject); |
| 770 v8::Local<v8::Object> pObj = | 781 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords); |
| 771 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); | 782 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator); |
| 772 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor); | 783 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer); |
| 773 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle); | 784 FXJS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate); |
| 774 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject); | 785 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate); |
| 775 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords); | 786 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped); |
| 776 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator); | |
| 777 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer); | |
| 778 FXJS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate); | |
| 779 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate); | |
| 780 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped); | |
| 781 | 787 |
| 782 // It's to be compatible to non-standard info dictionary. | 788 // It's to be compatible to non-standard info dictionary. |
| 783 for (const auto& it : *pDictionary) { | 789 for (const auto& it : *pDictionary) { |
| 784 const CFX_ByteString& bsKey = it.first; | 790 const CFX_ByteString& bsKey = it.first; |
| 785 CPDF_Object* pValueObj = it.second; | 791 CPDF_Object* pValueObj = it.second; |
| 786 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); | 792 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); |
| 787 if (pValueObj->IsString() || pValueObj->IsName()) { | 793 if (pValueObj->IsString() || pValueObj->IsName()) { |
| 788 FXJS_PutObjectString(isolate, pObj, wsKey, pValueObj->GetUnicodeText()); | 794 FXJS_PutObjectString(isolate, pObj, wsKey, pValueObj->GetUnicodeText()); |
| 789 } else if (pValueObj->IsNumber()) { | 795 } else if (pValueObj->IsNumber()) { |
| 790 FXJS_PutObjectNumber(isolate, pObj, wsKey, | 796 FXJS_PutObjectNumber(isolate, pObj, wsKey, (float)pValueObj->GetNumber()); |
| 791 (float)pValueObj->GetNumber()); | 797 } else if (pValueObj->IsBoolean()) { |
| 792 } else if (pValueObj->IsBoolean()) { | 798 FXJS_PutObjectBoolean(isolate, pObj, wsKey, !!pValueObj->GetInteger()); |
| 793 FXJS_PutObjectBoolean(isolate, pObj, wsKey, !!pValueObj->GetInteger()); | |
| 794 } | |
| 795 } | 799 } |
| 796 vp << pObj; | |
| 797 } | 800 } |
| 801 vp << pObj; |
| 798 return TRUE; | 802 return TRUE; |
| 799 } | 803 } |
| 800 | 804 |
| 801 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, | 805 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, |
| 802 CJS_PropValue& vp, | 806 CJS_PropValue& vp, |
| 803 const CFX_ByteString& propName, | 807 const CFX_ByteString& propName, |
| 804 CFX_WideString& sError) { | 808 CFX_WideString& sError) { |
| 805 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | 809 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
| 806 if (!pDictionary) | 810 if (!pDictionary) |
| 807 return FALSE; | 811 return FALSE; |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 } | 1578 } |
| 1575 } | 1579 } |
| 1576 | 1580 |
| 1577 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1581 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1578 Field::DoDelay(m_pDocument, pData.get()); | 1582 Field::DoDelay(m_pDocument, pData.get()); |
| 1579 } | 1583 } |
| 1580 | 1584 |
| 1581 CJS_Document* Document::GetCJSDoc() const { | 1585 CJS_Document* Document::GetCJSDoc() const { |
| 1582 return static_cast<CJS_Document*>(m_pJSObject); | 1586 return static_cast<CJS_Document*>(m_pJSObject); |
| 1583 } | 1587 } |
| OLD | NEW |