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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 JS_STATIC_METHOD_ENTRY(replacePages) | 133 JS_STATIC_METHOD_ENTRY(replacePages) |
134 JS_STATIC_METHOD_ENTRY(resetForm) | 134 JS_STATIC_METHOD_ENTRY(resetForm) |
135 JS_STATIC_METHOD_ENTRY(removeIcon) | 135 JS_STATIC_METHOD_ENTRY(removeIcon) |
136 JS_STATIC_METHOD_ENTRY(saveAs) | 136 JS_STATIC_METHOD_ENTRY(saveAs) |
137 JS_STATIC_METHOD_ENTRY(submitForm) | 137 JS_STATIC_METHOD_ENTRY(submitForm) |
138 JS_STATIC_METHOD_ENTRY(mailDoc) | 138 JS_STATIC_METHOD_ENTRY(mailDoc) |
139 END_JS_STATIC_METHOD() | 139 END_JS_STATIC_METHOD() |
140 | 140 |
141 IMPLEMENT_JS_CLASS(CJS_Document, Document) | 141 IMPLEMENT_JS_CLASS(CJS_Document, Document) |
142 | 142 |
143 FX_BOOL CJS_Document::InitInstance(IJS_Context* cc) { | 143 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
144 CJS_Context* pContext = (CJS_Context*)cc; | 144 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
145 ASSERT(pContext != NULL); | 145 Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
146 | 146 pDoc->AttachDoc(pRuntime->GetReaderDocument()); |
147 Document* pDoc = (Document*)GetEmbedObject(); | 147 pDoc->SetIsolate(pRuntime->GetIsolate()); |
148 ASSERT(pDoc != NULL); | 148 } |
149 | |
150 pDoc->AttachDoc(pContext->GetReaderDocument()); | |
151 pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); | |
152 return TRUE; | |
153 }; | |
154 | 149 |
155 /* --------------------------------- Document --------------------------------- | 150 /* --------------------------------- Document --------------------------------- |
156 */ | 151 */ |
157 | 152 |
158 Document::Document(CJS_Object* pJSObject) | 153 Document::Document(CJS_Object* pJSObject) |
159 : CJS_EmbedObj(pJSObject), | 154 : CJS_EmbedObj(pJSObject), |
160 m_isolate(NULL), | 155 m_isolate(NULL), |
161 m_pIconTree(NULL), | 156 m_pIconTree(NULL), |
162 m_pDocument(NULL), | 157 m_pDocument(NULL), |
163 m_cwBaseURL(L""), | 158 m_cwBaseURL(L""), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 314 |
320 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 315 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
321 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 316 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
322 if (pPDFForm->CountFields(wideName) <= 0) { | 317 if (pPDFForm->CountFields(wideName) <= 0) { |
323 vRet.SetNull(); | 318 vRet.SetNull(); |
324 return TRUE; | 319 return TRUE; |
325 } | 320 } |
326 | 321 |
327 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 322 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
328 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj( | 323 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj( |
329 pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID); | 324 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); |
330 | 325 |
331 v8::Isolate* isolate = GetIsolate(cc); | 326 v8::Isolate* isolate = GetIsolate(cc); |
332 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); | 327 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); |
333 Field* pField = (Field*)pJSField->GetEmbedObject(); | 328 Field* pField = (Field*)pJSField->GetEmbedObject(); |
334 pField->AttachField(this, wideName); | 329 pField->AttachField(this, wideName); |
335 | 330 |
336 vRet = pJSField; | 331 vRet = pJSField; |
337 return TRUE; | 332 return TRUE; |
338 } | 333 } |
339 | 334 |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); | 823 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); |
829 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); | 824 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); |
830 CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate"); | 825 CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate"); |
831 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped"); | 826 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped"); |
832 | 827 |
833 v8::Isolate* isolate = GetIsolate(cc); | 828 v8::Isolate* isolate = GetIsolate(cc); |
834 if (vp.IsGetting()) { | 829 if (vp.IsGetting()) { |
835 CJS_Context* pContext = (CJS_Context*)cc; | 830 CJS_Context* pContext = (CJS_Context*)cc; |
836 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 831 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
837 v8::Local<v8::Object> pObj = | 832 v8::Local<v8::Object> pObj = |
838 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1); | 833 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); |
839 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); | 834 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); |
840 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); | 835 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); |
841 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); | 836 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); |
842 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); | 837 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); |
843 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); | 838 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); |
844 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); | 839 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); |
845 FXJS_PutObjectString(isolate, pObj, L"CreationDate", | 840 FXJS_PutObjectString(isolate, pObj, L"CreationDate", |
846 cwCreationDate.c_str()); | 841 cwCreationDate.c_str()); |
847 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); | 842 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); |
848 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); | 843 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1382 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1388 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | 1383 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
1389 return FALSE; | 1384 return FALSE; |
1390 } | 1385 } |
1391 | 1386 |
1392 if (!m_pIconTree) { | 1387 if (!m_pIconTree) { |
1393 vp.SetNull(); | 1388 vp.SetNull(); |
1394 return TRUE; | 1389 return TRUE; |
1395 } | 1390 } |
1396 | 1391 |
1397 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1398 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1392 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1399 CJS_Array Icons(pRuntime); | 1393 CJS_Array Icons(pRuntime); |
1400 IconElement* pIconElement = NULL; | 1394 IconElement* pIconElement = NULL; |
1401 int iIconTreeLength = m_pIconTree->GetLength(); | 1395 int iIconTreeLength = m_pIconTree->GetLength(); |
1402 for (int i = 0; i < iIconTreeLength; i++) { | 1396 for (int i = 0; i < iIconTreeLength; i++) { |
1403 pIconElement = (*m_pIconTree)[i]; | 1397 pIconElement = (*m_pIconTree)[i]; |
1404 | 1398 |
1405 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 1399 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
1406 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); | 1400 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
1407 if (pObj.IsEmpty()) | 1401 if (pObj.IsEmpty()) |
1408 return FALSE; | 1402 return FALSE; |
1409 | 1403 |
1410 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | 1404 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
1411 if (!pJS_Icon) | 1405 if (!pJS_Icon) |
1412 return FALSE; | 1406 return FALSE; |
1413 | 1407 |
1414 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1408 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
1415 if (!pIcon) | 1409 if (!pIcon) |
1416 return FALSE; | 1410 return FALSE; |
(...skipping 22 matching lines...) Expand all Loading... |
1439 CFX_WideString swIconName = params[0].ToCFXWideString(); | 1433 CFX_WideString swIconName = params[0].ToCFXWideString(); |
1440 int iIconCounts = m_pIconTree->GetLength(); | 1434 int iIconCounts = m_pIconTree->GetLength(); |
1441 | 1435 |
1442 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1436 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1443 | 1437 |
1444 for (int i = 0; i < iIconCounts; i++) { | 1438 for (int i = 0; i < iIconCounts; i++) { |
1445 if ((*m_pIconTree)[i]->IconName == swIconName) { | 1439 if ((*m_pIconTree)[i]->IconName == swIconName) { |
1446 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; | 1440 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; |
1447 | 1441 |
1448 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 1442 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
1449 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); | 1443 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
1450 if (pObj.IsEmpty()) | 1444 if (pObj.IsEmpty()) |
1451 return FALSE; | 1445 return FALSE; |
1452 | 1446 |
1453 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | 1447 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
1454 if (!pJS_Icon) | 1448 if (!pJS_Icon) |
1455 return FALSE; | 1449 return FALSE; |
1456 | 1450 |
1457 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1451 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
1458 if (!pIcon) | 1452 if (!pIcon) |
1459 return FALSE; | 1453 return FALSE; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 return TRUE; | 1629 return TRUE; |
1636 } | 1630 } |
1637 | 1631 |
1638 FX_BOOL Document::getPrintParams(IJS_Context* cc, | 1632 FX_BOOL Document::getPrintParams(IJS_Context* cc, |
1639 const CJS_Parameters& params, | 1633 const CJS_Parameters& params, |
1640 CJS_Value& vRet, | 1634 CJS_Value& vRet, |
1641 CFX_WideString& sError) { | 1635 CFX_WideString& sError) { |
1642 CJS_Context* pContext = (CJS_Context*)cc; | 1636 CJS_Context* pContext = (CJS_Context*)cc; |
1643 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1637 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1644 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 1638 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
1645 pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID); | 1639 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); |
1646 | 1640 |
1647 // Not implemented yet. | 1641 // Not implemented yet. |
1648 | 1642 |
1649 vRet = pRetObj; | 1643 vRet = pRetObj; |
1650 return TRUE; | 1644 return TRUE; |
1651 } | 1645 } |
1652 | 1646 |
1653 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) | 1647 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
1654 | 1648 |
1655 int Document::CountWords(CPDF_TextObject* pTextObj) { | 1649 int Document::CountWords(CPDF_TextObject* pTextObj) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 CFX_DWordArray DelArray; | 1821 CFX_DWordArray DelArray; |
1828 | 1822 |
1829 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1823 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
1830 m_DelayData.RemoveAt(DelArray[j]); | 1824 m_DelayData.RemoveAt(DelArray[j]); |
1831 } | 1825 } |
1832 } | 1826 } |
1833 | 1827 |
1834 CJS_Document* Document::GetCJSDoc() const { | 1828 CJS_Document* Document::GetCJSDoc() const { |
1835 return static_cast<CJS_Document*>(m_pJSObject); | 1829 return static_cast<CJS_Document*>(m_pJSObject); |
1836 } | 1830 } |
OLD | NEW |