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

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

Issue 2394313002: Convert IJS_Runtime to CPDFSDK_FormFillEnvironment (Closed)
Patch Set: Rebase to master Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/javascript/Document.h" 7 #include "fpdfsdk/javascript/Document.h"
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 JS_STATIC_METHOD_ENTRY(submitForm) 142 JS_STATIC_METHOD_ENTRY(submitForm)
143 JS_STATIC_METHOD_ENTRY(syncAnnotScan) 143 JS_STATIC_METHOD_ENTRY(syncAnnotScan)
144 JS_STATIC_METHOD_ENTRY(mailDoc) 144 JS_STATIC_METHOD_ENTRY(mailDoc)
145 END_JS_STATIC_METHOD() 145 END_JS_STATIC_METHOD()
146 146
147 IMPLEMENT_JS_CLASS(CJS_Document, Document) 147 IMPLEMENT_JS_CLASS(CJS_Document, Document)
148 148
149 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { 149 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
150 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); 150 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
151 Document* pDoc = static_cast<Document*>(GetEmbedObject()); 151 Document* pDoc = static_cast<Document*>(GetEmbedObject());
152 pDoc->AttachDoc(pRuntime->GetReaderDocument()); 152 pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv());
153 } 153 }
154 154
155 Document::Document(CJS_Object* pJSObject) 155 Document::Document(CJS_Object* pJSObject)
156 : CJS_EmbedObj(pJSObject), 156 : CJS_EmbedObj(pJSObject),
157 m_pDocument(nullptr), 157 m_pFormFillEnv(nullptr),
158 m_cwBaseURL(L""), 158 m_cwBaseURL(L""),
159 m_bDelay(FALSE) {} 159 m_bDelay(FALSE) {}
160 160
161 Document::~Document() { 161 Document::~Document() {
162 } 162 }
163 163
164 // the total number of fileds in document. 164 // the total number of fileds in document.
165 FX_BOOL Document::numFields(IJS_Context* cc, 165 FX_BOOL Document::numFields(IJS_Context* cc,
166 CJS_PropValue& vp, 166 CJS_PropValue& vp,
167 CFX_WideString& sError) { 167 CFX_WideString& sError) {
168 if (vp.IsSetting()) { 168 if (vp.IsSetting()) {
169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
170 return FALSE; 170 return FALSE;
171 } 171 }
172 if (!m_pDocument) { 172 if (!m_pFormFillEnv) {
173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
174 return FALSE; 174 return FALSE;
175 } 175 }
176 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 176 CPDFSDK_InterForm* pInterForm =
177 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 178 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
178 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); 179 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString()));
179 return TRUE; 180 return TRUE;
180 } 181 }
181 182
182 FX_BOOL Document::dirty(IJS_Context* cc, 183 FX_BOOL Document::dirty(IJS_Context* cc,
183 CJS_PropValue& vp, 184 CJS_PropValue& vp,
184 CFX_WideString& sError) { 185 CFX_WideString& sError) {
185 if (!m_pDocument) { 186 if (!m_pFormFillEnv) {
186 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 187 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
187 return FALSE; 188 return FALSE;
188 } 189 }
189 if (vp.IsGetting()) { 190 if (vp.IsGetting()) {
190 vp << !!m_pDocument->GetChangeMark(); 191 vp << !!m_pFormFillEnv->GetSDKDocument()->GetChangeMark();
191 } else { 192 } else {
192 bool bChanged = false; 193 bool bChanged = false;
193 vp >> bChanged; 194 vp >> bChanged;
194 195
195 if (bChanged) 196 if (bChanged)
196 m_pDocument->SetChangeMark(); 197 m_pFormFillEnv->GetSDKDocument()->SetChangeMark();
197 else 198 else
198 m_pDocument->ClearChangeMark(); 199 m_pFormFillEnv->GetSDKDocument()->ClearChangeMark();
199 } 200 }
200 return TRUE; 201 return TRUE;
201 } 202 }
202 203
203 FX_BOOL Document::ADBE(IJS_Context* cc, 204 FX_BOOL Document::ADBE(IJS_Context* cc,
204 CJS_PropValue& vp, 205 CJS_PropValue& vp,
205 CFX_WideString& sError) { 206 CFX_WideString& sError) {
206 if (vp.IsGetting()) 207 if (vp.IsGetting())
207 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); 208 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc));
208 209
209 return TRUE; 210 return TRUE;
210 } 211 }
211 212
212 FX_BOOL Document::pageNum(IJS_Context* cc, 213 FX_BOOL Document::pageNum(IJS_Context* cc,
213 CJS_PropValue& vp, 214 CJS_PropValue& vp,
214 CFX_WideString& sError) { 215 CFX_WideString& sError) {
215 if (!m_pDocument) { 216 if (!m_pFormFillEnv) {
216 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 217 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
217 return FALSE; 218 return FALSE;
218 } 219 }
219 if (vp.IsGetting()) { 220 if (vp.IsGetting()) {
220 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { 221 if (CPDFSDK_PageView* pPageView =
222 m_pFormFillEnv->GetSDKDocument()->GetCurrentView()) {
221 vp << pPageView->GetPageIndex(); 223 vp << pPageView->GetPageIndex();
222 } 224 }
223 } else { 225 } else {
224 int iPageCount = m_pDocument->GetPageCount(); 226 int iPageCount = m_pFormFillEnv->GetSDKDocument()->GetPageCount();
225 int iPageNum = 0; 227 int iPageNum = 0;
226 vp >> iPageNum; 228 vp >> iPageNum;
227 229
228 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
229 if (iPageNum >= 0 && iPageNum < iPageCount) { 230 if (iPageNum >= 0 && iPageNum < iPageCount) {
230 pEnv->JS_docgotoPage(iPageNum); 231 m_pFormFillEnv->JS_docgotoPage(iPageNum);
231 } else if (iPageNum >= iPageCount) { 232 } else if (iPageNum >= iPageCount) {
232 pEnv->JS_docgotoPage(iPageCount - 1); 233 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1);
233 } else if (iPageNum < 0) { 234 } else if (iPageNum < 0) {
234 pEnv->JS_docgotoPage(0); 235 m_pFormFillEnv->JS_docgotoPage(0);
235 } 236 }
236 } 237 }
237 238
238 return TRUE; 239 return TRUE;
239 } 240 }
240 241
241 FX_BOOL Document::addAnnot(IJS_Context* cc, 242 FX_BOOL Document::addAnnot(IJS_Context* cc,
242 const std::vector<CJS_Value>& params, 243 const std::vector<CJS_Value>& params,
243 CJS_Value& vRet, 244 CJS_Value& vRet,
244 CFX_WideString& sError) { 245 CFX_WideString& sError) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // valiable filed name in this document 285 // valiable filed name in this document
285 286
286 FX_BOOL Document::getField(IJS_Context* cc, 287 FX_BOOL Document::getField(IJS_Context* cc,
287 const std::vector<CJS_Value>& params, 288 const std::vector<CJS_Value>& params,
288 CJS_Value& vRet, 289 CJS_Value& vRet,
289 CFX_WideString& sError) { 290 CFX_WideString& sError) {
290 if (params.size() < 1) { 291 if (params.size() < 1) {
291 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 292 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
292 return FALSE; 293 return FALSE;
293 } 294 }
294 if (!m_pDocument) { 295 if (!m_pFormFillEnv) {
295 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 296 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
296 return FALSE; 297 return FALSE;
297 } 298 }
298 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 299 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
299 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 300 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
300 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); 301 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
301 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 302 CPDFSDK_InterForm* pInterForm =
303 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
302 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 304 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
303 if (pPDFForm->CountFields(wideName) <= 0) { 305 if (pPDFForm->CountFields(wideName) <= 0) {
304 vRet.SetNull(pRuntime); 306 vRet.SetNull(pRuntime);
305 return TRUE; 307 return TRUE;
306 } 308 }
307 309
308 v8::Local<v8::Object> pFieldObj = 310 v8::Local<v8::Object> pFieldObj =
309 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); 311 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
310 CJS_Field* pJSField = 312 CJS_Field* pJSField =
311 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); 313 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
312 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); 314 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
313 pField->AttachField(this, wideName); 315 pField->AttachField(this, wideName);
314 316
315 vRet = CJS_Value(pRuntime, pJSField); 317 vRet = CJS_Value(pRuntime, pJSField);
316 return TRUE; 318 return TRUE;
317 } 319 }
318 320
319 // Gets the name of the nth field in the document 321 // Gets the name of the nth field in the document
320 FX_BOOL Document::getNthFieldName(IJS_Context* cc, 322 FX_BOOL Document::getNthFieldName(IJS_Context* cc,
321 const std::vector<CJS_Value>& params, 323 const std::vector<CJS_Value>& params,
322 CJS_Value& vRet, 324 CJS_Value& vRet,
323 CFX_WideString& sError) { 325 CFX_WideString& sError) {
324 if (params.size() != 1) { 326 if (params.size() != 1) {
325 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 327 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
326 return FALSE; 328 return FALSE;
327 } 329 }
328 if (!m_pDocument) { 330 if (!m_pFormFillEnv) {
329 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 331 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
330 return FALSE; 332 return FALSE;
331 } 333 }
332 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 334 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
333 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 335 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
334 int nIndex = params[0].ToInt(pRuntime); 336 int nIndex = params[0].ToInt(pRuntime);
335 if (nIndex < 0) { 337 if (nIndex < 0) {
336 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); 338 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
337 return FALSE; 339 return FALSE;
338 } 340 }
339 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 341 CPDFSDK_InterForm* pInterForm =
342 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
340 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 343 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
341 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); 344 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString());
342 if (!pField) 345 if (!pField)
343 return FALSE; 346 return FALSE;
344 347
345 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); 348 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str());
346 return TRUE; 349 return TRUE;
347 } 350 }
348 351
349 FX_BOOL Document::importAnFDF(IJS_Context* cc, 352 FX_BOOL Document::importAnFDF(IJS_Context* cc,
(...skipping 24 matching lines...) Expand all
374 // all recipients. 377 // all recipients.
375 // comment: need reader supports 378 // comment: need reader supports
376 // note: 379 // note:
377 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string 380 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string
378 // cbcc,string cSubject,string cms); 381 // cbcc,string cSubject,string cms);
379 382
380 FX_BOOL Document::mailForm(IJS_Context* cc, 383 FX_BOOL Document::mailForm(IJS_Context* cc,
381 const std::vector<CJS_Value>& params, 384 const std::vector<CJS_Value>& params,
382 CJS_Value& vRet, 385 CJS_Value& vRet,
383 CFX_WideString& sError) { 386 CFX_WideString& sError) {
384 if (!m_pDocument) { 387 if (!m_pFormFillEnv) {
385 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 388 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
386 return FALSE; 389 return FALSE;
387 } 390 }
388 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { 391 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(
392 FPDFPERM_EXTRACT_ACCESS)) {
389 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 393 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
390 return FALSE; 394 return FALSE;
391 } 395 }
392 396
393 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 397 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
394 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 398 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
395 399
396 int iLength = params.size(); 400 int iLength = params.size();
397 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; 401 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE;
398 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; 402 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L"";
399 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; 403 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L"";
400 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; 404 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L"";
401 CFX_WideString cSubject = 405 CFX_WideString cSubject =
402 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; 406 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L"";
403 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; 407 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L"";
404 408
405 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 409 CPDFSDK_InterForm* pInterForm =
410 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
406 CFX_ByteTextBuf textBuf; 411 CFX_ByteTextBuf textBuf;
407 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) 412 if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
408 return FALSE; 413 return FALSE;
409 414
410 pRuntime->BeginBlock(); 415 pRuntime->BeginBlock();
411 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetFormFillEnv(); 416 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetFormFillEnv();
412 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, 417 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
413 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), 418 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(),
414 cMsg.c_str()); 419 cMsg.c_str());
415 pRuntime->EndBlock(); 420 pRuntime->EndBlock();
416 return TRUE; 421 return TRUE;
417 } 422 }
418 423
419 FX_BOOL Document::print(IJS_Context* cc, 424 FX_BOOL Document::print(IJS_Context* cc,
420 const std::vector<CJS_Value>& params, 425 const std::vector<CJS_Value>& params,
421 CJS_Value& vRet, 426 CJS_Value& vRet,
422 CFX_WideString& sError) { 427 CFX_WideString& sError) {
423 if (!m_pDocument) { 428 if (!m_pFormFillEnv) {
424 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 429 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
425 return FALSE; 430 return FALSE;
426 } 431 }
427 432
428 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 433 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
429 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 434 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
430 435
431 FX_BOOL bUI = TRUE; 436 FX_BOOL bUI = TRUE;
432 int nStart = 0; 437 int nStart = 0;
433 int nEnd = 0; 438 int nEnd = 0;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if (nlength >= 5) 475 if (nlength >= 5)
471 bShrinkToFit = params[4].ToBool(pRuntime); 476 bShrinkToFit = params[4].ToBool(pRuntime);
472 if (nlength >= 6) 477 if (nlength >= 6)
473 bPrintAsImage = params[5].ToBool(pRuntime); 478 bPrintAsImage = params[5].ToBool(pRuntime);
474 if (nlength >= 7) 479 if (nlength >= 7)
475 bReverse = params[6].ToBool(pRuntime); 480 bReverse = params[6].ToBool(pRuntime);
476 if (nlength >= 8) 481 if (nlength >= 8)
477 bAnnotations = params[7].ToBool(pRuntime); 482 bAnnotations = params[7].ToBool(pRuntime);
478 } 483 }
479 484
480 if (CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv()) { 485 if (m_pFormFillEnv) {
481 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, 486 m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit,
482 bReverse, bAnnotations); 487 bPrintAsImage, bReverse, bAnnotations);
483 return TRUE; 488 return TRUE;
484 } 489 }
485 return FALSE; 490 return FALSE;
486 } 491 }
487 492
488 // removes the specified field from the document. 493 // removes the specified field from the document.
489 // comment: 494 // comment:
490 // note: if the filed name is not rational, adobe is dumb for it. 495 // note: if the filed name is not rational, adobe is dumb for it.
491 496
492 FX_BOOL Document::removeField(IJS_Context* cc, 497 FX_BOOL Document::removeField(IJS_Context* cc,
493 const std::vector<CJS_Value>& params, 498 const std::vector<CJS_Value>& params,
494 CJS_Value& vRet, 499 CJS_Value& vRet,
495 CFX_WideString& sError) { 500 CFX_WideString& sError) {
496 if (params.size() != 1) { 501 if (params.size() != 1) {
497 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 502 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
498 return FALSE; 503 return FALSE;
499 } 504 }
500 if (!m_pDocument) { 505 if (!m_pFormFillEnv) {
501 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 506 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
502 return FALSE; 507 return FALSE;
503 } 508 }
504 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || 509 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) ||
505 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { 510 m_pFormFillEnv->GetSDKDocument()->GetPermissions(
511 FPDFPERM_ANNOT_FORM))) {
506 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 512 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
507 return FALSE; 513 return FALSE;
508 } 514 }
509 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 515 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
510 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 516 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
511 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); 517 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime);
512 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 518 CPDFSDK_InterForm* pInterForm =
519 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
513 std::vector<CPDFSDK_Widget*> widgets; 520 std::vector<CPDFSDK_Widget*> widgets;
514 pInterForm->GetWidgets(sFieldName, &widgets); 521 pInterForm->GetWidgets(sFieldName, &widgets);
515 if (widgets.empty()) 522 if (widgets.empty())
516 return TRUE; 523 return TRUE;
517 524
518 for (CPDFSDK_Widget* pWidget : widgets) { 525 for (CPDFSDK_Widget* pWidget : widgets) {
519 CFX_FloatRect rcAnnot = pWidget->GetRect(); 526 CFX_FloatRect rcAnnot = pWidget->GetRect();
520 --rcAnnot.left; 527 --rcAnnot.left;
521 --rcAnnot.bottom; 528 --rcAnnot.bottom;
522 ++rcAnnot.right; 529 ++rcAnnot.right;
523 ++rcAnnot.top; 530 ++rcAnnot.top;
524 531
525 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); 532 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot);
526 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); 533 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
527 ASSERT(pPage); 534 ASSERT(pPage);
528 535
529 // If there is currently no pageview associated with the page being used 536 // If there is currently no pageview associated with the page being used
530 // do not create one. We may be in the process of tearing down the document 537 // do not create one. We may be in the process of tearing down the document
531 // and creating a new pageview at this point will cause bad things. 538 // and creating a new pageview at this point will cause bad things.
532 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); 539 CPDFSDK_PageView* pPageView =
540 m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false);
533 if (pPageView) { 541 if (pPageView) {
534 #if PDF_ENABLE_XFA 542 #if PDF_ENABLE_XFA
535 pPageView->DeleteAnnot(pWidget); 543 pPageView->DeleteAnnot(pWidget);
536 #endif // PDF_ENABLE_XFA 544 #endif // PDF_ENABLE_XFA
537 pPageView->UpdateRects(aRefresh); 545 pPageView->UpdateRects(aRefresh);
538 } 546 }
539 } 547 }
540 m_pDocument->SetChangeMark(); 548 m_pFormFillEnv->GetSDKDocument()->SetChangeMark();
541 549
542 return TRUE; 550 return TRUE;
543 } 551 }
544 552
545 // reset filed values within a document. 553 // reset filed values within a document.
546 // comment: 554 // comment:
547 // note: if the fields names r not rational, aodbe is dumb for it. 555 // note: if the fields names r not rational, aodbe is dumb for it.
548 556
549 FX_BOOL Document::resetForm(IJS_Context* cc, 557 FX_BOOL Document::resetForm(IJS_Context* cc,
550 const std::vector<CJS_Value>& params, 558 const std::vector<CJS_Value>& params,
551 CJS_Value& vRet, 559 CJS_Value& vRet,
552 CFX_WideString& sError) { 560 CFX_WideString& sError) {
553 if (!m_pDocument) { 561 if (!m_pFormFillEnv) {
554 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 562 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
555 return FALSE; 563 return FALSE;
556 } 564 }
557 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || 565 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) ||
558 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || 566 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) ||
559 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { 567 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) {
560 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 568 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
561 return FALSE; 569 return FALSE;
562 } 570 }
563 571
564 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 572 CPDFSDK_InterForm* pInterForm =
573 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
565 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 574 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
566 CJS_Array aName; 575 CJS_Array aName;
567 576
568 if (params.empty()) { 577 if (params.empty()) {
569 pPDFForm->ResetForm(TRUE); 578 pPDFForm->ResetForm(TRUE);
570 m_pDocument->SetChangeMark(); 579 m_pFormFillEnv->GetSDKDocument()->SetChangeMark();
571 return TRUE; 580 return TRUE;
572 } 581 }
573 582
574 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 583 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
575 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 584 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
576 585
577 switch (params[0].GetType()) { 586 switch (params[0].GetType()) {
578 default: 587 default:
579 aName.Attach(params[0].ToV8Array(pRuntime)); 588 aName.Attach(params[0].ToV8Array(pRuntime));
580 break; 589 break;
581 case CJS_Value::VT_string: 590 case CJS_Value::VT_string:
582 aName.SetElement(pRuntime, 0, params[0]); 591 aName.SetElement(pRuntime, 0, params[0]);
583 break; 592 break;
584 } 593 }
585 594
586 std::vector<CPDF_FormField*> aFields; 595 std::vector<CPDF_FormField*> aFields;
587 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { 596 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) {
588 CJS_Value valElement(pRuntime); 597 CJS_Value valElement(pRuntime);
589 aName.GetElement(pRuntime, i, valElement); 598 aName.GetElement(pRuntime, i, valElement);
590 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); 599 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime);
591 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) 600 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
592 aFields.push_back(pPDFForm->GetField(j, swVal)); 601 aFields.push_back(pPDFForm->GetField(j, swVal));
593 } 602 }
594 603
595 if (!aFields.empty()) { 604 if (!aFields.empty()) {
596 pPDFForm->ResetForm(aFields, TRUE, TRUE); 605 pPDFForm->ResetForm(aFields, TRUE, TRUE);
597 m_pDocument->SetChangeMark(); 606 m_pFormFillEnv->GetSDKDocument()->SetChangeMark();
598 } 607 }
599 608
600 return TRUE; 609 return TRUE;
601 } 610 }
602 611
603 FX_BOOL Document::saveAs(IJS_Context* cc, 612 FX_BOOL Document::saveAs(IJS_Context* cc,
604 const std::vector<CJS_Value>& params, 613 const std::vector<CJS_Value>& params,
605 CJS_Value& vRet, 614 CJS_Value& vRet,
606 CFX_WideString& sError) { 615 CFX_WideString& sError) {
607 // Unsafe, not supported. 616 // Unsafe, not supported.
608 return TRUE; 617 return TRUE;
609 } 618 }
610 619
611 FX_BOOL Document::syncAnnotScan(IJS_Context* cc, 620 FX_BOOL Document::syncAnnotScan(IJS_Context* cc,
612 const std::vector<CJS_Value>& params, 621 const std::vector<CJS_Value>& params,
613 CJS_Value& vRet, 622 CJS_Value& vRet,
614 CFX_WideString& sError) { 623 CFX_WideString& sError) {
615 return TRUE; 624 return TRUE;
616 } 625 }
617 626
618 FX_BOOL Document::submitForm(IJS_Context* cc, 627 FX_BOOL Document::submitForm(IJS_Context* cc,
619 const std::vector<CJS_Value>& params, 628 const std::vector<CJS_Value>& params,
620 CJS_Value& vRet, 629 CJS_Value& vRet,
621 CFX_WideString& sError) { 630 CFX_WideString& sError) {
622 int nSize = params.size(); 631 int nSize = params.size();
623 if (nSize < 1) { 632 if (nSize < 1) {
624 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 633 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
625 return FALSE; 634 return FALSE;
626 } 635 }
627 if (!m_pDocument) { 636 if (!m_pFormFillEnv) {
628 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 637 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
629 return FALSE; 638 return FALSE;
630 } 639 }
631 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 640 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
632 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 641 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
633 CJS_Array aFields; 642 CJS_Array aFields;
634 CFX_WideString strURL; 643 CFX_WideString strURL;
635 FX_BOOL bFDF = TRUE; 644 FX_BOOL bFDF = TRUE;
636 FX_BOOL bEmpty = FALSE; 645 FX_BOOL bEmpty = FALSE;
637 CJS_Value v = params[0]; 646 CJS_Value v = params[0];
(...skipping 14 matching lines...) Expand all
652 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); 661 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF");
653 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); 662 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime);
654 663
655 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); 664 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty");
656 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); 665 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime);
657 666
658 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); 667 pValue = pRuntime->GetObjectProperty(pObj, L"aFields");
659 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); 668 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime));
660 } 669 }
661 670
662 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 671 CPDFSDK_InterForm* pInterForm =
672 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
663 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 673 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
664 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { 674 if (aFields.GetLength(pRuntime) == 0 && bEmpty) {
665 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { 675 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) {
666 pRuntime->BeginBlock(); 676 pRuntime->BeginBlock();
667 pInterForm->SubmitForm(strURL, FALSE); 677 pInterForm->SubmitForm(strURL, FALSE);
668 pRuntime->EndBlock(); 678 pRuntime->EndBlock();
669 } 679 }
670 return TRUE; 680 return TRUE;
671 } 681 }
672 682
(...skipping 14 matching lines...) Expand all
687 } 697 }
688 698
689 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { 699 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) {
690 pRuntime->BeginBlock(); 700 pRuntime->BeginBlock();
691 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); 701 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF);
692 pRuntime->EndBlock(); 702 pRuntime->EndBlock();
693 } 703 }
694 return TRUE; 704 return TRUE;
695 } 705 }
696 706
697 void Document::AttachDoc(CPDFSDK_Document* pDoc) { 707 void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
698 m_pDocument.Reset(pDoc); 708 m_pFormFillEnv.Reset(pFormFillEnv);
699 } 709 }
700 710
701 FX_BOOL Document::bookmarkRoot(IJS_Context* cc, 711 FX_BOOL Document::bookmarkRoot(IJS_Context* cc,
702 CJS_PropValue& vp, 712 CJS_PropValue& vp,
703 CFX_WideString& sError) { 713 CFX_WideString& sError) {
704 return TRUE; 714 return TRUE;
705 } 715 }
706 716
707 FX_BOOL Document::mailDoc(IJS_Context* cc, 717 FX_BOOL Document::mailDoc(IJS_Context* cc,
708 const std::vector<CJS_Value>& params, 718 const std::vector<CJS_Value>& params,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); 760 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
751 761
752 pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); 762 pValue = pRuntime->GetObjectProperty(pObj, L"cSubject");
753 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); 763 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
754 764
755 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); 765 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg");
756 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); 766 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
757 } 767 }
758 768
759 pRuntime->BeginBlock(); 769 pRuntime->BeginBlock();
760 CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetReaderEnv(); 770 CPDFSDK_FormFillEnvironment* pEnv = pRuntime->GetFormFillEnv();
761 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), 771 pEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(),
762 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); 772 cCc.c_str(), cBcc.c_str(), cMsg.c_str());
763 pRuntime->EndBlock(); 773 pRuntime->EndBlock();
764 774
765 return TRUE; 775 return TRUE;
766 } 776 }
767 777
768 FX_BOOL Document::author(IJS_Context* cc, 778 FX_BOOL Document::author(IJS_Context* cc,
769 CJS_PropValue& vp, 779 CJS_PropValue& vp,
770 CFX_WideString& sError) { 780 CFX_WideString& sError) {
771 return getPropertyInternal(cc, vp, "Author", sError); 781 return getPropertyInternal(cc, vp, "Author", sError);
772 } 782 }
773 783
774 FX_BOOL Document::info(IJS_Context* cc, 784 FX_BOOL Document::info(IJS_Context* cc,
775 CJS_PropValue& vp, 785 CJS_PropValue& vp,
776 CFX_WideString& sError) { 786 CFX_WideString& sError) {
777 if (vp.IsSetting()) { 787 if (vp.IsSetting()) {
778 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 788 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
779 return FALSE; 789 return FALSE;
780 } 790 }
781 if (!m_pDocument) { 791 if (!m_pFormFillEnv) {
782 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 792 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
783 return FALSE; 793 return FALSE;
784 } 794 }
785 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); 795 CPDF_Dictionary* pDictionary =
796 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo();
786 if (!pDictionary) 797 if (!pDictionary)
787 return FALSE; 798 return FALSE;
788 799
789 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); 800 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author");
790 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); 801 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title");
791 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); 802 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject");
792 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); 803 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords");
793 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); 804 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator");
794 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); 805 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer");
795 CFX_WideString cwCreationDate = 806 CFX_WideString cwCreationDate =
(...skipping 29 matching lines...) Expand all
825 } 836 }
826 } 837 }
827 vp << pObj; 838 vp << pObj;
828 return TRUE; 839 return TRUE;
829 } 840 }
830 841
831 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, 842 FX_BOOL Document::getPropertyInternal(IJS_Context* cc,
832 CJS_PropValue& vp, 843 CJS_PropValue& vp,
833 const CFX_ByteString& propName, 844 const CFX_ByteString& propName,
834 CFX_WideString& sError) { 845 CFX_WideString& sError) {
835 if (!m_pDocument) { 846 if (!m_pFormFillEnv) {
836 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 847 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
837 return FALSE; 848 return FALSE;
838 } 849 }
839 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); 850 CPDF_Dictionary* pDictionary =
851 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo();
840 if (!pDictionary) 852 if (!pDictionary)
841 return FALSE; 853 return FALSE;
842 854
843 if (vp.IsGetting()) { 855 if (vp.IsGetting()) {
844 vp << pDictionary->GetUnicodeTextFor(propName); 856 vp << pDictionary->GetUnicodeTextFor(propName);
845 } else { 857 } else {
846 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) { 858 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) {
847 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 859 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
848 return FALSE; 860 return FALSE;
849 } 861 }
850 CFX_WideString csProperty; 862 CFX_WideString csProperty;
851 vp >> csProperty; 863 vp >> csProperty;
852 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); 864 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty));
853 m_pDocument->SetChangeMark(); 865 m_pFormFillEnv->GetSDKDocument()->SetChangeMark();
854 } 866 }
855 return TRUE; 867 return TRUE;
856 } 868 }
857 869
858 FX_BOOL Document::creationDate(IJS_Context* cc, 870 FX_BOOL Document::creationDate(IJS_Context* cc,
859 CJS_PropValue& vp, 871 CJS_PropValue& vp,
860 CFX_WideString& sError) { 872 CFX_WideString& sError) {
861 return getPropertyInternal(cc, vp, "CreationDate", sError); 873 return getPropertyInternal(cc, vp, "CreationDate", sError);
862 } 874 }
863 875
864 FX_BOOL Document::creator(IJS_Context* cc, 876 FX_BOOL Document::creator(IJS_Context* cc,
865 CJS_PropValue& vp, 877 CJS_PropValue& vp,
866 CFX_WideString& sError) { 878 CFX_WideString& sError) {
867 return getPropertyInternal(cc, vp, "Creator", sError); 879 return getPropertyInternal(cc, vp, "Creator", sError);
868 } 880 }
869 881
870 FX_BOOL Document::delay(IJS_Context* cc, 882 FX_BOOL Document::delay(IJS_Context* cc,
871 CJS_PropValue& vp, 883 CJS_PropValue& vp,
872 CFX_WideString& sError) { 884 CFX_WideString& sError) {
873 if (!m_pDocument) { 885 if (!m_pFormFillEnv) {
874 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 886 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
875 return FALSE; 887 return FALSE;
876 } 888 }
877 if (vp.IsGetting()) { 889 if (vp.IsGetting()) {
878 vp << m_bDelay; 890 vp << m_bDelay;
879 } else { 891 } else {
880 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) { 892 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) {
881 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 893 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
882 return FALSE; 894 return FALSE;
883 } 895 }
884 vp >> m_bDelay; 896 vp >> m_bDelay;
885 if (m_bDelay) { 897 if (m_bDelay) {
886 m_DelayData.clear(); 898 m_DelayData.clear();
887 } else { 899 } else {
888 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; 900 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess;
889 DelayDataToProcess.swap(m_DelayData); 901 DelayDataToProcess.swap(m_DelayData);
890 for (const auto& pData : DelayDataToProcess) { 902 for (const auto& pData : DelayDataToProcess)
891 if (m_pDocument.Get()) 903 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
892 Field::DoDelay(m_pDocument->GetEnv(), pData.get());
893 }
894 } 904 }
895 } 905 }
896 return TRUE; 906 return TRUE;
897 } 907 }
898 908
899 FX_BOOL Document::keywords(IJS_Context* cc, 909 FX_BOOL Document::keywords(IJS_Context* cc,
900 CJS_PropValue& vp, 910 CJS_PropValue& vp,
901 CFX_WideString& sError) { 911 CFX_WideString& sError) {
902 return getPropertyInternal(cc, vp, "Keywords", sError); 912 return getPropertyInternal(cc, vp, "Keywords", sError);
903 } 913 }
(...skipping 12 matching lines...) Expand all
916 926
917 FX_BOOL Document::subject(IJS_Context* cc, 927 FX_BOOL Document::subject(IJS_Context* cc,
918 CJS_PropValue& vp, 928 CJS_PropValue& vp,
919 CFX_WideString& sError) { 929 CFX_WideString& sError) {
920 return getPropertyInternal(cc, vp, "Subject", sError); 930 return getPropertyInternal(cc, vp, "Subject", sError);
921 } 931 }
922 932
923 FX_BOOL Document::title(IJS_Context* cc, 933 FX_BOOL Document::title(IJS_Context* cc,
924 CJS_PropValue& vp, 934 CJS_PropValue& vp,
925 CFX_WideString& sError) { 935 CFX_WideString& sError) {
926 if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) { 936 if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) {
927 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 937 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
928 return FALSE; 938 return FALSE;
929 } 939 }
930 return getPropertyInternal(cc, vp, "Title", sError); 940 return getPropertyInternal(cc, vp, "Title", sError);
931 } 941 }
932 942
933 FX_BOOL Document::numPages(IJS_Context* cc, 943 FX_BOOL Document::numPages(IJS_Context* cc,
934 CJS_PropValue& vp, 944 CJS_PropValue& vp,
935 CFX_WideString& sError) { 945 CFX_WideString& sError) {
936 if (vp.IsSetting()) { 946 if (vp.IsSetting()) {
937 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 947 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
938 return FALSE; 948 return FALSE;
939 } 949 }
940 if (!m_pDocument) { 950 if (!m_pFormFillEnv) {
941 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 951 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
942 return FALSE; 952 return FALSE;
943 } 953 }
944 vp << m_pDocument->GetPageCount(); 954 vp << m_pFormFillEnv->GetSDKDocument()->GetPageCount();
945 return TRUE; 955 return TRUE;
946 } 956 }
947 957
948 FX_BOOL Document::external(IJS_Context* cc, 958 FX_BOOL Document::external(IJS_Context* cc,
949 CJS_PropValue& vp, 959 CJS_PropValue& vp,
950 CFX_WideString& sError) { 960 CFX_WideString& sError) {
951 // In Chrome case, should always return true. 961 // In Chrome case, should always return true.
952 if (vp.IsGetting()) { 962 if (vp.IsGetting()) {
953 vp << true; 963 vp << true;
954 } 964 }
(...skipping 23 matching lines...) Expand all
978 return TRUE; 988 return TRUE;
979 } 989 }
980 990
981 FX_BOOL Document::URL(IJS_Context* cc, 991 FX_BOOL Document::URL(IJS_Context* cc,
982 CJS_PropValue& vp, 992 CJS_PropValue& vp,
983 CFX_WideString& sError) { 993 CFX_WideString& sError) {
984 if (vp.IsSetting()) { 994 if (vp.IsSetting()) {
985 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 995 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
986 return FALSE; 996 return FALSE;
987 } 997 }
988 if (!m_pDocument) { 998 if (!m_pFormFillEnv) {
989 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 999 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
990 return FALSE; 1000 return FALSE;
991 } 1001 }
992 vp << m_pDocument->GetPath(); 1002 vp << m_pFormFillEnv->GetSDKDocument()->GetPath();
993 return TRUE; 1003 return TRUE;
994 } 1004 }
995 1005
996 FX_BOOL Document::baseURL(IJS_Context* cc, 1006 FX_BOOL Document::baseURL(IJS_Context* cc,
997 CJS_PropValue& vp, 1007 CJS_PropValue& vp,
998 CFX_WideString& sError) { 1008 CFX_WideString& sError) {
999 if (vp.IsGetting()) { 1009 if (vp.IsGetting()) {
1000 vp << m_cwBaseURL; 1010 vp << m_cwBaseURL;
1001 } else { 1011 } else {
1002 vp >> m_cwBaseURL; 1012 vp >> m_cwBaseURL;
1003 } 1013 }
1004 return TRUE; 1014 return TRUE;
1005 } 1015 }
1006 1016
1007 FX_BOOL Document::calculate(IJS_Context* cc, 1017 FX_BOOL Document::calculate(IJS_Context* cc,
1008 CJS_PropValue& vp, 1018 CJS_PropValue& vp,
1009 CFX_WideString& sError) { 1019 CFX_WideString& sError) {
1010 if (!m_pDocument) { 1020 if (!m_pFormFillEnv) {
1011 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1021 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1012 return FALSE; 1022 return FALSE;
1013 } 1023 }
1014 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 1024 CPDFSDK_InterForm* pInterForm =
1025 m_pFormFillEnv->GetSDKDocument()->GetInterForm();
1015 if (vp.IsGetting()) { 1026 if (vp.IsGetting()) {
1016 vp << !!pInterForm->IsCalculateEnabled(); 1027 vp << !!pInterForm->IsCalculateEnabled();
1017 } else { 1028 } else {
1018 bool bCalculate; 1029 bool bCalculate;
1019 vp >> bCalculate; 1030 vp >> bCalculate;
1020 pInterForm->EnableCalculate(bCalculate); 1031 pInterForm->EnableCalculate(bCalculate);
1021 } 1032 }
1022 return TRUE; 1033 return TRUE;
1023 } 1034 }
1024 1035
1025 FX_BOOL Document::documentFileName(IJS_Context* cc, 1036 FX_BOOL Document::documentFileName(IJS_Context* cc,
1026 CJS_PropValue& vp, 1037 CJS_PropValue& vp,
1027 CFX_WideString& sError) { 1038 CFX_WideString& sError) {
1028 if (vp.IsSetting()) { 1039 if (vp.IsSetting()) {
1029 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 1040 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1030 return FALSE; 1041 return FALSE;
1031 } 1042 }
1032 if (!m_pDocument) { 1043 if (!m_pFormFillEnv) {
1033 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1044 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1034 return FALSE; 1045 return FALSE;
1035 } 1046 }
1036 CFX_WideString wsFilePath = m_pDocument->GetPath(); 1047 CFX_WideString wsFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath();
1037 int32_t i = wsFilePath.GetLength() - 1; 1048 int32_t i = wsFilePath.GetLength() - 1;
1038 for (; i >= 0; i--) { 1049 for (; i >= 0; i--) {
1039 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') 1050 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/')
1040 break; 1051 break;
1041 } 1052 }
1042 if (i >= 0 && i < wsFilePath.GetLength() - 1) { 1053 if (i >= 0 && i < wsFilePath.GetLength() - 1) {
1043 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); 1054 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1);
1044 } else { 1055 } else {
1045 vp << L""; 1056 vp << L"";
1046 } 1057 }
1047 return TRUE; 1058 return TRUE;
1048 } 1059 }
1049 1060
1050 FX_BOOL Document::path(IJS_Context* cc, 1061 FX_BOOL Document::path(IJS_Context* cc,
1051 CJS_PropValue& vp, 1062 CJS_PropValue& vp,
1052 CFX_WideString& sError) { 1063 CFX_WideString& sError) {
1053 if (vp.IsSetting()) { 1064 if (vp.IsSetting()) {
1054 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 1065 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1055 return FALSE; 1066 return FALSE;
1056 } 1067 }
1057 if (!m_pDocument) { 1068 if (!m_pFormFillEnv) {
1058 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1069 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1059 return FALSE; 1070 return FALSE;
1060 } 1071 }
1061 vp << app::SysPathToPDFPath(m_pDocument->GetPath()); 1072 vp << app::SysPathToPDFPath(m_pFormFillEnv->GetSDKDocument()->GetPath());
1062 return TRUE; 1073 return TRUE;
1063 } 1074 }
1064 1075
1065 FX_BOOL Document::pageWindowRect(IJS_Context* cc, 1076 FX_BOOL Document::pageWindowRect(IJS_Context* cc,
1066 CJS_PropValue& vp, 1077 CJS_PropValue& vp,
1067 CFX_WideString& sError) { 1078 CFX_WideString& sError) {
1068 return TRUE; 1079 return TRUE;
1069 } 1080 }
1070 1081
1071 FX_BOOL Document::layout(IJS_Context* cc, 1082 FX_BOOL Document::layout(IJS_Context* cc,
(...skipping 24 matching lines...) Expand all
1096 } 1107 }
1097 1108
1098 FX_BOOL Document::getAnnot(IJS_Context* cc, 1109 FX_BOOL Document::getAnnot(IJS_Context* cc,
1099 const std::vector<CJS_Value>& params, 1110 const std::vector<CJS_Value>& params,
1100 CJS_Value& vRet, 1111 CJS_Value& vRet,
1101 CFX_WideString& sError) { 1112 CFX_WideString& sError) {
1102 if (params.size() != 2) { 1113 if (params.size() != 2) {
1103 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 1114 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
1104 return FALSE; 1115 return FALSE;
1105 } 1116 }
1106 if (!m_pDocument) { 1117 if (!m_pFormFillEnv) {
1107 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1118 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1108 return FALSE; 1119 return FALSE;
1109 } 1120 }
1110 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1121 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1111 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1122 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1112 int nPageNo = params[0].ToInt(pRuntime); 1123 int nPageNo = params[0].ToInt(pRuntime);
1113 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); 1124 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
1114 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(nPageNo); 1125 CPDFSDK_PageView* pPageView =
1126 m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageNo);
1115 if (!pPageView) 1127 if (!pPageView)
1116 return FALSE; 1128 return FALSE;
1117 1129
1118 CPDFSDK_AnnotIterator annotIterator(pPageView, false); 1130 CPDFSDK_AnnotIterator annotIterator(pPageView, false);
1119 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; 1131 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
1120 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { 1132 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
1121 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); 1133 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
1122 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { 1134 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
1123 pSDKBAAnnot = pBAAnnot; 1135 pSDKBAAnnot = pBAAnnot;
1124 break; 1136 break;
(...skipping 20 matching lines...) Expand all
1145 pAnnot->SetSDKAnnot(pSDKBAAnnot); 1157 pAnnot->SetSDKAnnot(pSDKBAAnnot);
1146 1158
1147 vRet = CJS_Value(pRuntime, pJS_Annot); 1159 vRet = CJS_Value(pRuntime, pJS_Annot);
1148 return TRUE; 1160 return TRUE;
1149 } 1161 }
1150 1162
1151 FX_BOOL Document::getAnnots(IJS_Context* cc, 1163 FX_BOOL Document::getAnnots(IJS_Context* cc,
1152 const std::vector<CJS_Value>& params, 1164 const std::vector<CJS_Value>& params,
1153 CJS_Value& vRet, 1165 CJS_Value& vRet,
1154 CFX_WideString& sError) { 1166 CFX_WideString& sError) {
1155 if (!m_pDocument) { 1167 if (!m_pFormFillEnv) {
1156 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1168 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1157 return FALSE; 1169 return FALSE;
1158 } 1170 }
1159 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1171 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1160 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1172 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1161 1173
1162 // TODO(tonikitoo): Add support supported parameters as per 1174 // TODO(tonikitoo): Add support supported parameters as per
1163 // the PDF spec. 1175 // the PDF spec.
1164 1176
1165 int nPageNo = m_pDocument->GetPageCount(); 1177 int nPageNo = m_pFormFillEnv->GetSDKDocument()->GetPageCount();
1166 CJS_Array annots; 1178 CJS_Array annots;
1167 1179
1168 for (int i = 0; i < nPageNo; ++i) { 1180 for (int i = 0; i < nPageNo; ++i) {
1169 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(i); 1181 CPDFSDK_PageView* pPageView =
1182 m_pFormFillEnv->GetSDKDocument()->GetPageView(i);
1170 if (!pPageView) 1183 if (!pPageView)
1171 return FALSE; 1184 return FALSE;
1172 1185
1173 CPDFSDK_AnnotIterator annotIterator(pPageView, false); 1186 CPDFSDK_AnnotIterator annotIterator(pPageView, false);
1174 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { 1187 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
1175 CPDFSDK_BAAnnot* pSDKBAAnnot = 1188 CPDFSDK_BAAnnot* pSDKBAAnnot =
1176 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); 1189 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
1177 if (!pSDKBAAnnot) 1190 if (!pSDKBAAnnot)
1178 return FALSE; 1191 return FALSE;
1179 1192
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 FX_BOOL Document::media(IJS_Context* cc, 1385 FX_BOOL Document::media(IJS_Context* cc,
1373 CJS_PropValue& vp, 1386 CJS_PropValue& vp,
1374 CFX_WideString& sError) { 1387 CFX_WideString& sError) {
1375 return TRUE; 1388 return TRUE;
1376 } 1389 }
1377 1390
1378 FX_BOOL Document::calculateNow(IJS_Context* cc, 1391 FX_BOOL Document::calculateNow(IJS_Context* cc,
1379 const std::vector<CJS_Value>& params, 1392 const std::vector<CJS_Value>& params,
1380 CJS_Value& vRet, 1393 CJS_Value& vRet,
1381 CFX_WideString& sError) { 1394 CFX_WideString& sError) {
1382 if (!m_pDocument) { 1395 if (!m_pFormFillEnv) {
1383 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1396 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1384 return FALSE; 1397 return FALSE;
1385 } 1398 }
1386 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || 1399 if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) ||
1387 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || 1400 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) ||
1388 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { 1401 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) {
1389 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 1402 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
1390 return FALSE; 1403 return FALSE;
1391 } 1404 }
1392 m_pDocument->GetInterForm()->OnCalculate(); 1405 m_pFormFillEnv->GetSDKDocument()->GetInterForm()->OnCalculate();
1393 return TRUE; 1406 return TRUE;
1394 } 1407 }
1395 1408
1396 FX_BOOL Document::Collab(IJS_Context* cc, 1409 FX_BOOL Document::Collab(IJS_Context* cc,
1397 CJS_PropValue& vp, 1410 CJS_PropValue& vp,
1398 CFX_WideString& sError) { 1411 CFX_WideString& sError) {
1399 return TRUE; 1412 return TRUE;
1400 } 1413 }
1401 1414
1402 FX_BOOL Document::getPageNthWord(IJS_Context* cc, 1415 FX_BOOL Document::getPageNthWord(IJS_Context* cc,
1403 const std::vector<CJS_Value>& params, 1416 const std::vector<CJS_Value>& params,
1404 CJS_Value& vRet, 1417 CJS_Value& vRet,
1405 CFX_WideString& sError) { 1418 CFX_WideString& sError) {
1406 if (!m_pDocument) { 1419 if (!m_pFormFillEnv) {
1407 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1420 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1408 return FALSE; 1421 return FALSE;
1409 } 1422 }
1410 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { 1423 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(
1424 FPDFPERM_EXTRACT_ACCESS)) {
1411 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 1425 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
1412 return FALSE; 1426 return FALSE;
1413 } 1427 }
1414 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1428 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1415 1429
1416 // TODO(tsepez): check maximum allowable params. 1430 // TODO(tsepez): check maximum allowable params.
1417 1431
1418 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; 1432 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
1419 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; 1433 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0;
1420 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; 1434 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true;
1421 1435
1422 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1436 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument();
1423 if (!pDocument) 1437 if (!pDocument)
1424 return FALSE; 1438 return FALSE;
1425 1439
1426 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { 1440 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1427 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); 1441 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
1428 return FALSE; 1442 return FALSE;
1429 } 1443 }
1430 1444
1431 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1445 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1432 if (!pPageDict) 1446 if (!pPageDict)
(...skipping 22 matching lines...) Expand all
1455 } 1469 }
1456 1470
1457 vRet = CJS_Value(pRuntime, swRet.c_str()); 1471 vRet = CJS_Value(pRuntime, swRet.c_str());
1458 return TRUE; 1472 return TRUE;
1459 } 1473 }
1460 1474
1461 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, 1475 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc,
1462 const std::vector<CJS_Value>& params, 1476 const std::vector<CJS_Value>& params,
1463 CJS_Value& vRet, 1477 CJS_Value& vRet,
1464 CFX_WideString& sError) { 1478 CFX_WideString& sError) {
1465 if (!m_pDocument) { 1479 if (!m_pFormFillEnv) {
1466 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1480 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1467 return FALSE; 1481 return FALSE;
1468 } 1482 }
1469 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { 1483 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(
1484 FPDFPERM_EXTRACT_ACCESS)) {
1470 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1485 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1471 return FALSE; 1486 return FALSE;
1472 } 1487 }
1473 return FALSE; 1488 return FALSE;
1474 } 1489 }
1475 1490
1476 FX_BOOL Document::getPageNumWords(IJS_Context* cc, 1491 FX_BOOL Document::getPageNumWords(IJS_Context* cc,
1477 const std::vector<CJS_Value>& params, 1492 const std::vector<CJS_Value>& params,
1478 CJS_Value& vRet, 1493 CJS_Value& vRet,
1479 CFX_WideString& sError) { 1494 CFX_WideString& sError) {
1480 if (!m_pDocument) { 1495 if (!m_pFormFillEnv) {
1481 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1496 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1482 return FALSE; 1497 return FALSE;
1483 } 1498 }
1484 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { 1499 if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(
1500 FPDFPERM_EXTRACT_ACCESS)) {
1485 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); 1501 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
1486 return FALSE; 1502 return FALSE;
1487 } 1503 }
1488 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1504 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1489 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; 1505 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
1490 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1506 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument();
1491 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { 1507 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1492 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); 1508 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
1493 return FALSE; 1509 return FALSE;
1494 } 1510 }
1495 1511
1496 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1512 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1497 if (!pPageDict) 1513 if (!pPageDict)
1498 return FALSE; 1514 return FALSE;
1499 1515
1500 CPDF_Page page(pDocument, pPageDict, true); 1516 CPDF_Page page(pDocument, pPageDict, true);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 } 1676 }
1661 1677
1662 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, 1678 FX_BOOL Document::gotoNamedDest(IJS_Context* cc,
1663 const std::vector<CJS_Value>& params, 1679 const std::vector<CJS_Value>& params,
1664 CJS_Value& vRet, 1680 CJS_Value& vRet,
1665 CFX_WideString& sError) { 1681 CFX_WideString& sError) {
1666 if (params.size() != 1) { 1682 if (params.size() != 1) {
1667 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 1683 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
1668 return FALSE; 1684 return FALSE;
1669 } 1685 }
1670 if (!m_pDocument) { 1686 if (!m_pFormFillEnv) {
1671 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1687 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1672 return FALSE; 1688 return FALSE;
1673 } 1689 }
1674 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1690 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1675 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); 1691 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
1676 CFX_ByteString utf8Name = wideName.UTF8Encode(); 1692 CFX_ByteString utf8Name = wideName.UTF8Encode();
1677 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 1693 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument();
1678 if (!pDocument) 1694 if (!pDocument)
1679 return FALSE; 1695 return FALSE;
1680 1696
1681 CPDF_NameTree nameTree(pDocument, "Dests"); 1697 CPDF_NameTree nameTree(pDocument, "Dests");
1682 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); 1698 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name);
1683 if (!destArray) 1699 if (!destArray)
1684 return FALSE; 1700 return FALSE;
1685 1701
1686 CPDF_Dest dest(destArray); 1702 CPDF_Dest dest(destArray);
1687 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); 1703 const CPDF_Array* arrayObject = ToArray(dest.GetObject());
1688 1704
1689 std::unique_ptr<float[]> scrollPositionArray; 1705 std::unique_ptr<float[]> scrollPositionArray;
1690 int scrollPositionArraySize = 0; 1706 int scrollPositionArraySize = 0;
1691 1707
1692 if (arrayObject) { 1708 if (arrayObject) {
1693 scrollPositionArray.reset(new float[arrayObject->GetCount()]); 1709 scrollPositionArray.reset(new float[arrayObject->GetCount()]);
1694 int j = 0; 1710 int j = 0;
1695 for (size_t i = 2; i < arrayObject->GetCount(); i++) 1711 for (size_t i = 2; i < arrayObject->GetCount(); i++)
1696 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); 1712 scrollPositionArray[j++] = arrayObject->GetFloatAt(i);
1697 scrollPositionArraySize = j; 1713 scrollPositionArraySize = j;
1698 } 1714 }
1699 1715
1700 pRuntime->BeginBlock(); 1716 pRuntime->BeginBlock();
1701 CPDFSDK_FormFillEnvironment* pApp = m_pDocument->GetEnv(); 1717 m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(),
1702 pApp->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), 1718 scrollPositionArray.get(),
1703 scrollPositionArray.get(), scrollPositionArraySize); 1719 scrollPositionArraySize);
1704 pRuntime->EndBlock(); 1720 pRuntime->EndBlock();
1705 1721
1706 return TRUE; 1722 return TRUE;
1707 } 1723 }
1708 1724
1709 void Document::AddDelayData(CJS_DelayData* pData) { 1725 void Document::AddDelayData(CJS_DelayData* pData) {
1710 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); 1726 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData));
1711 } 1727 }
1712 1728
1713 void Document::DoFieldDelay(const CFX_WideString& sFieldName, 1729 void Document::DoFieldDelay(const CFX_WideString& sFieldName,
1714 int nControlIndex) { 1730 int nControlIndex) {
1715 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; 1731 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex;
1716 auto iter = m_DelayData.begin(); 1732 auto iter = m_DelayData.begin();
1717 while (iter != m_DelayData.end()) { 1733 while (iter != m_DelayData.end()) {
1718 auto old = iter++; 1734 auto old = iter++;
1719 if ((*old)->sFieldName == sFieldName && 1735 if ((*old)->sFieldName == sFieldName &&
1720 (*old)->nControlIndex == nControlIndex) { 1736 (*old)->nControlIndex == nControlIndex) {
1721 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); 1737 DelayDataForFieldAndControlIndex.push_back(std::move(*old));
1722 m_DelayData.erase(old); 1738 m_DelayData.erase(old);
1723 } 1739 }
1724 } 1740 }
1725 1741
1726 for (const auto& pData : DelayDataForFieldAndControlIndex) { 1742 for (const auto& pData : DelayDataForFieldAndControlIndex)
1727 if (m_pDocument.Get()) 1743 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
1728 Field::DoDelay(m_pDocument->GetEnv(), pData.get());
1729 }
1730 } 1744 }
1731 1745
1732 CJS_Document* Document::GetCJSDoc() const { 1746 CJS_Document* Document::GetCJSDoc() const {
1733 return static_cast<CJS_Document*>(m_pJSObject); 1747 return static_cast<CJS_Document*>(m_pJSObject);
1734 } 1748 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698