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