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

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

Powered by Google App Engine
This is Rietveld 408576698