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