blob: 0b08f66f338a7142a2ec76e187ab0d856a6c5fe5 [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 Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/Document.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008
thestig7c292e02016-09-28 14:14:26 -07009#include <utility>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050010#include <vector>
11
dsinclairbc5e6d22016-10-04 11:08:49 -070012#include "core/fpdfapi/font/cpdf_font.h"
dsinclair41872fa2016-10-04 11:29:35 -070013#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070014#include "core/fpdfapi/parser/cpdf_array.h"
15#include "core/fpdfapi/parser/cpdf_document.h"
16#include "core/fpdfapi/parser/fpdf_parser_decode.h"
dsinclair1727aee2016-09-29 13:12:56 -070017#include "core/fpdfdoc/cpdf_interform.h"
18#include "core/fpdfdoc/cpdf_nametree.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_annotiterator.h"
dsinclair735606d2016-10-05 15:47:02 -070020#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070021#include "fpdfsdk/cpdfsdk_interform.h"
22#include "fpdfsdk/cpdfsdk_pageview.h"
23#include "fpdfsdk/cpdfsdk_widget.h"
tonikitoo618cb1f2016-08-18 20:10:17 -070024#include "fpdfsdk/javascript/Annot.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040025#include "fpdfsdk/javascript/Field.h"
26#include "fpdfsdk/javascript/Icon.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040027#include "fpdfsdk/javascript/JS_Define.h"
28#include "fpdfsdk/javascript/JS_EventHandler.h"
29#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040030#include "fpdfsdk/javascript/JS_Value.h"
31#include "fpdfsdk/javascript/app.h"
dsinclair64376be2016-03-31 20:03:24 -070032#include "fpdfsdk/javascript/cjs_context.h"
33#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040034#include "fpdfsdk/javascript/resource.h"
Lei Zhang8241df72015-11-06 14:38:48 -080035#include "third_party/base/numerics/safe_math.h"
Chris Palmer9108ad22014-06-26 16:01:46 -070036
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
38END_JS_STATIC_CONST()
39
40BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
41END_JS_STATIC_PROP()
42
43BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
44END_JS_STATIC_METHOD()
45
46IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
47
48PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 : CJS_EmbedObj(pJSObject) {
50 bUI = TRUE;
51 nStart = 0;
52 nEnd = 0;
53 bSilent = FALSE;
54 bShrinkToFit = FALSE;
55 bPrintAsImage = FALSE;
56 bReverse = FALSE;
57 bAnnotations = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058}
59
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060#define MINWIDTH 5.0f
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061#define MINHEIGHT 5.0f
62
63BEGIN_JS_STATIC_CONST(CJS_Document)
64END_JS_STATIC_CONST()
65
66BEGIN_JS_STATIC_PROP(CJS_Document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067JS_STATIC_PROP_ENTRY(ADBE)
68JS_STATIC_PROP_ENTRY(author)
69JS_STATIC_PROP_ENTRY(baseURL)
70JS_STATIC_PROP_ENTRY(bookmarkRoot)
71JS_STATIC_PROP_ENTRY(calculate)
72JS_STATIC_PROP_ENTRY(Collab)
73JS_STATIC_PROP_ENTRY(creationDate)
74JS_STATIC_PROP_ENTRY(creator)
75JS_STATIC_PROP_ENTRY(delay)
76JS_STATIC_PROP_ENTRY(dirty)
77JS_STATIC_PROP_ENTRY(documentFileName)
78JS_STATIC_PROP_ENTRY(external)
79JS_STATIC_PROP_ENTRY(filesize)
80JS_STATIC_PROP_ENTRY(icons)
81JS_STATIC_PROP_ENTRY(info)
82JS_STATIC_PROP_ENTRY(keywords)
83JS_STATIC_PROP_ENTRY(layout)
84JS_STATIC_PROP_ENTRY(media)
85JS_STATIC_PROP_ENTRY(modDate)
86JS_STATIC_PROP_ENTRY(mouseX)
87JS_STATIC_PROP_ENTRY(mouseY)
88JS_STATIC_PROP_ENTRY(numFields)
89JS_STATIC_PROP_ENTRY(numPages)
90JS_STATIC_PROP_ENTRY(pageNum)
91JS_STATIC_PROP_ENTRY(pageWindowRect)
92JS_STATIC_PROP_ENTRY(path)
93JS_STATIC_PROP_ENTRY(producer)
94JS_STATIC_PROP_ENTRY(subject)
95JS_STATIC_PROP_ENTRY(title)
tonikitoo33c4cdb2016-08-08 10:52:51 -070096JS_STATIC_PROP_ENTRY(URL)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097JS_STATIC_PROP_ENTRY(zoom)
98JS_STATIC_PROP_ENTRY(zoomType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099END_JS_STATIC_PROP()
100
101BEGIN_JS_STATIC_METHOD(CJS_Document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102JS_STATIC_METHOD_ENTRY(addAnnot)
103JS_STATIC_METHOD_ENTRY(addField)
104JS_STATIC_METHOD_ENTRY(addLink)
105JS_STATIC_METHOD_ENTRY(addIcon)
106JS_STATIC_METHOD_ENTRY(calculateNow)
107JS_STATIC_METHOD_ENTRY(closeDoc)
108JS_STATIC_METHOD_ENTRY(createDataObject)
109JS_STATIC_METHOD_ENTRY(deletePages)
110JS_STATIC_METHOD_ENTRY(exportAsText)
111JS_STATIC_METHOD_ENTRY(exportAsFDF)
112JS_STATIC_METHOD_ENTRY(exportAsXFDF)
113JS_STATIC_METHOD_ENTRY(extractPages)
114JS_STATIC_METHOD_ENTRY(getAnnot)
115JS_STATIC_METHOD_ENTRY(getAnnots)
116JS_STATIC_METHOD_ENTRY(getAnnot3D)
117JS_STATIC_METHOD_ENTRY(getAnnots3D)
118JS_STATIC_METHOD_ENTRY(getField)
119JS_STATIC_METHOD_ENTRY(getIcon)
120JS_STATIC_METHOD_ENTRY(getLinks)
121JS_STATIC_METHOD_ENTRY(getNthFieldName)
122JS_STATIC_METHOD_ENTRY(getOCGs)
123JS_STATIC_METHOD_ENTRY(getPageBox)
124JS_STATIC_METHOD_ENTRY(getPageNthWord)
125JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
126JS_STATIC_METHOD_ENTRY(getPageNumWords)
127JS_STATIC_METHOD_ENTRY(getPrintParams)
128JS_STATIC_METHOD_ENTRY(getURL)
tonikitoo1c836752016-08-08 16:14:05 -0700129JS_STATIC_METHOD_ENTRY(gotoNamedDest)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130JS_STATIC_METHOD_ENTRY(importAnFDF)
131JS_STATIC_METHOD_ENTRY(importAnXFDF)
132JS_STATIC_METHOD_ENTRY(importTextData)
133JS_STATIC_METHOD_ENTRY(insertPages)
134JS_STATIC_METHOD_ENTRY(mailForm)
135JS_STATIC_METHOD_ENTRY(print)
136JS_STATIC_METHOD_ENTRY(removeField)
137JS_STATIC_METHOD_ENTRY(replacePages)
138JS_STATIC_METHOD_ENTRY(resetForm)
139JS_STATIC_METHOD_ENTRY(removeIcon)
140JS_STATIC_METHOD_ENTRY(saveAs)
141JS_STATIC_METHOD_ENTRY(submitForm)
tonikitoobb5fa042016-08-19 11:18:29 -0700142JS_STATIC_METHOD_ENTRY(syncAnnotScan)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143JS_STATIC_METHOD_ENTRY(mailDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144END_JS_STATIC_METHOD()
145
146IMPLEMENT_JS_CLASS(CJS_Document, Document)
147
Tom Sepez33420902015-10-13 15:00:10 -0700148void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
149 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
150 Document* pDoc = static_cast<Document*>(GetEmbedObject());
dsinclair82e17672016-10-11 12:38:01 -0700151 pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv());
Tom Sepez33420902015-10-13 15:00:10 -0700152}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154Document::Document(CJS_Object* pJSObject)
155 : CJS_EmbedObj(pJSObject),
dsinclair82e17672016-10-11 12:38:01 -0700156 m_pFormFillEnv(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 m_cwBaseURL(L""),
158 m_bDelay(FALSE) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160Document::~Document() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161}
162
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163// the total number of fileds in document.
Tom Sepezba038bc2015-10-08 12:03:00 -0700164FX_BOOL Document::numFields(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 CJS_PropValue& vp,
166 CFX_WideString& sError) {
167 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -0700168 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700169 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 }
dsinclair82e17672016-10-11 12:38:01 -0700171 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700172 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
173 return FALSE;
174 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700175 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
thestig7c292e02016-09-28 14:14:26 -0700177 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179}
180
Tom Sepezba038bc2015-10-08 12:03:00 -0700181FX_BOOL Document::dirty(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 CJS_PropValue& vp,
183 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700184 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700185 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
186 return FALSE;
187 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 if (vp.IsGetting()) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700189 vp << !!m_pFormFillEnv->GetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190 } else {
191 bool bChanged = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 vp >> bChanged;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 if (bChanged)
dsinclair7cbe68e2016-10-12 11:56:23 -0700195 m_pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 else
dsinclair7cbe68e2016-10-12 11:56:23 -0700197 m_pFormFillEnv->ClearChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200}
201
Tom Sepezba038bc2015-10-08 12:03:00 -0700202FX_BOOL Document::ADBE(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 CJS_PropValue& vp,
204 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -0700205 if (vp.IsGetting())
206 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207
208 return TRUE;
209}
210
Tom Sepezba038bc2015-10-08 12:03:00 -0700211FX_BOOL Document::pageNum(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 CJS_PropValue& vp,
213 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700214 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700215 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
216 return FALSE;
217 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 if (vp.IsGetting()) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700219 if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 vp << pPageView->GetPageIndex();
221 }
222 } else {
dsinclair7cbe68e2016-10-12 11:56:23 -0700223 int iPageCount = m_pFormFillEnv->GetPageCount();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 int iPageNum = 0;
225 vp >> iPageNum;
226
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 if (iPageNum >= 0 && iPageNum < iPageCount) {
dsinclair82e17672016-10-11 12:38:01 -0700228 m_pFormFillEnv->JS_docgotoPage(iPageNum);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 } else if (iPageNum >= iPageCount) {
dsinclair82e17672016-10-11 12:38:01 -0700230 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 } else if (iPageNum < 0) {
dsinclair82e17672016-10-11 12:38:01 -0700232 m_pFormFillEnv->JS_docgotoPage(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 }
234 }
235
236 return TRUE;
237}
238
Tom Sepezba038bc2015-10-08 12:03:00 -0700239FX_BOOL Document::addAnnot(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800240 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 CJS_Value& vRet,
242 CFX_WideString& sError) {
243 // Not supported.
244 return TRUE;
245}
246
Tom Sepezba038bc2015-10-08 12:03:00 -0700247FX_BOOL Document::addField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800248 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 CJS_Value& vRet,
250 CFX_WideString& sError) {
251 // Not supported.
252 return TRUE;
253}
254
Tom Sepezba038bc2015-10-08 12:03:00 -0700255FX_BOOL Document::exportAsText(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800256 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 CJS_Value& vRet,
258 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800259 // Unsafe, not supported.
260 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261}
262
Tom Sepezba038bc2015-10-08 12:03:00 -0700263FX_BOOL Document::exportAsFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800264 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 CJS_Value& vRet,
266 CFX_WideString& sError) {
267 // Unsafe, not supported.
268 return TRUE;
269}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700270
Tom Sepezba038bc2015-10-08 12:03:00 -0700271FX_BOOL Document::exportAsXFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800272 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 CJS_Value& vRet,
274 CFX_WideString& sError) {
275 // Unsafe, not supported.
276 return TRUE;
277}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279// Maps a field object in PDF document to a JavaScript variable
280// comment:
281// note: the paremter cName, this is clue how to treat if the cName is not a
282// valiable filed name in this document
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283
Tom Sepezba038bc2015-10-08 12:03:00 -0700284FX_BOOL Document::getField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800285 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 CJS_Value& vRet,
287 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 if (params.size() < 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700289 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 return FALSE;
291 }
dsinclair82e17672016-10-11 12:38:01 -0700292 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700293 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
294 return FALSE;
295 }
tsepezcd5dc852016-09-08 11:23:24 -0700296 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezf3dc8c62016-08-10 06:29:29 -0700297 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -0700298 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
dsinclair7cbe68e2016-10-12 11:56:23 -0700299 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
301 if (pPDFForm->CountFields(wideName) <= 0) {
tsepezf3dc8c62016-08-10 06:29:29 -0700302 vRet.SetNull(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 return TRUE;
304 }
305
tsepezf3dc8c62016-08-10 06:29:29 -0700306 v8::Local<v8::Object> pFieldObj =
tsepezb4694242016-08-15 16:44:55 -0700307 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
tsepezf3dc8c62016-08-10 06:29:29 -0700308 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -0700309 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
tsepezf3dc8c62016-08-10 06:29:29 -0700310 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 pField->AttachField(this, wideName);
312
tsepezf3dc8c62016-08-10 06:29:29 -0700313 vRet = CJS_Value(pRuntime, pJSField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 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) {
tsepezcd5dc852016-09-08 11:23:24 -0700322 if (params.size() != 1) {
323 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
324 return FALSE;
325 }
dsinclair82e17672016-10-11 12:38:01 -0700326 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700327 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
328 return FALSE;
329 }
tsepezf3dc8c62016-08-10 06:29:29 -0700330 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezb4694242016-08-15 16:44:55 -0700331 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -0700332 int nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 if (nIndex < 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700334 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 return FALSE;
336 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700337 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
thestig7c292e02016-09-28 14:14:26 -0700339 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 if (!pField)
341 return FALSE;
342
tsepezf3dc8c62016-08-10 06:29:29 -0700343 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 return TRUE;
345}
346
Tom Sepezba038bc2015-10-08 12:03:00 -0700347FX_BOOL Document::importAnFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800348 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 CJS_Value& vRet,
350 CFX_WideString& sError) {
351 // Unsafe, not supported.
352 return TRUE;
353}
354
Tom Sepezba038bc2015-10-08 12:03:00 -0700355FX_BOOL Document::importAnXFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800356 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 CJS_Value& vRet,
358 CFX_WideString& sError) {
359 // Unsafe, not supported.
360 return TRUE;
361}
362
Tom Sepezba038bc2015-10-08 12:03:00 -0700363FX_BOOL Document::importTextData(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800364 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 CJS_Value& vRet,
366 CFX_WideString& sError) {
367 // Unsafe, not supported.
368 return TRUE;
369}
370
371// exports the form data and mails the resulting fdf file as an attachment to
372// all recipients.
373// comment: need reader supports
Tom Sepezba038bc2015-10-08 12:03:00 -0700374FX_BOOL Document::mailForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800375 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 CJS_Value& vRet,
377 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700378 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700379 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
380 return FALSE;
381 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700382 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
tsepez55be02e2016-09-12 11:21:42 -0700383 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
384 return FALSE;
385 }
386
tsepezf3dc8c62016-08-10 06:29:29 -0700387 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezb4694242016-08-15 16:44:55 -0700388 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezf3dc8c62016-08-10 06:29:29 -0700389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 int iLength = params.size();
tsepezb4694242016-08-15 16:44:55 -0700391 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE;
392 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L"";
393 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L"";
394 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L"";
tsepezf3dc8c62016-08-10 06:29:29 -0700395 CFX_WideString cSubject =
tsepezb4694242016-08-15 16:44:55 -0700396 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L"";
397 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398
dsinclair7cbe68e2016-10-12 11:56:23 -0700399 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 CFX_ByteTextBuf textBuf;
401 if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
402 return FALSE;
403
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 pRuntime->BeginBlock();
dsinclair8779fa82016-10-12 12:05:44 -0700405 CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv();
406 pFormFillEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
407 cTo.c_str(), cSubject.c_str(), cCc.c_str(),
408 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 pRuntime->EndBlock();
410 return TRUE;
411}
412
Tom Sepezba038bc2015-10-08 12:03:00 -0700413FX_BOOL Document::print(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800414 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 CJS_Value& vRet,
416 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700417 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700418 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
419 return FALSE;
420 }
421
tsepezf3dc8c62016-08-10 06:29:29 -0700422 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
423 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezf3dc8c62016-08-10 06:29:29 -0700424
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 FX_BOOL bUI = TRUE;
426 int nStart = 0;
427 int nEnd = 0;
428 FX_BOOL bSilent = FALSE;
429 FX_BOOL bShrinkToFit = FALSE;
430 FX_BOOL bPrintAsImage = FALSE;
431 FX_BOOL bReverse = FALSE;
432 FX_BOOL bAnnotations = FALSE;
433
434 int nlength = params.size();
435 if (nlength == 9) {
tsepez40faa792016-07-15 17:58:02 -0700436 if (params[8].GetType() == CJS_Value::VT_object) {
tsepezb4694242016-08-15 16:44:55 -0700437 v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime);
438 if (CFXJS_Engine::GetObjDefnID(pObj) ==
439 CJS_PrintParamsObj::g_nObjDefnID) {
440 if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) {
tsepez40faa792016-07-15 17:58:02 -0700441 if (PrintParamsObj* pprintparamsObj =
442 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) {
443 bUI = pprintparamsObj->bUI;
444 nStart = pprintparamsObj->nStart;
445 nEnd = pprintparamsObj->nEnd;
446 bSilent = pprintparamsObj->bSilent;
447 bShrinkToFit = pprintparamsObj->bShrinkToFit;
448 bPrintAsImage = pprintparamsObj->bPrintAsImage;
449 bReverse = pprintparamsObj->bReverse;
450 bAnnotations = pprintparamsObj->bAnnotations;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700452 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 }
454 }
455 } else {
456 if (nlength >= 1)
tsepezb4694242016-08-15 16:44:55 -0700457 bUI = params[0].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 if (nlength >= 2)
tsepezb4694242016-08-15 16:44:55 -0700459 nStart = params[1].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 if (nlength >= 3)
tsepezb4694242016-08-15 16:44:55 -0700461 nEnd = params[2].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 if (nlength >= 4)
tsepezb4694242016-08-15 16:44:55 -0700463 bSilent = params[3].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 if (nlength >= 5)
tsepezb4694242016-08-15 16:44:55 -0700465 bShrinkToFit = params[4].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (nlength >= 6)
tsepezb4694242016-08-15 16:44:55 -0700467 bPrintAsImage = params[5].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 if (nlength >= 7)
tsepezb4694242016-08-15 16:44:55 -0700469 bReverse = params[6].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 if (nlength >= 8)
tsepezb4694242016-08-15 16:44:55 -0700471 bAnnotations = params[7].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 }
473
dsinclair82e17672016-10-11 12:38:01 -0700474 if (m_pFormFillEnv) {
475 m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit,
476 bPrintAsImage, bReverse, bAnnotations);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 return TRUE;
478 }
479 return FALSE;
480}
481
482// removes the specified field from the document.
483// comment:
dsinclair1897bdc2016-09-06 14:18:57 -0700484// note: if the filed name is not rational, adobe is dumb for it.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485
Tom Sepezba038bc2015-10-08 12:03:00 -0700486FX_BOOL Document::removeField(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800487 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 CJS_Value& vRet,
489 CFX_WideString& sError) {
tsepez55be02e2016-09-12 11:21:42 -0700490 if (params.size() != 1) {
491 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
492 return FALSE;
493 }
dsinclair82e17672016-10-11 12:38:01 -0700494 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700495 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
496 return FALSE;
497 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700498 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) ||
499 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) {
tsepezcd5dc852016-09-08 11:23:24 -0700500 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 return FALSE;
502 }
tsepezcd5dc852016-09-08 11:23:24 -0700503 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezf3dc8c62016-08-10 06:29:29 -0700504 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -0700505 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime);
dsinclair7cbe68e2016-10-12 11:56:23 -0700506 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800507 std::vector<CPDFSDK_Widget*> widgets;
508 pInterForm->GetWidgets(sFieldName, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -0800509 if (widgets.empty())
510 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511
Lei Zhangd88a3642015-11-10 09:38:57 -0800512 for (CPDFSDK_Widget* pWidget : widgets) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800513 CFX_FloatRect rcAnnot = pWidget->GetRect();
Lei Zhangd88a3642015-11-10 09:38:57 -0800514 --rcAnnot.left;
515 --rcAnnot.bottom;
516 ++rcAnnot.right;
517 ++rcAnnot.top;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518
tsepezdf964df2016-04-21 12:09:41 -0700519 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800520 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
Lei Zhangd88a3642015-11-10 09:38:57 -0800521 ASSERT(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522
dsinclair1897bdc2016-09-06 14:18:57 -0700523 // If there is currently no pageview associated with the page being used
524 // do not create one. We may be in the process of tearing down the document
525 // and creating a new pageview at this point will cause bad things.
dsinclair7cbe68e2016-10-12 11:56:23 -0700526 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false);
dsinclair1897bdc2016-09-06 14:18:57 -0700527 if (pPageView) {
dsinclair8afe15a2016-10-05 12:00:34 -0700528#if PDF_ENABLE_XFA
dsinclair1897bdc2016-09-06 14:18:57 -0700529 pPageView->DeleteAnnot(pWidget);
dsinclair8afe15a2016-10-05 12:00:34 -0700530#endif // PDF_ENABLE_XFA
dsinclair1897bdc2016-09-06 14:18:57 -0700531 pPageView->UpdateRects(aRefresh);
532 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700534 m_pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535
536 return TRUE;
537}
538
539// reset filed values within a document.
540// comment:
541// note: if the fields names r not rational, aodbe is dumb for it.
542
Tom Sepezba038bc2015-10-08 12:03:00 -0700543FX_BOOL Document::resetForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800544 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 CJS_Value& vRet,
546 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700547 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700548 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
549 return FALSE;
550 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700551 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) ||
552 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
553 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) {
tsepez55be02e2016-09-12 11:21:42 -0700554 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -0700556 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557
dsinclair7cbe68e2016-10-12 11:56:23 -0700558 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
tsepeze5aff742016-08-08 09:49:42 -0700560 CJS_Array aName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561
Lei Zhangdd734de2015-11-11 10:16:52 -0800562 if (params.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 pPDFForm->ResetForm(TRUE);
dsinclair7cbe68e2016-10-12 11:56:23 -0700564 m_pFormFillEnv->SetChangeMark();
Lei Zhangd88a3642015-11-10 09:38:57 -0800565 return TRUE;
566 }
567
tsepez55be02e2016-09-12 11:21:42 -0700568 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezf3dc8c62016-08-10 06:29:29 -0700569 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezf3dc8c62016-08-10 06:29:29 -0700570
Lei Zhangd88a3642015-11-10 09:38:57 -0800571 switch (params[0].GetType()) {
572 default:
tsepezb4694242016-08-15 16:44:55 -0700573 aName.Attach(params[0].ToV8Array(pRuntime));
Lei Zhangd88a3642015-11-10 09:38:57 -0800574 break;
575 case CJS_Value::VT_string:
tsepezb4694242016-08-15 16:44:55 -0700576 aName.SetElement(pRuntime, 0, params[0]);
Lei Zhangd88a3642015-11-10 09:38:57 -0800577 break;
578 }
579
580 std::vector<CPDF_FormField*> aFields;
tsepezb4694242016-08-15 16:44:55 -0700581 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800582 CJS_Value valElement(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700583 aName.GetElement(pRuntime, i, valElement);
584 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -0800585 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
586 aFields.push_back(pPDFForm->GetField(j, swVal));
587 }
588
589 if (!aFields.empty()) {
590 pPDFForm->ResetForm(aFields, TRUE, TRUE);
dsinclair7cbe68e2016-10-12 11:56:23 -0700591 m_pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 }
593
594 return TRUE;
595}
596
Tom Sepezba038bc2015-10-08 12:03:00 -0700597FX_BOOL Document::saveAs(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800598 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 CJS_Value& vRet,
600 CFX_WideString& sError) {
601 // Unsafe, not supported.
602 return TRUE;
603}
604
tonikitoobb5fa042016-08-19 11:18:29 -0700605FX_BOOL Document::syncAnnotScan(IJS_Context* cc,
606 const std::vector<CJS_Value>& params,
607 CJS_Value& vRet,
608 CFX_WideString& sError) {
609 return TRUE;
610}
611
Tom Sepezba038bc2015-10-08 12:03:00 -0700612FX_BOOL Document::submitForm(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800613 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 CJS_Value& vRet,
615 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 int nSize = params.size();
617 if (nSize < 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700618 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 return FALSE;
620 }
dsinclair82e17672016-10-11 12:38:01 -0700621 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700622 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
623 return FALSE;
624 }
tsepezcd5dc852016-09-08 11:23:24 -0700625 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
626 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepeze5aff742016-08-08 09:49:42 -0700627 CJS_Array aFields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 CFX_WideString strURL;
629 FX_BOOL bFDF = TRUE;
630 FX_BOOL bEmpty = FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 CJS_Value v = params[0];
Tom Sepez39bfe122015-09-17 15:25:23 -0700632 if (v.GetType() == CJS_Value::VT_string) {
tsepezb4694242016-08-15 16:44:55 -0700633 strURL = params[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 if (nSize > 1)
tsepezb4694242016-08-15 16:44:55 -0700635 bFDF = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 if (nSize > 2)
tsepezb4694242016-08-15 16:44:55 -0700637 bEmpty = params[2].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 if (nSize > 3)
tsepezb4694242016-08-15 16:44:55 -0700639 aFields.Attach(params[3].ToV8Array(pRuntime));
Tom Sepez39bfe122015-09-17 15:25:23 -0700640 } else if (v.GetType() == CJS_Value::VT_object) {
tsepezb4694242016-08-15 16:44:55 -0700641 v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime);
642 v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"cURL");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643 if (!pValue.IsEmpty())
tsepezb4694242016-08-15 16:44:55 -0700644 strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700645
tsepezb4694242016-08-15 16:44:55 -0700646 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF");
647 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700648
tsepezb4694242016-08-15 16:44:55 -0700649 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty");
650 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700651
tsepezb4694242016-08-15 16:44:55 -0700652 pValue = pRuntime->GetObjectProperty(pObj, L"aFields");
653 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 }
655
dsinclair7cbe68e2016-10-12 11:56:23 -0700656 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
tsepezb4694242016-08-15 16:44:55 -0700658 if (aFields.GetLength(pRuntime) == 0 && bEmpty) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800659 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 pRuntime->BeginBlock();
661 pInterForm->SubmitForm(strURL, FALSE);
662 pRuntime->EndBlock();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700663 }
664 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 }
666
Lei Zhangd88a3642015-11-10 09:38:57 -0800667 std::vector<CPDF_FormField*> fieldObjects;
tsepezb4694242016-08-15 16:44:55 -0700668 for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700669 CJS_Value valName(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700670 aFields.GetElement(pRuntime, i, valName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
tsepezb4694242016-08-15 16:44:55 -0700672 CFX_WideString sName = valName.ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
674 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) {
675 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
676 if (!bEmpty && pField->GetValue().IsEmpty())
677 continue;
678
Lei Zhangd88a3642015-11-10 09:38:57 -0800679 fieldObjects.push_back(pField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 }
681 }
682
Lei Zhangd88a3642015-11-10 09:38:57 -0800683 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 pRuntime->BeginBlock();
Wei Li97da9762016-03-11 17:00:48 -0800685 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 pRuntime->EndBlock();
687 }
688 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
dsinclair82e17672016-10-11 12:38:01 -0700691void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
692 m_pFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
Tom Sepezba038bc2015-10-08 12:03:00 -0700695FX_BOOL Document::bookmarkRoot(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 CJS_PropValue& vp,
697 CFX_WideString& sError) {
698 return TRUE;
699}
700
Tom Sepezba038bc2015-10-08 12:03:00 -0700701FX_BOOL Document::mailDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800702 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 CJS_Value& vRet,
704 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -0700705 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
706
707 // TODO(tsepez): Check maximum number of allowed params.
708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 FX_BOOL bUI = TRUE;
710 CFX_WideString cTo = L"";
711 CFX_WideString cCc = L"";
712 CFX_WideString cBcc = L"";
713 CFX_WideString cSubject = L"";
714 CFX_WideString cMsg = L"";
715
tsepezf3dc8c62016-08-10 06:29:29 -0700716 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717
tsepezf3dc8c62016-08-10 06:29:29 -0700718 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -0700719 bUI = params[0].ToBool(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -0700720 if (params.size() >= 2)
tsepezb4694242016-08-15 16:44:55 -0700721 cTo = params[1].ToCFXWideString(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -0700722 if (params.size() >= 3)
tsepezb4694242016-08-15 16:44:55 -0700723 cCc = params[2].ToCFXWideString(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -0700724 if (params.size() >= 4)
tsepezb4694242016-08-15 16:44:55 -0700725 cBcc = params[3].ToCFXWideString(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -0700726 if (params.size() >= 5)
tsepezb4694242016-08-15 16:44:55 -0700727 cSubject = params[4].ToCFXWideString(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -0700728 if (params.size() >= 6)
tsepezb4694242016-08-15 16:44:55 -0700729 cMsg = params[5].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730
Tom Sepez39bfe122015-09-17 15:25:23 -0700731 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
tsepezb4694242016-08-15 16:44:55 -0700732 v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733
tsepezb4694242016-08-15 16:44:55 -0700734 v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"bUI");
735 bUI = CJS_Value(pRuntime, pValue).ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736
tsepezb4694242016-08-15 16:44:55 -0700737 pValue = pRuntime->GetObjectProperty(pObj, L"cTo");
738 cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739
tsepezb4694242016-08-15 16:44:55 -0700740 pValue = pRuntime->GetObjectProperty(pObj, L"cCc");
741 cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742
tsepezb4694242016-08-15 16:44:55 -0700743 pValue = pRuntime->GetObjectProperty(pObj, L"cBcc");
744 cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745
tsepezb4694242016-08-15 16:44:55 -0700746 pValue = pRuntime->GetObjectProperty(pObj, L"cSubject");
747 cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748
tsepezb4694242016-08-15 16:44:55 -0700749 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg");
750 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 }
752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 pRuntime->BeginBlock();
dsinclair8779fa82016-10-12 12:05:44 -0700754 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
755 pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(),
756 cCc.c_str(), cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757 pRuntime->EndBlock();
758
759 return TRUE;
760}
761
Tom Sepezba038bc2015-10-08 12:03:00 -0700762FX_BOOL Document::author(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763 CJS_PropValue& vp,
764 CFX_WideString& sError) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700765 return getPropertyInternal(cc, vp, "Author", sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Tom Sepezba038bc2015-10-08 12:03:00 -0700768FX_BOOL Document::info(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 CJS_PropValue& vp,
770 CFX_WideString& sError) {
tonikitooec268762016-08-10 12:29:28 -0700771 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -0700772 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tonikitooec268762016-08-10 12:29:28 -0700773 return FALSE;
774 }
dsinclair82e17672016-10-11 12:38:01 -0700775 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700776 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
777 return FALSE;
778 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700779 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 if (!pDictionary)
781 return FALSE;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800782
dsinclair38fd8442016-09-15 10:15:32 -0700783 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author");
784 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title");
785 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject");
786 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords");
787 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator");
788 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer");
789 CFX_WideString cwCreationDate =
790 pDictionary->GetUnicodeTextFor("CreationDate");
791 CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate");
792 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped");
Tom Sepezc6ab1722015-02-05 15:27:25 -0800793
tonikitooec268762016-08-10 12:29:28 -0700794 CJS_Context* pContext = (CJS_Context*)cc;
795 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800796
tsepezb4694242016-08-15 16:44:55 -0700797 v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1);
798 pRuntime->PutObjectString(pObj, L"Author", cwAuthor);
799 pRuntime->PutObjectString(pObj, L"Title", cwTitle);
800 pRuntime->PutObjectString(pObj, L"Subject", cwSubject);
801 pRuntime->PutObjectString(pObj, L"Keywords", cwKeywords);
802 pRuntime->PutObjectString(pObj, L"Creator", cwCreator);
803 pRuntime->PutObjectString(pObj, L"Producer", cwProducer);
804 pRuntime->PutObjectString(pObj, L"CreationDate", cwCreationDate);
805 pRuntime->PutObjectString(pObj, L"ModDate", cwModDate);
806 pRuntime->PutObjectString(pObj, L"Trapped", cwTrapped);
tonikitooec268762016-08-10 12:29:28 -0700807
808 // It's to be compatible to non-standard info dictionary.
809 for (const auto& it : *pDictionary) {
810 const CFX_ByteString& bsKey = it.first;
tsepezd5bd8a12016-10-17 11:13:54 -0700811 CPDF_Object* pValueObj = it.second;
tonikitooec268762016-08-10 12:29:28 -0700812 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC());
813 if (pValueObj->IsString() || pValueObj->IsName()) {
tsepezb4694242016-08-15 16:44:55 -0700814 pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText());
tonikitooec268762016-08-10 12:29:28 -0700815 } else if (pValueObj->IsNumber()) {
tsepezb4694242016-08-15 16:44:55 -0700816 pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber());
tonikitooec268762016-08-10 12:29:28 -0700817 } else if (pValueObj->IsBoolean()) {
tsepezb4694242016-08-15 16:44:55 -0700818 pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700819 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820 }
tonikitooec268762016-08-10 12:29:28 -0700821 vp << pObj;
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700822 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823}
824
tonikitooea3ff9e2016-08-02 11:52:28 -0700825FX_BOOL Document::getPropertyInternal(IJS_Context* cc,
826 CJS_PropValue& vp,
827 const CFX_ByteString& propName,
828 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700829 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700830 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
831 return FALSE;
832 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700833 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834 if (!pDictionary)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700835 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836
837 if (vp.IsGetting()) {
dsinclair38fd8442016-09-15 10:15:32 -0700838 vp << pDictionary->GetUnicodeTextFor(propName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 } else {
dsinclair7cbe68e2016-10-12 11:56:23 -0700840 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) {
tsepez55be02e2016-09-12 11:21:42 -0700841 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -0700843 }
tonikitooea3ff9e2016-08-02 11:52:28 -0700844 CFX_WideString csProperty;
845 vp >> csProperty;
dsinclair38fd8442016-09-15 10:15:32 -0700846 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty));
dsinclair7cbe68e2016-10-12 11:56:23 -0700847 m_pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 }
849 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850}
851
tonikitooea3ff9e2016-08-02 11:52:28 -0700852FX_BOOL Document::creationDate(IJS_Context* cc,
853 CJS_PropValue& vp,
854 CFX_WideString& sError) {
855 return getPropertyInternal(cc, vp, "CreationDate", sError);
856}
857
Tom Sepezba038bc2015-10-08 12:03:00 -0700858FX_BOOL Document::creator(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 CJS_PropValue& vp,
860 CFX_WideString& sError) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700861 return getPropertyInternal(cc, vp, "Creator", sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862}
863
Tom Sepezba038bc2015-10-08 12:03:00 -0700864FX_BOOL Document::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 CJS_PropValue& vp,
866 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700867 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700868 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
869 return FALSE;
870 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 if (vp.IsGetting()) {
872 vp << m_bDelay;
873 } else {
dsinclair7cbe68e2016-10-12 11:56:23 -0700874 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) {
tsepez55be02e2016-09-12 11:21:42 -0700875 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -0700877 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 vp >> m_bDelay;
879 if (m_bDelay) {
Tom Sepez56c10192016-03-15 12:34:17 -0700880 m_DelayData.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 } else {
Tom Sepez56c10192016-03-15 12:34:17 -0700882 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess;
883 DelayDataToProcess.swap(m_DelayData);
dsinclair82e17672016-10-11 12:38:01 -0700884 for (const auto& pData : DelayDataToProcess)
885 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
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) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700894 return getPropertyInternal(cc, vp, "Keywords", sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895}
896
Tom Sepezba038bc2015-10-08 12:03:00 -0700897FX_BOOL Document::modDate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898 CJS_PropValue& vp,
899 CFX_WideString& sError) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700900 return getPropertyInternal(cc, vp, "ModDate", sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901}
902
Tom Sepezba038bc2015-10-08 12:03:00 -0700903FX_BOOL Document::producer(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 CJS_PropValue& vp,
905 CFX_WideString& sError) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700906 return getPropertyInternal(cc, vp, "Producer", sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907}
908
Tom Sepezba038bc2015-10-08 12:03:00 -0700909FX_BOOL Document::subject(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 CJS_PropValue& vp,
911 CFX_WideString& sError) {
tonikitooea3ff9e2016-08-02 11:52:28 -0700912 return getPropertyInternal(cc, vp, "Subject", sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913}
914
Tom Sepezba038bc2015-10-08 12:03:00 -0700915FX_BOOL Document::title(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 CJS_PropValue& vp,
917 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -0700918 if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) {
tsepez55be02e2016-09-12 11:21:42 -0700919 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -0700921 }
tonikitooea3ff9e2016-08-02 11:52:28 -0700922 return getPropertyInternal(cc, vp, "Title", sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923}
924
Tom Sepezba038bc2015-10-08 12:03:00 -0700925FX_BOOL Document::numPages(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 CJS_PropValue& vp,
927 CFX_WideString& sError) {
928 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -0700929 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930 return FALSE;
931 }
dsinclair82e17672016-10-11 12:38:01 -0700932 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700933 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
934 return FALSE;
935 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700936 vp << m_pFormFillEnv->GetPageCount();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 return TRUE;
938}
939
Tom Sepezba038bc2015-10-08 12:03:00 -0700940FX_BOOL Document::external(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 CJS_PropValue& vp,
942 CFX_WideString& sError) {
tsepezcd5dc852016-09-08 11:23:24 -0700943 // In Chrome case, should always return true.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700944 if (vp.IsGetting()) {
945 vp << true;
946 }
947 return TRUE;
948}
949
Tom Sepezba038bc2015-10-08 12:03:00 -0700950FX_BOOL Document::filesize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 CJS_PropValue& vp,
952 CFX_WideString& sError) {
953 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -0700954 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 return FALSE;
956 }
957 vp << 0;
958 return TRUE;
959}
960
Tom Sepezba038bc2015-10-08 12:03:00 -0700961FX_BOOL Document::mouseX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962 CJS_PropValue& vp,
963 CFX_WideString& sError) {
964 return TRUE;
965}
966
Tom Sepezba038bc2015-10-08 12:03:00 -0700967FX_BOOL Document::mouseY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 CJS_PropValue& vp,
969 CFX_WideString& sError) {
970 return TRUE;
971}
972
tonikitoo33c4cdb2016-08-08 10:52:51 -0700973FX_BOOL Document::URL(IJS_Context* cc,
974 CJS_PropValue& vp,
975 CFX_WideString& sError) {
976 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -0700977 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tonikitoo33c4cdb2016-08-08 10:52:51 -0700978 return FALSE;
979 }
dsinclair82e17672016-10-11 12:38:01 -0700980 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -0700981 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
982 return FALSE;
983 }
dsinclair7cbe68e2016-10-12 11:56:23 -0700984 vp << m_pFormFillEnv->JS_docGetFilePath();
tonikitoo33c4cdb2016-08-08 10:52:51 -0700985 return TRUE;
986}
987
Tom Sepezba038bc2015-10-08 12:03:00 -0700988FX_BOOL Document::baseURL(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 CJS_PropValue& vp,
990 CFX_WideString& sError) {
991 if (vp.IsGetting()) {
992 vp << m_cwBaseURL;
993 } else {
994 vp >> m_cwBaseURL;
995 }
996 return TRUE;
997}
998
Tom Sepezba038bc2015-10-08 12:03:00 -0700999FX_BOOL Document::calculate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 CJS_PropValue& vp,
1001 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001002 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001003 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1004 return FALSE;
1005 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001006 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 if (vp.IsGetting()) {
tsepez55be02e2016-09-12 11:21:42 -07001008 vp << !!pInterForm->IsCalculateEnabled();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009 } else {
1010 bool bCalculate;
1011 vp >> bCalculate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 pInterForm->EnableCalculate(bCalculate);
1013 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014 return TRUE;
1015}
1016
Tom Sepezba038bc2015-10-08 12:03:00 -07001017FX_BOOL Document::documentFileName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018 CJS_PropValue& vp,
1019 CFX_WideString& sError) {
1020 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -07001021 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022 return FALSE;
1023 }
dsinclair82e17672016-10-11 12:38:01 -07001024 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001025 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1026 return FALSE;
1027 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001028 CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029 int32_t i = wsFilePath.GetLength() - 1;
1030 for (; i >= 0; i--) {
1031 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/')
1032 break;
1033 }
1034 if (i >= 0 && i < wsFilePath.GetLength() - 1) {
1035 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1);
1036 } else {
1037 vp << L"";
1038 }
1039 return TRUE;
1040}
1041
Tom Sepezba038bc2015-10-08 12:03:00 -07001042FX_BOOL Document::path(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001043 CJS_PropValue& vp,
1044 CFX_WideString& sError) {
1045 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -07001046 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047 return FALSE;
1048 }
dsinclair82e17672016-10-11 12:38:01 -07001049 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001050 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1051 return FALSE;
1052 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001053 vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054 return TRUE;
1055}
1056
Tom Sepezba038bc2015-10-08 12:03:00 -07001057FX_BOOL Document::pageWindowRect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001058 CJS_PropValue& vp,
1059 CFX_WideString& sError) {
1060 return TRUE;
1061}
1062
Tom Sepezba038bc2015-10-08 12:03:00 -07001063FX_BOOL Document::layout(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 CJS_PropValue& vp,
1065 CFX_WideString& sError) {
1066 return TRUE;
1067}
1068
Tom Sepezba038bc2015-10-08 12:03:00 -07001069FX_BOOL Document::addLink(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001070 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001071 CJS_Value& vRet,
1072 CFX_WideString& sError) {
1073 return TRUE;
1074}
1075
Tom Sepezba038bc2015-10-08 12:03:00 -07001076FX_BOOL Document::closeDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001077 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001078 CJS_Value& vRet,
1079 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001080 return TRUE;
1081}
1082
Tom Sepezba038bc2015-10-08 12:03:00 -07001083FX_BOOL Document::getPageBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001084 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001085 CJS_Value& vRet,
1086 CFX_WideString& sError) {
1087 return TRUE;
1088}
1089
Tom Sepezba038bc2015-10-08 12:03:00 -07001090FX_BOOL Document::getAnnot(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001091 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092 CJS_Value& vRet,
1093 CFX_WideString& sError) {
tonikitoo618cb1f2016-08-18 20:10:17 -07001094 if (params.size() != 2) {
tsepezcd5dc852016-09-08 11:23:24 -07001095 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tonikitoo618cb1f2016-08-18 20:10:17 -07001096 return FALSE;
1097 }
dsinclair82e17672016-10-11 12:38:01 -07001098 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001099 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1100 return FALSE;
1101 }
tsepezcd5dc852016-09-08 11:23:24 -07001102 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tonikitoo618cb1f2016-08-18 20:10:17 -07001103 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1104 int nPageNo = params[0].ToInt(pRuntime);
1105 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
dsinclair7cbe68e2016-10-12 11:56:23 -07001106 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo);
tonikitoo618cb1f2016-08-18 20:10:17 -07001107 if (!pPageView)
1108 return FALSE;
1109
1110 CPDFSDK_AnnotIterator annotIterator(pPageView, false);
1111 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
1112 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
1113 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
1114 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
1115 pSDKBAAnnot = pBAAnnot;
1116 break;
1117 }
1118 }
1119
1120 if (!pSDKBAAnnot)
1121 return FALSE;
1122
1123 v8::Local<v8::Object> pObj =
1124 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
1125 if (pObj.IsEmpty())
1126 return FALSE;
1127
1128 CJS_Annot* pJS_Annot =
1129 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
1130 if (!pJS_Annot)
1131 return FALSE;
1132
1133 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
1134 if (!pAnnot)
1135 return FALSE;
1136
1137 pAnnot->SetSDKAnnot(pSDKBAAnnot);
1138
1139 vRet = CJS_Value(pRuntime, pJS_Annot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 return TRUE;
1141}
1142
Tom Sepezba038bc2015-10-08 12:03:00 -07001143FX_BOOL Document::getAnnots(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001144 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001145 CJS_Value& vRet,
1146 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001147 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001148 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1149 return FALSE;
1150 }
tonikitoo0ee35902016-08-26 14:41:29 -07001151 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepez55be02e2016-09-12 11:21:42 -07001152 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tonikitoo0ee35902016-08-26 14:41:29 -07001153
1154 // TODO(tonikitoo): Add support supported parameters as per
1155 // the PDF spec.
1156
dsinclair7cbe68e2016-10-12 11:56:23 -07001157 int nPageNo = m_pFormFillEnv->GetPageCount();
tonikitoo0ee35902016-08-26 14:41:29 -07001158 CJS_Array annots;
1159
1160 for (int i = 0; i < nPageNo; ++i) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001161 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i);
tonikitoo0ee35902016-08-26 14:41:29 -07001162 if (!pPageView)
1163 return FALSE;
1164
1165 CPDFSDK_AnnotIterator annotIterator(pPageView, false);
1166 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
1167 CPDFSDK_BAAnnot* pSDKBAAnnot =
1168 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
1169 if (!pSDKBAAnnot)
1170 return FALSE;
1171
1172 v8::Local<v8::Object> pObj =
1173 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
1174 if (pObj.IsEmpty())
1175 return FALSE;
1176
1177 CJS_Annot* pJS_Annot =
1178 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
1179 if (!pJS_Annot)
1180 return FALSE;
1181
1182 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
1183 if (!pAnnot)
1184 return FALSE;
1185
1186 pAnnot->SetSDKAnnot(pSDKBAAnnot);
1187 annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot));
1188 }
1189 }
1190
1191 vRet = CJS_Value(pRuntime, annots);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192 return TRUE;
1193}
1194
Tom Sepezba038bc2015-10-08 12:03:00 -07001195FX_BOOL Document::getAnnot3D(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001196 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001197 CJS_Value& vRet,
1198 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07001199 vRet.SetNull(CJS_Runtime::FromContext(cc));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001200 return TRUE;
1201}
1202
Tom Sepezba038bc2015-10-08 12:03:00 -07001203FX_BOOL Document::getAnnots3D(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001204 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001205 CJS_Value& vRet,
1206 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001207 return TRUE;
1208}
1209
Tom Sepezba038bc2015-10-08 12:03:00 -07001210FX_BOOL Document::getOCGs(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001211 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212 CJS_Value& vRet,
1213 CFX_WideString& sError) {
1214 return TRUE;
1215}
1216
Tom Sepezba038bc2015-10-08 12:03:00 -07001217FX_BOOL Document::getLinks(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001218 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001219 CJS_Value& vRet,
1220 CFX_WideString& sError) {
1221 return TRUE;
1222}
1223
1224bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) {
1225 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top &&
1226 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
1227}
1228
Tom Sepezba038bc2015-10-08 12:03:00 -07001229FX_BOOL Document::addIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001230 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001231 CJS_Value& vRet,
1232 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001233 if (params.size() != 2) {
tsepezcd5dc852016-09-08 11:23:24 -07001234 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001235 return FALSE;
1236 }
tsepezf3dc8c62016-08-10 06:29:29 -07001237
tsepezcd5dc852016-09-08 11:23:24 -07001238 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
tsepezf3dc8c62016-08-10 06:29:29 -07001239 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -07001240 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
Tom Sepezaecd9d02015-08-31 15:04:12 -07001241
Tom Sepez39bfe122015-09-17 15:25:23 -07001242 if (params[1].GetType() != CJS_Value::VT_object) {
tsepezcd5dc852016-09-08 11:23:24 -07001243 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
Tom Sepezaecd9d02015-08-31 15:04:12 -07001244 return FALSE;
1245 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001246
tsepezb4694242016-08-15 16:44:55 -07001247 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime);
1248 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
tsepezcd5dc852016-09-08 11:23:24 -07001249 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001250 return FALSE;
1251 }
1252
tsepezb4694242016-08-15 16:44:55 -07001253 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001254 if (!pEmbedObj) {
tsepezcd5dc852016-09-08 11:23:24 -07001255 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001256 return FALSE;
1257 }
1258
Tom Sepez6ba32d92016-01-05 16:26:32 -08001259 m_IconList.push_back(std::unique_ptr<IconElement>(
1260 new IconElement(swIconName, (Icon*)pEmbedObj)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001261 return TRUE;
1262}
1263
Tom Sepezba038bc2015-10-08 12:03:00 -07001264FX_BOOL Document::icons(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001265 CJS_PropValue& vp,
1266 CFX_WideString& sError) {
1267 if (vp.IsSetting()) {
tsepezcd5dc852016-09-08 11:23:24 -07001268 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001269 return FALSE;
1270 }
1271
tsepezf3dc8c62016-08-10 06:29:29 -07001272 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepez6ba32d92016-01-05 16:26:32 -08001273 if (m_IconList.empty()) {
tsepezf3dc8c62016-08-10 06:29:29 -07001274 vp.GetJSValue()->SetNull(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001275 return TRUE;
1276 }
1277
tsepeze5aff742016-08-08 09:49:42 -07001278 CJS_Array Icons;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001279
Tom Sepez6ba32d92016-01-05 16:26:32 -08001280 int i = 0;
1281 for (const auto& pIconElement : m_IconList) {
tsepezb4694242016-08-15 16:44:55 -07001282 v8::Local<v8::Object> pObj =
1283 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001284 if (pObj.IsEmpty())
1285 return FALSE;
1286
tsepezb4694242016-08-15 16:44:55 -07001287 CJS_Icon* pJS_Icon =
1288 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001289 if (!pJS_Icon)
1290 return FALSE;
1291
1292 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1293 if (!pIcon)
1294 return FALSE;
1295
1296 pIcon->SetStream(pIconElement->IconStream->GetStream());
1297 pIcon->SetIconName(pIconElement->IconName);
tsepezb4694242016-08-15 16:44:55 -07001298 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001299 }
1300
1301 vp << Icons;
1302 return TRUE;
1303}
1304
Tom Sepezba038bc2015-10-08 12:03:00 -07001305FX_BOOL Document::getIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001306 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001307 CJS_Value& vRet,
1308 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001309 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -07001310 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001311 return FALSE;
1312 }
1313
Tom Sepez6ba32d92016-01-05 16:26:32 -08001314 if (m_IconList.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001315 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316
tsepezcd5dc852016-09-08 11:23:24 -07001317 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -07001318 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001319
Tom Sepez6ba32d92016-01-05 16:26:32 -08001320 for (const auto& pIconElement : m_IconList) {
1321 if (pIconElement->IconName == swIconName) {
1322 Icon* pRetIcon = pIconElement->IconStream;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001323
tsepezb4694242016-08-15 16:44:55 -07001324 v8::Local<v8::Object> pObj =
1325 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001326 if (pObj.IsEmpty())
1327 return FALSE;
1328
tsepezb4694242016-08-15 16:44:55 -07001329 CJS_Icon* pJS_Icon =
1330 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001331 if (!pJS_Icon)
1332 return FALSE;
1333
1334 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1335 if (!pIcon)
1336 return FALSE;
1337
1338 pIcon->SetIconName(swIconName);
1339 pIcon->SetStream(pRetIcon->GetStream());
tsepezf3dc8c62016-08-10 06:29:29 -07001340 vRet = CJS_Value(pRuntime, pJS_Icon);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001341 return TRUE;
1342 }
1343 }
1344
1345 return FALSE;
1346}
1347
Tom Sepezba038bc2015-10-08 12:03:00 -07001348FX_BOOL Document::removeIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001349 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001350 CJS_Value& vRet,
1351 CFX_WideString& sError) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001352 // Unsafe, no supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001353 return TRUE;
1354}
1355
Tom Sepezba038bc2015-10-08 12:03:00 -07001356FX_BOOL Document::createDataObject(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001357 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358 CJS_Value& vRet,
1359 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -08001360 // Unsafe, not implemented.
1361 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001362}
1363
Tom Sepezba038bc2015-10-08 12:03:00 -07001364FX_BOOL Document::media(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365 CJS_PropValue& vp,
1366 CFX_WideString& sError) {
1367 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001368}
1369
Tom Sepezba038bc2015-10-08 12:03:00 -07001370FX_BOOL Document::calculateNow(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001371 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001372 CJS_Value& vRet,
1373 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001374 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001375 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1376 return FALSE;
1377 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001378 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) ||
1379 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
1380 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) {
tsepez55be02e2016-09-12 11:21:42 -07001381 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001382 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -07001383 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001384 m_pFormFillEnv->GetInterForm()->OnCalculate();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001385 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001386}
1387
Tom Sepezba038bc2015-10-08 12:03:00 -07001388FX_BOOL Document::Collab(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001389 CJS_PropValue& vp,
1390 CFX_WideString& sError) {
1391 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001392}
1393
Tom Sepezba038bc2015-10-08 12:03:00 -07001394FX_BOOL Document::getPageNthWord(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001395 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001396 CJS_Value& vRet,
1397 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001398 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001399 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1400 return FALSE;
1401 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001402 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
tsepezcd5dc852016-09-08 11:23:24 -07001403 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001404 return FALSE;
tsepezcd5dc852016-09-08 11:23:24 -07001405 }
1406 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepez55be02e2016-09-12 11:21:42 -07001407
1408 // TODO(tsepez): check maximum allowable params.
1409
tsepezb4694242016-08-15 16:44:55 -07001410 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
1411 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0;
1412 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001413
dsinclair7cbe68e2016-10-12 11:56:23 -07001414 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001415 if (!pDocument)
1416 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001417
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
tsepezcd5dc852016-09-08 11:23:24 -07001419 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001420 return FALSE;
1421 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001422
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001423 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1424 if (!pPageDict)
1425 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001426
thestig5cc24652016-04-26 11:46:02 -07001427 CPDF_Page page(pDocument, pPageDict, true);
1428 page.ParseContent();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001429
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001430 int nWords = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001431 CFX_WideString swRet;
Tom Sepez2398d892016-02-17 16:46:26 -08001432 for (auto& pPageObj : *page.GetPageObjectList()) {
Wei Li7cf13c92016-02-19 11:53:03 -08001433 if (pPageObj->IsText()) {
1434 CPDF_TextObject* pTextObj = pPageObj->AsText();
Tom Sepez2398d892016-02-17 16:46:26 -08001435 int nObjWords = CountWords(pTextObj);
1436 if (nWords + nObjWords >= nWordNo) {
1437 swRet = GetObjWordStr(pTextObj, nWordNo - nWords);
1438 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439 }
Tom Sepez2398d892016-02-17 16:46:26 -08001440 nWords += nObjWords;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001441 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001442 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001443
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444 if (bStrip) {
1445 swRet.TrimLeft();
1446 swRet.TrimRight();
1447 }
1448
tsepezf3dc8c62016-08-10 06:29:29 -07001449 vRet = CJS_Value(pRuntime, swRet.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001450 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001451}
1452
Tom Sepezba038bc2015-10-08 12:03:00 -07001453FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001454 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001455 CJS_Value& vRet,
1456 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001457 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001458 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001459 return FALSE;
tsepez55be02e2016-09-12 11:21:42 -07001460 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001461 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
tsepez55be02e2016-09-12 11:21:42 -07001462 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1463 return FALSE;
1464 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001465 return FALSE;
1466}
1467
Tom Sepezba038bc2015-10-08 12:03:00 -07001468FX_BOOL Document::getPageNumWords(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001469 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001470 CJS_Value& vRet,
1471 CFX_WideString& sError) {
dsinclair82e17672016-10-11 12:38:01 -07001472 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001473 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1474 return FALSE;
1475 }
dsinclair7cbe68e2016-10-12 11:56:23 -07001476 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
tsepezcd5dc852016-09-08 11:23:24 -07001477 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001478 return FALSE;
tsepezcd5dc852016-09-08 11:23:24 -07001479 }
1480 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -07001481 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
dsinclair7cbe68e2016-10-12 11:56:23 -07001482 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001483 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
tsepezcd5dc852016-09-08 11:23:24 -07001484 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001485 return FALSE;
1486 }
1487
1488 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1489 if (!pPageDict)
1490 return FALSE;
1491
thestig5cc24652016-04-26 11:46:02 -07001492 CPDF_Page page(pDocument, pPageDict, true);
1493 page.ParseContent();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001494
1495 int nWords = 0;
Tom Sepez2398d892016-02-17 16:46:26 -08001496 for (auto& pPageObj : *page.GetPageObjectList()) {
Wei Li7cf13c92016-02-19 11:53:03 -08001497 if (pPageObj->IsText())
1498 nWords += CountWords(pPageObj->AsText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001499 }
1500
tsepezf3dc8c62016-08-10 06:29:29 -07001501 vRet = CJS_Value(pRuntime, nWords);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 return TRUE;
1503}
1504
Tom Sepezba038bc2015-10-08 12:03:00 -07001505FX_BOOL Document::getPrintParams(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001506 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001507 CJS_Value& vRet,
1508 CFX_WideString& sError) {
1509 CJS_Context* pContext = (CJS_Context*)cc;
1510 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -07001511 v8::Local<v8::Object> pRetObj =
1512 pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001513
1514 // Not implemented yet.
1515
tsepezf3dc8c62016-08-10 06:29:29 -07001516 vRet = CJS_Value(pRuntime, pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001517 return TRUE;
1518}
1519
1520#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
1521
1522int Document::CountWords(CPDF_TextObject* pTextObj) {
1523 if (!pTextObj)
1524 return 0;
1525
1526 int nWords = 0;
1527
1528 CPDF_Font* pFont = pTextObj->GetFont();
1529 if (!pFont)
1530 return 0;
1531
1532 FX_BOOL bIsLatin = FALSE;
1533
1534 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
Wei Li89409932016-03-28 10:33:33 -07001535 uint32_t charcode = CPDF_Font::kInvalidCharCode;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001536 FX_FLOAT kerning;
1537
1538 pTextObj->GetCharInfo(i, charcode, kerning);
1539 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
1540
Tom Sepez62a70f92016-03-21 15:00:20 -07001541 uint16_t unicode = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001542 if (swUnicode.GetLength() > 0)
1543 unicode = swUnicode[0];
1544
1545 if (ISLATINWORD(unicode) && bIsLatin)
1546 continue;
1547
1548 bIsLatin = ISLATINWORD(unicode);
1549 if (unicode != 0x20)
1550 nWords++;
1551 }
1552
1553 return nWords;
1554}
1555
1556CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj,
1557 int nWordIndex) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001558 CFX_WideString swRet;
1559
1560 CPDF_Font* pFont = pTextObj->GetFont();
1561 if (!pFont)
1562 return L"";
1563
1564 int nWords = 0;
1565 FX_BOOL bIsLatin = FALSE;
1566
1567 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
Wei Li89409932016-03-28 10:33:33 -07001568 uint32_t charcode = CPDF_Font::kInvalidCharCode;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001569 FX_FLOAT kerning;
1570
1571 pTextObj->GetCharInfo(i, charcode, kerning);
1572 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
1573
Tom Sepez62a70f92016-03-21 15:00:20 -07001574 uint16_t unicode = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001575 if (swUnicode.GetLength() > 0)
1576 unicode = swUnicode[0];
1577
1578 if (ISLATINWORD(unicode) && bIsLatin) {
1579 } else {
1580 bIsLatin = ISLATINWORD(unicode);
1581 if (unicode != 0x20)
1582 nWords++;
1583 }
1584
1585 if (nWords - 1 == nWordIndex)
1586 swRet += unicode;
1587 }
1588
1589 return swRet;
1590}
1591
Tom Sepezba038bc2015-10-08 12:03:00 -07001592FX_BOOL Document::zoom(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001593 CJS_PropValue& vp,
1594 CFX_WideString& sError) {
1595 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001596}
1597
1598/**
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001599(none, NoVary)
1600(fitP, FitPage)
1601(fitW, FitWidth)
1602(fitH, FitHeight)
1603(fitV, FitVisibleWidth)
1604(pref, Preferred)
1605(refW, ReflowWidth)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001606*/
1607
Tom Sepezba038bc2015-10-08 12:03:00 -07001608FX_BOOL Document::zoomType(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001609 CJS_PropValue& vp,
1610 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -08001611 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001612}
1613
Tom Sepezba038bc2015-10-08 12:03:00 -07001614FX_BOOL Document::deletePages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001615 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001616 CJS_Value& vRet,
1617 CFX_WideString& sError) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -07001618 // Unsafe, no supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001619 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001620}
JUN FANG33f6f0d2015-04-06 12:39:51 -07001621
Tom Sepezba038bc2015-10-08 12:03:00 -07001622FX_BOOL Document::extractPages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001623 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001624 CJS_Value& vRet,
1625 CFX_WideString& sError) {
1626 // Unsafe, not supported.
1627 return TRUE;
1628}
1629
Tom Sepezba038bc2015-10-08 12:03:00 -07001630FX_BOOL Document::insertPages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001631 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001632 CJS_Value& vRet,
1633 CFX_WideString& sError) {
1634 // Unsafe, not supported.
1635 return TRUE;
1636}
1637
Tom Sepezba038bc2015-10-08 12:03:00 -07001638FX_BOOL Document::replacePages(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001639 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001640 CJS_Value& vRet,
1641 CFX_WideString& sError) {
1642 // Unsafe, not supported.
1643 return TRUE;
1644}
1645
Tom Sepezba038bc2015-10-08 12:03:00 -07001646FX_BOOL Document::getURL(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08001647 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001648 CJS_Value& vRet,
1649 CFX_WideString& sError) {
1650 // Unsafe, not supported.
1651 return TRUE;
1652}
1653
tonikitoo1c836752016-08-08 16:14:05 -07001654FX_BOOL Document::gotoNamedDest(IJS_Context* cc,
1655 const std::vector<CJS_Value>& params,
1656 CJS_Value& vRet,
1657 CFX_WideString& sError) {
tonikitoo1c836752016-08-08 16:14:05 -07001658 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -07001659 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tonikitoo1c836752016-08-08 16:14:05 -07001660 return FALSE;
1661 }
dsinclair82e17672016-10-11 12:38:01 -07001662 if (!m_pFormFillEnv) {
tsepez55be02e2016-09-12 11:21:42 -07001663 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1664 return FALSE;
1665 }
tsepezcd5dc852016-09-08 11:23:24 -07001666 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -07001667 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
tsepezf3dc8c62016-08-10 06:29:29 -07001668 CFX_ByteString utf8Name = wideName.UTF8Encode();
dsinclair7cbe68e2016-10-12 11:56:23 -07001669 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
tonikitoo1c836752016-08-08 16:14:05 -07001670 if (!pDocument)
1671 return FALSE;
1672
tonikitoo1c836752016-08-08 16:14:05 -07001673 CPDF_NameTree nameTree(pDocument, "Dests");
1674 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name);
1675 if (!destArray)
1676 return FALSE;
1677
1678 CPDF_Dest dest(destArray);
1679 const CPDF_Array* arrayObject = ToArray(dest.GetObject());
1680
1681 std::unique_ptr<float[]> scrollPositionArray;
1682 int scrollPositionArraySize = 0;
1683
1684 if (arrayObject) {
1685 scrollPositionArray.reset(new float[arrayObject->GetCount()]);
1686 int j = 0;
1687 for (size_t i = 2; i < arrayObject->GetCount(); i++)
1688 scrollPositionArray[j++] = arrayObject->GetFloatAt(i);
1689 scrollPositionArraySize = j;
1690 }
1691
tsepezb4694242016-08-15 16:44:55 -07001692 pRuntime->BeginBlock();
dsinclair82e17672016-10-11 12:38:01 -07001693 m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(),
1694 scrollPositionArray.get(),
1695 scrollPositionArraySize);
tsepezb4694242016-08-15 16:44:55 -07001696 pRuntime->EndBlock();
tonikitoo1c836752016-08-08 16:14:05 -07001697
1698 return TRUE;
1699}
1700
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001701void Document::AddDelayData(CJS_DelayData* pData) {
Tom Sepez56c10192016-03-15 12:34:17 -07001702 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001703}
1704
1705void Document::DoFieldDelay(const CFX_WideString& sFieldName,
1706 int nControlIndex) {
Tom Sepez56c10192016-03-15 12:34:17 -07001707 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex;
1708 auto iter = m_DelayData.begin();
1709 while (iter != m_DelayData.end()) {
1710 auto old = iter++;
1711 if ((*old)->sFieldName == sFieldName &&
1712 (*old)->nControlIndex == nControlIndex) {
1713 DelayDataForFieldAndControlIndex.push_back(std::move(*old));
1714 m_DelayData.erase(old);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001715 }
1716 }
1717
dsinclair82e17672016-10-11 12:38:01 -07001718 for (const auto& pData : DelayDataForFieldAndControlIndex)
1719 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720}
1721
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001722CJS_Document* Document::GetCJSDoc() const {
1723 return static_cast<CJS_Document*>(m_pJSObject);
JUN FANG33f6f0d2015-04-06 12:39:51 -07001724}