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); |
Tom Sepez | c6dc69f | 2017-02-23 09:53:09 -0800 | [diff] [blame^] | 769 | pRuntime->PutObjectProperty(pObj, L"Author", |
| 770 | pRuntime->NewString(cwAuthor.AsStringC())); |
| 771 | pRuntime->PutObjectProperty(pObj, L"Title", |
| 772 | pRuntime->NewString(cwTitle.AsStringC())); |
| 773 | pRuntime->PutObjectProperty(pObj, L"Subject", |
| 774 | pRuntime->NewString(cwSubject.AsStringC())); |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 775 | pRuntime->PutObjectProperty(pObj, L"Keywords", |
Tom Sepez | c6dc69f | 2017-02-23 09:53:09 -0800 | [diff] [blame^] | 776 | pRuntime->NewString(cwKeywords.AsStringC())); |
| 777 | pRuntime->PutObjectProperty(pObj, L"Creator", |
| 778 | pRuntime->NewString(cwCreator.AsStringC())); |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 779 | pRuntime->PutObjectProperty(pObj, L"Producer", |
Tom Sepez | c6dc69f | 2017-02-23 09:53:09 -0800 | [diff] [blame^] | 780 | pRuntime->NewString(cwProducer.AsStringC())); |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 781 | pRuntime->PutObjectProperty(pObj, L"CreationDate", |
Tom Sepez | c6dc69f | 2017-02-23 09:53:09 -0800 | [diff] [blame^] | 782 | pRuntime->NewString(cwCreationDate.AsStringC())); |
| 783 | pRuntime->PutObjectProperty(pObj, L"ModDate", |
| 784 | pRuntime->NewString(cwModDate.AsStringC())); |
| 785 | pRuntime->PutObjectProperty(pObj, L"Trapped", |
| 786 | pRuntime->NewString(cwTrapped.AsStringC())); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 787 | |
| 788 | // It's to be compatible to non-standard info dictionary. |
| 789 | for (const auto& it : *pDictionary) { |
| 790 | const CFX_ByteString& bsKey = it.first; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 791 | CPDF_Object* pValueObj = it.second.get(); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 792 | CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); |
| 793 | if (pValueObj->IsString() || pValueObj->IsName()) { |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 794 | pRuntime->PutObjectProperty( |
Tom Sepez | c6dc69f | 2017-02-23 09:53:09 -0800 | [diff] [blame^] | 795 | pObj, wsKey, |
| 796 | pRuntime->NewString(pValueObj->GetUnicodeText().AsStringC())); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 797 | } else if (pValueObj->IsNumber()) { |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 798 | pRuntime->PutObjectProperty(pObj, wsKey, |
| 799 | pRuntime->NewNumber(pValueObj->GetNumber())); |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 800 | } else if (pValueObj->IsBoolean()) { |
tsepez | e6cf013 | 2017-01-18 14:38:18 -0800 | [diff] [blame] | 801 | pRuntime->PutObjectProperty( |
| 802 | pObj, wsKey, pRuntime->NewBoolean(!!pValueObj->GetInteger())); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 803 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 804 | } |
tonikitoo | ec26876 | 2016-08-10 12:29:28 -0700 | [diff] [blame] | 805 | vp << pObj; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 806 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 809 | bool Document::getPropertyInternal(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 810 | CJS_PropValue& vp, |
| 811 | const CFX_ByteString& propName, |
| 812 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 813 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 814 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 815 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 816 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 817 | CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 818 | if (!pDictionary) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 819 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | |
| 821 | if (vp.IsGetting()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 822 | vp << pDictionary->GetUnicodeTextFor(propName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | } else { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 824 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 825 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 826 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 827 | } |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 828 | CFX_WideString csProperty; |
| 829 | vp >> csProperty; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 830 | pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty), |
| 831 | false); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 832 | m_pFormFillEnv->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 833 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 834 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 837 | bool Document::creationDate(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 838 | CJS_PropValue& vp, |
| 839 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 840 | return getPropertyInternal(pRuntime, vp, "CreationDate", sError); |
tonikitoo | ea3ff9e | 2016-08-02 11:52:28 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 843 | bool Document::creator(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 844 | CJS_PropValue& vp, |
| 845 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 846 | return getPropertyInternal(pRuntime, vp, "Creator", sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 849 | bool Document::delay(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 850 | CJS_PropValue& vp, |
| 851 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 852 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 853 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 854 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 855 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 856 | if (vp.IsGetting()) { |
| 857 | vp << m_bDelay; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 858 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 859 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 860 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
| 861 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 862 | return false; |
| 863 | } |
| 864 | vp >> m_bDelay; |
| 865 | if (m_bDelay) { |
| 866 | m_DelayData.clear(); |
| 867 | return true; |
| 868 | } |
| 869 | std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
| 870 | DelayDataToProcess.swap(m_DelayData); |
| 871 | for (const auto& pData : DelayDataToProcess) |
| 872 | Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
| 873 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 874 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 877 | bool Document::keywords(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 878 | CJS_PropValue& vp, |
| 879 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 880 | return getPropertyInternal(pRuntime, vp, "Keywords", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 883 | bool Document::modDate(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 884 | CJS_PropValue& vp, |
| 885 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 886 | return getPropertyInternal(pRuntime, vp, "ModDate", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 889 | bool Document::producer(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 890 | CJS_PropValue& vp, |
| 891 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 892 | return getPropertyInternal(pRuntime, vp, "Producer", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 895 | bool Document::subject(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 896 | CJS_PropValue& vp, |
| 897 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 898 | return getPropertyInternal(pRuntime, vp, "Subject", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 901 | bool Document::title(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 902 | CJS_PropValue& vp, |
| 903 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 904 | if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 905 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 906 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 907 | } |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 908 | return getPropertyInternal(pRuntime, vp, "Title", sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 911 | bool Document::numPages(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 912 | CJS_PropValue& vp, |
| 913 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 915 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 916 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 918 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 919 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 920 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 921 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 922 | vp << m_pFormFillEnv->GetPageCount(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 923 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 926 | bool Document::external(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 927 | CJS_PropValue& vp, |
| 928 | CFX_WideString& sError) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 929 | // In Chrome case, should always return true. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 930 | if (vp.IsGetting()) { |
| 931 | vp << true; |
| 932 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 933 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 936 | bool Document::filesize(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 937 | CJS_PropValue& vp, |
| 938 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 939 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 940 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 941 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 942 | } |
| 943 | vp << 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 944 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 947 | bool Document::mouseX(CJS_Runtime* pRuntime, |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 948 | CJS_PropValue& vp, |
| 949 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 950 | return true; |
| 951 | } |
| 952 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 953 | bool Document::mouseY(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 954 | CJS_PropValue& vp, |
| 955 | CFX_WideString& sError) { |
| 956 | return true; |
| 957 | } |
| 958 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 959 | bool Document::URL(CJS_Runtime* pRuntime, |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 960 | CJS_PropValue& vp, |
| 961 | CFX_WideString& sError) { |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 962 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 963 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 964 | return false; |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 965 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 966 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 967 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 968 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 969 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 970 | vp << m_pFormFillEnv->JS_docGetFilePath(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 971 | return true; |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 974 | bool Document::baseURL(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 975 | CJS_PropValue& vp, |
| 976 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | if (vp.IsGetting()) { |
| 978 | vp << m_cwBaseURL; |
| 979 | } else { |
| 980 | vp >> m_cwBaseURL; |
| 981 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 982 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 985 | bool Document::calculate(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 986 | CJS_PropValue& vp, |
| 987 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 988 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 989 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 990 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 991 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 992 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | if (vp.IsGetting()) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 994 | vp << !!pInterForm->IsCalculateEnabled(); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 995 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 996 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 997 | bool bCalculate; |
| 998 | vp >> bCalculate; |
| 999 | pInterForm->EnableCalculate(bCalculate); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1000 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1003 | bool Document::documentFileName(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1004 | CJS_PropValue& vp, |
| 1005 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1006 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1007 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1008 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1009 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1010 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1011 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1012 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1013 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1014 | CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | int32_t i = wsFilePath.GetLength() - 1; |
| 1016 | for (; i >= 0; i--) { |
| 1017 | if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1018 | break; |
| 1019 | } |
| 1020 | if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1021 | vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1022 | } else { |
| 1023 | vp << L""; |
| 1024 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1025 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1028 | bool Document::path(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1029 | CJS_PropValue& vp, |
| 1030 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1031 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1032 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1033 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1035 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1036 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1037 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1038 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1039 | vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1040 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1043 | bool Document::pageWindowRect(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1044 | CJS_PropValue& vp, |
| 1045 | CFX_WideString& sError) { |
| 1046 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1049 | bool Document::layout(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1050 | CJS_PropValue& vp, |
| 1051 | CFX_WideString& sError) { |
| 1052 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1055 | bool Document::addLink(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::closeDoc(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1063 | const std::vector<CJS_Value>& params, |
| 1064 | CJS_Value& vRet, |
| 1065 | CFX_WideString& sError) { |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1069 | bool Document::getPageBox(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1070 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1071 | CJS_Value& vRet, |
| 1072 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1073 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1076 | bool Document::getAnnot(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1077 | const std::vector<CJS_Value>& params, |
| 1078 | CJS_Value& vRet, |
| 1079 | CFX_WideString& sError) { |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1080 | if (params.size() != 2) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1081 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1082 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1083 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1084 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1085 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1086 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1087 | } |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1088 | int nPageNo = params[0].ToInt(pRuntime); |
| 1089 | CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1090 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1091 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1092 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1093 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 1094 | CPDFSDK_AnnotIteration annotIteration(pPageView, false); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1095 | CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 1096 | for (const auto& pSDKAnnotCur : annotIteration) { |
| 1097 | CPDFSDK_BAAnnot* pBAAnnot = |
| 1098 | static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1099 | if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { |
| 1100 | pSDKBAAnnot = pBAAnnot; |
| 1101 | break; |
| 1102 | } |
| 1103 | } |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1104 | if (!pSDKBAAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1105 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1106 | |
| 1107 | v8::Local<v8::Object> pObj = |
| 1108 | pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1109 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1110 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1111 | |
| 1112 | CJS_Annot* pJS_Annot = |
| 1113 | static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1114 | if (!pJS_Annot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1115 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1116 | |
| 1117 | Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1118 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1119 | return false; |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1120 | |
| 1121 | pAnnot->SetSDKAnnot(pSDKBAAnnot); |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 1122 | vRet = CJS_Value(pRuntime, pJS_Annot); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1123 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1126 | bool Document::getAnnots(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1127 | const std::vector<CJS_Value>& params, |
| 1128 | CJS_Value& vRet, |
| 1129 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1130 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1131 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1132 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1133 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1134 | // TODO(tonikitoo): Add support supported parameters as per |
| 1135 | // the PDF spec. |
| 1136 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1137 | int nPageNo = m_pFormFillEnv->GetPageCount(); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1138 | CJS_Array annots; |
| 1139 | |
| 1140 | for (int i = 0; i < nPageNo; ++i) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1141 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1142 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1143 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1144 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 1145 | CPDFSDK_AnnotIteration annotIteration(pPageView, false); |
| 1146 | for (const auto& pSDKAnnotCur : annotIteration) { |
| 1147 | if (!pSDKAnnotCur) { |
| 1148 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1149 | return false; |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 1150 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1151 | v8::Local<v8::Object> pObj = |
| 1152 | pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1153 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1154 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1155 | |
| 1156 | CJS_Annot* pJS_Annot = |
| 1157 | static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1158 | if (!pJS_Annot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1159 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1160 | |
| 1161 | Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1162 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1163 | return false; |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1164 | |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 1165 | pAnnot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get())); |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1166 | annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); |
| 1167 | } |
| 1168 | } |
tonikitoo | 0ee3590 | 2016-08-26 14:41:29 -0700 | [diff] [blame] | 1169 | vRet = CJS_Value(pRuntime, annots); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1170 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1173 | bool Document::getAnnot3D(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1174 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1175 | CJS_Value& vRet, |
| 1176 | CFX_WideString& sError) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1177 | vRet.SetNull(pRuntime); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1178 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1181 | bool Document::getAnnots3D(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1182 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1183 | CJS_Value& vRet, |
| 1184 | CFX_WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1185 | return true; |
| 1186 | } |
| 1187 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1188 | bool Document::getOCGs(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; |
| 1193 | } |
| 1194 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1195 | bool Document::getLinks(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1196 | const std::vector<CJS_Value>& params, |
| 1197 | CJS_Value& vRet, |
| 1198 | CFX_WideString& sError) { |
| 1199 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| 1203 | return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
| 1204 | rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| 1205 | } |
| 1206 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1207 | bool Document::addIcon(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1208 | const std::vector<CJS_Value>& params, |
| 1209 | CJS_Value& vRet, |
| 1210 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1211 | if (params.size() != 2) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1212 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1213 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1214 | } |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1215 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1216 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1217 | if (params[1].GetType() != CJS_Value::VT_object) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1218 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1219 | return false; |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1220 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1221 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1222 | v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
| 1223 | if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1224 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1225 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1228 | CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1229 | if (!pEmbedObj) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1230 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1231 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1234 | m_Icons.push_back(pdfium::MakeUnique<IconElement>( |
| 1235 | swIconName, static_cast<Icon*>(pEmbedObj))); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1236 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1239 | bool Document::icons(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1240 | CJS_PropValue& vp, |
| 1241 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1242 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1243 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1244 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1245 | } |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1246 | if (m_Icons.empty()) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1247 | vp.GetJSValue()->SetNull(pRuntime); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1248 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 1251 | CJS_Array Icons; |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1252 | int i = 0; |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1253 | for (const auto& pIconElement : m_Icons) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1254 | v8::Local<v8::Object> pObj = |
| 1255 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1256 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1257 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1258 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1259 | CJS_Icon* pJS_Icon = |
| 1260 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1261 | if (!pJS_Icon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1262 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1263 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1264 | Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1265 | if (!pIcon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1266 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1267 | |
dsinclair | 09bad1c | 2016-10-18 19:26:30 -0700 | [diff] [blame] | 1268 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1269 | pIcon->SetIconName(pIconElement->IconName); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1270 | Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | vp << Icons; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1274 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1277 | bool Document::getIcon(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1278 | const std::vector<CJS_Value>& params, |
| 1279 | CJS_Value& vRet, |
| 1280 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1281 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1282 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1283 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1286 | if (m_Icons.empty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1287 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1289 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1290 | for (const auto& pIconElement : m_Icons) { |
| 1291 | if (pIconElement->IconName != swIconName) |
| 1292 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1294 | v8::Local<v8::Object> pObj = |
| 1295 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1296 | if (pObj.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1297 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1298 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1299 | CJS_Icon* pJS_Icon = |
| 1300 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1301 | if (!pJS_Icon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1302 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1303 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1304 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1305 | if (!pIcon) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1306 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1307 | |
thestig | dadea5f | 2016-10-19 13:29:48 -0700 | [diff] [blame] | 1308 | pIcon->SetIconName(swIconName); |
| 1309 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1310 | |
| 1311 | vRet = CJS_Value(pRuntime, pJS_Icon); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1312 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1315 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1318 | bool Document::removeIcon(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1319 | const std::vector<CJS_Value>& params, |
| 1320 | CJS_Value& vRet, |
| 1321 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1322 | // Unsafe, no supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1323 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1326 | bool Document::createDataObject(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1327 | const std::vector<CJS_Value>& params, |
| 1328 | CJS_Value& vRet, |
| 1329 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1330 | // Unsafe, not implemented. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1331 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1334 | bool Document::media(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1335 | CJS_PropValue& vp, |
| 1336 | CFX_WideString& sError) { |
| 1337 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1340 | bool Document::calculateNow(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1341 | const std::vector<CJS_Value>& params, |
| 1342 | CJS_Value& vRet, |
| 1343 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1344 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1345 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1346 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1347 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1348 | if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 1349 | m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1350 | m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1351 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1352 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1353 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1354 | m_pFormFillEnv->GetInterForm()->OnCalculate(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1355 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1358 | bool Document::Collab(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1359 | CJS_PropValue& vp, |
| 1360 | CFX_WideString& sError) { |
| 1361 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1364 | bool Document::getPageNthWord(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1365 | const std::vector<CJS_Value>& params, |
| 1366 | CJS_Value& vRet, |
| 1367 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1368 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1369 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1370 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1371 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1372 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1373 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1374 | return false; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1375 | } |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1376 | |
| 1377 | // TODO(tsepez): check maximum allowable params. |
| 1378 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1379 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1380 | int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1381 | bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1382 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1383 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1384 | if (!pDocument) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1385 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1386 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1387 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1388 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1389 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1390 | } |
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 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1393 | if (!pPageDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1394 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1395 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1396 | CPDF_Page page(pDocument, pPageDict, true); |
| 1397 | page.ParseContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1398 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1399 | int nWords = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1400 | CFX_WideString swRet; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1401 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1402 | if (pPageObj->IsText()) { |
| 1403 | CPDF_TextObject* pTextObj = pPageObj->AsText(); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1404 | int nObjWords = CountWords(pTextObj); |
| 1405 | if (nWords + nObjWords >= nWordNo) { |
| 1406 | swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1407 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1409 | nWords += nObjWords; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1410 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1411 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1412 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1413 | if (bStrip) { |
| 1414 | swRet.TrimLeft(); |
| 1415 | swRet.TrimRight(); |
| 1416 | } |
| 1417 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1418 | vRet = CJS_Value(pRuntime, swRet.c_str()); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1419 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1422 | bool Document::getPageNthWordQuads(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1423 | const std::vector<CJS_Value>& params, |
| 1424 | CJS_Value& vRet, |
| 1425 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1426 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1427 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1428 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1429 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1430 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1431 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1432 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1433 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1434 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1437 | bool Document::getPageNumWords(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1438 | const std::vector<CJS_Value>& params, |
| 1439 | CJS_Value& vRet, |
| 1440 | CFX_WideString& sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1441 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1442 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1443 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1444 | } |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1445 | if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1446 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1447 | return false; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1448 | } |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1449 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1450 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1451 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1452 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1453 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1457 | if (!pPageDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1458 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1459 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1460 | CPDF_Page page(pDocument, pPageDict, true); |
| 1461 | page.ParseContent(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1462 | |
| 1463 | int nWords = 0; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1464 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1465 | if (pPageObj->IsText()) |
| 1466 | nWords += CountWords(pPageObj->AsText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1469 | vRet = CJS_Value(pRuntime, nWords); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1470 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1473 | bool Document::getPrintParams(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1474 | const std::vector<CJS_Value>& params, |
| 1475 | CJS_Value& vRet, |
| 1476 | CFX_WideString& sError) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1477 | v8::Local<v8::Object> pRetObj = |
| 1478 | pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1479 | |
| 1480 | // Not implemented yet. |
| 1481 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1482 | vRet = CJS_Value(pRuntime, pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1483 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1487 | |
| 1488 | int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1489 | if (!pTextObj) |
| 1490 | return 0; |
| 1491 | |
| 1492 | int nWords = 0; |
| 1493 | |
| 1494 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1495 | if (!pFont) |
| 1496 | return 0; |
| 1497 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1498 | bool bIsLatin = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1499 | |
| 1500 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1501 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1502 | FX_FLOAT kerning; |
| 1503 | |
Nicolas Pena | 58e4c5a | 2017-02-13 16:08:51 -0500 | [diff] [blame] | 1504 | pTextObj->GetCharInfo(i, &charcode, &kerning); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1505 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1506 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1507 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1508 | if (swUnicode.GetLength() > 0) |
| 1509 | unicode = swUnicode[0]; |
| 1510 | |
| 1511 | if (ISLATINWORD(unicode) && bIsLatin) |
| 1512 | continue; |
| 1513 | |
| 1514 | bIsLatin = ISLATINWORD(unicode); |
| 1515 | if (unicode != 0x20) |
| 1516 | nWords++; |
| 1517 | } |
| 1518 | |
| 1519 | return nWords; |
| 1520 | } |
| 1521 | |
| 1522 | CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1523 | int nWordIndex) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1524 | CFX_WideString swRet; |
| 1525 | |
| 1526 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1527 | if (!pFont) |
| 1528 | return L""; |
| 1529 | |
| 1530 | int nWords = 0; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1531 | bool bIsLatin = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1532 | |
| 1533 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1534 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1535 | FX_FLOAT kerning; |
| 1536 | |
Nicolas Pena | 58e4c5a | 2017-02-13 16:08:51 -0500 | [diff] [blame] | 1537 | pTextObj->GetCharInfo(i, &charcode, &kerning); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1538 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1539 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1540 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1541 | if (swUnicode.GetLength() > 0) |
| 1542 | unicode = swUnicode[0]; |
| 1543 | |
| 1544 | if (ISLATINWORD(unicode) && bIsLatin) { |
| 1545 | } else { |
| 1546 | bIsLatin = ISLATINWORD(unicode); |
| 1547 | if (unicode != 0x20) |
| 1548 | nWords++; |
| 1549 | } |
| 1550 | |
| 1551 | if (nWords - 1 == nWordIndex) |
| 1552 | swRet += unicode; |
| 1553 | } |
| 1554 | |
| 1555 | return swRet; |
| 1556 | } |
| 1557 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1558 | bool Document::zoom(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1559 | CJS_PropValue& vp, |
| 1560 | CFX_WideString& sError) { |
| 1561 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | /** |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1565 | (none, NoVary) |
| 1566 | (fitP, FitPage) |
| 1567 | (fitW, FitWidth) |
| 1568 | (fitH, FitHeight) |
| 1569 | (fitV, FitVisibleWidth) |
| 1570 | (pref, Preferred) |
| 1571 | (refW, ReflowWidth) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1572 | */ |
| 1573 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1574 | bool Document::zoomType(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1575 | CJS_PropValue& vp, |
| 1576 | CFX_WideString& sError) { |
| 1577 | return true; |
| 1578 | } |
| 1579 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1580 | bool Document::deletePages(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1581 | const std::vector<CJS_Value>& params, |
| 1582 | CJS_Value& vRet, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1583 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1584 | // Unsafe, no supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1585 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1586 | } |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1587 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1588 | bool Document::extractPages(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1589 | const std::vector<CJS_Value>& params, |
| 1590 | CJS_Value& vRet, |
| 1591 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1592 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1593 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1596 | bool Document::insertPages(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1597 | const std::vector<CJS_Value>& params, |
| 1598 | CJS_Value& vRet, |
| 1599 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1600 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1601 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1604 | bool Document::replacePages(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1605 | const std::vector<CJS_Value>& params, |
| 1606 | CJS_Value& vRet, |
| 1607 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1608 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1609 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1612 | bool Document::getURL(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1613 | const std::vector<CJS_Value>& params, |
| 1614 | CJS_Value& vRet, |
| 1615 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1616 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1617 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 1620 | bool Document::gotoNamedDest(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1621 | const std::vector<CJS_Value>& params, |
| 1622 | CJS_Value& vRet, |
| 1623 | CFX_WideString& sError) { |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1624 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1625 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1626 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1627 | } |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1628 | if (!m_pFormFillEnv) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1629 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1630 | return false; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1631 | } |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1632 | CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1633 | CFX_ByteString utf8Name = wideName.UTF8Encode(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1634 | CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1635 | if (!pDocument) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1636 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1637 | |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1638 | CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1639 | CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1640 | if (!destArray) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1641 | return false; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1642 | |
| 1643 | CPDF_Dest dest(destArray); |
| 1644 | const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1645 | |
| 1646 | std::unique_ptr<float[]> scrollPositionArray; |
| 1647 | int scrollPositionArraySize = 0; |
| 1648 | |
| 1649 | if (arrayObject) { |
| 1650 | scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1651 | int j = 0; |
| 1652 | for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1653 | scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1654 | scrollPositionArraySize = j; |
| 1655 | } |
| 1656 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1657 | pRuntime->BeginBlock(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1658 | m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1659 | scrollPositionArray.get(), |
| 1660 | scrollPositionArraySize); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1661 | pRuntime->EndBlock(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1662 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1663 | return true; |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1666 | void Document::AddDelayData(CJS_DelayData* pData) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1667 | m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1671 | int nControlIndex) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1672 | std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1673 | auto iter = m_DelayData.begin(); |
| 1674 | while (iter != m_DelayData.end()) { |
| 1675 | auto old = iter++; |
| 1676 | if ((*old)->sFieldName == sFieldName && |
| 1677 | (*old)->nControlIndex == nControlIndex) { |
| 1678 | DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1679 | m_DelayData.erase(old); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1683 | for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1684 | Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1687 | CJS_Document* Document::GetCJSDoc() const { |
| 1688 | return static_cast<CJS_Document*>(m_pJSObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1689 | } |