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