John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/javascript/Document.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 9 | #include <utility> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
dsinclair | bc5e6d2 | 2016-10-04 11:08:49 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/font/cpdf_font.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 15 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_interform.h" |
| 19 | #include "core/fpdfdoc/cpdf_nametree.h" |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 20 | #include "fpdfsdk/cpdfsdk_annotiteration.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 22 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 23 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 24 | #include "fpdfsdk/cpdfsdk_widget.h" |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/javascript/Annot.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 26 | #include "fpdfsdk/javascript/Field.h" |
| 27 | #include "fpdfsdk/javascript/Icon.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 28 | #include "fpdfsdk/javascript/JS_Define.h" |
| 29 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 30 | #include "fpdfsdk/javascript/JS_Object.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 31 | #include "fpdfsdk/javascript/JS_Value.h" |
| 32 | #include "fpdfsdk/javascript/app.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/javascript/cjs_context.h" |
| 34 | #include "fpdfsdk/javascript/cjs_runtime.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 35 | #include "fpdfsdk/javascript/resource.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 36 | #include "third_party/base/numerics/safe_math.h" |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 37 | #include "third_party/base/ptr_util.h" |
Chris Palmer | 9108ad2 | 2014-06-26 16:01:46 -0700 | [diff] [blame] | 38 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) |
| 40 | END_JS_STATIC_CONST() |
| 41 | |
| 42 | BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
| 43 | END_JS_STATIC_PROP() |
| 44 | |
| 45 | BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
| 46 | END_JS_STATIC_METHOD() |
| 47 | |
| 48 | IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) |
| 49 | |
| 50 | PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | : CJS_EmbedObj(pJSObject) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 52 | bUI = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | nStart = 0; |
| 54 | nEnd = 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 55 | bSilent = false; |
| 56 | bShrinkToFit = false; |
| 57 | bPrintAsImage = false; |
| 58 | bReverse = false; |
| 59 | bAnnotations = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | #define MINWIDTH 5.0f |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | #define MINHEIGHT 5.0f |
| 64 | |
| 65 | BEGIN_JS_STATIC_CONST(CJS_Document) |
| 66 | END_JS_STATIC_CONST() |
| 67 | |
| 68 | BEGIN_JS_STATIC_PROP(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | JS_STATIC_PROP_ENTRY(ADBE) |
| 70 | JS_STATIC_PROP_ENTRY(author) |
| 71 | JS_STATIC_PROP_ENTRY(baseURL) |
| 72 | JS_STATIC_PROP_ENTRY(bookmarkRoot) |
| 73 | JS_STATIC_PROP_ENTRY(calculate) |
| 74 | JS_STATIC_PROP_ENTRY(Collab) |
| 75 | JS_STATIC_PROP_ENTRY(creationDate) |
| 76 | JS_STATIC_PROP_ENTRY(creator) |
| 77 | JS_STATIC_PROP_ENTRY(delay) |
| 78 | JS_STATIC_PROP_ENTRY(dirty) |
| 79 | JS_STATIC_PROP_ENTRY(documentFileName) |
| 80 | JS_STATIC_PROP_ENTRY(external) |
| 81 | JS_STATIC_PROP_ENTRY(filesize) |
| 82 | JS_STATIC_PROP_ENTRY(icons) |
| 83 | JS_STATIC_PROP_ENTRY(info) |
| 84 | JS_STATIC_PROP_ENTRY(keywords) |
| 85 | JS_STATIC_PROP_ENTRY(layout) |
| 86 | JS_STATIC_PROP_ENTRY(media) |
| 87 | JS_STATIC_PROP_ENTRY(modDate) |
| 88 | JS_STATIC_PROP_ENTRY(mouseX) |
| 89 | JS_STATIC_PROP_ENTRY(mouseY) |
| 90 | JS_STATIC_PROP_ENTRY(numFields) |
| 91 | JS_STATIC_PROP_ENTRY(numPages) |
| 92 | JS_STATIC_PROP_ENTRY(pageNum) |
| 93 | JS_STATIC_PROP_ENTRY(pageWindowRect) |
| 94 | JS_STATIC_PROP_ENTRY(path) |
| 95 | JS_STATIC_PROP_ENTRY(producer) |
| 96 | JS_STATIC_PROP_ENTRY(subject) |
| 97 | JS_STATIC_PROP_ENTRY(title) |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 98 | JS_STATIC_PROP_ENTRY(URL) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | JS_STATIC_PROP_ENTRY(zoom) |
| 100 | JS_STATIC_PROP_ENTRY(zoomType) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | END_JS_STATIC_PROP() |
| 102 | |
| 103 | BEGIN_JS_STATIC_METHOD(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | JS_STATIC_METHOD_ENTRY(addAnnot) |
| 105 | JS_STATIC_METHOD_ENTRY(addField) |
| 106 | JS_STATIC_METHOD_ENTRY(addLink) |
| 107 | JS_STATIC_METHOD_ENTRY(addIcon) |
| 108 | JS_STATIC_METHOD_ENTRY(calculateNow) |
| 109 | JS_STATIC_METHOD_ENTRY(closeDoc) |
| 110 | JS_STATIC_METHOD_ENTRY(createDataObject) |
| 111 | JS_STATIC_METHOD_ENTRY(deletePages) |
| 112 | JS_STATIC_METHOD_ENTRY(exportAsText) |
| 113 | JS_STATIC_METHOD_ENTRY(exportAsFDF) |
| 114 | JS_STATIC_METHOD_ENTRY(exportAsXFDF) |
| 115 | JS_STATIC_METHOD_ENTRY(extractPages) |
| 116 | JS_STATIC_METHOD_ENTRY(getAnnot) |
| 117 | JS_STATIC_METHOD_ENTRY(getAnnots) |
| 118 | JS_STATIC_METHOD_ENTRY(getAnnot3D) |
| 119 | JS_STATIC_METHOD_ENTRY(getAnnots3D) |
| 120 | JS_STATIC_METHOD_ENTRY(getField) |
| 121 | JS_STATIC_METHOD_ENTRY(getIcon) |
| 122 | JS_STATIC_METHOD_ENTRY(getLinks) |
| 123 | JS_STATIC_METHOD_ENTRY(getNthFieldName) |
| 124 | JS_STATIC_METHOD_ENTRY(getOCGs) |
| 125 | JS_STATIC_METHOD_ENTRY(getPageBox) |
| 126 | JS_STATIC_METHOD_ENTRY(getPageNthWord) |
| 127 | JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) |
| 128 | JS_STATIC_METHOD_ENTRY(getPageNumWords) |
| 129 | JS_STATIC_METHOD_ENTRY(getPrintParams) |
| 130 | JS_STATIC_METHOD_ENTRY(getURL) |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 131 | JS_STATIC_METHOD_ENTRY(gotoNamedDest) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | JS_STATIC_METHOD_ENTRY(importAnFDF) |
| 133 | JS_STATIC_METHOD_ENTRY(importAnXFDF) |
| 134 | JS_STATIC_METHOD_ENTRY(importTextData) |
| 135 | JS_STATIC_METHOD_ENTRY(insertPages) |
| 136 | JS_STATIC_METHOD_ENTRY(mailForm) |
| 137 | JS_STATIC_METHOD_ENTRY(print) |
| 138 | JS_STATIC_METHOD_ENTRY(removeField) |
| 139 | JS_STATIC_METHOD_ENTRY(replacePages) |
| 140 | JS_STATIC_METHOD_ENTRY(resetForm) |
| 141 | JS_STATIC_METHOD_ENTRY(removeIcon) |
| 142 | JS_STATIC_METHOD_ENTRY(saveAs) |
| 143 | JS_STATIC_METHOD_ENTRY(submitForm) |
tonikitoo | bb5fa04 | 2016-08-19 11:18:29 -0700 | [diff] [blame] | 144 | JS_STATIC_METHOD_ENTRY(syncAnnotScan) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | JS_STATIC_METHOD_ENTRY(mailDoc) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 146 | END_JS_STATIC_METHOD() |
| 147 | |
| 148 | IMPLEMENT_JS_CLASS(CJS_Document, Document) |
| 149 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 150 | void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| 151 | CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 152 | Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 153 | pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv()); |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 154 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 155 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | Document::Document(CJS_Object* pJSObject) |
| 157 | : CJS_EmbedObj(pJSObject), |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 158 | m_pFormFillEnv(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | m_cwBaseURL(L""), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 160 | m_bDelay(false) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | Document::~Document() { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | // the total number of fileds in document. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 166 | bool Document::numFields(IJS_Context* cc, |
| 167 | CJS_PropValue& vp, |
| 168 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 170 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 173 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 174 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 175 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 176 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 177 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 179 | vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 180 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | } |
| 182 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 183 | bool Document::dirty(IJS_Context* cc, |
| 184 | CJS_PropValue& vp, |
| 185 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 186 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 187 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 188 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 189 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | if (vp.IsGetting()) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 191 | vp << !!m_pFormFillEnv->GetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | } else { |
| 193 | bool bChanged = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | vp >> bChanged; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 195 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | if (bChanged) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 197 | m_pFormFillEnv->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 198 | else |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 199 | m_pFormFillEnv->ClearChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 201 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | bool Document::ADBE(IJS_Context* cc, |
| 205 | CJS_PropValue& vp, |
| 206 | CFX_WideString& sError) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 207 | if (vp.IsGetting()) |
| 208 | vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 210 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | } |
| 212 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 213 | bool Document::pageNum(IJS_Context* cc, |
| 214 | CJS_PropValue& vp, |
| 215 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 216 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 217 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 218 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 219 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | if (vp.IsGetting()) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 221 | if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | vp << pPageView->GetPageIndex(); |
| 223 | } |
| 224 | } else { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 225 | int iPageCount = m_pFormFillEnv->GetPageCount(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | int iPageNum = 0; |
| 227 | vp >> iPageNum; |
| 228 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | if (iPageNum >= 0 && iPageNum < iPageCount) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 230 | m_pFormFillEnv->JS_docgotoPage(iPageNum); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | } else if (iPageNum >= iPageCount) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 232 | m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | } else if (iPageNum < 0) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 234 | m_pFormFillEnv->JS_docgotoPage(0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 238 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | } |
| 240 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 241 | bool Document::addAnnot(IJS_Context* cc, |
| 242 | const std::vector<CJS_Value>& params, |
| 243 | CJS_Value& vRet, |
| 244 | CFX_WideString& sError) { |
| 245 | // Not supported. |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | bool Document::addField(IJS_Context* cc, |
| 250 | const std::vector<CJS_Value>& params, |
| 251 | CJS_Value& vRet, |
| 252 | CFX_WideString& sError) { |
| 253 | // Not supported. |
| 254 | return true; |
| 255 | } |
| 256 | |
| 257 | bool Document::exportAsText(IJS_Context* cc, |
| 258 | const std::vector<CJS_Value>& params, |
| 259 | CJS_Value& vRet, |
| 260 | CFX_WideString& sError) { |
| 261 | // Unsafe, not supported. |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | bool Document::exportAsFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 266 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | CJS_Value& vRet, |
| 268 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 269 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 270 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | } |
| 272 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 273 | bool Document::exportAsXFDF(IJS_Context* cc, |
| 274 | const std::vector<CJS_Value>& params, |
| 275 | CJS_Value& vRet, |
| 276 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 278 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 280 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | // Maps a field object in PDF document to a JavaScript variable |
| 282 | // comment: |
| 283 | // note: the paremter cName, this is clue how to treat if the cName is not a |
| 284 | // valiable filed name in this document |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 285 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 286 | bool Document::getField(IJS_Context* cc, |
| 287 | const std::vector<CJS_Value>& params, |
| 288 | CJS_Value& vRet, |
| 289 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | if (params.size() < 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 291 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 292 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 294 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 295 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 297 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 298 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 299 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 300 | CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 301 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 303 | if (pPDFForm->CountFields(wideName) <= 0) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 304 | vRet.SetNull(pRuntime); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 305 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | } |
| 307 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 308 | v8::Local<v8::Object> pFieldObj = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 309 | pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 310 | CJS_Field* pJSField = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 311 | static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 312 | Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | pField->AttachField(this, wideName); |
| 314 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 315 | vRet = CJS_Value(pRuntime, pJSField); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 316 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Gets the name of the nth field in the document |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 320 | bool Document::getNthFieldName(IJS_Context* cc, |
| 321 | const std::vector<CJS_Value>& params, |
| 322 | CJS_Value& vRet, |
| 323 | CFX_WideString& sError) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 324 | if (params.size() != 1) { |
| 325 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 326 | return false; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 327 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 328 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 329 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 330 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 331 | } |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 332 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 333 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 334 | int nIndex = params[0].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | if (nIndex < 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 336 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 337 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 339 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 341 | CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 342 | if (!pField) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 343 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 345 | vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 346 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | } |
| 348 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 349 | bool Document::importAnFDF(IJS_Context* cc, |
| 350 | const std::vector<CJS_Value>& params, |
| 351 | CJS_Value& vRet, |
| 352 | CFX_WideString& sError) { |
| 353 | // Unsafe, not supported. |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | bool Document::importAnXFDF(IJS_Context* cc, |
| 358 | const std::vector<CJS_Value>& params, |
| 359 | CJS_Value& vRet, |
| 360 | CFX_WideString& sError) { |
| 361 | // Unsafe, not supported. |
| 362 | return true; |
| 363 | } |
| 364 | |
| 365 | bool Document::importTextData(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 366 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | CJS_Value& vRet, |
| 368 | CFX_WideString& sError) { |
| 369 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 370 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // exports the form data and mails the resulting fdf file as an attachment to |
| 374 | // all recipients. |
| 375 | // comment: need reader supports |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 376 | bool Document::mailForm(IJS_Context* cc, |
| 377 | const std::vector<CJS_Value>& params, |
| 378 | CJS_Value& vRet, |
| 379 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 380 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 381 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 382 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 383 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 384 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 385 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 386 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 387 | } |
| 388 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 389 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 390 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 391 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | int iLength = params.size(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 393 | bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 394 | CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 395 | CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 396 | CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 397 | CFX_WideString cSubject = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 398 | iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 399 | CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 401 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | CFX_ByteTextBuf textBuf; |
| 403 | if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 404 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 406 | pRuntime->BeginBlock(); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 407 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv(); |
| 408 | pFormFillEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 409 | cTo.c_str(), cSubject.c_str(), cCc.c_str(), |
| 410 | cBcc.c_str(), cMsg.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | pRuntime->EndBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 412 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | } |
| 414 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 415 | bool Document::print(IJS_Context* cc, |
| 416 | const std::vector<CJS_Value>& params, |
| 417 | CJS_Value& vRet, |
| 418 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 419 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 420 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 421 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 422 | } |
| 423 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 424 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 425 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 426 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 427 | bool bUI = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | int nStart = 0; |
| 429 | int nEnd = 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 430 | bool bSilent = false; |
| 431 | bool bShrinkToFit = false; |
| 432 | bool bPrintAsImage = false; |
| 433 | bool bReverse = false; |
| 434 | bool bAnnotations = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 435 | |
| 436 | int nlength = params.size(); |
| 437 | if (nlength == 9) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 438 | if (params[8].GetType() == CJS_Value::VT_object) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 439 | v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); |
| 440 | if (CFXJS_Engine::GetObjDefnID(pObj) == |
| 441 | CJS_PrintParamsObj::g_nObjDefnID) { |
| 442 | if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 443 | if (PrintParamsObj* pprintparamsObj = |
| 444 | static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { |
| 445 | bUI = pprintparamsObj->bUI; |
| 446 | nStart = pprintparamsObj->nStart; |
| 447 | nEnd = pprintparamsObj->nEnd; |
| 448 | bSilent = pprintparamsObj->bSilent; |
| 449 | bShrinkToFit = pprintparamsObj->bShrinkToFit; |
| 450 | bPrintAsImage = pprintparamsObj->bPrintAsImage; |
| 451 | bReverse = pprintparamsObj->bReverse; |
| 452 | bAnnotations = pprintparamsObj->bAnnotations; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 454 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | } else { |
| 458 | if (nlength >= 1) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 459 | bUI = params[0].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | if (nlength >= 2) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 461 | nStart = params[1].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 462 | if (nlength >= 3) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 463 | nEnd = params[2].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 464 | if (nlength >= 4) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 465 | bSilent = params[3].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | if (nlength >= 5) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 467 | bShrinkToFit = params[4].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | if (nlength >= 6) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 469 | bPrintAsImage = params[5].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | if (nlength >= 7) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 471 | bReverse = params[6].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | if (nlength >= 8) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 473 | bAnnotations = params[7].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | } |
| 475 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 476 | if (m_pFormFillEnv) { |
| 477 | m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, |
| 478 | bPrintAsImage, bReverse, bAnnotations); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 479 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 480 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 481 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // removes the specified field from the document. |
| 485 | // comment: |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 486 | // note: if the filed name is not rational, adobe is dumb for it. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 488 | bool Document::removeField(IJS_Context* cc, |
| 489 | const std::vector<CJS_Value>& params, |
| 490 | CJS_Value& vRet, |
| 491 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 492 | if (params.size() != 1) { |
| 493 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 494 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 495 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 496 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 497 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 498 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 499 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 500 | if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 501 | m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 502 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 503 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 504 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 505 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 506 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 507 | CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 508 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 509 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 510 | pInterForm->GetWidgets(sFieldName, &widgets); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 511 | if (widgets.empty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 512 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 514 | for (const auto& pAnnot : widgets) { |
| 515 | CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot.Get()); |
| 516 | if (!pWidget) |
| 517 | continue; |
| 518 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 519 | CFX_FloatRect rcAnnot = pWidget->GetRect(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 520 | --rcAnnot.left; |
| 521 | --rcAnnot.bottom; |
| 522 | ++rcAnnot.right; |
| 523 | ++rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 525 | std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 526 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 527 | ASSERT(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 529 | // If there is currently no pageview associated with the page being used |
| 530 | // do not create one. We may be in the process of tearing down the document |
| 531 | // and creating a new pageview at this point will cause bad things. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 532 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 533 | if (pPageView) { |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 534 | #if PDF_ENABLE_XFA |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 535 | pPageView->DeleteAnnot(pWidget); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 536 | #endif // PDF_ENABLE_XFA |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 537 | pPageView->UpdateRects(aRefresh); |
| 538 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 540 | m_pFormFillEnv->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 542 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | // reset filed values within a document. |
| 546 | // comment: |
| 547 | // note: if the fields names r not rational, aodbe is dumb for it. |
| 548 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 549 | bool Document::resetForm(IJS_Context* cc, |
| 550 | const std::vector<CJS_Value>& params, |
| 551 | CJS_Value& vRet, |
| 552 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 553 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 554 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 555 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 556 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 557 | if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 558 | m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 559 | m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 560 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 561 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 562 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 563 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 564 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 566 | CJS_Array aName; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 567 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 568 | if (params.empty()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 569 | pPDFForm->ResetForm(true); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 570 | m_pFormFillEnv->SetChangeMark(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 571 | return true; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 572 | } |
| 573 | |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 574 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 575 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 576 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 577 | switch (params[0].GetType()) { |
| 578 | default: |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 579 | aName.Attach(params[0].ToV8Array(pRuntime)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 580 | break; |
| 581 | case CJS_Value::VT_string: |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 582 | aName.SetElement(pRuntime, 0, params[0]); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 583 | break; |
| 584 | } |
| 585 | |
| 586 | std::vector<CPDF_FormField*> aFields; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 587 | for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 588 | CJS_Value valElement(pRuntime); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 589 | aName.GetElement(pRuntime, i, valElement); |
| 590 | CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 591 | for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 592 | aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 593 | } |
| 594 | |
| 595 | if (!aFields.empty()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 596 | pPDFForm->ResetForm(aFields, true, true); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 597 | m_pFormFillEnv->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | } |
| 599 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 600 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | } |
| 602 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 603 | bool Document::saveAs(IJS_Context* cc, |
| 604 | const std::vector<CJS_Value>& params, |
| 605 | CJS_Value& vRet, |
| 606 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 607 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 608 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | } |
| 610 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 611 | bool Document::syncAnnotScan(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 612 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 613 | CJS_Value& vRet, |
| 614 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 615 | return true; |
| 616 | } |
| 617 | |
| 618 | bool Document::submitForm(IJS_Context* cc, |
| 619 | const std::vector<CJS_Value>& params, |
| 620 | CJS_Value& vRet, |
| 621 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | int nSize = params.size(); |
| 623 | if (nSize < 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 624 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 625 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 627 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 628 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 629 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 630 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 631 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 632 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 633 | CJS_Array aFields; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 634 | CFX_WideString strURL; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 635 | bool bFDF = true; |
| 636 | bool bEmpty = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | CJS_Value v = params[0]; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 638 | if (v.GetType() == CJS_Value::VT_string) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 639 | strURL = params[0].ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | if (nSize > 1) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 641 | bFDF = params[1].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 642 | if (nSize > 2) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 643 | bEmpty = params[2].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 644 | if (nSize > 3) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 645 | aFields.Attach(params[3].ToV8Array(pRuntime)); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 646 | } else if (v.GetType() == CJS_Value::VT_object) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 647 | v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); |
| 648 | v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"cURL"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 649 | if (!pValue.IsEmpty()) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 650 | strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 651 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 652 | pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); |
| 653 | bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 654 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 655 | pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); |
| 656 | bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 657 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 658 | pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); |
| 659 | aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 660 | } |
| 661 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 662 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 663 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 664 | if (aFields.GetLength(pRuntime) == 0 && bEmpty) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 665 | if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | pRuntime->BeginBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 667 | pInterForm->SubmitForm(strURL, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | pRuntime->EndBlock(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 669 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 670 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 673 | std::vector<CPDF_FormField*> fieldObjects; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 674 | for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 675 | CJS_Value valName(pRuntime); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 676 | aFields.GetElement(pRuntime, i, valName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 677 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 678 | CFX_WideString sName = valName.ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 680 | for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 681 | CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 682 | if (!bEmpty && pField->GetValue().IsEmpty()) |
| 683 | continue; |
| 684 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 685 | fieldObjects.push_back(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 689 | if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | pRuntime->BeginBlock(); |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 691 | pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | pRuntime->EndBlock(); |
| 693 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 694 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 695 | } |
| 696 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 697 | void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 698 | m_pFormFillEnv.Reset(pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 699 | } |
| 700 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 701 | bool Document::bookmarkRoot(IJS_Context* cc, |
| 702 | CJS_PropValue& vp, |
| 703 | CFX_WideString& sError) { |
| 704 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 705 | } |
| 706 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 707 | bool Document::mailDoc(IJS_Context* cc, |
| 708 | const std::vector<CJS_Value>& params, |
| 709 | CJS_Value& vRet, |
| 710 | CFX_WideString& sError) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 711 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 712 | |
| 713 | // TODO(tsepez): Check maximum number of allowed params. |
| 714 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 715 | bool bUI = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 716 | CFX_WideString cTo = L""; |
| 717 | CFX_WideString cCc = L""; |
| 718 | CFX_WideString cBcc = L""; |
| 719 | CFX_WideString cSubject = L""; |
| 720 | CFX_WideString cMsg = L""; |
| 721 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 722 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 724 | if (params.size() >= 1) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 725 | bUI = params[0].ToBool(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 726 | if (params.size() >= 2) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 727 | cTo = params[1].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 728 | if (params.size() >= 3) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 729 | cCc = params[2].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 730 | if (params.size() >= 4) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 731 | cBcc = params[3].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 732 | if (params.size() >= 5) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 733 | cSubject = params[4].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 734 | if (params.size() >= 6) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 735 | cMsg = params[5].ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 737 | if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 738 | v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 739 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 740 | v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"bUI"); |
tsepez | 71ba588 | 2016-10-28 09:35:49 -0700 | [diff] [blame] | 741 | bUI = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 742 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 743 | pValue = pRuntime->GetObjectProperty(pObj, L"cTo"); |
| 744 | cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 745 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 746 | pValue = pRuntime->GetObjectProperty(pObj, L"cCc"); |
| 747 | cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 749 | pValue = pRuntime->GetObjectProperty(pObj, L"cBcc"); |
| 750 | cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 752 | pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); |
| 753 | cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 755 | pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); |
| 756 | cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | pRuntime->BeginBlock(); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 760 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
| 761 | pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), |
| 762 | cCc.c_str(), cBcc.c_str(), cMsg.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 763 | pRuntime->EndBlock(); |
| 764 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 765 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | } |
| 767 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 768 | bool Document::author(IJS_Context* cc, |
| 769 | CJS_PropValue& vp, |
| 770 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 771 | return getPropertyInternal(cc, vp, "Author", sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 772 | } |
| 773 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 774 | bool Document::info(IJS_Context* cc, |
| 775 | CJS_PropValue& vp, |
| 776 | CFX_WideString& sError) { |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 777 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 778 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 779 | return false; |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 780 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 781 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 782 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 783 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 784 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 785 | CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 786 | if (!pDictionary) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 787 | return false; |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 788 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 789 | CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); |
| 790 | CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); |
| 791 | CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); |
| 792 | CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); |
| 793 | CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); |
| 794 | CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); |
| 795 | CFX_WideString cwCreationDate = |
| 796 | pDictionary->GetUnicodeTextFor("CreationDate"); |
| 797 | CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate"); |
| 798 | CFX_WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped"); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 799 | |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 800 | CJS_Context* pContext = (CJS_Context*)cc; |
| 801 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 802 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 803 | v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1); |
| 804 | pRuntime->PutObjectString(pObj, L"Author", cwAuthor); |
| 805 | pRuntime->PutObjectString(pObj, L"Title", cwTitle); |
| 806 | pRuntime->PutObjectString(pObj, L"Subject", cwSubject); |
| 807 | pRuntime->PutObjectString(pObj, L"Keywords", cwKeywords); |
| 808 | pRuntime->PutObjectString(pObj, L"Creator", cwCreator); |
| 809 | pRuntime->PutObjectString(pObj, L"Producer", cwProducer); |
| 810 | pRuntime->PutObjectString(pObj, L"CreationDate", cwCreationDate); |
| 811 | pRuntime->PutObjectString(pObj, L"ModDate", cwModDate); |
| 812 | pRuntime->PutObjectString(pObj, L"Trapped", cwTrapped); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 813 | |
| 814 | // It's to be compatible to non-standard info dictionary. |
| 815 | for (const auto& it : *pDictionary) { |
| 816 | const CFX_ByteString& bsKey = it.first; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 817 | CPDF_Object* pValueObj = it.second.get(); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 818 | CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); |
| 819 | if (pValueObj->IsString() || pValueObj->IsName()) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 820 | pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText()); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 821 | } else if (pValueObj->IsNumber()) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 822 | pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber()); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 823 | } else if (pValueObj->IsBoolean()) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 824 | pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger()); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 825 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 826 | } |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 827 | vp << pObj; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 828 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 829 | } |
| 830 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 831 | bool Document::getPropertyInternal(IJS_Context* cc, |
| 832 | CJS_PropValue& vp, |
| 833 | const CFX_ByteString& propName, |
| 834 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 835 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 836 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 837 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 838 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 839 | CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 840 | if (!pDictionary) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 841 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | |
| 843 | if (vp.IsGetting()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 844 | vp << pDictionary->GetUnicodeTextFor(propName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | } else { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 846 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 847 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 848 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 849 | } |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 850 | CFX_WideString csProperty; |
| 851 | vp >> csProperty; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 852 | pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty), |
| 853 | false); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 854 | m_pFormFillEnv->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 855 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 856 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 857 | } |
| 858 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 859 | bool Document::creationDate(IJS_Context* cc, |
| 860 | CJS_PropValue& vp, |
| 861 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 862 | return getPropertyInternal(cc, vp, "CreationDate", sError); |
| 863 | } |
| 864 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 865 | bool Document::creator(IJS_Context* cc, |
| 866 | CJS_PropValue& vp, |
| 867 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 868 | return getPropertyInternal(cc, vp, "Creator", sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 869 | } |
| 870 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 871 | bool Document::delay(IJS_Context* cc, |
| 872 | CJS_PropValue& vp, |
| 873 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 874 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 875 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 876 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 877 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | if (vp.IsGetting()) { |
| 879 | vp << m_bDelay; |
| 880 | } else { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 881 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 882 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 883 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 884 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | vp >> m_bDelay; |
| 886 | if (m_bDelay) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 887 | m_DelayData.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | } else { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 889 | std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
| 890 | DelayDataToProcess.swap(m_DelayData); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 891 | for (const auto& pData : DelayDataToProcess) |
| 892 | Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 895 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 896 | } |
| 897 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 898 | bool Document::keywords(IJS_Context* cc, |
| 899 | CJS_PropValue& vp, |
| 900 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 901 | return getPropertyInternal(cc, vp, "Keywords", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | } |
| 903 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 904 | bool Document::modDate(IJS_Context* cc, |
| 905 | CJS_PropValue& vp, |
| 906 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 907 | return getPropertyInternal(cc, vp, "ModDate", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | } |
| 909 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 910 | bool Document::producer(IJS_Context* cc, |
| 911 | CJS_PropValue& vp, |
| 912 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 913 | return getPropertyInternal(cc, vp, "Producer", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | } |
| 915 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 916 | bool Document::subject(IJS_Context* cc, |
| 917 | CJS_PropValue& vp, |
| 918 | CFX_WideString& sError) { |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 919 | return getPropertyInternal(cc, vp, "Subject", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 920 | } |
| 921 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 922 | bool Document::title(IJS_Context* cc, |
| 923 | CJS_PropValue& vp, |
| 924 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 925 | if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 926 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 927 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 928 | } |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 929 | return getPropertyInternal(cc, vp, "Title", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 930 | } |
| 931 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 932 | bool Document::numPages(IJS_Context* cc, |
| 933 | CJS_PropValue& vp, |
| 934 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 935 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 936 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 937 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 938 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 939 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 940 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 941 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 942 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 943 | vp << m_pFormFillEnv->GetPageCount(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 944 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | } |
| 946 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 947 | bool Document::external(IJS_Context* cc, |
| 948 | CJS_PropValue& vp, |
| 949 | CFX_WideString& sError) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 950 | // In Chrome case, should always return true. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | if (vp.IsGetting()) { |
| 952 | vp << true; |
| 953 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 954 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | } |
| 956 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 957 | bool Document::filesize(IJS_Context* cc, |
| 958 | CJS_PropValue& vp, |
| 959 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 961 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 962 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 963 | } |
| 964 | vp << 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 965 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | } |
| 967 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 968 | bool Document::mouseX(IJS_Context* cc, |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 969 | CJS_PropValue& vp, |
| 970 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 971 | return true; |
| 972 | } |
| 973 | |
| 974 | bool Document::mouseY(IJS_Context* cc, |
| 975 | CJS_PropValue& vp, |
| 976 | CFX_WideString& sError) { |
| 977 | return true; |
| 978 | } |
| 979 | |
| 980 | bool Document::URL(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 981 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 982 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 983 | return false; |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 984 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 985 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 986 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 987 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 988 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 989 | vp << m_pFormFillEnv->JS_docGetFilePath(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 990 | return true; |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 991 | } |
| 992 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 993 | bool Document::baseURL(IJS_Context* cc, |
| 994 | CJS_PropValue& vp, |
| 995 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 996 | if (vp.IsGetting()) { |
| 997 | vp << m_cwBaseURL; |
| 998 | } else { |
| 999 | vp >> m_cwBaseURL; |
| 1000 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1001 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1004 | bool Document::calculate(IJS_Context* cc, |
| 1005 | CJS_PropValue& vp, |
| 1006 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1007 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1008 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1009 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1010 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1011 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | if (vp.IsGetting()) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1013 | vp << !!pInterForm->IsCalculateEnabled(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1014 | } else { |
| 1015 | bool bCalculate; |
| 1016 | vp >> bCalculate; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1017 | pInterForm->EnableCalculate(bCalculate); |
| 1018 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1019 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1022 | bool Document::documentFileName(IJS_Context* cc, |
| 1023 | CJS_PropValue& vp, |
| 1024 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1025 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1026 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1027 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1028 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1029 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1030 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1031 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1032 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1033 | CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | int32_t i = wsFilePath.GetLength() - 1; |
| 1035 | for (; i >= 0; i--) { |
| 1036 | if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1037 | break; |
| 1038 | } |
| 1039 | if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1040 | vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1041 | } else { |
| 1042 | vp << L""; |
| 1043 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1044 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1047 | bool Document::path(IJS_Context* cc, |
| 1048 | CJS_PropValue& vp, |
| 1049 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1051 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1052 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1053 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1054 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1055 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1056 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1057 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1058 | vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1059 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1062 | bool Document::pageWindowRect(IJS_Context* cc, |
| 1063 | CJS_PropValue& vp, |
| 1064 | CFX_WideString& sError) { |
| 1065 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1068 | bool Document::layout(IJS_Context* cc, |
| 1069 | CJS_PropValue& vp, |
| 1070 | CFX_WideString& sError) { |
| 1071 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1074 | bool Document::addLink(IJS_Context* cc, |
| 1075 | const std::vector<CJS_Value>& params, |
| 1076 | CJS_Value& vRet, |
| 1077 | CFX_WideString& sError) { |
| 1078 | return true; |
| 1079 | } |
| 1080 | |
| 1081 | bool Document::closeDoc(IJS_Context* cc, |
| 1082 | const std::vector<CJS_Value>& params, |
| 1083 | CJS_Value& vRet, |
| 1084 | CFX_WideString& sError) { |
| 1085 | return true; |
| 1086 | } |
| 1087 | |
| 1088 | bool Document::getPageBox(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1089 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1090 | CJS_Value& vRet, |
| 1091 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1092 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1095 | bool Document::getAnnot(IJS_Context* cc, |
| 1096 | const std::vector<CJS_Value>& params, |
| 1097 | CJS_Value& vRet, |
| 1098 | CFX_WideString& sError) { |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1099 | if (params.size() != 2) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1100 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1101 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1102 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1103 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1104 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1105 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1106 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1107 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1108 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1109 | int nPageNo = params[0].ToInt(pRuntime); |
| 1110 | CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1111 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1112 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1113 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1114 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 1115 | CPDFSDK_AnnotIteration annotIteration(pPageView, false); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1116 | CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 1117 | for (const auto& pSDKAnnotCur : annotIteration) { |
| 1118 | CPDFSDK_BAAnnot* pBAAnnot = |
| 1119 | static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1120 | if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { |
| 1121 | pSDKBAAnnot = pBAAnnot; |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1125 | if (!pSDKBAAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1126 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1127 | |
| 1128 | v8::Local<v8::Object> pObj = |
| 1129 | pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1130 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1131 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1132 | |
| 1133 | CJS_Annot* pJS_Annot = |
| 1134 | static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1135 | if (!pJS_Annot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1136 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1137 | |
| 1138 | Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1139 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1140 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1141 | |
| 1142 | pAnnot->SetSDKAnnot(pSDKBAAnnot); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1143 | vRet = CJS_Value(pRuntime, pJS_Annot); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1144 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1147 | bool Document::getAnnots(IJS_Context* cc, |
| 1148 | const std::vector<CJS_Value>& params, |
| 1149 | CJS_Value& vRet, |
| 1150 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1151 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1152 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1153 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1154 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1155 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1156 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1157 | |
| 1158 | // TODO(tonikitoo): Add support supported parameters as per |
| 1159 | // the PDF spec. |
| 1160 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1161 | int nPageNo = m_pFormFillEnv->GetPageCount(); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1162 | CJS_Array annots; |
| 1163 | |
| 1164 | for (int i = 0; i < nPageNo; ++i) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1165 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1166 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1167 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1168 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 1169 | CPDFSDK_AnnotIteration annotIteration(pPageView, false); |
| 1170 | for (const auto& pSDKAnnotCur : annotIteration) { |
| 1171 | if (!pSDKAnnotCur) { |
| 1172 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1173 | return false; |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 1174 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1175 | v8::Local<v8::Object> pObj = |
| 1176 | pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1177 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1178 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1179 | |
| 1180 | CJS_Annot* pJS_Annot = |
| 1181 | static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1182 | if (!pJS_Annot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1183 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1184 | |
| 1185 | Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1186 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1187 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1188 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame^] | 1189 | pAnnot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get())); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1190 | annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); |
| 1191 | } |
| 1192 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1193 | vRet = CJS_Value(pRuntime, annots); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1194 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1197 | bool Document::getAnnot3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1198 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1199 | CJS_Value& vRet, |
| 1200 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1201 | vRet.SetNull(CJS_Runtime::FromContext(cc)); |
| 1202 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1205 | bool Document::getAnnots3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1206 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1207 | CJS_Value& vRet, |
| 1208 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1209 | return true; |
| 1210 | } |
| 1211 | |
| 1212 | bool Document::getOCGs(IJS_Context* cc, |
| 1213 | const std::vector<CJS_Value>& params, |
| 1214 | CJS_Value& vRet, |
| 1215 | CFX_WideString& sError) { |
| 1216 | return true; |
| 1217 | } |
| 1218 | |
| 1219 | bool Document::getLinks(IJS_Context* cc, |
| 1220 | const std::vector<CJS_Value>& params, |
| 1221 | CJS_Value& vRet, |
| 1222 | CFX_WideString& sError) { |
| 1223 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| 1227 | return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
| 1228 | rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| 1229 | } |
| 1230 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1231 | bool Document::addIcon(IJS_Context* cc, |
| 1232 | const std::vector<CJS_Value>& params, |
| 1233 | CJS_Value& vRet, |
| 1234 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1235 | if (params.size() != 2) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1236 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1237 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1238 | } |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1239 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1240 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1241 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1242 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1243 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1244 | if (params[1].GetType() != CJS_Value::VT_object) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1245 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1246 | return false; |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1247 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1248 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1249 | v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
| 1250 | if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1251 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1252 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1255 | CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1256 | if (!pEmbedObj) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1257 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1258 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1261 | m_Icons.push_back(pdfium::MakeUnique<IconElement>( |
| 1262 | swIconName, static_cast<Icon*>(pEmbedObj))); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1263 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1266 | bool Document::icons(IJS_Context* cc, |
| 1267 | CJS_PropValue& vp, |
| 1268 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1269 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1270 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1271 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1274 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1275 | if (m_Icons.empty()) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1276 | vp.GetJSValue()->SetNull(pRuntime); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1277 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 1280 | CJS_Array Icons; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1281 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1282 | int i = 0; |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1283 | for (const auto& pIconElement : m_Icons) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1284 | v8::Local<v8::Object> pObj = |
| 1285 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1286 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1287 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1289 | CJS_Icon* pJS_Icon = |
| 1290 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1291 | if (!pJS_Icon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1292 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1294 | Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1295 | if (!pIcon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1296 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1297 | |
dsinclair | 09bad1c | 2016-10-18 19:26:30 -0700 | [diff] [blame] | 1298 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1299 | pIcon->SetIconName(pIconElement->IconName); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1300 | Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | vp << Icons; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1304 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1307 | bool Document::getIcon(IJS_Context* cc, |
| 1308 | const std::vector<CJS_Value>& params, |
| 1309 | CJS_Value& vRet, |
| 1310 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1311 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1312 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1313 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1316 | if (m_Icons.empty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1317 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1318 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1319 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1320 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1321 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1322 | for (const auto& pIconElement : m_Icons) { |
| 1323 | if (pIconElement->IconName != swIconName) |
| 1324 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1325 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1326 | v8::Local<v8::Object> pObj = |
| 1327 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1328 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1329 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1330 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1331 | CJS_Icon* pJS_Icon = |
| 1332 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1333 | if (!pJS_Icon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1334 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1335 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1336 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1337 | if (!pIcon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1338 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1339 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1340 | pIcon->SetIconName(swIconName); |
| 1341 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1342 | |
| 1343 | vRet = CJS_Value(pRuntime, pJS_Icon); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1344 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1347 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1350 | bool Document::removeIcon(IJS_Context* cc, |
| 1351 | const std::vector<CJS_Value>& params, |
| 1352 | CJS_Value& vRet, |
| 1353 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1354 | // Unsafe, no supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1355 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1358 | bool Document::createDataObject(IJS_Context* cc, |
| 1359 | const std::vector<CJS_Value>& params, |
| 1360 | CJS_Value& vRet, |
| 1361 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1362 | // Unsafe, not implemented. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1363 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1366 | bool Document::media(IJS_Context* cc, |
| 1367 | CJS_PropValue& vp, |
| 1368 | CFX_WideString& sError) { |
| 1369 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1372 | bool Document::calculateNow(IJS_Context* cc, |
| 1373 | const std::vector<CJS_Value>& params, |
| 1374 | CJS_Value& vRet, |
| 1375 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1376 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1377 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1378 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1379 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1380 | if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 1381 | m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1382 | m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1383 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1384 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1385 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1386 | m_pFormFillEnv->GetInterForm()->OnCalculate(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1387 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1390 | bool Document::Collab(IJS_Context* cc, |
| 1391 | CJS_PropValue& vp, |
| 1392 | CFX_WideString& sError) { |
| 1393 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1396 | bool Document::getPageNthWord(IJS_Context* cc, |
| 1397 | const std::vector<CJS_Value>& params, |
| 1398 | CJS_Value& vRet, |
| 1399 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1400 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1401 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1402 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1403 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1404 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1405 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1406 | return false; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1407 | } |
| 1408 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1409 | |
| 1410 | // TODO(tsepez): check maximum allowable params. |
| 1411 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1412 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1413 | int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1414 | bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1415 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1416 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1417 | if (!pDocument) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1418 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1419 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1420 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1421 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1422 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1423 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1424 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1425 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1426 | if (!pPageDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1427 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1428 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1429 | CPDF_Page page(pDocument, pPageDict, true); |
| 1430 | page.ParseContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1431 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1432 | int nWords = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1433 | CFX_WideString swRet; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1434 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1435 | if (pPageObj->IsText()) { |
| 1436 | CPDF_TextObject* pTextObj = pPageObj->AsText(); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1437 | int nObjWords = CountWords(pTextObj); |
| 1438 | if (nWords + nObjWords >= nWordNo) { |
| 1439 | swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1440 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1441 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1442 | nWords += nObjWords; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1443 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1444 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1445 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1446 | if (bStrip) { |
| 1447 | swRet.TrimLeft(); |
| 1448 | swRet.TrimRight(); |
| 1449 | } |
| 1450 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1451 | vRet = CJS_Value(pRuntime, swRet.c_str()); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1452 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1455 | bool Document::getPageNthWordQuads(IJS_Context* cc, |
| 1456 | const std::vector<CJS_Value>& params, |
| 1457 | CJS_Value& vRet, |
| 1458 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1459 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1460 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1461 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1462 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1463 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1464 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1465 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1466 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1467 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1470 | bool Document::getPageNumWords(IJS_Context* cc, |
| 1471 | const std::vector<CJS_Value>& params, |
| 1472 | CJS_Value& vRet, |
| 1473 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1474 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1475 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1476 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1477 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1478 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1479 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1480 | return false; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1481 | } |
| 1482 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1483 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1484 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1485 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1486 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1487 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1491 | if (!pPageDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1492 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1493 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1494 | CPDF_Page page(pDocument, pPageDict, true); |
| 1495 | page.ParseContent(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1496 | |
| 1497 | int nWords = 0; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1498 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1499 | if (pPageObj->IsText()) |
| 1500 | nWords += CountWords(pPageObj->AsText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1503 | vRet = CJS_Value(pRuntime, nWords); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1504 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1507 | bool Document::getPrintParams(IJS_Context* cc, |
| 1508 | const std::vector<CJS_Value>& params, |
| 1509 | CJS_Value& vRet, |
| 1510 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1511 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1512 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1513 | v8::Local<v8::Object> pRetObj = |
| 1514 | pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1515 | |
| 1516 | // Not implemented yet. |
| 1517 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1518 | vRet = CJS_Value(pRuntime, pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1519 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1523 | |
| 1524 | int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1525 | if (!pTextObj) |
| 1526 | return 0; |
| 1527 | |
| 1528 | int nWords = 0; |
| 1529 | |
| 1530 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1531 | if (!pFont) |
| 1532 | return 0; |
| 1533 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1534 | bool bIsLatin = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1535 | |
| 1536 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1537 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1538 | FX_FLOAT kerning; |
| 1539 | |
| 1540 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1541 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1542 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1543 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1544 | if (swUnicode.GetLength() > 0) |
| 1545 | unicode = swUnicode[0]; |
| 1546 | |
| 1547 | if (ISLATINWORD(unicode) && bIsLatin) |
| 1548 | continue; |
| 1549 | |
| 1550 | bIsLatin = ISLATINWORD(unicode); |
| 1551 | if (unicode != 0x20) |
| 1552 | nWords++; |
| 1553 | } |
| 1554 | |
| 1555 | return nWords; |
| 1556 | } |
| 1557 | |
| 1558 | CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1559 | int nWordIndex) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1560 | CFX_WideString swRet; |
| 1561 | |
| 1562 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1563 | if (!pFont) |
| 1564 | return L""; |
| 1565 | |
| 1566 | int nWords = 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1567 | bool bIsLatin = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1568 | |
| 1569 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1570 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1571 | FX_FLOAT kerning; |
| 1572 | |
| 1573 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1574 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1575 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1576 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1577 | if (swUnicode.GetLength() > 0) |
| 1578 | unicode = swUnicode[0]; |
| 1579 | |
| 1580 | if (ISLATINWORD(unicode) && bIsLatin) { |
| 1581 | } else { |
| 1582 | bIsLatin = ISLATINWORD(unicode); |
| 1583 | if (unicode != 0x20) |
| 1584 | nWords++; |
| 1585 | } |
| 1586 | |
| 1587 | if (nWords - 1 == nWordIndex) |
| 1588 | swRet += unicode; |
| 1589 | } |
| 1590 | |
| 1591 | return swRet; |
| 1592 | } |
| 1593 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1594 | bool Document::zoom(IJS_Context* cc, |
| 1595 | CJS_PropValue& vp, |
| 1596 | CFX_WideString& sError) { |
| 1597 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /** |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1601 | (none, NoVary) |
| 1602 | (fitP, FitPage) |
| 1603 | (fitW, FitWidth) |
| 1604 | (fitH, FitHeight) |
| 1605 | (fitV, FitVisibleWidth) |
| 1606 | (pref, Preferred) |
| 1607 | (refW, ReflowWidth) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1608 | */ |
| 1609 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1610 | bool Document::zoomType(IJS_Context* cc, |
| 1611 | CJS_PropValue& vp, |
| 1612 | CFX_WideString& sError) { |
| 1613 | return true; |
| 1614 | } |
| 1615 | |
| 1616 | bool Document::deletePages(IJS_Context* cc, |
| 1617 | const std::vector<CJS_Value>& params, |
| 1618 | CJS_Value& vRet, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1619 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1620 | // Unsafe, no supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1621 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1622 | } |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1623 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1624 | bool Document::extractPages(IJS_Context* cc, |
| 1625 | const std::vector<CJS_Value>& params, |
| 1626 | CJS_Value& vRet, |
| 1627 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1628 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1629 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1632 | bool Document::insertPages(IJS_Context* cc, |
| 1633 | const std::vector<CJS_Value>& params, |
| 1634 | CJS_Value& vRet, |
| 1635 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1636 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1637 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1640 | bool Document::replacePages(IJS_Context* cc, |
| 1641 | const std::vector<CJS_Value>& params, |
| 1642 | CJS_Value& vRet, |
| 1643 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1644 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1645 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1648 | bool Document::getURL(IJS_Context* cc, |
| 1649 | const std::vector<CJS_Value>& params, |
| 1650 | CJS_Value& vRet, |
| 1651 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1652 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1653 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1656 | bool Document::gotoNamedDest(IJS_Context* cc, |
| 1657 | const std::vector<CJS_Value>& params, |
| 1658 | CJS_Value& vRet, |
| 1659 | CFX_WideString& sError) { |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1660 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1661 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1662 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1663 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1664 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1665 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1666 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1667 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1668 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1669 | CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1670 | CFX_ByteString utf8Name = wideName.UTF8Encode(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1671 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1672 | if (!pDocument) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1673 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1674 | |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1675 | CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1676 | CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1677 | if (!destArray) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1678 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1679 | |
| 1680 | CPDF_Dest dest(destArray); |
| 1681 | const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1682 | |
| 1683 | std::unique_ptr<float[]> scrollPositionArray; |
| 1684 | int scrollPositionArraySize = 0; |
| 1685 | |
| 1686 | if (arrayObject) { |
| 1687 | scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1688 | int j = 0; |
| 1689 | for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1690 | scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1691 | scrollPositionArraySize = j; |
| 1692 | } |
| 1693 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1694 | pRuntime->BeginBlock(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1695 | m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1696 | scrollPositionArray.get(), |
| 1697 | scrollPositionArraySize); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1698 | pRuntime->EndBlock(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1699 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1700 | return true; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1703 | void Document::AddDelayData(CJS_DelayData* pData) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1704 | m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1708 | int nControlIndex) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1709 | std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1710 | auto iter = m_DelayData.begin(); |
| 1711 | while (iter != m_DelayData.end()) { |
| 1712 | auto old = iter++; |
| 1713 | if ((*old)->sFieldName == sFieldName && |
| 1714 | (*old)->nControlIndex == nControlIndex) { |
| 1715 | DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1716 | m_DelayData.erase(old); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1720 | for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1721 | Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1724 | CJS_Document* Document::GetCJSDoc() const { |
| 1725 | return static_cast<CJS_Document*>(m_pJSObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1726 | } |