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

Side by Side Diff: fpdfsdk/fsdk_actionhandler.cpp

Issue 2394313002: Convert IJS_Runtime to CPDFSDK_FormFillEnvironment (Closed)
Patch Set: Rebase to master Created 4 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
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 "fpdfsdk/fsdk_actionhandler.h" 7 #include "fpdfsdk/fsdk_actionhandler.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 visited->insert(pDict); 149 visited->insert(pDict);
150 150
151 CPDFSDK_FormFillEnvironment* pFormFillEnv = pDocument->GetEnv(); 151 CPDFSDK_FormFillEnvironment* pFormFillEnv = pDocument->GetEnv();
152 ASSERT(pFormFillEnv); 152 ASSERT(pFormFillEnv);
153 if (action.GetType() == CPDF_Action::JavaScript) { 153 if (action.GetType() == CPDF_Action::JavaScript) {
154 if (pFormFillEnv->IsJSInitiated()) { 154 if (pFormFillEnv->IsJSInitiated()) {
155 CFX_WideString swJS = action.GetJavaScript(); 155 CFX_WideString swJS = action.GetJavaScript();
156 if (!swJS.IsEmpty()) { 156 if (!swJS.IsEmpty()) {
157 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime(); 157 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
158 pRuntime->SetReaderDocument(pDocument);
dsinclair 2016/10/11 17:37:45 We got the env from the Document, then get the run
159
160 IJS_Context* pContext = pRuntime->NewContext(); 158 IJS_Context* pContext = pRuntime->NewContext();
161 pContext->OnLink_MouseUp(pFormFillEnv); 159 pContext->OnLink_MouseUp(pFormFillEnv);
162 160
163 CFX_WideString csInfo; 161 CFX_WideString csInfo;
164 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); 162 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo);
165 if (!bRet) { 163 if (!bRet) {
166 // FIXME: return error. 164 // FIXME: return error.
167 } 165 }
168 166
169 pRuntime->ReleaseContext(pContext); 167 pRuntime->ReleaseContext(pContext);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 275
278 visited->insert(pDict); 276 visited->insert(pDict);
279 277
280 CPDFSDK_FormFillEnvironment* pEnv = pDocument->GetEnv(); 278 CPDFSDK_FormFillEnvironment* pEnv = pDocument->GetEnv();
281 ASSERT(pEnv); 279 ASSERT(pEnv);
282 if (action.GetType() == CPDF_Action::JavaScript) { 280 if (action.GetType() == CPDF_Action::JavaScript) {
283 if (pEnv->IsJSInitiated()) { 281 if (pEnv->IsJSInitiated()) {
284 CFX_WideString swJS = action.GetJavaScript(); 282 CFX_WideString swJS = action.GetJavaScript();
285 if (!swJS.IsEmpty()) { 283 if (!swJS.IsEmpty()) {
286 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 284 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
287 pRuntime->SetReaderDocument(pDocument);
288
289 IJS_Context* pContext = pRuntime->NewContext(); 285 IJS_Context* pContext = pRuntime->NewContext();
290 CFX_WideString csInfo; 286 CFX_WideString csInfo;
291 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); 287 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo);
292 if (!bRet) { 288 if (!bRet) {
293 // FIXME: return error. 289 // FIXME: return error.
294 } 290 }
295 291
296 pRuntime->ReleaseContext(pContext); 292 pRuntime->ReleaseContext(pContext);
297 } 293 }
298 } 294 }
(...skipping 21 matching lines...) Expand all
320 316
321 visited->insert(pDict); 317 visited->insert(pDict);
322 318
323 CPDFSDK_FormFillEnvironment* pEnv = pDocument->GetEnv(); 319 CPDFSDK_FormFillEnvironment* pEnv = pDocument->GetEnv();
324 ASSERT(pEnv); 320 ASSERT(pEnv);
325 if (action.GetType() == CPDF_Action::JavaScript) { 321 if (action.GetType() == CPDF_Action::JavaScript) {
326 if (pEnv->IsJSInitiated()) { 322 if (pEnv->IsJSInitiated()) {
327 CFX_WideString swJS = action.GetJavaScript(); 323 CFX_WideString swJS = action.GetJavaScript();
328 if (!swJS.IsEmpty()) { 324 if (!swJS.IsEmpty()) {
329 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 325 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
330 pRuntime->SetReaderDocument(pDocument);
331
332 IJS_Context* pContext = pRuntime->NewContext(); 326 IJS_Context* pContext = pRuntime->NewContext();
333 pContext->OnBookmark_MouseUp(pBookmark); 327 pContext->OnBookmark_MouseUp(pBookmark);
334 328
335 CFX_WideString csInfo; 329 CFX_WideString csInfo;
336 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); 330 FX_BOOL bRet = pContext->RunScript(swJS, &csInfo);
337 if (!bRet) { 331 if (!bRet) {
338 // FIXME: return error. 332 // FIXME: return error.
339 } 333 }
340 334
341 pRuntime->ReleaseContext(pContext); 335 pRuntime->ReleaseContext(pContext);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 465
472 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, 466 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
473 CPDF_FormField* pFormField, 467 CPDF_FormField* pFormField,
474 CPDF_AAction::AActionType type, 468 CPDF_AAction::AActionType type,
475 PDFSDK_FieldAction& data, 469 PDFSDK_FieldAction& data,
476 const CFX_WideString& script) { 470 const CFX_WideString& script) {
477 ASSERT(type != CPDF_AAction::Calculate); 471 ASSERT(type != CPDF_AAction::Calculate);
478 ASSERT(type != CPDF_AAction::Format); 472 ASSERT(type != CPDF_AAction::Format);
479 473
480 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 474 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
481 pRuntime->SetReaderDocument(pDocument);
482
483 IJS_Context* pContext = pRuntime->NewContext(); 475 IJS_Context* pContext = pRuntime->NewContext();
484 switch (type) { 476 switch (type) {
485 case CPDF_AAction::CursorEnter: 477 case CPDF_AAction::CursorEnter:
486 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField); 478 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
487 break; 479 break;
488 case CPDF_AAction::CursorExit: 480 case CPDF_AAction::CursorExit:
489 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField); 481 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
490 break; 482 break;
491 case CPDF_AAction::ButtonDown: 483 case CPDF_AAction::ButtonDown:
492 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField); 484 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 517 }
526 518
527 pRuntime->ReleaseContext(pContext); 519 pRuntime->ReleaseContext(pContext);
528 } 520 }
529 521
530 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript( 522 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
531 CPDFSDK_Document* pDocument, 523 CPDFSDK_Document* pDocument,
532 const CFX_WideString& sScriptName, 524 const CFX_WideString& sScriptName,
533 const CFX_WideString& script) { 525 const CFX_WideString& script) {
534 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 526 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
535 pRuntime->SetReaderDocument(pDocument);
536 IJS_Context* pContext = pRuntime->NewContext(); 527 IJS_Context* pContext = pRuntime->NewContext();
537 pContext->OnDoc_Open(pDocument->GetEnv(), sScriptName); 528 pContext->OnDoc_Open(pDocument->GetEnv(), sScriptName);
538 529
539 CFX_WideString csInfo; 530 CFX_WideString csInfo;
540 FX_BOOL bRet = pContext->RunScript(script, &csInfo); 531 FX_BOOL bRet = pContext->RunScript(script, &csInfo);
541 if (!bRet) { 532 if (!bRet) {
542 // FIXME: return error. 533 // FIXME: return error.
543 } 534 }
544 535
545 pRuntime->ReleaseContext(pContext); 536 pRuntime->ReleaseContext(pContext);
546 } 537 }
547 538
548 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( 539 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
549 CPDFSDK_Document* pDocument, 540 CPDFSDK_Document* pDocument,
550 CPDF_AAction::AActionType type, 541 CPDF_AAction::AActionType type,
551 const CFX_WideString& script) { 542 const CFX_WideString& script) {
552 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 543 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
553 pRuntime->SetReaderDocument(pDocument);
554
555 IJS_Context* pContext = pRuntime->NewContext(); 544 IJS_Context* pContext = pRuntime->NewContext();
556 switch (type) { 545 switch (type) {
557 case CPDF_AAction::OpenPage: 546 case CPDF_AAction::OpenPage:
558 pContext->OnPage_Open(pDocument->GetEnv()); 547 pContext->OnPage_Open(pDocument->GetEnv());
559 break; 548 break;
560 case CPDF_AAction::ClosePage: 549 case CPDF_AAction::ClosePage:
561 pContext->OnPage_Close(pDocument->GetEnv()); 550 pContext->OnPage_Close(pDocument->GetEnv());
562 break; 551 break;
563 case CPDF_AAction::CloseDocument: 552 case CPDF_AAction::CloseDocument:
564 pContext->OnDoc_WillClose(pDocument->GetEnv()); 553 pContext->OnDoc_WillClose(pDocument->GetEnv());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 const CPDF_Action& action, 612 const CPDF_Action& action,
624 CPDFSDK_Document* pDocument) { 613 CPDFSDK_Document* pDocument) {
625 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); 614 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
626 if (pInterForm->DoAction_ImportData(action)) { 615 if (pInterForm->DoAction_ImportData(action)) {
627 pDocument->SetChangeMark(); 616 pDocument->SetChangeMark();
628 return TRUE; 617 return TRUE;
629 } 618 }
630 619
631 return FALSE; 620 return FALSE;
632 } 621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698