| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 #include "fpdfsdk/javascript/JS_Define.h" | 21 #include "fpdfsdk/javascript/JS_Define.h" |
| 22 #include "fpdfsdk/javascript/JS_EventHandler.h" | 22 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 23 #include "fpdfsdk/javascript/JS_Object.h" | 23 #include "fpdfsdk/javascript/JS_Object.h" |
| 24 #include "fpdfsdk/javascript/JS_Value.h" | 24 #include "fpdfsdk/javascript/JS_Value.h" |
| 25 #include "fpdfsdk/javascript/app.h" | 25 #include "fpdfsdk/javascript/app.h" |
| 26 #include "fpdfsdk/javascript/cjs_context.h" | 26 #include "fpdfsdk/javascript/cjs_context.h" |
| 27 #include "fpdfsdk/javascript/cjs_runtime.h" | 27 #include "fpdfsdk/javascript/cjs_runtime.h" |
| 28 #include "fpdfsdk/javascript/resource.h" | 28 #include "fpdfsdk/javascript/resource.h" |
| 29 #include "third_party/base/numerics/safe_math.h" | 29 #include "third_party/base/numerics/safe_math.h" |
| 30 | 30 |
| 31 static v8::Isolate* GetIsolate(IJS_Context* cc) { | |
| 32 CJS_Context* pContext = (CJS_Context*)cc; | |
| 33 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 34 return pRuntime->GetIsolate(); | |
| 35 } | |
| 36 | |
| 37 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) | 31 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) |
| 38 END_JS_STATIC_CONST() | 32 END_JS_STATIC_CONST() |
| 39 | 33 |
| 40 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) | 34 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
| 41 END_JS_STATIC_PROP() | 35 END_JS_STATIC_PROP() |
| 42 | 36 |
| 43 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) | 37 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
| 44 END_JS_STATIC_METHOD() | 38 END_JS_STATIC_METHOD() |
| 45 | 39 |
| 46 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) | 40 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 JS_STATIC_METHOD_ENTRY(submitForm) | 135 JS_STATIC_METHOD_ENTRY(submitForm) |
| 142 JS_STATIC_METHOD_ENTRY(mailDoc) | 136 JS_STATIC_METHOD_ENTRY(mailDoc) |
| 143 END_JS_STATIC_METHOD() | 137 END_JS_STATIC_METHOD() |
| 144 | 138 |
| 145 IMPLEMENT_JS_CLASS(CJS_Document, Document) | 139 IMPLEMENT_JS_CLASS(CJS_Document, Document) |
| 146 | 140 |
| 147 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { | 141 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| 148 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | 142 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 149 Document* pDoc = static_cast<Document*>(GetEmbedObject()); | 143 Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
| 150 pDoc->AttachDoc(pRuntime->GetReaderDocument()); | 144 pDoc->AttachDoc(pRuntime->GetReaderDocument()); |
| 151 pDoc->SetIsolate(pRuntime->GetIsolate()); | |
| 152 } | 145 } |
| 153 | 146 |
| 154 Document::Document(CJS_Object* pJSObject) | 147 Document::Document(CJS_Object* pJSObject) |
| 155 : CJS_EmbedObj(pJSObject), | 148 : CJS_EmbedObj(pJSObject), |
| 156 m_isolate(nullptr), | |
| 157 m_pDocument(nullptr), | 149 m_pDocument(nullptr), |
| 158 m_cwBaseURL(L""), | 150 m_cwBaseURL(L""), |
| 159 m_bDelay(FALSE) {} | 151 m_bDelay(FALSE) {} |
| 160 | 152 |
| 161 Document::~Document() { | 153 Document::~Document() { |
| 162 } | 154 } |
| 163 | 155 |
| 164 // the total number of fileds in document. | 156 // the total number of fileds in document. |
| 165 FX_BOOL Document::numFields(IJS_Context* cc, | 157 FX_BOOL Document::numFields(IJS_Context* cc, |
| 166 CJS_PropValue& vp, | 158 CJS_PropValue& vp, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 CJS_Value& vRet, | 274 CJS_Value& vRet, |
| 283 CFX_WideString& sError) { | 275 CFX_WideString& sError) { |
| 284 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 276 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 285 | 277 |
| 286 if (params.size() < 1) { | 278 if (params.size() < 1) { |
| 287 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 279 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 288 return FALSE; | 280 return FALSE; |
| 289 } | 281 } |
| 290 | 282 |
| 291 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 283 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 292 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | 284 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 293 | |
| 294 CFX_WideString wideName = params[0].ToCFXWideString(pIsolate); | |
| 295 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 285 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 296 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 286 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 297 if (pPDFForm->CountFields(wideName) <= 0) { | 287 if (pPDFForm->CountFields(wideName) <= 0) { |
| 298 vRet.SetNull(pRuntime); | 288 vRet.SetNull(pRuntime); |
| 299 return TRUE; | 289 return TRUE; |
| 300 } | 290 } |
| 301 | 291 |
| 302 v8::Local<v8::Object> pFieldObj = | 292 v8::Local<v8::Object> pFieldObj = |
| 303 FXJS_NewFxDynamicObj(pIsolate, pRuntime, CJS_Field::g_nObjDefnID); | 293 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
| 304 | |
| 305 CJS_Field* pJSField = | 294 CJS_Field* pJSField = |
| 306 static_cast<CJS_Field*>(FXJS_GetPrivate(pIsolate, pFieldObj)); | 295 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
| 307 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); | 296 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
| 308 pField->AttachField(this, wideName); | 297 pField->AttachField(this, wideName); |
| 309 | 298 |
| 310 vRet = CJS_Value(pRuntime, pJSField); | 299 vRet = CJS_Value(pRuntime, pJSField); |
| 311 return TRUE; | 300 return TRUE; |
| 312 } | 301 } |
| 313 | 302 |
| 314 // Gets the name of the nth field in the document | 303 // Gets the name of the nth field in the document |
| 315 FX_BOOL Document::getNthFieldName(IJS_Context* cc, | 304 FX_BOOL Document::getNthFieldName(IJS_Context* cc, |
| 316 const std::vector<CJS_Value>& params, | 305 const std::vector<CJS_Value>& params, |
| 317 CJS_Value& vRet, | 306 CJS_Value& vRet, |
| 318 CFX_WideString& sError) { | 307 CFX_WideString& sError) { |
| 319 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 308 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 309 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 320 | 310 |
| 321 if (params.size() != 1) { | 311 if (params.size() != 1) { |
| 322 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 312 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 323 return FALSE; | 313 return FALSE; |
| 324 } | 314 } |
| 325 | 315 int nIndex = params[0].ToInt(pRuntime); |
| 326 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 327 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 328 | |
| 329 int nIndex = params[0].ToInt(pIsolate); | |
| 330 if (nIndex < 0) { | 316 if (nIndex < 0) { |
| 331 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 317 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 332 return FALSE; | 318 return FALSE; |
| 333 } | 319 } |
| 334 | 320 |
| 335 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 321 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 336 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 322 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 337 CPDF_FormField* pField = pPDFForm->GetField(nIndex); | 323 CPDF_FormField* pField = pPDFForm->GetField(nIndex); |
| 338 if (!pField) | 324 if (!pField) |
| 339 return FALSE; | 325 return FALSE; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // comment: need reader supports | 357 // comment: need reader supports |
| 372 // note: | 358 // note: |
| 373 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string | 359 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string |
| 374 // cbcc,string cSubject,string cms); | 360 // cbcc,string cSubject,string cms); |
| 375 | 361 |
| 376 FX_BOOL Document::mailForm(IJS_Context* cc, | 362 FX_BOOL Document::mailForm(IJS_Context* cc, |
| 377 const std::vector<CJS_Value>& params, | 363 const std::vector<CJS_Value>& params, |
| 378 CJS_Value& vRet, | 364 CJS_Value& vRet, |
| 379 CFX_WideString& sError) { | 365 CFX_WideString& sError) { |
| 380 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 366 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 367 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 381 | 368 |
| 382 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 369 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 383 return FALSE; | 370 return FALSE; |
| 384 | 371 |
| 385 int iLength = params.size(); | 372 int iLength = params.size(); |
| 386 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 373 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; |
| 387 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | 374 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 388 | 375 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 389 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pIsolate) : TRUE; | 376 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
| 390 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pIsolate) : L""; | |
| 391 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pIsolate) : L""; | |
| 392 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pIsolate) : L""; | |
| 393 CFX_WideString cSubject = | 377 CFX_WideString cSubject = |
| 394 iLength > 4 ? params[4].ToCFXWideString(pIsolate) : L""; | 378 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 395 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pIsolate) : L""; | 379 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
| 396 | 380 |
| 397 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 381 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 398 CFX_ByteTextBuf textBuf; | 382 CFX_ByteTextBuf textBuf; |
| 399 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | 383 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 400 return FALSE; | 384 return FALSE; |
| 401 | 385 |
| 402 pRuntime->BeginBlock(); | 386 pRuntime->BeginBlock(); |
| 403 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); | 387 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); |
| 404 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | 388 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 405 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), | 389 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 406 cMsg.c_str()); | 390 cMsg.c_str()); |
| 407 pRuntime->EndBlock(); | 391 pRuntime->EndBlock(); |
| 408 return TRUE; | 392 return TRUE; |
| 409 } | 393 } |
| 410 | 394 |
| 411 FX_BOOL Document::print(IJS_Context* cc, | 395 FX_BOOL Document::print(IJS_Context* cc, |
| 412 const std::vector<CJS_Value>& params, | 396 const std::vector<CJS_Value>& params, |
| 413 CJS_Value& vRet, | 397 CJS_Value& vRet, |
| 414 CFX_WideString& sError) { | 398 CFX_WideString& sError) { |
| 415 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 399 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 416 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 400 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 417 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 418 | 401 |
| 419 FX_BOOL bUI = TRUE; | 402 FX_BOOL bUI = TRUE; |
| 420 int nStart = 0; | 403 int nStart = 0; |
| 421 int nEnd = 0; | 404 int nEnd = 0; |
| 422 FX_BOOL bSilent = FALSE; | 405 FX_BOOL bSilent = FALSE; |
| 423 FX_BOOL bShrinkToFit = FALSE; | 406 FX_BOOL bShrinkToFit = FALSE; |
| 424 FX_BOOL bPrintAsImage = FALSE; | 407 FX_BOOL bPrintAsImage = FALSE; |
| 425 FX_BOOL bReverse = FALSE; | 408 FX_BOOL bReverse = FALSE; |
| 426 FX_BOOL bAnnotations = FALSE; | 409 FX_BOOL bAnnotations = FALSE; |
| 427 | 410 |
| 428 int nlength = params.size(); | 411 int nlength = params.size(); |
| 429 if (nlength == 9) { | 412 if (nlength == 9) { |
| 430 if (params[8].GetType() == CJS_Value::VT_object) { | 413 if (params[8].GetType() == CJS_Value::VT_object) { |
| 431 v8::Local<v8::Object> pObj = params[8].ToV8Object(pIsolate); | 414 v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); |
| 432 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { | 415 if (CFXJS_Engine::GetObjDefnID(pObj) == |
| 433 if (CJS_Object* pJSObj = params[8].ToCJSObject(pIsolate)) { | 416 CJS_PrintParamsObj::g_nObjDefnID) { |
| 417 if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { |
| 434 if (PrintParamsObj* pprintparamsObj = | 418 if (PrintParamsObj* pprintparamsObj = |
| 435 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { | 419 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { |
| 436 bUI = pprintparamsObj->bUI; | 420 bUI = pprintparamsObj->bUI; |
| 437 nStart = pprintparamsObj->nStart; | 421 nStart = pprintparamsObj->nStart; |
| 438 nEnd = pprintparamsObj->nEnd; | 422 nEnd = pprintparamsObj->nEnd; |
| 439 bSilent = pprintparamsObj->bSilent; | 423 bSilent = pprintparamsObj->bSilent; |
| 440 bShrinkToFit = pprintparamsObj->bShrinkToFit; | 424 bShrinkToFit = pprintparamsObj->bShrinkToFit; |
| 441 bPrintAsImage = pprintparamsObj->bPrintAsImage; | 425 bPrintAsImage = pprintparamsObj->bPrintAsImage; |
| 442 bReverse = pprintparamsObj->bReverse; | 426 bReverse = pprintparamsObj->bReverse; |
| 443 bAnnotations = pprintparamsObj->bAnnotations; | 427 bAnnotations = pprintparamsObj->bAnnotations; |
| 444 } | 428 } |
| 445 } | 429 } |
| 446 } | 430 } |
| 447 } | 431 } |
| 448 } else { | 432 } else { |
| 449 if (nlength >= 1) | 433 if (nlength >= 1) |
| 450 bUI = params[0].ToBool(pIsolate); | 434 bUI = params[0].ToBool(pRuntime); |
| 451 if (nlength >= 2) | 435 if (nlength >= 2) |
| 452 nStart = params[1].ToInt(pIsolate); | 436 nStart = params[1].ToInt(pRuntime); |
| 453 if (nlength >= 3) | 437 if (nlength >= 3) |
| 454 nEnd = params[2].ToInt(pIsolate); | 438 nEnd = params[2].ToInt(pRuntime); |
| 455 if (nlength >= 4) | 439 if (nlength >= 4) |
| 456 bSilent = params[3].ToBool(pIsolate); | 440 bSilent = params[3].ToBool(pRuntime); |
| 457 if (nlength >= 5) | 441 if (nlength >= 5) |
| 458 bShrinkToFit = params[4].ToBool(pIsolate); | 442 bShrinkToFit = params[4].ToBool(pRuntime); |
| 459 if (nlength >= 6) | 443 if (nlength >= 6) |
| 460 bPrintAsImage = params[5].ToBool(pIsolate); | 444 bPrintAsImage = params[5].ToBool(pRuntime); |
| 461 if (nlength >= 7) | 445 if (nlength >= 7) |
| 462 bReverse = params[6].ToBool(pIsolate); | 446 bReverse = params[6].ToBool(pRuntime); |
| 463 if (nlength >= 8) | 447 if (nlength >= 8) |
| 464 bAnnotations = params[7].ToBool(pIsolate); | 448 bAnnotations = params[7].ToBool(pRuntime); |
| 465 } | 449 } |
| 466 | 450 |
| 467 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { | 451 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { |
| 468 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, | 452 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, |
| 469 bReverse, bAnnotations); | 453 bReverse, bAnnotations); |
| 470 return TRUE; | 454 return TRUE; |
| 471 } | 455 } |
| 472 return FALSE; | 456 return FALSE; |
| 473 } | 457 } |
| 474 | 458 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 485 return FALSE; | 469 return FALSE; |
| 486 | 470 |
| 487 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 471 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 488 | 472 |
| 489 if (params.size() != 1) { | 473 if (params.size() != 1) { |
| 490 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 474 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 491 return FALSE; | 475 return FALSE; |
| 492 } | 476 } |
| 493 | 477 |
| 494 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 478 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 495 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 496 | 479 |
| 497 CFX_WideString sFieldName = params[0].ToCFXWideString(pIsolate); | 480 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
| 498 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 481 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 499 std::vector<CPDFSDK_Widget*> widgets; | 482 std::vector<CPDFSDK_Widget*> widgets; |
| 500 pInterForm->GetWidgets(sFieldName, &widgets); | 483 pInterForm->GetWidgets(sFieldName, &widgets); |
| 501 if (widgets.empty()) | 484 if (widgets.empty()) |
| 502 return TRUE; | 485 return TRUE; |
| 503 | 486 |
| 504 for (CPDFSDK_Widget* pWidget : widgets) { | 487 for (CPDFSDK_Widget* pWidget : widgets) { |
| 505 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 488 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
| 506 --rcAnnot.left; | 489 --rcAnnot.left; |
| 507 --rcAnnot.bottom; | 490 --rcAnnot.bottom; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 523 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 541 CJS_Array aName; | 524 CJS_Array aName; |
| 542 | 525 |
| 543 if (params.empty()) { | 526 if (params.empty()) { |
| 544 pPDFForm->ResetForm(TRUE); | 527 pPDFForm->ResetForm(TRUE); |
| 545 m_pDocument->SetChangeMark(); | 528 m_pDocument->SetChangeMark(); |
| 546 return TRUE; | 529 return TRUE; |
| 547 } | 530 } |
| 548 | 531 |
| 549 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 532 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 550 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 551 | 533 |
| 552 switch (params[0].GetType()) { | 534 switch (params[0].GetType()) { |
| 553 default: | 535 default: |
| 554 aName.Attach(params[0].ToV8Array(pIsolate)); | 536 aName.Attach(params[0].ToV8Array(pRuntime)); |
| 555 break; | 537 break; |
| 556 case CJS_Value::VT_string: | 538 case CJS_Value::VT_string: |
| 557 aName.SetElement(pRuntime->GetIsolate(), 0, params[0]); | 539 aName.SetElement(pRuntime, 0, params[0]); |
| 558 break; | 540 break; |
| 559 } | 541 } |
| 560 | 542 |
| 561 std::vector<CPDF_FormField*> aFields; | 543 std::vector<CPDF_FormField*> aFields; |
| 562 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { | 544 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { |
| 563 CJS_Value valElement(pRuntime); | 545 CJS_Value valElement(pRuntime); |
| 564 aName.GetElement(pRuntime->GetIsolate(), i, valElement); | 546 aName.GetElement(pRuntime, i, valElement); |
| 565 CFX_WideString swVal = valElement.ToCFXWideString(pIsolate); | 547 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); |
| 566 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) | 548 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 567 aFields.push_back(pPDFForm->GetField(j, swVal)); | 549 aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 568 } | 550 } |
| 569 | 551 |
| 570 if (!aFields.empty()) { | 552 if (!aFields.empty()) { |
| 571 pPDFForm->ResetForm(aFields, TRUE, TRUE); | 553 pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 572 m_pDocument->SetChangeMark(); | 554 m_pDocument->SetChangeMark(); |
| 573 } | 555 } |
| 574 | 556 |
| 575 return TRUE; | 557 return TRUE; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 594 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 576 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 595 return FALSE; | 577 return FALSE; |
| 596 } | 578 } |
| 597 | 579 |
| 598 CJS_Array aFields; | 580 CJS_Array aFields; |
| 599 CFX_WideString strURL; | 581 CFX_WideString strURL; |
| 600 FX_BOOL bFDF = TRUE; | 582 FX_BOOL bFDF = TRUE; |
| 601 FX_BOOL bEmpty = FALSE; | 583 FX_BOOL bEmpty = FALSE; |
| 602 | 584 |
| 603 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 585 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 604 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 605 | 586 |
| 606 CJS_Value v = params[0]; | 587 CJS_Value v = params[0]; |
| 607 if (v.GetType() == CJS_Value::VT_string) { | 588 if (v.GetType() == CJS_Value::VT_string) { |
| 608 strURL = params[0].ToCFXWideString(pIsolate); | 589 strURL = params[0].ToCFXWideString(pRuntime); |
| 609 if (nSize > 1) | 590 if (nSize > 1) |
| 610 bFDF = params[1].ToBool(pIsolate); | 591 bFDF = params[1].ToBool(pRuntime); |
| 611 if (nSize > 2) | 592 if (nSize > 2) |
| 612 bEmpty = params[2].ToBool(pIsolate); | 593 bEmpty = params[2].ToBool(pRuntime); |
| 613 if (nSize > 3) | 594 if (nSize > 3) |
| 614 aFields.Attach(params[3].ToV8Array(pIsolate)); | 595 aFields.Attach(params[3].ToV8Array(pRuntime)); |
| 615 } else if (v.GetType() == CJS_Value::VT_object) { | 596 } else if (v.GetType() == CJS_Value::VT_object) { |
| 616 v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate); | 597 v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); |
| 617 v8::Local<v8::Value> pValue = | 598 v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"cURL"); |
| 618 FXJS_GetObjectProperty(pIsolate, pObj, L"cURL"); | |
| 619 if (!pValue.IsEmpty()) | 599 if (!pValue.IsEmpty()) |
| 620 strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 600 strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 621 | 601 |
| 622 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bFDF"); | 602 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); |
| 623 bFDF = CJS_Value(pRuntime, pValue).ToBool(pIsolate); | 603 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 624 | 604 |
| 625 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bEmpty"); | 605 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); |
| 626 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pIsolate); | 606 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 627 | 607 |
| 628 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"aFields"); | 608 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); |
| 629 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pIsolate)); | 609 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); |
| 630 } | 610 } |
| 631 | 611 |
| 632 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 612 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 633 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 613 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 634 if (aFields.GetLength() == 0 && bEmpty) { | 614 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { |
| 635 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | 615 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 636 pRuntime->BeginBlock(); | 616 pRuntime->BeginBlock(); |
| 637 pInterForm->SubmitForm(strURL, FALSE); | 617 pInterForm->SubmitForm(strURL, FALSE); |
| 638 pRuntime->EndBlock(); | 618 pRuntime->EndBlock(); |
| 639 } | 619 } |
| 640 return TRUE; | 620 return TRUE; |
| 641 } | 621 } |
| 642 | 622 |
| 643 std::vector<CPDF_FormField*> fieldObjects; | 623 std::vector<CPDF_FormField*> fieldObjects; |
| 644 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { | 624 for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { |
| 645 CJS_Value valName(pRuntime); | 625 CJS_Value valName(pRuntime); |
| 646 aFields.GetElement(pRuntime->GetIsolate(), i, valName); | 626 aFields.GetElement(pRuntime, i, valName); |
| 647 | 627 |
| 648 CFX_WideString sName = valName.ToCFXWideString(pIsolate); | 628 CFX_WideString sName = valName.ToCFXWideString(pRuntime); |
| 649 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 629 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 650 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { | 630 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 651 CPDF_FormField* pField = pPDFForm->GetField(j, sName); | 631 CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 652 if (!bEmpty && pField->GetValue().IsEmpty()) | 632 if (!bEmpty && pField->GetValue().IsEmpty()) |
| 653 continue; | 633 continue; |
| 654 | 634 |
| 655 fieldObjects.push_back(pField); | 635 fieldObjects.push_back(pField); |
| 656 } | 636 } |
| 657 } | 637 } |
| 658 | 638 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 687 // TODO(tsepez): Check maximum number of allowed params. | 667 // TODO(tsepez): Check maximum number of allowed params. |
| 688 | 668 |
| 689 FX_BOOL bUI = TRUE; | 669 FX_BOOL bUI = TRUE; |
| 690 CFX_WideString cTo = L""; | 670 CFX_WideString cTo = L""; |
| 691 CFX_WideString cCc = L""; | 671 CFX_WideString cCc = L""; |
| 692 CFX_WideString cBcc = L""; | 672 CFX_WideString cBcc = L""; |
| 693 CFX_WideString cSubject = L""; | 673 CFX_WideString cSubject = L""; |
| 694 CFX_WideString cMsg = L""; | 674 CFX_WideString cMsg = L""; |
| 695 | 675 |
| 696 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 676 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 697 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 698 | 677 |
| 699 if (params.size() >= 1) | 678 if (params.size() >= 1) |
| 700 bUI = params[0].ToBool(pIsolate); | 679 bUI = params[0].ToBool(pRuntime); |
| 701 if (params.size() >= 2) | 680 if (params.size() >= 2) |
| 702 cTo = params[1].ToCFXWideString(pIsolate); | 681 cTo = params[1].ToCFXWideString(pRuntime); |
| 703 if (params.size() >= 3) | 682 if (params.size() >= 3) |
| 704 cCc = params[2].ToCFXWideString(pIsolate); | 683 cCc = params[2].ToCFXWideString(pRuntime); |
| 705 if (params.size() >= 4) | 684 if (params.size() >= 4) |
| 706 cBcc = params[3].ToCFXWideString(pIsolate); | 685 cBcc = params[3].ToCFXWideString(pRuntime); |
| 707 if (params.size() >= 5) | 686 if (params.size() >= 5) |
| 708 cSubject = params[4].ToCFXWideString(pIsolate); | 687 cSubject = params[4].ToCFXWideString(pRuntime); |
| 709 if (params.size() >= 6) | 688 if (params.size() >= 6) |
| 710 cMsg = params[5].ToCFXWideString(pIsolate); | 689 cMsg = params[5].ToCFXWideString(pRuntime); |
| 711 | 690 |
| 712 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { | 691 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { |
| 713 v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate); | 692 v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); |
| 714 | 693 |
| 715 v8::Local<v8::Value> pValue = | 694 v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"bUI"); |
| 716 FXJS_GetObjectProperty(pIsolate, pObj, L"bUI"); | 695 bUI = CJS_Value(pRuntime, pValue).ToInt(pRuntime); |
| 717 bUI = CJS_Value(pRuntime, pValue).ToInt(pIsolate); | |
| 718 | 696 |
| 719 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cTo"); | 697 pValue = pRuntime->GetObjectProperty(pObj, L"cTo"); |
| 720 cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 698 cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 721 | 699 |
| 722 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cCc"); | 700 pValue = pRuntime->GetObjectProperty(pObj, L"cCc"); |
| 723 cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 701 cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 724 | 702 |
| 725 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cBcc"); | 703 pValue = pRuntime->GetObjectProperty(pObj, L"cBcc"); |
| 726 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 704 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 727 | 705 |
| 728 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cSubject"); | 706 pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); |
| 729 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 707 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 730 | 708 |
| 731 pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cMsg"); | 709 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); |
| 732 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); | 710 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 733 } | 711 } |
| 734 | 712 |
| 735 pRuntime->BeginBlock(); | 713 pRuntime->BeginBlock(); |
| 736 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); | 714 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); |
| 737 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), | 715 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), |
| 738 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); | 716 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); |
| 739 pRuntime->EndBlock(); | 717 pRuntime->EndBlock(); |
| 740 | 718 |
| 741 return TRUE; | 719 return TRUE; |
| 742 } | 720 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 765 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); | 743 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); |
| 766 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); | 744 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); |
| 767 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); | 745 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); |
| 768 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); | 746 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); |
| 769 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); | 747 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); |
| 770 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); | 748 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); |
| 771 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); | 749 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); |
| 772 | 750 |
| 773 CJS_Context* pContext = (CJS_Context*)cc; | 751 CJS_Context* pContext = (CJS_Context*)cc; |
| 774 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 752 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 775 v8::Local<v8::Object> pObj = | |
| 776 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); | |
| 777 | 753 |
| 778 v8::Isolate* isolate = GetIsolate(cc); | 754 v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1); |
| 779 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor); | 755 pRuntime->PutObjectString(pObj, L"Author", cwAuthor); |
| 780 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle); | 756 pRuntime->PutObjectString(pObj, L"Title", cwTitle); |
| 781 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject); | 757 pRuntime->PutObjectString(pObj, L"Subject", cwSubject); |
| 782 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords); | 758 pRuntime->PutObjectString(pObj, L"Keywords", cwKeywords); |
| 783 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator); | 759 pRuntime->PutObjectString(pObj, L"Creator", cwCreator); |
| 784 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer); | 760 pRuntime->PutObjectString(pObj, L"Producer", cwProducer); |
| 785 FXJS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate); | 761 pRuntime->PutObjectString(pObj, L"CreationDate", cwCreationDate); |
| 786 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate); | 762 pRuntime->PutObjectString(pObj, L"ModDate", cwModDate); |
| 787 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped); | 763 pRuntime->PutObjectString(pObj, L"Trapped", cwTrapped); |
| 788 | 764 |
| 789 // It's to be compatible to non-standard info dictionary. | 765 // It's to be compatible to non-standard info dictionary. |
| 790 for (const auto& it : *pDictionary) { | 766 for (const auto& it : *pDictionary) { |
| 791 const CFX_ByteString& bsKey = it.first; | 767 const CFX_ByteString& bsKey = it.first; |
| 792 CPDF_Object* pValueObj = it.second; | 768 CPDF_Object* pValueObj = it.second; |
| 793 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); | 769 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); |
| 794 if (pValueObj->IsString() || pValueObj->IsName()) { | 770 if (pValueObj->IsString() || pValueObj->IsName()) { |
| 795 FXJS_PutObjectString(isolate, pObj, wsKey, pValueObj->GetUnicodeText()); | 771 pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText()); |
| 796 } else if (pValueObj->IsNumber()) { | 772 } else if (pValueObj->IsNumber()) { |
| 797 FXJS_PutObjectNumber(isolate, pObj, wsKey, (float)pValueObj->GetNumber()); | 773 pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber()); |
| 798 } else if (pValueObj->IsBoolean()) { | 774 } else if (pValueObj->IsBoolean()) { |
| 799 FXJS_PutObjectBoolean(isolate, pObj, wsKey, !!pValueObj->GetInteger()); | 775 pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger()); |
| 800 } | 776 } |
| 801 } | 777 } |
| 802 vp << pObj; | 778 vp << pObj; |
| 803 return TRUE; | 779 return TRUE; |
| 804 } | 780 } |
| 805 | 781 |
| 806 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, | 782 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, |
| 807 CJS_PropValue& vp, | 783 CJS_PropValue& vp, |
| 808 const CFX_ByteString& propName, | 784 const CFX_ByteString& propName, |
| 809 CFX_WideString& sError) { | 785 CFX_WideString& sError) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 CJS_Value& vRet, | 1077 CJS_Value& vRet, |
| 1102 CFX_WideString& sError) { | 1078 CFX_WideString& sError) { |
| 1103 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1079 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1104 | 1080 |
| 1105 if (params.size() != 2) { | 1081 if (params.size() != 2) { |
| 1106 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1082 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1107 return FALSE; | 1083 return FALSE; |
| 1108 } | 1084 } |
| 1109 | 1085 |
| 1110 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1086 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1111 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 1112 | 1087 |
| 1113 CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate); | 1088 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
| 1114 | 1089 |
| 1115 if (params[1].GetType() != CJS_Value::VT_object) { | 1090 if (params[1].GetType() != CJS_Value::VT_object) { |
| 1116 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1091 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1117 return FALSE; | 1092 return FALSE; |
| 1118 } | 1093 } |
| 1119 | 1094 |
| 1120 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pIsolate); | 1095 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
| 1121 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { | 1096 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
| 1122 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1097 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1123 return FALSE; | 1098 return FALSE; |
| 1124 } | 1099 } |
| 1125 | 1100 |
| 1126 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pIsolate)->GetEmbedObject(); | 1101 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
| 1127 if (!pEmbedObj) { | 1102 if (!pEmbedObj) { |
| 1128 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | 1103 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1129 return FALSE; | 1104 return FALSE; |
| 1130 } | 1105 } |
| 1131 | 1106 |
| 1132 m_IconList.push_back(std::unique_ptr<IconElement>( | 1107 m_IconList.push_back(std::unique_ptr<IconElement>( |
| 1133 new IconElement(swIconName, (Icon*)pEmbedObj))); | 1108 new IconElement(swIconName, (Icon*)pEmbedObj))); |
| 1134 return TRUE; | 1109 return TRUE; |
| 1135 } | 1110 } |
| 1136 | 1111 |
| 1137 FX_BOOL Document::icons(IJS_Context* cc, | 1112 FX_BOOL Document::icons(IJS_Context* cc, |
| 1138 CJS_PropValue& vp, | 1113 CJS_PropValue& vp, |
| 1139 CFX_WideString& sError) { | 1114 CFX_WideString& sError) { |
| 1140 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1115 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1141 if (vp.IsSetting()) { | 1116 if (vp.IsSetting()) { |
| 1142 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | 1117 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1143 return FALSE; | 1118 return FALSE; |
| 1144 } | 1119 } |
| 1145 | 1120 |
| 1146 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1121 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1147 if (m_IconList.empty()) { | 1122 if (m_IconList.empty()) { |
| 1148 vp.GetJSValue()->SetNull(pRuntime); | 1123 vp.GetJSValue()->SetNull(pRuntime); |
| 1149 return TRUE; | 1124 return TRUE; |
| 1150 } | 1125 } |
| 1151 | 1126 |
| 1152 CJS_Array Icons; | 1127 CJS_Array Icons; |
| 1153 | 1128 |
| 1154 int i = 0; | 1129 int i = 0; |
| 1155 for (const auto& pIconElement : m_IconList) { | 1130 for (const auto& pIconElement : m_IconList) { |
| 1156 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 1131 v8::Local<v8::Object> pObj = |
| 1157 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | 1132 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1158 if (pObj.IsEmpty()) | 1133 if (pObj.IsEmpty()) |
| 1159 return FALSE; | 1134 return FALSE; |
| 1160 | 1135 |
| 1161 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | 1136 CJS_Icon* pJS_Icon = |
| 1137 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1162 if (!pJS_Icon) | 1138 if (!pJS_Icon) |
| 1163 return FALSE; | 1139 return FALSE; |
| 1164 | 1140 |
| 1165 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1141 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1166 if (!pIcon) | 1142 if (!pIcon) |
| 1167 return FALSE; | 1143 return FALSE; |
| 1168 | 1144 |
| 1169 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1145 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1170 pIcon->SetIconName(pIconElement->IconName); | 1146 pIcon->SetIconName(pIconElement->IconName); |
| 1171 Icons.SetElement(pRuntime->GetIsolate(), i++, | 1147 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
| 1172 CJS_Value(pRuntime, pJS_Icon)); | |
| 1173 } | 1148 } |
| 1174 | 1149 |
| 1175 vp << Icons; | 1150 vp << Icons; |
| 1176 return TRUE; | 1151 return TRUE; |
| 1177 } | 1152 } |
| 1178 | 1153 |
| 1179 FX_BOOL Document::getIcon(IJS_Context* cc, | 1154 FX_BOOL Document::getIcon(IJS_Context* cc, |
| 1180 const std::vector<CJS_Value>& params, | 1155 const std::vector<CJS_Value>& params, |
| 1181 CJS_Value& vRet, | 1156 CJS_Value& vRet, |
| 1182 CFX_WideString& sError) { | 1157 CFX_WideString& sError) { |
| 1183 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1158 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1184 if (params.size() != 1) { | 1159 if (params.size() != 1) { |
| 1185 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1160 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1186 return FALSE; | 1161 return FALSE; |
| 1187 } | 1162 } |
| 1188 | 1163 |
| 1189 if (m_IconList.empty()) | 1164 if (m_IconList.empty()) |
| 1190 return FALSE; | 1165 return FALSE; |
| 1191 | 1166 |
| 1192 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1167 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1193 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 1194 | 1168 |
| 1195 CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate); | 1169 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
| 1196 | 1170 |
| 1197 for (const auto& pIconElement : m_IconList) { | 1171 for (const auto& pIconElement : m_IconList) { |
| 1198 if (pIconElement->IconName == swIconName) { | 1172 if (pIconElement->IconName == swIconName) { |
| 1199 Icon* pRetIcon = pIconElement->IconStream; | 1173 Icon* pRetIcon = pIconElement->IconStream; |
| 1200 | 1174 |
| 1201 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 1175 v8::Local<v8::Object> pObj = |
| 1202 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | 1176 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1203 if (pObj.IsEmpty()) | 1177 if (pObj.IsEmpty()) |
| 1204 return FALSE; | 1178 return FALSE; |
| 1205 | 1179 |
| 1206 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | 1180 CJS_Icon* pJS_Icon = |
| 1181 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1207 if (!pJS_Icon) | 1182 if (!pJS_Icon) |
| 1208 return FALSE; | 1183 return FALSE; |
| 1209 | 1184 |
| 1210 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1185 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1211 if (!pIcon) | 1186 if (!pIcon) |
| 1212 return FALSE; | 1187 return FALSE; |
| 1213 | 1188 |
| 1214 pIcon->SetIconName(swIconName); | 1189 pIcon->SetIconName(swIconName); |
| 1215 pIcon->SetStream(pRetIcon->GetStream()); | 1190 pIcon->SetStream(pRetIcon->GetStream()); |
| 1216 vRet = CJS_Value(pRuntime, pJS_Icon); | 1191 vRet = CJS_Value(pRuntime, pJS_Icon); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 CJS_Value& vRet, | 1243 CJS_Value& vRet, |
| 1269 CFX_WideString& sError) { | 1244 CFX_WideString& sError) { |
| 1270 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1245 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1271 | 1246 |
| 1272 // TODO(tsepez): check maximum allowable params. | 1247 // TODO(tsepez): check maximum allowable params. |
| 1273 | 1248 |
| 1274 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1249 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1275 return FALSE; | 1250 return FALSE; |
| 1276 | 1251 |
| 1277 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1252 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1278 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 1279 | 1253 |
| 1280 int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0; | 1254 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1281 int nWordNo = params.size() > 1 ? params[1].ToInt(pIsolate) : 0; | 1255 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1282 bool bStrip = params.size() > 2 ? params[2].ToBool(pIsolate) : true; | 1256 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
| 1283 | 1257 |
| 1284 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1258 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1285 if (!pDocument) | 1259 if (!pDocument) |
| 1286 return FALSE; | 1260 return FALSE; |
| 1287 | 1261 |
| 1288 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1262 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1289 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1263 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1290 return FALSE; | 1264 return FALSE; |
| 1291 } | 1265 } |
| 1292 | 1266 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | 1307 FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
| 1334 const std::vector<CJS_Value>& params, | 1308 const std::vector<CJS_Value>& params, |
| 1335 CJS_Value& vRet, | 1309 CJS_Value& vRet, |
| 1336 CFX_WideString& sError) { | 1310 CFX_WideString& sError) { |
| 1337 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1311 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1338 | 1312 |
| 1339 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1313 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1340 return FALSE; | 1314 return FALSE; |
| 1341 | 1315 |
| 1342 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1316 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1343 v8::Isolate* pIsolate = pRuntime->GetIsolate(); | |
| 1344 | 1317 |
| 1345 int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0; | 1318 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1346 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1319 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1347 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1320 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1348 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1321 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1349 return FALSE; | 1322 return FALSE; |
| 1350 } | 1323 } |
| 1351 | 1324 |
| 1352 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1325 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1353 if (!pPageDict) | 1326 if (!pPageDict) |
| 1354 return FALSE; | 1327 return FALSE; |
| 1355 | 1328 |
| 1356 CPDF_Page page(pDocument, pPageDict, true); | 1329 CPDF_Page page(pDocument, pPageDict, true); |
| 1357 page.ParseContent(); | 1330 page.ParseContent(); |
| 1358 | 1331 |
| 1359 int nWords = 0; | 1332 int nWords = 0; |
| 1360 for (auto& pPageObj : *page.GetPageObjectList()) { | 1333 for (auto& pPageObj : *page.GetPageObjectList()) { |
| 1361 if (pPageObj->IsText()) | 1334 if (pPageObj->IsText()) |
| 1362 nWords += CountWords(pPageObj->AsText()); | 1335 nWords += CountWords(pPageObj->AsText()); |
| 1363 } | 1336 } |
| 1364 | 1337 |
| 1365 vRet = CJS_Value(pRuntime, nWords); | 1338 vRet = CJS_Value(pRuntime, nWords); |
| 1366 return TRUE; | 1339 return TRUE; |
| 1367 } | 1340 } |
| 1368 | 1341 |
| 1369 FX_BOOL Document::getPrintParams(IJS_Context* cc, | 1342 FX_BOOL Document::getPrintParams(IJS_Context* cc, |
| 1370 const std::vector<CJS_Value>& params, | 1343 const std::vector<CJS_Value>& params, |
| 1371 CJS_Value& vRet, | 1344 CJS_Value& vRet, |
| 1372 CFX_WideString& sError) { | 1345 CFX_WideString& sError) { |
| 1373 CJS_Context* pContext = (CJS_Context*)cc; | 1346 CJS_Context* pContext = (CJS_Context*)cc; |
| 1374 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1347 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1375 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 1348 v8::Local<v8::Object> pRetObj = |
| 1376 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); | 1349 pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); |
| 1377 | 1350 |
| 1378 // Not implemented yet. | 1351 // Not implemented yet. |
| 1379 | 1352 |
| 1380 vRet = CJS_Value(pRuntime, pRetObj); | 1353 vRet = CJS_Value(pRuntime, pRetObj); |
| 1381 return TRUE; | 1354 return TRUE; |
| 1382 } | 1355 } |
| 1383 | 1356 |
| 1384 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) | 1357 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1385 | 1358 |
| 1386 int Document::CountWords(CPDF_TextObject* pTextObj) { | 1359 int Document::CountWords(CPDF_TextObject* pTextObj) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 const std::vector<CJS_Value>& params, | 1492 const std::vector<CJS_Value>& params, |
| 1520 CJS_Value& vRet, | 1493 CJS_Value& vRet, |
| 1521 CFX_WideString& sError) { | 1494 CFX_WideString& sError) { |
| 1522 CJS_Context* context = (CJS_Context*)cc; | 1495 CJS_Context* context = (CJS_Context*)cc; |
| 1523 | 1496 |
| 1524 if (params.size() != 1) { | 1497 if (params.size() != 1) { |
| 1525 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR); | 1498 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR); |
| 1526 return FALSE; | 1499 return FALSE; |
| 1527 } | 1500 } |
| 1528 | 1501 |
| 1529 CJS_Runtime* runtime = context->GetJSRuntime(); | 1502 CJS_Runtime* pRuntime = context->GetJSRuntime(); |
| 1530 CFX_WideString wideName = params[0].ToCFXWideString(runtime->GetIsolate()); | 1503 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 1531 CFX_ByteString utf8Name = wideName.UTF8Encode(); | 1504 CFX_ByteString utf8Name = wideName.UTF8Encode(); |
| 1532 | 1505 |
| 1533 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1506 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1534 if (!pDocument) | 1507 if (!pDocument) |
| 1535 return FALSE; | 1508 return FALSE; |
| 1536 | 1509 |
| 1537 CPDF_NameTree nameTree(pDocument, "Dests"); | 1510 CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1538 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); | 1511 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1539 if (!destArray) | 1512 if (!destArray) |
| 1540 return FALSE; | 1513 return FALSE; |
| 1541 | 1514 |
| 1542 CPDF_Dest dest(destArray); | 1515 CPDF_Dest dest(destArray); |
| 1543 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); | 1516 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1544 | 1517 |
| 1545 std::unique_ptr<float[]> scrollPositionArray; | 1518 std::unique_ptr<float[]> scrollPositionArray; |
| 1546 int scrollPositionArraySize = 0; | 1519 int scrollPositionArraySize = 0; |
| 1547 | 1520 |
| 1548 if (arrayObject) { | 1521 if (arrayObject) { |
| 1549 scrollPositionArray.reset(new float[arrayObject->GetCount()]); | 1522 scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1550 int j = 0; | 1523 int j = 0; |
| 1551 for (size_t i = 2; i < arrayObject->GetCount(); i++) | 1524 for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1552 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); | 1525 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1553 scrollPositionArraySize = j; | 1526 scrollPositionArraySize = j; |
| 1554 } | 1527 } |
| 1555 | 1528 |
| 1556 runtime->BeginBlock(); | 1529 pRuntime->BeginBlock(); |
| 1557 CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); | 1530 CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); |
| 1558 pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), | 1531 pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1559 scrollPositionArray.get(), scrollPositionArraySize); | 1532 scrollPositionArray.get(), scrollPositionArraySize); |
| 1560 runtime->EndBlock(); | 1533 pRuntime->EndBlock(); |
| 1561 | 1534 |
| 1562 return TRUE; | 1535 return TRUE; |
| 1563 } | 1536 } |
| 1564 | 1537 |
| 1565 void Document::AddDelayData(CJS_DelayData* pData) { | 1538 void Document::AddDelayData(CJS_DelayData* pData) { |
| 1566 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); | 1539 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
| 1567 } | 1540 } |
| 1568 | 1541 |
| 1569 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | 1542 void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1570 int nControlIndex) { | 1543 int nControlIndex) { |
| 1571 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; | 1544 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1572 auto iter = m_DelayData.begin(); | 1545 auto iter = m_DelayData.begin(); |
| 1573 while (iter != m_DelayData.end()) { | 1546 while (iter != m_DelayData.end()) { |
| 1574 auto old = iter++; | 1547 auto old = iter++; |
| 1575 if ((*old)->sFieldName == sFieldName && | 1548 if ((*old)->sFieldName == sFieldName && |
| 1576 (*old)->nControlIndex == nControlIndex) { | 1549 (*old)->nControlIndex == nControlIndex) { |
| 1577 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); | 1550 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1578 m_DelayData.erase(old); | 1551 m_DelayData.erase(old); |
| 1579 } | 1552 } |
| 1580 } | 1553 } |
| 1581 | 1554 |
| 1582 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1555 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1583 Field::DoDelay(m_pDocument, pData.get()); | 1556 Field::DoDelay(m_pDocument, pData.get()); |
| 1584 } | 1557 } |
| 1585 | 1558 |
| 1586 CJS_Document* Document::GetCJSDoc() const { | 1559 CJS_Document* Document::GetCJSDoc() const { |
| 1587 return static_cast<CJS_Document*>(m_pJSObject); | 1560 return static_cast<CJS_Document*>(m_pJSObject); |
| 1588 } | 1561 } |
| OLD | NEW |