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

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

Issue 1332973002: Remove some abstractions in fxjs_v8.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove implicit cast operator from CJS_Runtime. Created 5 years, 3 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/JS_Value.cpp ('k') | fpdfsdk/src/javascript/global.cpp » ('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 "../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../include/javascript/JavaScript.h" 8 #include "../../include/javascript/JavaScript.h"
9 #include "../../include/javascript/IJavaScript.h" 9 #include "../../include/javascript/IJavaScript.h"
10 #include "../../include/javascript/JS_Define.h" 10 #include "../../include/javascript/JS_Define.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return FALSE; 115 return FALSE;
116 116
117 CJS_Context* pContext = (CJS_Context*)cc; 117 CJS_Context* pContext = (CJS_Context*)cc;
118 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 118 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
119 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 119 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
120 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); 120 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
121 CJS_Array aDocs(pRuntime->GetIsolate()); 121 CJS_Array aDocs(pRuntime->GetIsolate());
122 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { 122 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
123 CJS_Document* pJSDocument = NULL; 123 CJS_Document* pJSDocument = NULL;
124 if (pDoc == pCurDoc) { 124 if (pDoc == pCurDoc) {
125 JSFXObject pObj = JS_GetThisObj(*pRuntime); 125 v8::Local<v8::Object> pObj = JS_GetThisObj(pRuntime->GetIsolate());
126 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) 126 if (JS_GetObjDefnID(pObj) ==
127 JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"))
127 pJSDocument = 128 pJSDocument =
128 (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj); 129 (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
129 } else { 130 } else {
130 JSFXObject pObj = JS_NewFxDynamicObj( 131 v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(
131 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Document")); 132 pRuntime->GetIsolate(), pContext,
133 JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
132 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj); 134 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
133 ASSERT(pJSDocument != NULL); 135 ASSERT(pJSDocument != NULL);
134 } 136 }
135 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); 137 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
136 } 138 }
137 if (aDocs.GetLength() > 0) 139 if (aDocs.GetLength() > 0)
138 vp << aDocs; 140 vp << aDocs;
139 else 141 else
140 vp.SetNull(); 142 vp.SetNull();
141 143
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 263
262 CFX_WideString swMsg = L""; 264 CFX_WideString swMsg = L"";
263 CFX_WideString swTitle = L""; 265 CFX_WideString swTitle = L"";
264 int iIcon = 0; 266 int iIcon = 0;
265 int iType = 0; 267 int iType = 0;
266 268
267 v8::Isolate* isolate = GetIsolate(cc); 269 v8::Isolate* isolate = GetIsolate(cc);
268 270
269 if (iSize == 1) { 271 if (iSize == 1) {
270 if (params[0].GetType() == VT_object) { 272 if (params[0].GetType() == VT_object) {
271 JSObject pObj = params[0].ToV8Object(); 273 v8::Local<v8::Object> pObj = params[0].ToV8Object();
272 { 274 {
273 v8::Local<v8::Value> pValue = 275 v8::Local<v8::Value> pValue =
274 JS_GetObjectElement(isolate, pObj, L"cMsg"); 276 JS_GetObjectElement(isolate, pObj, L"cMsg");
275 swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); 277 swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
276 278
277 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle"); 279 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
278 swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); 280 swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
279 281
280 pValue = JS_GetObjectElement(isolate, pObj, L"nIcon"); 282 pValue = JS_GetObjectElement(isolate, pObj, L"nIcon");
281 iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt(); 283 iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 408 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
407 m_aTimer.Add(pTimer); 409 m_aTimer.Add(pTimer);
408 410
409 pTimer->SetType(0); 411 pTimer->SetType(0);
410 pTimer->SetRuntime(pRuntime); 412 pTimer->SetRuntime(pRuntime);
411 pTimer->SetJScript(script); 413 pTimer->SetJScript(script);
412 pTimer->SetTimeOut(0); 414 pTimer->SetTimeOut(0);
413 // pTimer->SetStartTime(GetTickCount()); 415 // pTimer->SetStartTime(GetTickCount());
414 pTimer->SetJSTimer(dwInterval); 416 pTimer->SetJSTimer(dwInterval);
415 417
416 JSFXObject pRetObj = JS_NewFxDynamicObj( 418 v8::Local<v8::Object> pRetObj =
417 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); 419 JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
420 JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
418 421
419 CJS_TimerObj* pJS_TimerObj = 422 CJS_TimerObj* pJS_TimerObj =
420 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 423 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
421 ASSERT(pJS_TimerObj != NULL); 424 ASSERT(pJS_TimerObj != NULL);
422 425
423 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 426 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
424 ASSERT(pTimerObj != NULL); 427 ASSERT(pTimerObj != NULL);
425 428
426 pTimerObj->SetTimer(pTimer); 429 pTimerObj->SetTimer(pTimer);
427 430
(...skipping 30 matching lines...) Expand all
458 461
459 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 462 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
460 m_aTimer.Add(pTimer); 463 m_aTimer.Add(pTimer);
461 464
462 pTimer->SetType(1); 465 pTimer->SetType(1);
463 pTimer->SetRuntime(pRuntime); 466 pTimer->SetRuntime(pRuntime);
464 pTimer->SetJScript(script); 467 pTimer->SetJScript(script);
465 pTimer->SetTimeOut(dwTimeOut); 468 pTimer->SetTimeOut(dwTimeOut);
466 pTimer->SetJSTimer(dwTimeOut); 469 pTimer->SetJSTimer(dwTimeOut);
467 470
468 JSFXObject pRetObj = JS_NewFxDynamicObj( 471 v8::Local<v8::Object> pRetObj =
469 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); 472 JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
473 JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
470 474
471 CJS_TimerObj* pJS_TimerObj = 475 CJS_TimerObj* pJS_TimerObj =
472 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 476 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
473 ASSERT(pJS_TimerObj != NULL); 477 ASSERT(pJS_TimerObj != NULL);
474 478
475 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 479 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
476 ASSERT(pTimerObj != NULL); 480 ASSERT(pTimerObj != NULL);
477 481
478 pTimerObj->SetTimer(pTimer); 482 pTimerObj->SetTimer(pTimer);
479 483
(...skipping 10 matching lines...) Expand all
490 ASSERT(pContext != NULL); 494 ASSERT(pContext != NULL);
491 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 495 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
492 ASSERT(pRuntime != NULL); 496 ASSERT(pRuntime != NULL);
493 497
494 if (params.size() != 1) { 498 if (params.size() != 1) {
495 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 499 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
496 return FALSE; 500 return FALSE;
497 } 501 }
498 502
499 if (params[0].GetType() == VT_fxobject) { 503 if (params[0].GetType() == VT_fxobject) {
500 JSFXObject pObj = params[0].ToV8Object(); 504 v8::Local<v8::Object> pObj = params[0].ToV8Object();
501 { 505 {
502 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { 506 if (JS_GetObjDefnID(pObj) ==
507 JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
503 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { 508 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
504 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { 509 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
505 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { 510 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
506 pTimer->KillJSTimer(); 511 pTimer->KillJSTimer();
507 512
508 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { 513 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
509 if (m_aTimer[i] == pTimer) { 514 if (m_aTimer[i] == pTimer) {
510 m_aTimer.RemoveAt(i); 515 m_aTimer.RemoveAt(i);
511 break; 516 break;
512 } 517 }
(...skipping 19 matching lines...) Expand all
532 ASSERT(pContext != NULL); 537 ASSERT(pContext != NULL);
533 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 538 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
534 ASSERT(pRuntime != NULL); 539 ASSERT(pRuntime != NULL);
535 540
536 if (params.size() != 1) { 541 if (params.size() != 1) {
537 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 542 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
538 return FALSE; 543 return FALSE;
539 } 544 }
540 545
541 if (params[0].GetType() == VT_fxobject) { 546 if (params[0].GetType() == VT_fxobject) {
542 JSFXObject pObj = params[0].ToV8Object(); 547 v8::Local<v8::Object> pObj = params[0].ToV8Object();
543 { 548 {
544 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { 549 if (JS_GetObjDefnID(pObj) ==
550 JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
545 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { 551 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
546 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { 552 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
547 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { 553 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
548 pTimer->KillJSTimer(); 554 pTimer->KillJSTimer();
549 555
550 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { 556 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
551 if (m_aTimer[i] == pTimer) { 557 if (m_aTimer[i] == pTimer) {
552 m_aTimer.RemoveAt(i); 558 m_aTimer.RemoveAt(i);
553 break; 559 break;
554 } 560 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 CFX_WideString cTo = L""; 635 CFX_WideString cTo = L"";
630 CFX_WideString cCc = L""; 636 CFX_WideString cCc = L"";
631 CFX_WideString cBcc = L""; 637 CFX_WideString cBcc = L"";
632 CFX_WideString cSubject = L""; 638 CFX_WideString cSubject = L"";
633 CFX_WideString cMsg = L""; 639 CFX_WideString cMsg = L"";
634 640
635 if (params.size() < 1) 641 if (params.size() < 1)
636 return FALSE; 642 return FALSE;
637 643
638 if (params[0].GetType() == VT_object) { 644 if (params[0].GetType() == VT_object) {
639 JSObject pObj = params[0].ToV8Object(); 645 v8::Local<v8::Object> pObj = params[0].ToV8Object();
640 646
641 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); 647 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
642 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); 648 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
643 649
644 pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); 650 pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
645 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); 651 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
646 652
647 pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); 653 pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
648 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); 654 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
649 655
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 CFX_WideString swQuestion = L""; 773 CFX_WideString swQuestion = L"";
768 CFX_WideString swLabel = L""; 774 CFX_WideString swLabel = L"";
769 CFX_WideString swTitle = L"PDF"; 775 CFX_WideString swTitle = L"PDF";
770 CFX_WideString swDefault = L""; 776 CFX_WideString swDefault = L"";
771 bool bPassWord = false; 777 bool bPassWord = false;
772 778
773 v8::Isolate* isolate = GetIsolate(cc); 779 v8::Isolate* isolate = GetIsolate(cc);
774 780
775 int iLength = params.size(); 781 int iLength = params.size();
776 if (iLength > 0 && params[0].GetType() == VT_object) { 782 if (iLength > 0 && params[0].GetType() == VT_object) {
777 JSObject pObj = params[0].ToV8Object(); 783 v8::Local<v8::Object> pObj = params[0].ToV8Object();
778 v8::Local<v8::Value> pValue = 784 v8::Local<v8::Value> pValue =
779 JS_GetObjectElement(isolate, pObj, L"cQuestion"); 785 JS_GetObjectElement(isolate, pObj, L"cQuestion");
780 swQuestion = 786 swQuestion =
781 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); 787 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
782 788
783 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle"); 789 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
784 swTitle = 790 swTitle =
785 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); 791 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
786 792
787 pValue = JS_GetObjectElement(isolate, pObj, L"cDefault"); 793 pValue = JS_GetObjectElement(isolate, pObj, L"cDefault");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 CFX_WideString& sError) { 851 CFX_WideString& sError) {
846 return FALSE; 852 return FALSE;
847 } 853 }
848 854
849 FX_BOOL app::execDialog(IFXJS_Context* cc, 855 FX_BOOL app::execDialog(IFXJS_Context* cc,
850 const CJS_Parameters& params, 856 const CJS_Parameters& params,
851 CJS_Value& vRet, 857 CJS_Value& vRet,
852 CFX_WideString& sError) { 858 CFX_WideString& sError) {
853 return TRUE; 859 return TRUE;
854 } 860 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Value.cpp ('k') | fpdfsdk/src/javascript/global.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698