Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: fpdfsdk/src/javascript/Document.cpp

Issue 1394993006: Merge to XFA: Pass IJS_Runtime, not IJS_Context, to native object constructors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/Document.h ('k') | fpdfsdk/src/javascript/Field.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); 825 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
831 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); 826 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
832 CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate"); 827 CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
833 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped"); 828 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
834 829
835 v8::Isolate* isolate = GetIsolate(cc); 830 v8::Isolate* isolate = GetIsolate(cc);
836 if (vp.IsGetting()) { 831 if (vp.IsGetting()) {
837 CJS_Context* pContext = (CJS_Context*)cc; 832 CJS_Context* pContext = (CJS_Context*)cc;
838 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 833 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
839 v8::Local<v8::Object> pObj = 834 v8::Local<v8::Object> pObj =
840 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1); 835 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1);
841 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); 836 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
842 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); 837 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
843 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); 838 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
844 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); 839 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
845 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); 840 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
846 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); 841 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
847 FXJS_PutObjectString(isolate, pObj, L"CreationDate", 842 FXJS_PutObjectString(isolate, pObj, L"CreationDate",
848 cwCreationDate.c_str()); 843 cwCreationDate.c_str());
849 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); 844 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
850 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); 845 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1421 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); 1422 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1428 return FALSE; 1423 return FALSE;
1429 } 1424 }
1430 1425
1431 if (!m_pIconTree) { 1426 if (!m_pIconTree) {
1432 vp.SetNull(); 1427 vp.SetNull();
1433 return TRUE; 1428 return TRUE;
1434 } 1429 }
1435 1430
1436 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1437 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1431 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1438 CJS_Array Icons(pRuntime); 1432 CJS_Array Icons(pRuntime);
1439 IconElement* pIconElement = NULL; 1433 IconElement* pIconElement = NULL;
1440 int iIconTreeLength = m_pIconTree->GetLength(); 1434 int iIconTreeLength = m_pIconTree->GetLength();
1441 for (int i = 0; i < iIconTreeLength; i++) { 1435 for (int i = 0; i < iIconTreeLength; i++) {
1442 pIconElement = (*m_pIconTree)[i]; 1436 pIconElement = (*m_pIconTree)[i];
1443 1437
1444 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1438 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1445 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); 1439 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1446 if (pObj.IsEmpty()) 1440 if (pObj.IsEmpty())
1447 return FALSE; 1441 return FALSE;
1448 1442
1449 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1443 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1450 if (!pJS_Icon) 1444 if (!pJS_Icon)
1451 return FALSE; 1445 return FALSE;
1452 1446
1453 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1447 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1454 if (!pIcon) 1448 if (!pIcon)
1455 return FALSE; 1449 return FALSE;
(...skipping 22 matching lines...) Expand all
1478 CFX_WideString swIconName = params[0].ToCFXWideString(); 1472 CFX_WideString swIconName = params[0].ToCFXWideString();
1479 int iIconCounts = m_pIconTree->GetLength(); 1473 int iIconCounts = m_pIconTree->GetLength();
1480 1474
1481 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1475 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1482 1476
1483 for (int i = 0; i < iIconCounts; i++) { 1477 for (int i = 0; i < iIconCounts; i++) {
1484 if ((*m_pIconTree)[i]->IconName == swIconName) { 1478 if ((*m_pIconTree)[i]->IconName == swIconName) {
1485 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; 1479 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
1486 1480
1487 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1481 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1488 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); 1482 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1489 if (pObj.IsEmpty()) 1483 if (pObj.IsEmpty())
1490 return FALSE; 1484 return FALSE;
1491 1485
1492 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1486 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1493 if (!pJS_Icon) 1487 if (!pJS_Icon)
1494 return FALSE; 1488 return FALSE;
1495 1489
1496 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1490 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1497 if (!pIcon) 1491 if (!pIcon)
1498 return FALSE; 1492 return FALSE;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 return TRUE; 1673 return TRUE;
1680 } 1674 }
1681 1675
1682 FX_BOOL Document::getPrintParams(IJS_Context* cc, 1676 FX_BOOL Document::getPrintParams(IJS_Context* cc,
1683 const CJS_Parameters& params, 1677 const CJS_Parameters& params,
1684 CJS_Value& vRet, 1678 CJS_Value& vRet,
1685 CFX_WideString& sError) { 1679 CFX_WideString& sError) {
1686 CJS_Context* pContext = (CJS_Context*)cc; 1680 CJS_Context* pContext = (CJS_Context*)cc;
1687 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1681 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1688 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 1682 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
1689 pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID); 1683 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID);
1690 1684
1691 // Not implemented yet. 1685 // Not implemented yet.
1692 1686
1693 vRet = pRetObj; 1687 vRet = pRetObj;
1694 return TRUE; 1688 return TRUE;
1695 } 1689 }
1696 1690
1697 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) 1691 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
1698 1692
1699 int Document::CountWords(CPDF_TextObject* pTextObj) { 1693 int Document::CountWords(CPDF_TextObject* pTextObj) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 CFX_DWordArray DelArray; 1897 CFX_DWordArray DelArray;
1904 1898
1905 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { 1899 for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
1906 m_DelayData.RemoveAt(DelArray[j]); 1900 m_DelayData.RemoveAt(DelArray[j]);
1907 } 1901 }
1908 } 1902 }
1909 1903
1910 CJS_Document* Document::GetCJSDoc() const { 1904 CJS_Document* Document::GetCJSDoc() const {
1911 return static_cast<CJS_Document*>(m_pJSObject); 1905 return static_cast<CJS_Document*>(m_pJSObject);
1912 } 1906 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/Document.h ('k') | fpdfsdk/src/javascript/Field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698