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

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

Issue 1382263002: Store object definition ID in each js_class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use size_t vars with FX_ArraySize. 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 CFX_WideString wideName = params[0].ToCFXWideString(); 318 CFX_WideString wideName = params[0].ToCFXWideString();
319 319
320 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 320 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
321 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 321 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
322 if (pPDFForm->CountFields(wideName) <= 0) { 322 if (pPDFForm->CountFields(wideName) <= 0) {
323 vRet.SetNull(); 323 vRet.SetNull();
324 return TRUE; 324 return TRUE;
325 } 325 }
326 326
327 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 327 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
328 v8::Local<v8::Object> pFieldObj = 328 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
329 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, 329 pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID);
330 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
331 330
332 v8::Isolate* isolate = GetIsolate(cc); 331 v8::Isolate* isolate = GetIsolate(cc);
333 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); 332 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
334 Field* pField = (Field*)pJSField->GetEmbedObject(); 333 Field* pField = (Field*)pJSField->GetEmbedObject();
335 pField->AttachField(this, wideName); 334 pField->AttachField(this, wideName);
336 335
337 vRet = pJSField; 336 vRet = pJSField;
338 return TRUE; 337 return TRUE;
339 } 338 }
340 339
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), 433 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(),
435 cMsg.c_str()); 434 cMsg.c_str());
436 pRuntime->EndBlock(); 435 pRuntime->EndBlock();
437 return TRUE; 436 return TRUE;
438 } 437 }
439 438
440 FX_BOOL Document::print(IFXJS_Context* cc, 439 FX_BOOL Document::print(IFXJS_Context* cc,
441 const CJS_Parameters& params, 440 const CJS_Parameters& params,
442 CJS_Value& vRet, 441 CJS_Value& vRet,
443 CFX_WideString& sError) { 442 CFX_WideString& sError) {
444 CJS_Context* pContext = (CJS_Context*)cc;
445 ASSERT(pContext != NULL);
446 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
447 ASSERT(pRuntime != NULL);
448
449 FX_BOOL bUI = TRUE; 443 FX_BOOL bUI = TRUE;
450 int nStart = 0; 444 int nStart = 0;
451 int nEnd = 0; 445 int nEnd = 0;
452 FX_BOOL bSilent = FALSE; 446 FX_BOOL bSilent = FALSE;
453 FX_BOOL bShrinkToFit = FALSE; 447 FX_BOOL bShrinkToFit = FALSE;
454 FX_BOOL bPrintAsImage = FALSE; 448 FX_BOOL bPrintAsImage = FALSE;
455 FX_BOOL bReverse = FALSE; 449 FX_BOOL bReverse = FALSE;
456 FX_BOOL bAnnotations = FALSE; 450 FX_BOOL bAnnotations = FALSE;
457 451
458 int nlength = params.size(); 452 int nlength = params.size();
459 if (nlength == 9) { 453 if (nlength == 9) {
460 if (params[8].GetType() == CJS_Value::VT_fxobject) { 454 if (params[8].GetType() == CJS_Value::VT_fxobject) {
461 v8::Local<v8::Object> pObj = params[8].ToV8Object(); 455 v8::Local<v8::Object> pObj = params[8].ToV8Object();
462 { 456 {
463 if (FXJS_GetObjDefnID(pObj) == 457 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) {
464 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")) {
465 if (CJS_Object* pJSObj = params[8].ToCJSObject()) { 458 if (CJS_Object* pJSObj = params[8].ToCJSObject()) {
466 if (PrintParamsObj* pprintparamsObj = 459 if (PrintParamsObj* pprintparamsObj =
467 (PrintParamsObj*)pJSObj->GetEmbedObject()) { 460 (PrintParamsObj*)pJSObj->GetEmbedObject()) {
468 bUI = pprintparamsObj->bUI; 461 bUI = pprintparamsObj->bUI;
469 nStart = pprintparamsObj->nStart; 462 nStart = pprintparamsObj->nStart;
470 nEnd = pprintparamsObj->nEnd; 463 nEnd = pprintparamsObj->nEnd;
471 bSilent = pprintparamsObj->bSilent; 464 bSilent = pprintparamsObj->bSilent;
472 bShrinkToFit = pprintparamsObj->bShrinkToFit; 465 bShrinkToFit = pprintparamsObj->bShrinkToFit;
473 bPrintAsImage = pprintparamsObj->bPrintAsImage; 466 bPrintAsImage = pprintparamsObj->bPrintAsImage;
474 bReverse = pprintparamsObj->bReverse; 467 bReverse = pprintparamsObj->bReverse;
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 if (params.size() != 2) { 1357 if (params.size() != 2) {
1365 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1358 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1366 return FALSE; 1359 return FALSE;
1367 } 1360 }
1368 CFX_WideString swIconName = params[0].ToCFXWideString(); 1361 CFX_WideString swIconName = params[0].ToCFXWideString();
1369 1362
1370 if (params[1].GetType() != CJS_Value::VT_object) { 1363 if (params[1].GetType() != CJS_Value::VT_object) {
1371 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1364 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1372 return FALSE; 1365 return FALSE;
1373 } 1366 }
1367
1374 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); 1368 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
1375 1369 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
1376 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1377 if (FXJS_GetObjDefnID(pJSIcon) !=
1378 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")) {
1379 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1370 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1380 return FALSE; 1371 return FALSE;
1381 } 1372 }
1382 1373
1383 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); 1374 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
1384 if (!pEmbedObj) { 1375 if (!pEmbedObj) {
1385 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1376 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1386 return FALSE; 1377 return FALSE;
1387 } 1378 }
1388 1379
(...skipping 27 matching lines...) Expand all
1416 IconElement* pIconElement = NULL; 1407 IconElement* pIconElement = NULL;
1417 int iIconTreeLength = m_pIconTree->GetLength(); 1408 int iIconTreeLength = m_pIconTree->GetLength();
1418 1409
1419 CJS_Context* pContext = (CJS_Context*)cc; 1410 CJS_Context* pContext = (CJS_Context*)cc;
1420 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1411 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1421 1412
1422 for (int i = 0; i < iIconTreeLength; i++) { 1413 for (int i = 0; i < iIconTreeLength; i++) {
1423 pIconElement = (*m_pIconTree)[i]; 1414 pIconElement = (*m_pIconTree)[i];
1424 1415
1425 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1416 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1426 pRuntime->GetIsolate(), pContext, 1417 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
1427 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
1428 if (pObj.IsEmpty()) 1418 if (pObj.IsEmpty())
1429 return FALSE; 1419 return FALSE;
1430 1420
1431 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1421 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1432 if (!pJS_Icon) 1422 if (!pJS_Icon)
1433 return FALSE; 1423 return FALSE;
1434 1424
1435 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1425 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1436 if (!pIcon) 1426 if (!pIcon)
1437 return FALSE; 1427 return FALSE;
(...skipping 22 matching lines...) Expand all
1460 CFX_WideString swIconName = params[0].ToCFXWideString(); 1450 CFX_WideString swIconName = params[0].ToCFXWideString();
1461 int iIconCounts = m_pIconTree->GetLength(); 1451 int iIconCounts = m_pIconTree->GetLength();
1462 1452
1463 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1453 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1464 1454
1465 for (int i = 0; i < iIconCounts; i++) { 1455 for (int i = 0; i < iIconCounts; i++) {
1466 if ((*m_pIconTree)[i]->IconName == swIconName) { 1456 if ((*m_pIconTree)[i]->IconName == swIconName) {
1467 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; 1457 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
1468 1458
1469 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1459 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1470 pRuntime->GetIsolate(), pContext, 1460 pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
1471 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
1472 if (pObj.IsEmpty()) 1461 if (pObj.IsEmpty())
1473 return FALSE; 1462 return FALSE;
1474 1463
1475 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1464 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1476 if (!pJS_Icon) 1465 if (!pJS_Icon)
1477 return FALSE; 1466 return FALSE;
1478 1467
1479 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1468 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1480 if (!pIcon) 1469 if (!pIcon)
1481 return FALSE; 1470 return FALSE;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 return TRUE; 1646 return TRUE;
1658 } 1647 }
1659 1648
1660 FX_BOOL Document::getPrintParams(IFXJS_Context* cc, 1649 FX_BOOL Document::getPrintParams(IFXJS_Context* cc,
1661 const CJS_Parameters& params, 1650 const CJS_Parameters& params,
1662 CJS_Value& vRet, 1651 CJS_Value& vRet,
1663 CFX_WideString& sError) { 1652 CFX_WideString& sError) {
1664 CJS_Context* pContext = (CJS_Context*)cc; 1653 CJS_Context* pContext = (CJS_Context*)cc;
1665 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1654 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1666 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 1655 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
1667 pRuntime->GetIsolate(), pContext, 1656 pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID);
1668 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj"));
1669 1657
1670 // Not implemented yet. 1658 // Not implemented yet.
1671 1659
1672 vRet = pRetObj; 1660 vRet = pRetObj;
1673 return TRUE; 1661 return TRUE;
1674 } 1662 }
1675 1663
1676 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) 1664 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
1677 1665
1678 int Document::CountWords(CPDF_TextObject* pTextObj) { 1666 int Document::CountWords(CPDF_TextObject* pTextObj) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 CFX_DWordArray DelArray; 1838 CFX_DWordArray DelArray;
1851 1839
1852 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { 1840 for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
1853 m_DelayData.RemoveAt(DelArray[j]); 1841 m_DelayData.RemoveAt(DelArray[j]);
1854 } 1842 }
1855 } 1843 }
1856 1844
1857 CJS_Document* Document::GetCJSDoc() const { 1845 CJS_Document* Document::GetCJSDoc() const {
1858 return static_cast<CJS_Document*>(m_pJSObject); 1846 return static_cast<CJS_Document*>(m_pJSObject);
1859 } 1847 }
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