blob: 1c9c1f31f4aaa98c5335e53cd70d5ab1e2598277 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairefbc1912016-02-17 16:54:43 -05007#include "fpdfsdk/src/javascript/Document.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008
Dan Sinclair3ebd1212016-03-09 09:59:23 -05009#include <vector>
10
Tom Sepez310438f2016-03-08 13:10:55 -080011#include "core/include/fpdfapi/cpdf_document.h"
Dan Sinclair3ebd1212016-03-09 09:59:23 -050012#include "fpdfsdk/include/fsdk_mgr.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080013#include "fpdfsdk/include/javascript/IJavaScript.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050014#include "fpdfsdk/src/javascript/Field.h"
15#include "fpdfsdk/src/javascript/Icon.h"
16#include "fpdfsdk/src/javascript/JS_Context.h"
17#include "fpdfsdk/src/javascript/JS_Define.h"
18#include "fpdfsdk/src/javascript/JS_EventHandler.h"
19#include "fpdfsdk/src/javascript/JS_Object.h"
20#include "fpdfsdk/src/javascript/JS_Runtime.h"
21#include "fpdfsdk/src/javascript/JS_Value.h"
22#include "fpdfsdk/src/javascript/app.h"
23#include "fpdfsdk/src/javascript/resource.h"
Lei Zhang8241df72015-11-06 14:38:48 -080024#include "third_party/base/numerics/safe_math.h"
Chris Palmer9108ad22014-06-26 16:01:46 -070025
Tom Sepezba038bc2015-10-08 12:03:00 -070026static v8::Isolate* GetIsolate(IJS_Context* cc) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 return pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
32BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
33END_JS_STATIC_CONST()
34
35BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
36END_JS_STATIC_PROP()
37
38BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
39END_JS_STATIC_METHOD()
40
41IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
42
43PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 : CJS_EmbedObj(pJSObject) {
45 bUI = TRUE;
46 nStart = 0;
47 nEnd = 0;
48 bSilent = FALSE;
49 bShrinkToFit = FALSE;
50 bPrintAsImage = FALSE;
51 bReverse = FALSE;
52 bAnnotations = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053}
54
55/* ---------------------- Document ---------------------- */
56
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057#define MINWIDTH 5.0f
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058#define MINHEIGHT 5.0f
59
60BEGIN_JS_STATIC_CONST(CJS_Document)
61END_JS_STATIC_CONST()
62
63BEGIN_JS_STATIC_PROP(CJS_Document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064JS_STATIC_PROP_ENTRY(ADBE)
65JS_STATIC_PROP_ENTRY(author)
66JS_STATIC_PROP_ENTRY(baseURL)
67JS_STATIC_PROP_ENTRY(bookmarkRoot)
68JS_STATIC_PROP_ENTRY(calculate)
69JS_STATIC_PROP_ENTRY(Collab)
70JS_STATIC_PROP_ENTRY(creationDate)
71JS_STATIC_PROP_ENTRY(creator)
72JS_STATIC_PROP_ENTRY(delay)
73JS_STATIC_PROP_ENTRY(dirty)
74JS_STATIC_PROP_ENTRY(documentFileName)
75JS_STATIC_PROP_ENTRY(external)
76JS_STATIC_PROP_ENTRY(filesize)
77JS_STATIC_PROP_ENTRY(icons)
78JS_STATIC_PROP_ENTRY(info)
79JS_STATIC_PROP_ENTRY(keywords)
80JS_STATIC_PROP_ENTRY(layout)
81JS_STATIC_PROP_ENTRY(media)
82JS_STATIC_PROP_ENTRY(modDate)
83JS_STATIC_PROP_ENTRY(mouseX)
84JS_STATIC_PROP_ENTRY(mouseY)
85JS_STATIC_PROP_ENTRY(numFields)
86JS_STATIC_PROP_ENTRY(numPages)
87JS_STATIC_PROP_ENTRY(pageNum)
88JS_STATIC_PROP_ENTRY(pageWindowRect)
89JS_STATIC_PROP_ENTRY(path)
90JS_STATIC_PROP_ENTRY(producer)
91JS_STATIC_PROP_ENTRY(subject)
92JS_STATIC_PROP_ENTRY(title)
93JS_STATIC_PROP_ENTRY(zoom)
94JS_STATIC_PROP_ENTRY(zoomType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095END_JS_STATIC_PROP()
96
97BEGIN_JS_STATIC_METHOD(CJS_Document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098JS_STATIC_METHOD_ENTRY(addAnnot)
99JS_STATIC_METHOD_ENTRY(addField)
100JS_STATIC_METHOD_ENTRY(addLink)
101JS_STATIC_METHOD_ENTRY(addIcon)
102JS_STATIC_METHOD_ENTRY(calculateNow)
103JS_STATIC_METHOD_ENTRY(closeDoc)
104JS_STATIC_METHOD_ENTRY(createDataObject)
105JS_STATIC_METHOD_ENTRY(deletePages)
106JS_STATIC_METHOD_ENTRY(exportAsText)
107JS_STATIC_METHOD_ENTRY(exportAsFDF)
108JS_STATIC_METHOD_ENTRY(exportAsXFDF)
109JS_STATIC_METHOD_ENTRY(extractPages)
110JS_STATIC_METHOD_ENTRY(getAnnot)
111JS_STATIC_METHOD_ENTRY(getAnnots)
112JS_STATIC_METHOD_ENTRY(getAnnot3D)
113JS_STATIC_METHOD_ENTRY(getAnnots3D)
114JS_STATIC_METHOD_ENTRY(getField)
115JS_STATIC_METHOD_ENTRY(getIcon)
116JS_STATIC_METHOD_ENTRY(getLinks)
117JS_STATIC_METHOD_ENTRY(getNthFieldName)
118JS_STATIC_METHOD_ENTRY(getOCGs)
119JS_STATIC_METHOD_ENTRY(getPageBox)
120JS_STATIC_METHOD_ENTRY(getPageNthWord)
121JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
122JS_STATIC_METHOD_ENTRY(getPageNumWords)
123JS_STATIC_METHOD_ENTRY(getPrintParams)
124JS_STATIC_METHOD_ENTRY(getURL)
125JS_STATIC_METHOD_ENTRY(importAnFDF)
126JS_STATIC_METHOD_ENTRY(importAnXFDF)
127JS_STATIC_METHOD_ENTRY(importTextData)
128JS_STATIC_METHOD_ENTRY(insertPages)
129JS_STATIC_METHOD_ENTRY(mailForm)
130JS_STATIC_METHOD_ENTRY(print)
131JS_STATIC_METHOD_ENTRY(removeField)
132JS_STATIC_METHOD_ENTRY(replacePages)
133JS_STATIC_METHOD_ENTRY(resetForm)
134JS_STATIC_METHOD_ENTRY(removeIcon)
135JS_STATIC_METHOD_ENTRY(saveAs)
136JS_STATIC_METHOD_ENTRY(submitForm)
137JS_STATIC_METHOD_ENTRY(mailDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700138END_JS_STATIC_METHOD()
139
140IMPLEMENT_JS_CLASS(CJS_Document, Document)
141
Tom Sepez33420902015-10-13 15:00:10 -0700142void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
143 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
144 Document* pDoc = static_cast<Document*>(GetEmbedObject());
145 pDoc->AttachDoc(pRuntime->GetReaderDocument());
146 pDoc->SetIsolate(pRuntime->GetIsolate());
147}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149/* --------------------------------- Document ---------------------------------
150 */
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152Document::Document(CJS_Object* pJSObject)
153 : CJS_EmbedObj(pJSObject),
154 m_isolate(NULL),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 m_pDocument(NULL),
156 m_cwBaseURL(L""),
157 m_bDelay(FALSE) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159Document::~Document() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 for (int i = 0; i < m_DelayData.GetSize(); i++) {
Tom Sepez6ba32d92016-01-05 16:26:32 -0800161 delete m_DelayData.GetAt(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 m_DelayData.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165}
166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167// the total number of fileds in document.
Tom Sepezba038bc2015-10-08 12:03:00 -0700168FX_BOOL Document::numFields(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 CJS_PropValue& vp,
170 CFX_WideString& sError) {
171 if (vp.IsSetting()) {
172 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
173 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700174 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 }
176 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
178 vp << (int)pPDFForm->CountFields();
179 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180}
181
Tom Sepezba038bc2015-10-08 12:03:00 -0700182FX_BOOL Document::dirty(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 CJS_PropValue& vp,
184 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 if (vp.IsGetting()) {
186 if (m_pDocument->GetChangeMark())
187 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700188 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 vp << false;
190 } else {
191 bool bChanged = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 vp >> bChanged;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 if (bChanged)
196 m_pDocument->SetChangeMark();
197 else
198 m_pDocument->ClearChangeMark();
199 }
200
201 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
Tom Sepezba038bc2015-10-08 12:03:00 -0700204FX_BOOL Document::ADBE(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 CJS_PropValue& vp,
206 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 if (vp.IsGetting()) {
208 vp.SetNull();
209 } else {
210 }
211
212 return TRUE;
213}
214
Tom Sepezba038bc2015-10-08 12:03:00 -0700215FX_BOOL Document::pageNum(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 CJS_PropValue& vp,
217 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 if (vp.IsGetting()) {
219 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) {
220 vp << pPageView->GetPageIndex();
221 }
222 } else {
223 int iPageCount = m_pDocument->GetPageCount();
224 int iPageNum = 0;
225 vp >> iPageNum;
226
227 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
228 if (iPageNum >= 0 && iPageNum < iPageCount) {
229 pEnv->JS_docgotoPage(iPageNum);
230 } else if (iPageNum >= iPageCount) {
231 pEnv->JS_docgotoPage(iPageCount - 1);
232 } else if (iPageNum < 0) {
233 pEnv->JS_docgotoPage(0);
234 }
235 }
236
237 return TRUE;
238}
239
Tom Sepezba038bc2015-10-08 12:03:00 -0700240FX_BOOL Document::addAnnot(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800241 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 CJS_Value& vRet,
243 CFX_WideString& sError) {
244 // Not supported.
245 return TRUE;
246}
247
Tom Sepezba038bc2015-10-08 12:03:00 -0700248FX_BOOL Document::addField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800249 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 CJS_Value& vRet,
251 CFX_WideString& sError) {
252 // Not supported.
253 return TRUE;
254}
255
Tom Sepezba038bc2015-10-08 12:03:00 -0700256FX_BOOL Document::exportAsText(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800257 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 CJS_Value& vRet,
259 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800260 // Unsafe, not supported.
261 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Tom Sepezba038bc2015-10-08 12:03:00 -0700264FX_BOOL Document::exportAsFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800265 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 CJS_Value& vRet,
267 CFX_WideString& sError) {
268 // Unsafe, not supported.
269 return TRUE;
270}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271
Tom Sepezba038bc2015-10-08 12:03:00 -0700272FX_BOOL Document::exportAsXFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800273 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 CJS_Value& vRet,
275 CFX_WideString& sError) {
276 // Unsafe, not supported.
277 return TRUE;
278}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280// Maps a field object in PDF document to a JavaScript variable
281// comment:
282// note: the paremter cName, this is clue how to treat if the cName is not a
283// valiable filed name in this document
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284
Tom Sepezba038bc2015-10-08 12:03:00 -0700285FX_BOOL Document::getField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800286 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 CJS_Value& vRet,
288 CFX_WideString& sError) {
289 CJS_Context* pContext = (CJS_Context*)cc;
290 if (params.size() < 1) {
291 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
292 return FALSE;
293 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295 CFX_WideString wideName = params[0].ToCFXWideString();
296
297 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
298 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
299 if (pPDFForm->CountFields(wideName) <= 0) {
300 vRet.SetNull();
301 return TRUE;
302 }
303
304 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700305 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700306 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307
308 v8::Isolate* isolate = GetIsolate(cc);
Tom Sepez39bfe122015-09-17 15:25:23 -0700309 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 Field* pField = (Field*)pJSField->GetEmbedObject();
311 pField->AttachField(this, wideName);
312
313 vRet = pJSField;
314 return TRUE;
315}
316
317// Gets the name of the nth field in the document
Tom Sepezba038bc2015-10-08 12:03:00 -0700318FX_BOOL Document::getNthFieldName(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800319 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 CJS_Value& vRet,
321 CFX_WideString& sError) {
322 CJS_Context* pContext = (CJS_Context*)cc;
323 if (params.size() != 1) {
324 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
325 return FALSE;
326 }
327
328 int nIndex = params[0].ToInt();
329 if (nIndex < 0) {
330 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
331 return FALSE;
332 }
333
334 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
335 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
336 CPDF_FormField* pField = pPDFForm->GetField(nIndex);
337 if (!pField)
338 return FALSE;
339
340 vRet = pField->GetFullName().c_str();
341 return TRUE;
342}
343
Tom Sepezba038bc2015-10-08 12:03:00 -0700344FX_BOOL Document::importAnFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800345 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 CJS_Value& vRet,
347 CFX_WideString& sError) {
348 // Unsafe, not supported.
349 return TRUE;
350}
351
Tom Sepezba038bc2015-10-08 12:03:00 -0700352FX_BOOL Document::importAnXFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800353 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 CJS_Value& vRet,
355 CFX_WideString& sError) {
356 // Unsafe, not supported.
357 return TRUE;
358}
359
Tom Sepezba038bc2015-10-08 12:03:00 -0700360FX_BOOL Document::importTextData(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800361 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 CJS_Value& vRet,
363 CFX_WideString& sError) {
364 // Unsafe, not supported.
365 return TRUE;
366}
367
368// exports the form data and mails the resulting fdf file as an attachment to
369// all recipients.
370// comment: need reader supports
371// note:
372// int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string
373// cbcc,string cSubject,string cms);
374
Tom Sepezba038bc2015-10-08 12:03:00 -0700375FX_BOOL Document::mailForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800376 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 CJS_Value& vRet,
378 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
380 return FALSE;
381
382 int iLength = params.size();
383
384 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE;
385 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L"";
386 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L"";
387 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L"";
388 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L"";
389 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L"";
390
391 CPDFSDK_InterForm* pInterForm =
392 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 CFX_ByteTextBuf textBuf;
394 if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
395 return FALSE;
396
397 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400
401 pRuntime->BeginBlock();
402 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
403 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(),
404 cMsg.c_str());
405 pRuntime->EndBlock();
406 return TRUE;
407}
408
Tom Sepezba038bc2015-10-08 12:03:00 -0700409FX_BOOL Document::print(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800410 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 CJS_Value& vRet,
412 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 FX_BOOL bUI = TRUE;
414 int nStart = 0;
415 int nEnd = 0;
416 FX_BOOL bSilent = FALSE;
417 FX_BOOL bShrinkToFit = FALSE;
418 FX_BOOL bPrintAsImage = FALSE;
419 FX_BOOL bReverse = FALSE;
420 FX_BOOL bAnnotations = FALSE;
421
422 int nlength = params.size();
423 if (nlength == 9) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700424 if (params[8].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700425 v8::Local<v8::Object> pObj = params[8].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700427 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 if (CJS_Object* pJSObj = params[8].ToCJSObject()) {
429 if (PrintParamsObj* pprintparamsObj =
430 (PrintParamsObj*)pJSObj->GetEmbedObject()) {
431 bUI = pprintparamsObj->bUI;
432 nStart = pprintparamsObj->nStart;
433 nEnd = pprintparamsObj->nEnd;
434 bSilent = pprintparamsObj->bSilent;
435 bShrinkToFit = pprintparamsObj->bShrinkToFit;
436 bPrintAsImage = pprintparamsObj->bPrintAsImage;
437 bReverse = pprintparamsObj->bReverse;
438 bAnnotations = pprintparamsObj->bAnnotations;
439 }
440 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700441 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 }
443 }
444 } else {
445 if (nlength >= 1)
446 bUI = params[0].ToBool();
447 if (nlength >= 2)
448 nStart = params[1].ToInt();
449 if (nlength >= 3)
450 nEnd = params[2].ToInt();
451 if (nlength >= 4)
452 bSilent = params[3].ToBool();
453 if (nlength >= 5)
454 bShrinkToFit = params[4].ToBool();
455 if (nlength >= 6)
456 bPrintAsImage = params[5].ToBool();
457 if (nlength >= 7)
458 bReverse = params[6].ToBool();
459 if (nlength >= 8)
460 bAnnotations = params[7].ToBool();
461 }
462
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) {
464 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage,
465 bReverse, bAnnotations);
466 return TRUE;
467 }
468 return FALSE;
469}
470
471// removes the specified field from the document.
472// comment:
473// note: if the filed name is not retional, adobe is dumb for it.
474
Tom Sepezba038bc2015-10-08 12:03:00 -0700475FX_BOOL Document::removeField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800476 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 CJS_Value& vRet,
478 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
480 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM)))
481 return FALSE;
482
483 CJS_Context* pContext = (CJS_Context*)cc;
484 if (params.size() != 1) {
485 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
486 return FALSE;
487 }
488
489 CFX_WideString sFieldName = params[0].ToCFXWideString();
490 CPDFSDK_InterForm* pInterForm =
491 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492
Lei Zhangd88a3642015-11-10 09:38:57 -0800493 std::vector<CPDFSDK_Widget*> widgets;
494 pInterForm->GetWidgets(sFieldName, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495
Lei Zhangd88a3642015-11-10 09:38:57 -0800496 if (widgets.empty())
497 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498
Lei Zhangd88a3642015-11-10 09:38:57 -0800499 for (CPDFSDK_Widget* pWidget : widgets) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800500 CFX_FloatRect rcAnnot = pWidget->GetRect();
Lei Zhangd88a3642015-11-10 09:38:57 -0800501 --rcAnnot.left;
502 --rcAnnot.bottom;
503 ++rcAnnot.right;
504 ++rcAnnot.top;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505
Lei Zhangd88a3642015-11-10 09:38:57 -0800506 CFX_RectArray aRefresh;
507 aRefresh.Add(rcAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508
Tom Sepez50d12ad2015-11-24 09:50:51 -0800509 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
Lei Zhangd88a3642015-11-10 09:38:57 -0800510 ASSERT(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511
Lei Zhangd88a3642015-11-10 09:38:57 -0800512 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
513 pPageView->DeleteAnnot(pWidget);
514 pPageView->UpdateRects(aRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800516 m_pDocument->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517
518 return TRUE;
519}
520
521// reset filed values within a document.
522// comment:
523// note: if the fields names r not rational, aodbe is dumb for it.
524
Tom Sepezba038bc2015-10-08 12:03:00 -0700525FX_BOOL Document::resetForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800526 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 CJS_Value& vRet,
528 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
530 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
531 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
532 return FALSE;
533
534 CPDFSDK_InterForm* pInterForm =
535 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700537 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
538 CJS_Array aName(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539
Lei Zhangdd734de2015-11-11 10:16:52 -0800540 if (params.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 pPDFForm->ResetForm(TRUE);
542 m_pDocument->SetChangeMark();
Lei Zhangd88a3642015-11-10 09:38:57 -0800543 return TRUE;
544 }
545
546 switch (params[0].GetType()) {
547 default:
548 aName.Attach(params[0].ToV8Array());
549 break;
550 case CJS_Value::VT_string:
551 aName.SetElement(0, params[0]);
552 break;
553 }
554
555 std::vector<CPDF_FormField*> aFields;
556 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) {
557 CJS_Value valElement(pRuntime);
558 aName.GetElement(i, valElement);
559 CFX_WideString swVal = valElement.ToCFXWideString();
560 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
561 aFields.push_back(pPDFForm->GetField(j, swVal));
562 }
563
564 if (!aFields.empty()) {
565 pPDFForm->ResetForm(aFields, TRUE, TRUE);
566 m_pDocument->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 }
568
569 return TRUE;
570}
571
Tom Sepezba038bc2015-10-08 12:03:00 -0700572FX_BOOL Document::saveAs(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800573 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 CJS_Value& vRet,
575 CFX_WideString& sError) {
576 // Unsafe, not supported.
577 return TRUE;
578}
579
Tom Sepezba038bc2015-10-08 12:03:00 -0700580FX_BOOL Document::submitForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800581 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 CJS_Value& vRet,
583 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 CJS_Context* pContext = (CJS_Context*)cc;
585 int nSize = params.size();
586 if (nSize < 1) {
587 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
588 return FALSE;
589 }
590
Tom Sepez67fd5df2015-10-08 12:24:19 -0700591 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
592 v8::Isolate* isolate = pRuntime->GetIsolate();
593 CJS_Array aFields(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 CFX_WideString strURL;
595 FX_BOOL bFDF = TRUE;
596 FX_BOOL bEmpty = FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597
598 CJS_Value v = params[0];
Tom Sepez39bfe122015-09-17 15:25:23 -0700599 if (v.GetType() == CJS_Value::VT_string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600 strURL = params[0].ToCFXWideString();
601 if (nSize > 1)
602 bFDF = params[1].ToBool();
603 if (nSize > 2)
604 bEmpty = params[2].ToBool();
605 if (nSize > 3)
606 aFields.Attach(params[3].ToV8Array());
Tom Sepez39bfe122015-09-17 15:25:23 -0700607 } else if (v.GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700608 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepez39bfe122015-09-17 15:25:23 -0700609 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 if (!pValue.IsEmpty())
611 strURL =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700612 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
613
Tom Sepez39bfe122015-09-17 15:25:23 -0700614 pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700615 bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
616
Tom Sepez39bfe122015-09-17 15:25:23 -0700617 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700618 bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
619
Tom Sepez39bfe122015-09-17 15:25:23 -0700620 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 aFields.Attach(
Tom Sepez67fd5df2015-10-08 12:24:19 -0700622 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 }
624
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 CPDFSDK_InterForm* pInterForm =
626 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
627 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Tom Sepez007e6c02016-02-26 14:31:56 -0800628 if (aFields.GetLength() == 0 && bEmpty) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800629 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 pRuntime->BeginBlock();
631 pInterForm->SubmitForm(strURL, FALSE);
632 pRuntime->EndBlock();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700633 }
634 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 }
636
Lei Zhangd88a3642015-11-10 09:38:57 -0800637 std::vector<CPDF_FormField*> fieldObjects;
638 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700639 CJS_Value valName(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 aFields.GetElement(i, valName);
641
642 CFX_WideString sName = valName.ToCFXWideString();
643 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
644 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) {
645 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
646 if (!bEmpty && pField->GetValue().IsEmpty())
647 continue;
648
Lei Zhangd88a3642015-11-10 09:38:57 -0800649 fieldObjects.push_back(pField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 }
651 }
652
Lei Zhangd88a3642015-11-10 09:38:57 -0800653 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 pRuntime->BeginBlock();
655 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
656 pRuntime->EndBlock();
657 }
658 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661void Document::AttachDoc(CPDFSDK_Document* pDoc) {
662 m_pDocument = pDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665CPDFSDK_Document* Document::GetReaderDoc() {
666 return m_pDocument;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Tom Sepezba038bc2015-10-08 12:03:00 -0700669FX_BOOL Document::bookmarkRoot(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 CJS_PropValue& vp,
671 CFX_WideString& sError) {
672 return TRUE;
673}
674
Tom Sepezba038bc2015-10-08 12:03:00 -0700675FX_BOOL Document::mailDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800676 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 CJS_Value& vRet,
678 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 FX_BOOL bUI = TRUE;
680 CFX_WideString cTo = L"";
681 CFX_WideString cCc = L"";
682 CFX_WideString cBcc = L"";
683 CFX_WideString cSubject = L"";
684 CFX_WideString cMsg = L"";
685
686 if (params.size() >= 1)
687 bUI = params[0].ToBool();
688 if (params.size() >= 2)
689 cTo = params[1].ToCFXWideString();
690 if (params.size() >= 3)
691 cCc = params[2].ToCFXWideString();
692 if (params.size() >= 4)
693 cBcc = params[3].ToCFXWideString();
694 if (params.size() >= 5)
695 cSubject = params[4].ToCFXWideString();
696 if (params.size() >= 6)
697 cMsg = params[5].ToCFXWideString();
698
Tom Sepez67fd5df2015-10-08 12:24:19 -0700699 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
700 v8::Isolate* isolate = pRuntime->GetIsolate();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701
Tom Sepez39bfe122015-09-17 15:25:23 -0700702 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700703 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704
Tom Sepez39bfe122015-09-17 15:25:23 -0700705 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700706 bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707
Tom Sepez39bfe122015-09-17 15:25:23 -0700708 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700709 cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710
Tom Sepez39bfe122015-09-17 15:25:23 -0700711 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700712 cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713
Tom Sepez39bfe122015-09-17 15:25:23 -0700714 pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700715 cBcc =
716 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717
Tom Sepez39bfe122015-09-17 15:25:23 -0700718 pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 cSubject =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700720 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721
Tom Sepez39bfe122015-09-17 15:25:23 -0700722 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700723 cMsg =
724 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 }
726
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 pRuntime->BeginBlock();
728 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
729 pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
730 cBcc.c_str(), cMsg.c_str());
731 pRuntime->EndBlock();
732
733 return TRUE;
734}
735
Tom Sepezba038bc2015-10-08 12:03:00 -0700736FX_BOOL Document::author(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 CJS_PropValue& vp,
738 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800739 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 if (!pDictionary)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700741 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800744 vp << pDictionary->GetUnicodeTextBy("Author");
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700745 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 } else {
747 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
748 return FALSE;
749
750 CFX_WideString csAuthor;
751 vp >> csAuthor;
752 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
753 m_pDocument->SetChangeMark();
754 return TRUE;
755 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756}
757
Tom Sepezba038bc2015-10-08 12:03:00 -0700758FX_BOOL Document::info(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759 CJS_PropValue& vp,
760 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800761 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762 if (!pDictionary)
763 return FALSE;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800764
Wei Li9b761132016-01-29 15:44:20 -0800765 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author");
766 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title");
767 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject");
768 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords");
769 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator");
770 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer");
771 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate");
772 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate");
773 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped");
Tom Sepezc6ab1722015-02-05 15:27:25 -0800774
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 v8::Isolate* isolate = GetIsolate(cc);
776 if (vp.IsGetting()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700777 CJS_Context* pContext = (CJS_Context*)cc;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700778 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez808a99e2015-09-10 12:28:37 -0700779 v8::Local<v8::Object> pObj =
Tom Sepez33420902015-10-13 15:00:10 -0700780 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1);
Tom Sepez39bfe122015-09-17 15:25:23 -0700781 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
782 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
783 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
784 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
785 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
786 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
787 FXJS_PutObjectString(isolate, pObj, L"CreationDate",
788 cwCreationDate.c_str());
789 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
790 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
Tom Sepezc6ab1722015-02-05 15:27:25 -0800791
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792 // It's to be compatible to non-standard info dictionary.
Oliver Chang3f1c71f2016-01-11 08:45:31 -0800793 for (const auto& it : *pDictionary) {
794 const CFX_ByteString& bsKey = it.first;
795 CPDF_Object* pValueObj = it.second;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
Dan Sinclair710c9092015-10-21 15:46:10 -0400797
798 if (pValueObj->IsString() || pValueObj->IsName()) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700799 FXJS_PutObjectString(isolate, pObj, wsKey.c_str(),
800 pValueObj->GetUnicodeText().c_str());
Dan Sinclair710c9092015-10-21 15:46:10 -0400801 } else if (pValueObj->IsNumber()) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700802 FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(),
803 (float)pValueObj->GetNumber());
Dan Sinclair710c9092015-10-21 15:46:10 -0400804 } else if (pValueObj->IsBoolean()) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700805 FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
806 (bool)pValueObj->GetInteger());
Dan Sinclair05d9e932015-10-20 16:44:57 -0400807 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700808 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 vp << pObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810 }
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700811 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812}
813
Tom Sepezba038bc2015-10-08 12:03:00 -0700814FX_BOOL Document::creationDate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815 CJS_PropValue& vp,
816 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800817 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 if (!pDictionary)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700819 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820
821 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800822 vp << pDictionary->GetUnicodeTextBy("CreationDate");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 } else {
824 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
825 return FALSE;
826
827 CFX_WideString csCreationDate;
828 vp >> csCreationDate;
829 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
830 m_pDocument->SetChangeMark();
831 }
832 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833}
834
Tom Sepezba038bc2015-10-08 12:03:00 -0700835FX_BOOL Document::creator(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 CJS_PropValue& vp,
837 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800838 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 if (!pDictionary)
840 return FALSE;
Tom Sepeze5350ef2015-04-23 18:14:26 -0700841
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800843 vp << pDictionary->GetUnicodeTextBy("Creator");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 } else {
845 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
846 return FALSE;
847
848 CFX_WideString csCreator;
849 vp >> csCreator;
850 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
851 m_pDocument->SetChangeMark();
852 }
853 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854}
855
Tom Sepezba038bc2015-10-08 12:03:00 -0700856FX_BOOL Document::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 CJS_PropValue& vp,
858 CFX_WideString& sError) {
859 if (vp.IsGetting()) {
860 vp << m_bDelay;
861 } else {
862 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
863 return FALSE;
864
865 vp >> m_bDelay;
866 if (m_bDelay) {
867 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++)
868 delete m_DelayData.GetAt(i);
869
870 m_DelayData.RemoveAll();
871 } else {
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700872 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
874 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700875 DelayDataToProcess.Add(pData);
876 m_DelayData.SetAt(i, NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 }
878 }
879 m_DelayData.RemoveAll();
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700880 for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) {
881 CJS_DelayData* pData = DelayDataToProcess.GetAt(i);
882 Field::DoDelay(m_pDocument, pData);
883 DelayDataToProcess.SetAt(i, NULL);
884 delete pData;
885 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 }
887 }
888 return TRUE;
889}
890
Tom Sepezba038bc2015-10-08 12:03:00 -0700891FX_BOOL Document::keywords(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 CJS_PropValue& vp,
893 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800894 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 if (!pDictionary)
896 return FALSE;
897
898 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800899 vp << pDictionary->GetUnicodeTextBy("Keywords");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700900 } else {
901 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
902 return FALSE;
903
904 CFX_WideString csKeywords;
905 vp >> csKeywords;
906 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
907 m_pDocument->SetChangeMark();
908 }
909 return TRUE;
910}
911
Tom Sepezba038bc2015-10-08 12:03:00 -0700912FX_BOOL Document::modDate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 CJS_PropValue& vp,
914 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800915 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 if (!pDictionary)
917 return FALSE;
918
919 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800920 vp << pDictionary->GetUnicodeTextBy("ModDate");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921 } else {
922 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
923 return FALSE;
924
925 CFX_WideString csmodDate;
926 vp >> csmodDate;
927 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
928 m_pDocument->SetChangeMark();
929 }
930 return TRUE;
931}
932
Tom Sepezba038bc2015-10-08 12:03:00 -0700933FX_BOOL Document::producer(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 CJS_PropValue& vp,
935 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800936 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 if (!pDictionary)
938 return FALSE;
939
940 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800941 vp << pDictionary->GetUnicodeTextBy("Producer");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 } else {
943 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
944 return FALSE;
945
946 CFX_WideString csproducer;
947 vp >> csproducer;
948 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
949 m_pDocument->SetChangeMark();
950 }
951 return TRUE;
952}
953
Tom Sepezba038bc2015-10-08 12:03:00 -0700954FX_BOOL Document::subject(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 CJS_PropValue& vp,
956 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800957 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 if (!pDictionary)
959 return FALSE;
960
961 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800962 vp << pDictionary->GetUnicodeTextBy("Subject");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963 } else {
964 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
965 return FALSE;
966
967 CFX_WideString cssubject;
968 vp >> cssubject;
969 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
970 m_pDocument->SetChangeMark();
971 }
972 return TRUE;
973}
974
Tom Sepezba038bc2015-10-08 12:03:00 -0700975FX_BOOL Document::title(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976 CJS_PropValue& vp,
977 CFX_WideString& sError) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800978 if (!m_pDocument || !m_pDocument->GetUnderlyingDocument())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 return FALSE;
980
Tom Sepez50d12ad2015-11-24 09:50:51 -0800981 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700982 if (!pDictionary)
983 return FALSE;
984
985 if (vp.IsGetting()) {
Wei Li9b761132016-01-29 15:44:20 -0800986 vp << pDictionary->GetUnicodeTextBy("Title");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700987 } else {
988 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
989 return FALSE;
990
991 CFX_WideString cstitle;
992 vp >> cstitle;
993 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
994 m_pDocument->SetChangeMark();
995 }
996 return TRUE;
997}
998
Tom Sepezba038bc2015-10-08 12:03:00 -0700999FX_BOOL Document::numPages(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 CJS_PropValue& vp,
1001 CFX_WideString& sError) {
1002 if (vp.IsSetting()) {
1003 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1004 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1005 return FALSE;
1006 }
1007 vp << m_pDocument->GetPageCount();
1008 return TRUE;
1009}
1010
Tom Sepezba038bc2015-10-08 12:03:00 -07001011FX_BOOL Document::external(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 CJS_PropValue& vp,
1013 CFX_WideString& sError) {
1014 // In Chrome case,should always return true.
1015 if (vp.IsGetting()) {
1016 vp << true;
1017 }
1018 return TRUE;
1019}
1020
Tom Sepezba038bc2015-10-08 12:03:00 -07001021FX_BOOL Document::filesize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022 CJS_PropValue& vp,
1023 CFX_WideString& sError) {
1024 if (vp.IsSetting()) {
1025 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1026 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1027 return FALSE;
1028 }
1029 vp << 0;
1030 return TRUE;
1031}
1032
Tom Sepezba038bc2015-10-08 12:03:00 -07001033FX_BOOL Document::mouseX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 CJS_PropValue& vp,
1035 CFX_WideString& sError) {
1036 return TRUE;
1037}
1038
Tom Sepezba038bc2015-10-08 12:03:00 -07001039FX_BOOL Document::mouseY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001040 CJS_PropValue& vp,
1041 CFX_WideString& sError) {
1042 return TRUE;
1043}
1044
Tom Sepezba038bc2015-10-08 12:03:00 -07001045FX_BOOL Document::baseURL(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001046 CJS_PropValue& vp,
1047 CFX_WideString& sError) {
1048 if (vp.IsGetting()) {
1049 vp << m_cwBaseURL;
1050 } else {
1051 vp >> m_cwBaseURL;
1052 }
1053 return TRUE;
1054}
1055
Tom Sepezba038bc2015-10-08 12:03:00 -07001056FX_BOOL Document::calculate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001057 CJS_PropValue& vp,
1058 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 CPDFSDK_InterForm* pInterForm =
1060 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061
1062 if (vp.IsGetting()) {
1063 if (pInterForm->IsCalculateEnabled())
1064 vp << true;
1065 else
1066 vp << false;
1067 } else {
1068 bool bCalculate;
1069 vp >> bCalculate;
1070
1071 pInterForm->EnableCalculate(bCalculate);
1072 }
1073
1074 return TRUE;
1075}
1076
Tom Sepezba038bc2015-10-08 12:03:00 -07001077FX_BOOL Document::documentFileName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001078 CJS_PropValue& vp,
1079 CFX_WideString& sError) {
1080 if (vp.IsSetting()) {
1081 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1082 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1083 return FALSE;
1084 }
1085 CFX_WideString wsFilePath = m_pDocument->GetPath();
1086 int32_t i = wsFilePath.GetLength() - 1;
1087 for (; i >= 0; i--) {
1088 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/')
1089 break;
1090 }
1091 if (i >= 0 && i < wsFilePath.GetLength() - 1) {
1092 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1);
1093 } else {
1094 vp << L"";
1095 }
1096 return TRUE;
1097}
1098
Tom Sepezba038bc2015-10-08 12:03:00 -07001099FX_BOOL Document::path(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001100 CJS_PropValue& vp,
1101 CFX_WideString& sError) {
1102 if (vp.IsSetting()) {
1103 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1104 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1105 return FALSE;
1106 }
1107 vp << app::SysPathToPDFPath(m_pDocument->GetPath());
1108 return TRUE;
1109}
1110
Tom Sepezba038bc2015-10-08 12:03:00 -07001111FX_BOOL Document::pageWindowRect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112 CJS_PropValue& vp,
1113 CFX_WideString& sError) {
1114 return TRUE;
1115}
1116
Tom Sepezba038bc2015-10-08 12:03:00 -07001117FX_BOOL Document::layout(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001118 CJS_PropValue& vp,
1119 CFX_WideString& sError) {
1120 return TRUE;
1121}
1122
Tom Sepezba038bc2015-10-08 12:03:00 -07001123FX_BOOL Document::addLink(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001124 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125 CJS_Value& vRet,
1126 CFX_WideString& sError) {
1127 return TRUE;
1128}
1129
Tom Sepezba038bc2015-10-08 12:03:00 -07001130FX_BOOL Document::closeDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001131 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001132 CJS_Value& vRet,
1133 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001134 return TRUE;
1135}
1136
Tom Sepezba038bc2015-10-08 12:03:00 -07001137FX_BOOL Document::getPageBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001138 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139 CJS_Value& vRet,
1140 CFX_WideString& sError) {
1141 return TRUE;
1142}
1143
Tom Sepezba038bc2015-10-08 12:03:00 -07001144FX_BOOL Document::getAnnot(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001145 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001146 CJS_Value& vRet,
1147 CFX_WideString& sError) {
1148 return TRUE;
1149}
1150
Tom Sepezba038bc2015-10-08 12:03:00 -07001151FX_BOOL Document::getAnnots(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001152 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153 CJS_Value& vRet,
1154 CFX_WideString& sError) {
1155 vRet.SetNull();
1156 return TRUE;
1157}
1158
Tom Sepezba038bc2015-10-08 12:03:00 -07001159FX_BOOL Document::getAnnot3D(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001160 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001161 CJS_Value& vRet,
1162 CFX_WideString& sError) {
1163 vRet.SetNull();
1164 return TRUE;
1165}
1166
Tom Sepezba038bc2015-10-08 12:03:00 -07001167FX_BOOL Document::getAnnots3D(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001168 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001169 CJS_Value& vRet,
1170 CFX_WideString& sError) {
Tom Sepez39bfe122015-09-17 15:25:23 -07001171 vRet = CJS_Value::VT_undefined;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001172 return TRUE;
1173}
1174
Tom Sepezba038bc2015-10-08 12:03:00 -07001175FX_BOOL Document::getOCGs(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001176 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 CJS_Value& vRet,
1178 CFX_WideString& sError) {
1179 return TRUE;
1180}
1181
Tom Sepezba038bc2015-10-08 12:03:00 -07001182FX_BOOL Document::getLinks(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001183 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184 CJS_Value& vRet,
1185 CFX_WideString& sError) {
1186 return TRUE;
1187}
1188
1189bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) {
1190 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top &&
1191 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
1192}
1193
Tom Sepezba038bc2015-10-08 12:03:00 -07001194FX_BOOL Document::addIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001195 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196 CJS_Value& vRet,
1197 CFX_WideString& sError) {
1198 CJS_Context* pContext = (CJS_Context*)cc;
1199 if (params.size() != 2) {
1200 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1201 return FALSE;
1202 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203 CFX_WideString swIconName = params[0].ToCFXWideString();
Tom Sepezaecd9d02015-08-31 15:04:12 -07001204
Tom Sepez39bfe122015-09-17 15:25:23 -07001205 if (params[1].GetType() != CJS_Value::VT_object) {
Tom Sepezaecd9d02015-08-31 15:04:12 -07001206 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1207 return FALSE;
1208 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209
Tom Sepezcd56a7d2015-10-06 11:45:28 -07001210 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
1211 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1213 return FALSE;
1214 }
1215
1216 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
1217 if (!pEmbedObj) {
1218 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1219 return FALSE;
1220 }
1221
Tom Sepez6ba32d92016-01-05 16:26:32 -08001222 m_IconList.push_back(std::unique_ptr<IconElement>(
1223 new IconElement(swIconName, (Icon*)pEmbedObj)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001224 return TRUE;
1225}
1226
Tom Sepezba038bc2015-10-08 12:03:00 -07001227FX_BOOL Document::icons(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001228 CJS_PropValue& vp,
1229 CFX_WideString& sError) {
1230 if (vp.IsSetting()) {
1231 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1232 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1233 return FALSE;
1234 }
1235
Tom Sepez6ba32d92016-01-05 16:26:32 -08001236 if (m_IconList.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001237 vp.SetNull();
1238 return TRUE;
1239 }
1240
Tom Sepez67fd5df2015-10-08 12:24:19 -07001241 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1242 CJS_Array Icons(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001243
Tom Sepez6ba32d92016-01-05 16:26:32 -08001244 int i = 0;
1245 for (const auto& pIconElement : m_IconList) {
Tom Sepez39bfe122015-09-17 15:25:23 -07001246 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07001247 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001248 if (pObj.IsEmpty())
1249 return FALSE;
1250
Tom Sepezd5a0e952015-09-17 15:40:06 -07001251 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001252 if (!pJS_Icon)
1253 return FALSE;
1254
1255 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1256 if (!pIcon)
1257 return FALSE;
1258
1259 pIcon->SetStream(pIconElement->IconStream->GetStream());
1260 pIcon->SetIconName(pIconElement->IconName);
Tom Sepez6ba32d92016-01-05 16:26:32 -08001261 Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001262 }
1263
1264 vp << Icons;
1265 return TRUE;
1266}
1267
Tom Sepezba038bc2015-10-08 12:03:00 -07001268FX_BOOL Document::getIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001269 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001270 CJS_Value& vRet,
1271 CFX_WideString& sError) {
1272 CJS_Context* pContext = (CJS_Context*)cc;
1273 if (params.size() != 1) {
1274 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1275 return FALSE;
1276 }
1277
Tom Sepez6ba32d92016-01-05 16:26:32 -08001278 if (m_IconList.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001279 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001280
Tom Sepez6ba32d92016-01-05 16:26:32 -08001281 CFX_WideString swIconName = params[0].ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001282 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1283
Tom Sepez6ba32d92016-01-05 16:26:32 -08001284 for (const auto& pIconElement : m_IconList) {
1285 if (pIconElement->IconName == swIconName) {
1286 Icon* pRetIcon = pIconElement->IconStream;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001287
Tom Sepez39bfe122015-09-17 15:25:23 -07001288 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07001289 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001290 if (pObj.IsEmpty())
1291 return FALSE;
1292
Tom Sepezd5a0e952015-09-17 15:40:06 -07001293 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001294 if (!pJS_Icon)
1295 return FALSE;
1296
1297 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1298 if (!pIcon)
1299 return FALSE;
1300
1301 pIcon->SetIconName(swIconName);
1302 pIcon->SetStream(pRetIcon->GetStream());
1303 vRet = pJS_Icon;
1304 return TRUE;
1305 }
1306 }
1307
1308 return FALSE;
1309}
1310
Tom Sepezba038bc2015-10-08 12:03:00 -07001311FX_BOOL Document::removeIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001312 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001313 CJS_Value& vRet,
1314 CFX_WideString& sError) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001315 // Unsafe, no supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316 return TRUE;
1317}
1318
Tom Sepezba038bc2015-10-08 12:03:00 -07001319FX_BOOL Document::createDataObject(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001320 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001321 CJS_Value& vRet,
1322 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -08001323 // Unsafe, not implemented.
1324 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001325}
1326
Tom Sepezba038bc2015-10-08 12:03:00 -07001327FX_BOOL Document::media(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001328 CJS_PropValue& vp,
1329 CFX_WideString& sError) {
1330 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001331}
1332
Tom Sepezba038bc2015-10-08 12:03:00 -07001333FX_BOOL Document::calculateNow(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001334 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001335 CJS_Value& vRet,
1336 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001337 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001338 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001339 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001340 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001341
1342 CPDFSDK_InterForm* pInterForm =
1343 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001344 pInterForm->OnCalculate();
1345 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001346}
1347
Tom Sepezba038bc2015-10-08 12:03:00 -07001348FX_BOOL Document::Collab(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001349 CJS_PropValue& vp,
1350 CFX_WideString& sError) {
1351 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001352}
1353
Tom Sepezba038bc2015-10-08 12:03:00 -07001354FX_BOOL Document::getPageNthWord(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001355 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001356 CJS_Value& vRet,
1357 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1359 return FALSE;
Tom Sepeze5350ef2015-04-23 18:14:26 -07001360
Lei Zhangdd734de2015-11-11 10:16:52 -08001361 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0;
1362 int nWordNo = params.size() > 1 ? params[1].ToInt() : 0;
1363 bool bStrip = params.size() > 2 ? params[2].ToBool() : true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001364
Tom Sepez50d12ad2015-11-24 09:50:51 -08001365 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001366 if (!pDocument)
1367 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001368
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001369 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1370 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1371 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1372 return FALSE;
1373 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001374
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001375 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1376 if (!pPageDict)
1377 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001378
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001379 CPDF_Page page;
1380 page.Load(pDocument, pPageDict);
Tom Sepezb5b2a912016-01-21 11:04:37 -08001381 page.ParseContent(nullptr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001382
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001383 int nWords = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001384 CFX_WideString swRet;
Tom Sepez2398d892016-02-17 16:46:26 -08001385 for (auto& pPageObj : *page.GetPageObjectList()) {
Wei Li7cf13c92016-02-19 11:53:03 -08001386 if (pPageObj->IsText()) {
1387 CPDF_TextObject* pTextObj = pPageObj->AsText();
Tom Sepez2398d892016-02-17 16:46:26 -08001388 int nObjWords = CountWords(pTextObj);
1389 if (nWords + nObjWords >= nWordNo) {
1390 swRet = GetObjWordStr(pTextObj, nWordNo - nWords);
1391 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001392 }
Tom Sepez2398d892016-02-17 16:46:26 -08001393 nWords += nObjWords;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001394 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001395 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001396
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397 if (bStrip) {
1398 swRet.TrimLeft();
1399 swRet.TrimRight();
1400 }
1401
1402 vRet = swRet.c_str();
1403 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001404}
1405
Tom Sepezba038bc2015-10-08 12:03:00 -07001406FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001407 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408 CJS_Value& vRet,
1409 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1411 return FALSE;
1412
1413 return FALSE;
1414}
1415
Tom Sepezba038bc2015-10-08 12:03:00 -07001416FX_BOOL Document::getPageNumWords(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001417 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418 CJS_Value& vRet,
1419 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001420 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
1421 return FALSE;
1422
Lei Zhangdd734de2015-11-11 10:16:52 -08001423 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0;
Tom Sepez50d12ad2015-11-24 09:50:51 -08001424 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001425 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1426 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1428 return FALSE;
1429 }
1430
1431 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1432 if (!pPageDict)
1433 return FALSE;
1434
1435 CPDF_Page page;
1436 page.Load(pDocument, pPageDict);
Tom Sepezb5b2a912016-01-21 11:04:37 -08001437 page.ParseContent(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438
1439 int nWords = 0;
Tom Sepez2398d892016-02-17 16:46:26 -08001440 for (auto& pPageObj : *page.GetPageObjectList()) {
Wei Li7cf13c92016-02-19 11:53:03 -08001441 if (pPageObj->IsText())
1442 nWords += CountWords(pPageObj->AsText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001443 }
1444
1445 vRet = nWords;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446 return TRUE;
1447}
1448
Tom Sepezba038bc2015-10-08 12:03:00 -07001449FX_BOOL Document::getPrintParams(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001450 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001451 CJS_Value& vRet,
1452 CFX_WideString& sError) {
1453 CJS_Context* pContext = (CJS_Context*)cc;
1454 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez39bfe122015-09-17 15:25:23 -07001455 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07001456 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001457
1458 // Not implemented yet.
1459
1460 vRet = pRetObj;
1461 return TRUE;
1462}
1463
1464#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
1465
1466int Document::CountWords(CPDF_TextObject* pTextObj) {
1467 if (!pTextObj)
1468 return 0;
1469
1470 int nWords = 0;
1471
1472 CPDF_Font* pFont = pTextObj->GetFont();
1473 if (!pFont)
1474 return 0;
1475
1476 FX_BOOL bIsLatin = FALSE;
1477
1478 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
1479 FX_DWORD charcode = -1;
1480 FX_FLOAT kerning;
1481
1482 pTextObj->GetCharInfo(i, charcode, kerning);
1483 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
1484
1485 FX_WORD unicode = 0;
1486 if (swUnicode.GetLength() > 0)
1487 unicode = swUnicode[0];
1488
1489 if (ISLATINWORD(unicode) && bIsLatin)
1490 continue;
1491
1492 bIsLatin = ISLATINWORD(unicode);
1493 if (unicode != 0x20)
1494 nWords++;
1495 }
1496
1497 return nWords;
1498}
1499
1500CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj,
1501 int nWordIndex) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 CFX_WideString swRet;
1503
1504 CPDF_Font* pFont = pTextObj->GetFont();
1505 if (!pFont)
1506 return L"";
1507
1508 int nWords = 0;
1509 FX_BOOL bIsLatin = FALSE;
1510
1511 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
1512 FX_DWORD charcode = -1;
1513 FX_FLOAT kerning;
1514
1515 pTextObj->GetCharInfo(i, charcode, kerning);
1516 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
1517
1518 FX_WORD unicode = 0;
1519 if (swUnicode.GetLength() > 0)
1520 unicode = swUnicode[0];
1521
1522 if (ISLATINWORD(unicode) && bIsLatin) {
1523 } else {
1524 bIsLatin = ISLATINWORD(unicode);
1525 if (unicode != 0x20)
1526 nWords++;
1527 }
1528
1529 if (nWords - 1 == nWordIndex)
1530 swRet += unicode;
1531 }
1532
1533 return swRet;
1534}
1535
Tom Sepezba038bc2015-10-08 12:03:00 -07001536FX_BOOL Document::zoom(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001537 CJS_PropValue& vp,
1538 CFX_WideString& sError) {
1539 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001540}
1541
1542/**
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001543(none, NoVary)
1544(fitP, FitPage)
1545(fitW, FitWidth)
1546(fitH, FitHeight)
1547(fitV, FitVisibleWidth)
1548(pref, Preferred)
1549(refW, ReflowWidth)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001550*/
1551
Tom Sepezba038bc2015-10-08 12:03:00 -07001552FX_BOOL Document::zoomType(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001553 CJS_PropValue& vp,
1554 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -08001555 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001556}
1557
Tom Sepezba038bc2015-10-08 12:03:00 -07001558FX_BOOL Document::deletePages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001559 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560 CJS_Value& vRet,
1561 CFX_WideString& sError) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001562 // Unsafe, no supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001563 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001564}
JUN FANG33f6f0d2015-04-06 12:39:51 -07001565
Tom Sepezba038bc2015-10-08 12:03:00 -07001566FX_BOOL Document::extractPages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001567 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001568 CJS_Value& vRet,
1569 CFX_WideString& sError) {
1570 // Unsafe, not supported.
1571 return TRUE;
1572}
1573
Tom Sepezba038bc2015-10-08 12:03:00 -07001574FX_BOOL Document::insertPages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001575 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001576 CJS_Value& vRet,
1577 CFX_WideString& sError) {
1578 // Unsafe, not supported.
1579 return TRUE;
1580}
1581
Tom Sepezba038bc2015-10-08 12:03:00 -07001582FX_BOOL Document::replacePages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001583 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001584 CJS_Value& vRet,
1585 CFX_WideString& sError) {
1586 // Unsafe, not supported.
1587 return TRUE;
1588}
1589
Tom Sepezba038bc2015-10-08 12:03:00 -07001590FX_BOOL Document::getURL(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001591 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001592 CJS_Value& vRet,
1593 CFX_WideString& sError) {
1594 // Unsafe, not supported.
1595 return TRUE;
1596}
1597
1598void Document::AddDelayData(CJS_DelayData* pData) {
1599 m_DelayData.Add(pData);
1600}
1601
1602void Document::DoFieldDelay(const CFX_WideString& sFieldName,
1603 int nControlIndex) {
1604 CFX_DWordArray DelArray;
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001605 CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001606
1607 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
1608 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
1609 if (pData->sFieldName == sFieldName &&
1610 pData->nControlIndex == nControlIndex) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001611 DelayDataForFieldAndControlIndex.Add(pData);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001612 m_DelayData.SetAt(i, NULL);
1613 DelArray.Add(i);
1614 }
1615 }
1616 }
1617
1618 for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
1619 m_DelayData.RemoveAt(DelArray[j]);
1620 }
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001621
1622 for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz;
1623 i++) {
1624 CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i);
1625 Field::DoDelay(m_pDocument, pData);
1626 DelayDataForFieldAndControlIndex.SetAt(i, NULL);
1627 delete pData;
1628 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001629}
1630
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001631CJS_Document* Document::GetCJSDoc() const {
1632 return static_cast<CJS_Document*>(m_pJSObject);
JUN FANG33f6f0d2015-04-06 12:39:51 -07001633}