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

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

Issue 2227673005: Remove backpointer to CJS_Runtime from CJS_Value (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase Created 4 years, 4 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 | « no previous file | fpdfsdk/javascript/Field.cpp » ('j') | fpdfsdk/javascript/Field.cpp » ('J')
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 "fpdfsdk/javascript/Document.h" 7 #include "fpdfsdk/javascript/Document.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 else 194 else
195 m_pDocument->ClearChangeMark(); 195 m_pDocument->ClearChangeMark();
196 } 196 }
197 197
198 return TRUE; 198 return TRUE;
199 } 199 }
200 200
201 FX_BOOL Document::ADBE(IJS_Context* cc, 201 FX_BOOL Document::ADBE(IJS_Context* cc,
202 CJS_PropValue& vp, 202 CJS_PropValue& vp,
203 CFX_WideString& sError) { 203 CFX_WideString& sError) {
204 if (vp.IsGetting()) { 204 if (vp.IsGetting())
205 vp.SetNull(); 205 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc));
206 } else {
207 }
208 206
209 return TRUE; 207 return TRUE;
210 } 208 }
211 209
212 FX_BOOL Document::pageNum(IJS_Context* cc, 210 FX_BOOL Document::pageNum(IJS_Context* cc,
213 CJS_PropValue& vp, 211 CJS_PropValue& vp,
214 CFX_WideString& sError) { 212 CFX_WideString& sError) {
215 if (vp.IsGetting()) { 213 if (vp.IsGetting()) {
216 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { 214 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) {
217 vp << pPageView->GetPageIndex(); 215 vp << pPageView->GetPageIndex();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 274
277 // Maps a field object in PDF document to a JavaScript variable 275 // Maps a field object in PDF document to a JavaScript variable
278 // comment: 276 // comment:
279 // note: the paremter cName, this is clue how to treat if the cName is not a 277 // note: the paremter cName, this is clue how to treat if the cName is not a
280 // valiable filed name in this document 278 // valiable filed name in this document
281 279
282 FX_BOOL Document::getField(IJS_Context* cc, 280 FX_BOOL Document::getField(IJS_Context* cc,
283 const std::vector<CJS_Value>& params, 281 const std::vector<CJS_Value>& params,
284 CJS_Value& vRet, 282 CJS_Value& vRet,
285 CFX_WideString& sError) { 283 CFX_WideString& sError) {
286 CJS_Context* pContext = (CJS_Context*)cc; 284 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
285 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:33 Move 285 and 286 down to 293 where they're first n
Tom Sepez 2016/08/09 20:33:23 Done.
286 v8::Isolate* pIsolate = pRuntime->GetIsolate();
287
287 if (params.size() < 1) { 288 if (params.size() < 1) {
288 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 289 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
289 return FALSE; 290 return FALSE;
290 } 291 }
291 292
292 CFX_WideString wideName = params[0].ToCFXWideString(); 293 CFX_WideString wideName = params[0].ToCFXWideString(pIsolate);
293 294
294 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 295 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
295 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 296 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
296 if (pPDFForm->CountFields(wideName) <= 0) { 297 if (pPDFForm->CountFields(wideName) <= 0) {
297 vRet.SetNull(); 298 vRet.SetNull(pRuntime);
298 return TRUE; 299 return TRUE;
299 } 300 }
300 301
301 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 302 v8::Local<v8::Object> pFieldObj =
302 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj( 303 FXJS_NewFxDynamicObj(pIsolate, pRuntime, CJS_Field::g_nObjDefnID);
dsinclair 2016/08/09 19:25:32 Does this always take the isolate from the runtime
Tom Sepez 2016/08/09 20:33:23 That's a follow-on. Ideally, there'd be a CFXJS_R
303 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
304 304
305 v8::Isolate* isolate = GetIsolate(cc); 305 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pIsolate, pFieldObj);
dsinclair 2016/08/09 19:25:32 static_cast
Tom Sepez 2016/08/09 20:33:24 Done.
306 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
307 Field* pField = (Field*)pJSField->GetEmbedObject(); 306 Field* pField = (Field*)pJSField->GetEmbedObject();
dsinclair 2016/08/09 19:25:32 static_cast
Tom Sepez 2016/08/09 20:33:24 Done.
308 pField->AttachField(this, wideName); 307 pField->AttachField(this, wideName);
309 308
310 vRet = pJSField; 309 vRet = CJS_Value(pRuntime, pJSField);
311 return TRUE; 310 return TRUE;
312 } 311 }
313 312
314 // Gets the name of the nth field in the document 313 // Gets the name of the nth field in the document
315 FX_BOOL Document::getNthFieldName(IJS_Context* cc, 314 FX_BOOL Document::getNthFieldName(IJS_Context* cc,
316 const std::vector<CJS_Value>& params, 315 const std::vector<CJS_Value>& params,
317 CJS_Value& vRet, 316 CJS_Value& vRet,
318 CFX_WideString& sError) { 317 CFX_WideString& sError) {
319 CJS_Context* pContext = (CJS_Context*)cc; 318 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
319 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:32 Down to 327?
Tom Sepez 2016/08/09 20:33:23 Done.
320 v8::Isolate* pIsolate = pRuntime->GetIsolate();
321
320 if (params.size() != 1) { 322 if (params.size() != 1) {
321 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 323 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
322 return FALSE; 324 return FALSE;
323 } 325 }
324 326
325 int nIndex = params[0].ToInt(); 327 int nIndex = params[0].ToInt(pIsolate);
326 if (nIndex < 0) { 328 if (nIndex < 0) {
327 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); 329 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
328 return FALSE; 330 return FALSE;
329 } 331 }
330 332
331 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 333 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
332 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 334 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
333 CPDF_FormField* pField = pPDFForm->GetField(nIndex); 335 CPDF_FormField* pField = pPDFForm->GetField(nIndex);
334 if (!pField) 336 if (!pField)
335 return FALSE; 337 return FALSE;
336 338
337 vRet = pField->GetFullName().c_str(); 339 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str());
338 return TRUE; 340 return TRUE;
339 } 341 }
340 342
341 FX_BOOL Document::importAnFDF(IJS_Context* cc, 343 FX_BOOL Document::importAnFDF(IJS_Context* cc,
342 const std::vector<CJS_Value>& params, 344 const std::vector<CJS_Value>& params,
343 CJS_Value& vRet, 345 CJS_Value& vRet,
344 CFX_WideString& sError) { 346 CFX_WideString& sError) {
345 // Unsafe, not supported. 347 // Unsafe, not supported.
346 return TRUE; 348 return TRUE;
347 } 349 }
(...skipping 18 matching lines...) Expand all
366 // all recipients. 368 // all recipients.
367 // comment: need reader supports 369 // comment: need reader supports
368 // note: 370 // note:
369 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string 371 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string
370 // cbcc,string cSubject,string cms); 372 // cbcc,string cSubject,string cms);
371 373
372 FX_BOOL Document::mailForm(IJS_Context* cc, 374 FX_BOOL Document::mailForm(IJS_Context* cc,
373 const std::vector<CJS_Value>& params, 375 const std::vector<CJS_Value>& params,
374 CJS_Value& vRet, 376 CJS_Value& vRet,
375 CFX_WideString& sError) { 377 CFX_WideString& sError) {
378 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
379 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
380 v8::Isolate* pIsolate = pRuntime->GetIsolate();
dsinclair 2016/08/09 19:25:32 Down to 387
Tom Sepez 2016/08/09 20:33:23 Done.
381
376 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) 382 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
377 return FALSE; 383 return FALSE;
378 384
379 int iLength = params.size(); 385 int iLength = params.size();
380 386
381 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; 387 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pIsolate) : TRUE;
382 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; 388 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pIsolate) : L"";
383 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; 389 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pIsolate) : L"";
384 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; 390 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pIsolate) : L"";
385 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; 391 CFX_WideString cSubject =
386 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; 392 iLength > 4 ? params[4].ToCFXWideString(pIsolate) : L"";
393 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pIsolate) : L"";
387 394
388 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 395 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
389 CFX_ByteTextBuf textBuf; 396 CFX_ByteTextBuf textBuf;
390 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) 397 if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
391 return FALSE; 398 return FALSE;
392 399
393 CJS_Context* pContext = (CJS_Context*)cc; 400 pRuntime->BeginBlock();
394 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); 401 CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
dsinclair 2016/08/09 19:25:32 This was outside the Begin/End block previously, n
Tom Sepez 2016/08/09 20:33:23 Nope, it just guards against re-entrancy in the em
395 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
396
397 pRuntime->BeginBlock();
398 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, 402 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
399 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), 403 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(),
400 cMsg.c_str()); 404 cMsg.c_str());
401 pRuntime->EndBlock(); 405 pRuntime->EndBlock();
402 return TRUE; 406 return TRUE;
403 } 407 }
404 408
405 FX_BOOL Document::print(IJS_Context* cc, 409 FX_BOOL Document::print(IJS_Context* cc,
406 const std::vector<CJS_Value>& params, 410 const std::vector<CJS_Value>& params,
407 CJS_Value& vRet, 411 CJS_Value& vRet,
408 CFX_WideString& sError) { 412 CFX_WideString& sError) {
413 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
414 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
415 v8::Isolate* pIsolate = pRuntime->GetIsolate();
416
409 FX_BOOL bUI = TRUE; 417 FX_BOOL bUI = TRUE;
410 int nStart = 0; 418 int nStart = 0;
411 int nEnd = 0; 419 int nEnd = 0;
412 FX_BOOL bSilent = FALSE; 420 FX_BOOL bSilent = FALSE;
413 FX_BOOL bShrinkToFit = FALSE; 421 FX_BOOL bShrinkToFit = FALSE;
414 FX_BOOL bPrintAsImage = FALSE; 422 FX_BOOL bPrintAsImage = FALSE;
415 FX_BOOL bReverse = FALSE; 423 FX_BOOL bReverse = FALSE;
416 FX_BOOL bAnnotations = FALSE; 424 FX_BOOL bAnnotations = FALSE;
417 425
418 int nlength = params.size(); 426 int nlength = params.size();
419 if (nlength == 9) { 427 if (nlength == 9) {
420 if (params[8].GetType() == CJS_Value::VT_object) { 428 if (params[8].GetType() == CJS_Value::VT_object) {
421 v8::Local<v8::Object> pObj = params[8].ToV8Object(); 429 v8::Local<v8::Object> pObj = params[8].ToV8Object(pIsolate);
422 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { 430 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) {
423 if (CJS_Object* pJSObj = params[8].ToCJSObject()) { 431 if (CJS_Object* pJSObj = params[8].ToCJSObject(pIsolate)) {
424 if (PrintParamsObj* pprintparamsObj = 432 if (PrintParamsObj* pprintparamsObj =
425 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { 433 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) {
426 bUI = pprintparamsObj->bUI; 434 bUI = pprintparamsObj->bUI;
427 nStart = pprintparamsObj->nStart; 435 nStart = pprintparamsObj->nStart;
428 nEnd = pprintparamsObj->nEnd; 436 nEnd = pprintparamsObj->nEnd;
429 bSilent = pprintparamsObj->bSilent; 437 bSilent = pprintparamsObj->bSilent;
430 bShrinkToFit = pprintparamsObj->bShrinkToFit; 438 bShrinkToFit = pprintparamsObj->bShrinkToFit;
431 bPrintAsImage = pprintparamsObj->bPrintAsImage; 439 bPrintAsImage = pprintparamsObj->bPrintAsImage;
432 bReverse = pprintparamsObj->bReverse; 440 bReverse = pprintparamsObj->bReverse;
433 bAnnotations = pprintparamsObj->bAnnotations; 441 bAnnotations = pprintparamsObj->bAnnotations;
434 } 442 }
435 } 443 }
436 } 444 }
437 } 445 }
438 } else { 446 } else {
439 if (nlength >= 1) 447 if (nlength >= 1)
440 bUI = params[0].ToBool(); 448 bUI = params[0].ToBool(pIsolate);
441 if (nlength >= 2) 449 if (nlength >= 2)
442 nStart = params[1].ToInt(); 450 nStart = params[1].ToInt(pIsolate);
443 if (nlength >= 3) 451 if (nlength >= 3)
444 nEnd = params[2].ToInt(); 452 nEnd = params[2].ToInt(pIsolate);
445 if (nlength >= 4) 453 if (nlength >= 4)
446 bSilent = params[3].ToBool(); 454 bSilent = params[3].ToBool(pIsolate);
447 if (nlength >= 5) 455 if (nlength >= 5)
448 bShrinkToFit = params[4].ToBool(); 456 bShrinkToFit = params[4].ToBool(pIsolate);
449 if (nlength >= 6) 457 if (nlength >= 6)
450 bPrintAsImage = params[5].ToBool(); 458 bPrintAsImage = params[5].ToBool(pIsolate);
451 if (nlength >= 7) 459 if (nlength >= 7)
452 bReverse = params[6].ToBool(); 460 bReverse = params[6].ToBool(pIsolate);
453 if (nlength >= 8) 461 if (nlength >= 8)
454 bAnnotations = params[7].ToBool(); 462 bAnnotations = params[7].ToBool(pIsolate);
455 } 463 }
456 464
457 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { 465 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) {
458 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, 466 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage,
459 bReverse, bAnnotations); 467 bReverse, bAnnotations);
460 return TRUE; 468 return TRUE;
461 } 469 }
462 return FALSE; 470 return FALSE;
463 } 471 }
464 472
465 // removes the specified field from the document. 473 // removes the specified field from the document.
466 // comment: 474 // comment:
467 // note: if the filed name is not retional, adobe is dumb for it. 475 // note: if the filed name is not retional, adobe is dumb for it.
468 476
469 FX_BOOL Document::removeField(IJS_Context* cc, 477 FX_BOOL Document::removeField(IJS_Context* cc,
470 const std::vector<CJS_Value>& params, 478 const std::vector<CJS_Value>& params,
471 CJS_Value& vRet, 479 CJS_Value& vRet,
472 CFX_WideString& sError) { 480 CFX_WideString& sError) {
481 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
482 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
483 v8::Isolate* pIsolate = pRuntime->GetIsolate();
dsinclair 2016/08/09 19:25:32 Move to 488?
Tom Sepez 2016/08/09 20:33:23 Done.
484
473 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || 485 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
474 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) 486 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM)))
475 return FALSE; 487 return FALSE;
476 488
477 CJS_Context* pContext = (CJS_Context*)cc;
478 if (params.size() != 1) { 489 if (params.size() != 1) {
479 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 490 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
480 return FALSE; 491 return FALSE;
481 } 492 }
482 493
483 CFX_WideString sFieldName = params[0].ToCFXWideString(); 494 CFX_WideString sFieldName = params[0].ToCFXWideString(pIsolate);
484 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 495 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
485 std::vector<CPDFSDK_Widget*> widgets; 496 std::vector<CPDFSDK_Widget*> widgets;
486 pInterForm->GetWidgets(sFieldName, &widgets); 497 pInterForm->GetWidgets(sFieldName, &widgets);
487 if (widgets.empty()) 498 if (widgets.empty())
488 return TRUE; 499 return TRUE;
489 500
490 for (CPDFSDK_Widget* pWidget : widgets) { 501 for (CPDFSDK_Widget* pWidget : widgets) {
491 CFX_FloatRect rcAnnot = pWidget->GetRect(); 502 CFX_FloatRect rcAnnot = pWidget->GetRect();
492 --rcAnnot.left; 503 --rcAnnot.left;
493 --rcAnnot.bottom; 504 --rcAnnot.bottom;
(...skipping 14 matching lines...) Expand all
508 } 519 }
509 520
510 // reset filed values within a document. 521 // reset filed values within a document.
511 // comment: 522 // comment:
512 // note: if the fields names r not rational, aodbe is dumb for it. 523 // note: if the fields names r not rational, aodbe is dumb for it.
513 524
514 FX_BOOL Document::resetForm(IJS_Context* cc, 525 FX_BOOL Document::resetForm(IJS_Context* cc,
515 const std::vector<CJS_Value>& params, 526 const std::vector<CJS_Value>& params,
516 CJS_Value& vRet, 527 CJS_Value& vRet,
517 CFX_WideString& sError) { 528 CFX_WideString& sError) {
529 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
530 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
531 v8::Isolate* pIsolate = pRuntime->GetIsolate();
dsinclair 2016/08/09 19:25:32 Move to 548?
Tom Sepez 2016/08/09 20:33:23 Done.
532
518 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || 533 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
519 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || 534 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
520 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) 535 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
521 return FALSE; 536 return FALSE;
522 537
523 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 538 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
524 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 539 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
525 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
526 CJS_Array aName; 540 CJS_Array aName;
527 541
528 if (params.empty()) { 542 if (params.empty()) {
529 pPDFForm->ResetForm(TRUE); 543 pPDFForm->ResetForm(TRUE);
530 m_pDocument->SetChangeMark(); 544 m_pDocument->SetChangeMark();
531 return TRUE; 545 return TRUE;
532 } 546 }
533 547
534 switch (params[0].GetType()) { 548 switch (params[0].GetType()) {
535 default: 549 default:
536 aName.Attach(params[0].ToV8Array()); 550 aName.Attach(params[0].ToV8Array(pIsolate));
537 break; 551 break;
538 case CJS_Value::VT_string: 552 case CJS_Value::VT_string:
539 aName.SetElement(pRuntime->GetIsolate(), 0, params[0]); 553 aName.SetElement(pRuntime->GetIsolate(), 0, params[0]);
540 break; 554 break;
541 } 555 }
542 556
543 std::vector<CPDF_FormField*> aFields; 557 std::vector<CPDF_FormField*> aFields;
544 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { 558 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) {
545 CJS_Value valElement(pRuntime); 559 CJS_Value valElement(pRuntime);
546 aName.GetElement(pRuntime->GetIsolate(), i, valElement); 560 aName.GetElement(pRuntime->GetIsolate(), i, valElement);
547 CFX_WideString swVal = valElement.ToCFXWideString(); 561 CFX_WideString swVal = valElement.ToCFXWideString(pIsolate);
548 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) 562 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
549 aFields.push_back(pPDFForm->GetField(j, swVal)); 563 aFields.push_back(pPDFForm->GetField(j, swVal));
550 } 564 }
551 565
552 if (!aFields.empty()) { 566 if (!aFields.empty()) {
553 pPDFForm->ResetForm(aFields, TRUE, TRUE); 567 pPDFForm->ResetForm(aFields, TRUE, TRUE);
554 m_pDocument->SetChangeMark(); 568 m_pDocument->SetChangeMark();
555 } 569 }
556 570
557 return TRUE; 571 return TRUE;
558 } 572 }
559 573
560 FX_BOOL Document::saveAs(IJS_Context* cc, 574 FX_BOOL Document::saveAs(IJS_Context* cc,
561 const std::vector<CJS_Value>& params, 575 const std::vector<CJS_Value>& params,
562 CJS_Value& vRet, 576 CJS_Value& vRet,
563 CFX_WideString& sError) { 577 CFX_WideString& sError) {
564 // Unsafe, not supported. 578 // Unsafe, not supported.
565 return TRUE; 579 return TRUE;
566 } 580 }
567 581
568 FX_BOOL Document::submitForm(IJS_Context* cc, 582 FX_BOOL Document::submitForm(IJS_Context* cc,
569 const std::vector<CJS_Value>& params, 583 const std::vector<CJS_Value>& params,
570 CJS_Value& vRet, 584 CJS_Value& vRet,
571 CFX_WideString& sError) { 585 CFX_WideString& sError) {
572 CJS_Context* pContext = (CJS_Context*)cc; 586 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
587 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:32 Move to 596?
Tom Sepez 2016/08/09 20:33:23 Done.
588 v8::Isolate* pIsolate = pRuntime->GetIsolate();
589
573 int nSize = params.size(); 590 int nSize = params.size();
574 if (nSize < 1) { 591 if (nSize < 1) {
575 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 592 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
576 return FALSE; 593 return FALSE;
577 } 594 }
578 595
579 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
580 v8::Isolate* isolate = pRuntime->GetIsolate(); 596 v8::Isolate* isolate = pRuntime->GetIsolate();
581 CJS_Array aFields; 597 CJS_Array aFields;
582 CFX_WideString strURL; 598 CFX_WideString strURL;
583 FX_BOOL bFDF = TRUE; 599 FX_BOOL bFDF = TRUE;
584 FX_BOOL bEmpty = FALSE; 600 FX_BOOL bEmpty = FALSE;
585 601
586 CJS_Value v = params[0]; 602 CJS_Value v = params[0];
587 if (v.GetType() == CJS_Value::VT_string) { 603 if (v.GetType() == CJS_Value::VT_string) {
588 strURL = params[0].ToCFXWideString(); 604 strURL = params[0].ToCFXWideString(pIsolate);
589 if (nSize > 1) 605 if (nSize > 1)
590 bFDF = params[1].ToBool(); 606 bFDF = params[1].ToBool(pIsolate);
591 if (nSize > 2) 607 if (nSize > 2)
592 bEmpty = params[2].ToBool(); 608 bEmpty = params[2].ToBool(pIsolate);
593 if (nSize > 3) 609 if (nSize > 3)
594 aFields.Attach(params[3].ToV8Array()); 610 aFields.Attach(params[3].ToV8Array(pIsolate));
595 } else if (v.GetType() == CJS_Value::VT_object) { 611 } else if (v.GetType() == CJS_Value::VT_object) {
596 v8::Local<v8::Object> pObj = params[0].ToV8Object(); 612 v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate);
597 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL"); 613 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL");
598 if (!pValue.IsEmpty()) 614 if (!pValue.IsEmpty())
599 strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(); 615 strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
600 616
601 pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF"); 617 pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF");
602 bFDF = CJS_Value(pRuntime, pValue).ToBool(); 618 bFDF = CJS_Value(pRuntime, pValue).ToBool(pIsolate);
603 619
604 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); 620 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty");
605 bEmpty = CJS_Value(pRuntime, pValue).ToBool(); 621 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pIsolate);
606 622
607 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); 623 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
608 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array()); 624 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pIsolate));
609 } 625 }
610 626
611 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 627 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
612 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 628 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
613 if (aFields.GetLength() == 0 && bEmpty) { 629 if (aFields.GetLength() == 0 && bEmpty) {
614 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { 630 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) {
615 pRuntime->BeginBlock(); 631 pRuntime->BeginBlock();
616 pInterForm->SubmitForm(strURL, FALSE); 632 pInterForm->SubmitForm(strURL, FALSE);
617 pRuntime->EndBlock(); 633 pRuntime->EndBlock();
618 } 634 }
619 return TRUE; 635 return TRUE;
620 } 636 }
621 637
622 std::vector<CPDF_FormField*> fieldObjects; 638 std::vector<CPDF_FormField*> fieldObjects;
623 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { 639 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) {
624 CJS_Value valName(pRuntime); 640 CJS_Value valName(pRuntime);
625 aFields.GetElement(pRuntime->GetIsolate(), i, valName); 641 aFields.GetElement(pRuntime->GetIsolate(), i, valName);
626 642
627 CFX_WideString sName = valName.ToCFXWideString(); 643 CFX_WideString sName = valName.ToCFXWideString(pIsolate);
628 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 644 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
629 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { 645 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) {
630 CPDF_FormField* pField = pPDFForm->GetField(j, sName); 646 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
631 if (!bEmpty && pField->GetValue().IsEmpty()) 647 if (!bEmpty && pField->GetValue().IsEmpty())
632 continue; 648 continue;
633 649
634 fieldObjects.push_back(pField); 650 fieldObjects.push_back(pField);
635 } 651 }
636 } 652 }
637 653
(...skipping 16 matching lines...) Expand all
654 FX_BOOL Document::bookmarkRoot(IJS_Context* cc, 670 FX_BOOL Document::bookmarkRoot(IJS_Context* cc,
655 CJS_PropValue& vp, 671 CJS_PropValue& vp,
656 CFX_WideString& sError) { 672 CFX_WideString& sError) {
657 return TRUE; 673 return TRUE;
658 } 674 }
659 675
660 FX_BOOL Document::mailDoc(IJS_Context* cc, 676 FX_BOOL Document::mailDoc(IJS_Context* cc,
661 const std::vector<CJS_Value>& params, 677 const std::vector<CJS_Value>& params,
662 CJS_Value& vRet, 678 CJS_Value& vRet,
663 CFX_WideString& sError) { 679 CFX_WideString& sError) {
680 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
681 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:33 ...
Tom Sepez 2016/08/09 20:33:23 Done.
682 v8::Isolate* pIsolate = pRuntime->GetIsolate();
683
664 FX_BOOL bUI = TRUE; 684 FX_BOOL bUI = TRUE;
665 CFX_WideString cTo = L""; 685 CFX_WideString cTo = L"";
666 CFX_WideString cCc = L""; 686 CFX_WideString cCc = L"";
667 CFX_WideString cBcc = L""; 687 CFX_WideString cBcc = L"";
668 CFX_WideString cSubject = L""; 688 CFX_WideString cSubject = L"";
669 CFX_WideString cMsg = L""; 689 CFX_WideString cMsg = L"";
670 690
671 if (params.size() >= 1) 691 if (params.size() >= 1)
672 bUI = params[0].ToBool(); 692 bUI = params[0].ToBool(pIsolate);
673 if (params.size() >= 2) 693 if (params.size() >= 2)
674 cTo = params[1].ToCFXWideString(); 694 cTo = params[1].ToCFXWideString(pIsolate);
675 if (params.size() >= 3) 695 if (params.size() >= 3)
676 cCc = params[2].ToCFXWideString(); 696 cCc = params[2].ToCFXWideString(pIsolate);
677 if (params.size() >= 4) 697 if (params.size() >= 4)
678 cBcc = params[3].ToCFXWideString(); 698 cBcc = params[3].ToCFXWideString(pIsolate);
679 if (params.size() >= 5) 699 if (params.size() >= 5)
680 cSubject = params[4].ToCFXWideString(); 700 cSubject = params[4].ToCFXWideString(pIsolate);
681 if (params.size() >= 6) 701 if (params.size() >= 6)
682 cMsg = params[5].ToCFXWideString(); 702 cMsg = params[5].ToCFXWideString(pIsolate);
683
684 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
685 v8::Isolate* isolate = pRuntime->GetIsolate();
686 703
687 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { 704 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
688 v8::Local<v8::Object> pObj = params[0].ToV8Object(); 705 v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate);
689 706
690 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI"); 707 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(pIsolate, pObj, L"bUI");
691 bUI = CJS_Value(pRuntime, pValue).ToInt(); 708 bUI = CJS_Value(pRuntime, pValue).ToInt(pIsolate);
692 709
693 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo"); 710 pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cTo");
694 cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(); 711 cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
695 712
696 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc"); 713 pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cCc");
697 cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(); 714 cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
698 715
699 pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc"); 716 pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cBcc");
700 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(); 717 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
701 718
702 pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject"); 719 pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cSubject");
703 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(); 720 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
704 721
705 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); 722 pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cMsg");
706 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(); 723 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate);
707 } 724 }
708 725
709 pRuntime->BeginBlock(); 726 pRuntime->BeginBlock();
710 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); 727 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
711 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), 728 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(),
712 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); 729 cCc.c_str(), cBcc.c_str(), cMsg.c_str());
713 pRuntime->EndBlock(); 730 pRuntime->EndBlock();
714 731
715 return TRUE; 732 return TRUE;
716 } 733 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 const std::vector<CJS_Value>& params, 1038 const std::vector<CJS_Value>& params,
1022 CJS_Value& vRet, 1039 CJS_Value& vRet,
1023 CFX_WideString& sError) { 1040 CFX_WideString& sError) {
1024 return TRUE; 1041 return TRUE;
1025 } 1042 }
1026 1043
1027 FX_BOOL Document::getAnnots(IJS_Context* cc, 1044 FX_BOOL Document::getAnnots(IJS_Context* cc,
1028 const std::vector<CJS_Value>& params, 1045 const std::vector<CJS_Value>& params,
1029 CJS_Value& vRet, 1046 CJS_Value& vRet,
1030 CFX_WideString& sError) { 1047 CFX_WideString& sError) {
1031 vRet.SetNull(); 1048 vRet.SetNull(CJS_Runtime::FromContext(cc));
1032 return TRUE; 1049 return TRUE;
1033 } 1050 }
1034 1051
1035 FX_BOOL Document::getAnnot3D(IJS_Context* cc, 1052 FX_BOOL Document::getAnnot3D(IJS_Context* cc,
1036 const std::vector<CJS_Value>& params, 1053 const std::vector<CJS_Value>& params,
1037 CJS_Value& vRet, 1054 CJS_Value& vRet,
1038 CFX_WideString& sError) { 1055 CFX_WideString& sError) {
1039 vRet.SetNull(); 1056 vRet.SetNull(CJS_Runtime::FromContext(cc));
1040 return TRUE; 1057 return TRUE;
1041 } 1058 }
1042 1059
1043 FX_BOOL Document::getAnnots3D(IJS_Context* cc, 1060 FX_BOOL Document::getAnnots3D(IJS_Context* cc,
1044 const std::vector<CJS_Value>& params, 1061 const std::vector<CJS_Value>& params,
1045 CJS_Value& vRet, 1062 CJS_Value& vRet,
1046 CFX_WideString& sError) { 1063 CFX_WideString& sError) {
1047 vRet = CJS_Value::VT_undefined;
dsinclair 2016/08/09 19:25:32 Is this no longer needed?
Tom Sepez 2016/08/09 20:33:23 It was wrong. Not setting a value results in JS g
1048 return TRUE; 1064 return TRUE;
1049 } 1065 }
1050 1066
1051 FX_BOOL Document::getOCGs(IJS_Context* cc, 1067 FX_BOOL Document::getOCGs(IJS_Context* cc,
1052 const std::vector<CJS_Value>& params, 1068 const std::vector<CJS_Value>& params,
1053 CJS_Value& vRet, 1069 CJS_Value& vRet,
1054 CFX_WideString& sError) { 1070 CFX_WideString& sError) {
1055 return TRUE; 1071 return TRUE;
1056 } 1072 }
1057 1073
1058 FX_BOOL Document::getLinks(IJS_Context* cc, 1074 FX_BOOL Document::getLinks(IJS_Context* cc,
1059 const std::vector<CJS_Value>& params, 1075 const std::vector<CJS_Value>& params,
1060 CJS_Value& vRet, 1076 CJS_Value& vRet,
1061 CFX_WideString& sError) { 1077 CFX_WideString& sError) {
1062 return TRUE; 1078 return TRUE;
1063 } 1079 }
1064 1080
1065 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { 1081 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) {
1066 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && 1082 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top &&
1067 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); 1083 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
1068 } 1084 }
1069 1085
1070 FX_BOOL Document::addIcon(IJS_Context* cc, 1086 FX_BOOL Document::addIcon(IJS_Context* cc,
1071 const std::vector<CJS_Value>& params, 1087 const std::vector<CJS_Value>& params,
1072 CJS_Value& vRet, 1088 CJS_Value& vRet,
1073 CFX_WideString& sError) { 1089 CFX_WideString& sError) {
1074 CJS_Context* pContext = (CJS_Context*)cc; 1090 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1091 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:32 ...
Tom Sepez 2016/08/09 20:33:24 Done.
1092 v8::Isolate* pIsolate = pRuntime->GetIsolate();
1093
1075 if (params.size() != 2) { 1094 if (params.size() != 2) {
1076 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1095 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1077 return FALSE; 1096 return FALSE;
1078 } 1097 }
1079 CFX_WideString swIconName = params[0].ToCFXWideString(); 1098 CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate);
1080 1099
1081 if (params[1].GetType() != CJS_Value::VT_object) { 1100 if (params[1].GetType() != CJS_Value::VT_object) {
1082 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1101 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1083 return FALSE; 1102 return FALSE;
1084 } 1103 }
1085 1104
1086 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); 1105 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pIsolate);
1087 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { 1106 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
1088 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1107 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1089 return FALSE; 1108 return FALSE;
1090 } 1109 }
1091 1110
1092 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); 1111 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pIsolate)->GetEmbedObject();
1093 if (!pEmbedObj) { 1112 if (!pEmbedObj) {
1094 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1113 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1095 return FALSE; 1114 return FALSE;
1096 } 1115 }
1097 1116
1098 m_IconList.push_back(std::unique_ptr<IconElement>( 1117 m_IconList.push_back(std::unique_ptr<IconElement>(
1099 new IconElement(swIconName, (Icon*)pEmbedObj))); 1118 new IconElement(swIconName, (Icon*)pEmbedObj)));
1100 return TRUE; 1119 return TRUE;
1101 } 1120 }
1102 1121
1103 FX_BOOL Document::icons(IJS_Context* cc, 1122 FX_BOOL Document::icons(IJS_Context* cc,
1104 CJS_PropValue& vp, 1123 CJS_PropValue& vp,
1105 CFX_WideString& sError) { 1124 CFX_WideString& sError) {
1125 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1126 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
dsinclair 2016/08/09 19:25:32 ...
Tom Sepez 2016/08/09 20:33:23 Done.
1127
1106 if (vp.IsSetting()) { 1128 if (vp.IsSetting()) {
1107 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1108 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); 1129 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1109 return FALSE; 1130 return FALSE;
1110 } 1131 }
1111 1132
1112 if (m_IconList.empty()) { 1133 if (m_IconList.empty()) {
1113 vp.SetNull(); 1134 vp.GetJSValue()->SetNull(pRuntime);
1114 return TRUE; 1135 return TRUE;
1115 } 1136 }
1116 1137
1117 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1118 CJS_Array Icons; 1138 CJS_Array Icons;
1119 1139
1120 int i = 0; 1140 int i = 0;
1121 for (const auto& pIconElement : m_IconList) { 1141 for (const auto& pIconElement : m_IconList) {
1122 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1142 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1123 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); 1143 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1124 if (pObj.IsEmpty()) 1144 if (pObj.IsEmpty())
1125 return FALSE; 1145 return FALSE;
1126 1146
1127 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1147 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
(...skipping 11 matching lines...) Expand all
1139 } 1159 }
1140 1160
1141 vp << Icons; 1161 vp << Icons;
1142 return TRUE; 1162 return TRUE;
1143 } 1163 }
1144 1164
1145 FX_BOOL Document::getIcon(IJS_Context* cc, 1165 FX_BOOL Document::getIcon(IJS_Context* cc,
1146 const std::vector<CJS_Value>& params, 1166 const std::vector<CJS_Value>& params,
1147 CJS_Value& vRet, 1167 CJS_Value& vRet,
1148 CFX_WideString& sError) { 1168 CFX_WideString& sError) {
1149 CJS_Context* pContext = (CJS_Context*)cc; 1169 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1170 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair 2016/08/09 19:25:32 ...
Tom Sepez 2016/08/09 20:33:23 Done.
1171 v8::Isolate* pIsolate = pRuntime->GetIsolate();
1172
1150 if (params.size() != 1) { 1173 if (params.size() != 1) {
1151 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1174 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1152 return FALSE; 1175 return FALSE;
1153 } 1176 }
1154 1177
1155 if (m_IconList.empty()) 1178 if (m_IconList.empty())
1156 return FALSE; 1179 return FALSE;
1157 1180
1158 CFX_WideString swIconName = params[0].ToCFXWideString(); 1181 CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate);
1159 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1160 1182
1161 for (const auto& pIconElement : m_IconList) { 1183 for (const auto& pIconElement : m_IconList) {
1162 if (pIconElement->IconName == swIconName) { 1184 if (pIconElement->IconName == swIconName) {
1163 Icon* pRetIcon = pIconElement->IconStream; 1185 Icon* pRetIcon = pIconElement->IconStream;
1164 1186
1165 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1187 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1166 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); 1188 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1167 if (pObj.IsEmpty()) 1189 if (pObj.IsEmpty())
1168 return FALSE; 1190 return FALSE;
1169 1191
1170 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1192 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1171 if (!pJS_Icon) 1193 if (!pJS_Icon)
1172 return FALSE; 1194 return FALSE;
1173 1195
1174 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1196 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1175 if (!pIcon) 1197 if (!pIcon)
1176 return FALSE; 1198 return FALSE;
1177 1199
1178 pIcon->SetIconName(swIconName); 1200 pIcon->SetIconName(swIconName);
1179 pIcon->SetStream(pRetIcon->GetStream()); 1201 pIcon->SetStream(pRetIcon->GetStream());
1180 vRet = pJS_Icon; 1202 vRet = CJS_Value(pRuntime, pJS_Icon);
1181 return TRUE; 1203 return TRUE;
1182 } 1204 }
1183 } 1205 }
1184 1206
1185 return FALSE; 1207 return FALSE;
1186 } 1208 }
1187 1209
1188 FX_BOOL Document::removeIcon(IJS_Context* cc, 1210 FX_BOOL Document::removeIcon(IJS_Context* cc,
1189 const std::vector<CJS_Value>& params, 1211 const std::vector<CJS_Value>& params,
1190 CJS_Value& vRet, 1212 CJS_Value& vRet,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 FX_BOOL Document::Collab(IJS_Context* cc, 1246 FX_BOOL Document::Collab(IJS_Context* cc,
1225 CJS_PropValue& vp, 1247 CJS_PropValue& vp,
1226 CFX_WideString& sError) { 1248 CFX_WideString& sError) {
1227 return TRUE; 1249 return TRUE;
1228 } 1250 }
1229 1251
1230 FX_BOOL Document::getPageNthWord(IJS_Context* cc, 1252 FX_BOOL Document::getPageNthWord(IJS_Context* cc,
1231 const std::vector<CJS_Value>& params, 1253 const std::vector<CJS_Value>& params,
1232 CJS_Value& vRet, 1254 CJS_Value& vRet,
1233 CFX_WideString& sError) { 1255 CFX_WideString& sError) {
1256 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
dsinclair 2016/08/09 19:25:32 ...
Tom Sepez 2016/08/09 20:33:23 Done.
1257 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1258 v8::Isolate* pIsolate = pRuntime->GetIsolate();
1259
1234 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) 1260 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1235 return FALSE; 1261 return FALSE;
1236 1262
1237 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; 1263 int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0;
1238 int nWordNo = params.size() > 1 ? params[1].ToInt() : 0; 1264 int nWordNo = params.size() > 1 ? params[1].ToInt(pIsolate) : 0;
1239 bool bStrip = params.size() > 2 ? params[2].ToBool() : true; 1265 bool bStrip = params.size() > 2 ? params[2].ToBool(pIsolate) : true;
1240 1266
1241 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1267 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
1242 if (!pDocument) 1268 if (!pDocument)
1243 return FALSE; 1269 return FALSE;
1244 1270
1245 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1246 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { 1271 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1247 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); 1272 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1248 return FALSE; 1273 return FALSE;
1249 } 1274 }
1250 1275
1251 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1276 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1252 if (!pPageDict) 1277 if (!pPageDict)
1253 return FALSE; 1278 return FALSE;
1254 1279
1255 CPDF_Page page(pDocument, pPageDict, true); 1280 CPDF_Page page(pDocument, pPageDict, true);
(...skipping 11 matching lines...) Expand all
1267 } 1292 }
1268 nWords += nObjWords; 1293 nWords += nObjWords;
1269 } 1294 }
1270 } 1295 }
1271 1296
1272 if (bStrip) { 1297 if (bStrip) {
1273 swRet.TrimLeft(); 1298 swRet.TrimLeft();
1274 swRet.TrimRight(); 1299 swRet.TrimRight();
1275 } 1300 }
1276 1301
1277 vRet = swRet.c_str(); 1302 vRet = CJS_Value(pRuntime, swRet.c_str());
1278 return TRUE; 1303 return TRUE;
1279 } 1304 }
1280 1305
1281 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, 1306 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc,
1282 const std::vector<CJS_Value>& params, 1307 const std::vector<CJS_Value>& params,
1283 CJS_Value& vRet, 1308 CJS_Value& vRet,
1284 CFX_WideString& sError) { 1309 CFX_WideString& sError) {
1285 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) 1310 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1286 return FALSE; 1311 return FALSE;
1287 1312
1288 return FALSE; 1313 return FALSE;
1289 } 1314 }
1290 1315
1291 FX_BOOL Document::getPageNumWords(IJS_Context* cc, 1316 FX_BOOL Document::getPageNumWords(IJS_Context* cc,
1292 const std::vector<CJS_Value>& params, 1317 const std::vector<CJS_Value>& params,
1293 CJS_Value& vRet, 1318 CJS_Value& vRet,
1294 CFX_WideString& sError) { 1319 CFX_WideString& sError) {
1320 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1321 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1322 v8::Isolate* pIsolate = pRuntime->GetIsolate();
dsinclair 2016/08/09 19:25:33 ...
Tom Sepez 2016/08/09 20:33:23 Done.
1323
1295 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) 1324 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1296 return FALSE; 1325 return FALSE;
1297 1326
1298 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; 1327 int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0;
1299 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1328 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
1300 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1301 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { 1329 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1302 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); 1330 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1303 return FALSE; 1331 return FALSE;
1304 } 1332 }
1305 1333
1306 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1334 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1307 if (!pPageDict) 1335 if (!pPageDict)
1308 return FALSE; 1336 return FALSE;
1309 1337
1310 CPDF_Page page(pDocument, pPageDict, true); 1338 CPDF_Page page(pDocument, pPageDict, true);
1311 page.ParseContent(); 1339 page.ParseContent();
1312 1340
1313 int nWords = 0; 1341 int nWords = 0;
1314 for (auto& pPageObj : *page.GetPageObjectList()) { 1342 for (auto& pPageObj : *page.GetPageObjectList()) {
1315 if (pPageObj->IsText()) 1343 if (pPageObj->IsText())
1316 nWords += CountWords(pPageObj->AsText()); 1344 nWords += CountWords(pPageObj->AsText());
1317 } 1345 }
1318 1346
1319 vRet = nWords; 1347 vRet = CJS_Value(pRuntime, nWords);
1320 return TRUE; 1348 return TRUE;
1321 } 1349 }
1322 1350
1323 FX_BOOL Document::getPrintParams(IJS_Context* cc, 1351 FX_BOOL Document::getPrintParams(IJS_Context* cc,
1324 const std::vector<CJS_Value>& params, 1352 const std::vector<CJS_Value>& params,
1325 CJS_Value& vRet, 1353 CJS_Value& vRet,
1326 CFX_WideString& sError) { 1354 CFX_WideString& sError) {
1327 CJS_Context* pContext = (CJS_Context*)cc; 1355 CJS_Context* pContext = (CJS_Context*)cc;
1328 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1356 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1329 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 1357 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
1330 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); 1358 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID);
1331 1359
1332 // Not implemented yet. 1360 // Not implemented yet.
1333 1361
1334 vRet = pRetObj; 1362 vRet = CJS_Value(pRuntime, pRetObj);
1335 return TRUE; 1363 return TRUE;
1336 } 1364 }
1337 1365
1338 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) 1366 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
1339 1367
1340 int Document::CountWords(CPDF_TextObject* pTextObj) { 1368 int Document::CountWords(CPDF_TextObject* pTextObj) {
1341 if (!pTextObj) 1369 if (!pTextObj)
1342 return 0; 1370 return 0;
1343 1371
1344 int nWords = 0; 1372 int nWords = 0;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 CFX_WideString& sError) { 1495 CFX_WideString& sError) {
1468 // Unsafe, not supported. 1496 // Unsafe, not supported.
1469 return TRUE; 1497 return TRUE;
1470 } 1498 }
1471 1499
1472 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, 1500 FX_BOOL Document::gotoNamedDest(IJS_Context* cc,
1473 const std::vector<CJS_Value>& params, 1501 const std::vector<CJS_Value>& params,
1474 CJS_Value& vRet, 1502 CJS_Value& vRet,
1475 CFX_WideString& sError) { 1503 CFX_WideString& sError) {
1476 CJS_Context* context = (CJS_Context*)cc; 1504 CJS_Context* context = (CJS_Context*)cc;
1505 CJS_Runtime* runtime = context->GetJSRuntime();
dsinclair 2016/08/09 19:25:32 ...
Tom Sepez 2016/08/09 20:33:23 Done.
1506
1477 if (params.size() != 1) { 1507 if (params.size() != 1) {
1478 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR); 1508 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR);
1479 return FALSE; 1509 return FALSE;
1480 } 1510 }
1481 1511
1482 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1512 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
1483 if (!pDocument) 1513 if (!pDocument)
1484 return FALSE; 1514 return FALSE;
1485 1515
1486 CFX_WideString wideName = params[0].ToCFXWideString(); 1516 CFX_WideString wideName = params[0].ToCFXWideString(runtime->GetIsolate());
1487 CFX_ByteString utf8Name = wideName.UTF8Encode(); 1517 CFX_ByteString utf8Name = wideName.UTF8Encode();
1488 1518
1489 CPDF_NameTree nameTree(pDocument, "Dests"); 1519 CPDF_NameTree nameTree(pDocument, "Dests");
1490 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); 1520 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name);
1491 if (!destArray) 1521 if (!destArray)
1492 return FALSE; 1522 return FALSE;
1493 1523
1494 CPDF_Dest dest(destArray); 1524 CPDF_Dest dest(destArray);
1495 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); 1525 const CPDF_Array* arrayObject = ToArray(dest.GetObject());
1496 1526
1497 std::unique_ptr<float[]> scrollPositionArray; 1527 std::unique_ptr<float[]> scrollPositionArray;
1498 int scrollPositionArraySize = 0; 1528 int scrollPositionArraySize = 0;
1499 1529
1500 if (arrayObject) { 1530 if (arrayObject) {
1501 scrollPositionArray.reset(new float[arrayObject->GetCount()]); 1531 scrollPositionArray.reset(new float[arrayObject->GetCount()]);
1502 int j = 0; 1532 int j = 0;
1503 for (size_t i = 2; i < arrayObject->GetCount(); i++) 1533 for (size_t i = 2; i < arrayObject->GetCount(); i++)
1504 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); 1534 scrollPositionArray[j++] = arrayObject->GetFloatAt(i);
1505 scrollPositionArraySize = j; 1535 scrollPositionArraySize = j;
1506 } 1536 }
1507 1537
1508 CJS_Runtime* runtime = context->GetJSRuntime();
1509 runtime->BeginBlock(); 1538 runtime->BeginBlock();
1510 CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); 1539 CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
1511 pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), 1540 pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(),
1512 scrollPositionArray.get(), scrollPositionArraySize); 1541 scrollPositionArray.get(), scrollPositionArraySize);
1513 runtime->EndBlock(); 1542 runtime->EndBlock();
1514 1543
1515 return TRUE; 1544 return TRUE;
1516 } 1545 }
1517 1546
1518 void Document::AddDelayData(CJS_DelayData* pData) { 1547 void Document::AddDelayData(CJS_DelayData* pData) {
(...skipping 13 matching lines...) Expand all
1532 } 1561 }
1533 } 1562 }
1534 1563
1535 for (const auto& pData : DelayDataForFieldAndControlIndex) 1564 for (const auto& pData : DelayDataForFieldAndControlIndex)
1536 Field::DoDelay(m_pDocument, pData.get()); 1565 Field::DoDelay(m_pDocument, pData.get());
1537 } 1566 }
1538 1567
1539 CJS_Document* Document::GetCJSDoc() const { 1568 CJS_Document* Document::GetCJSDoc() const {
1540 return static_cast<CJS_Document*>(m_pJSObject); 1569 return static_cast<CJS_Document*>(m_pJSObject);
1541 } 1570 }
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/javascript/Field.cpp » ('j') | fpdfsdk/javascript/Field.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698