1 // Copyright 2017 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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FXJS_CJS_DOCUMENT_H_ 8 #define FXJS_CJS_DOCUMENT_H_ 9 10 #include <list> 11 #include <memory> 12 #include <vector> 13 14 #include "fxjs/JS_Define.h" 15 16 class CJS_Document; 17 class CPDF_TextObject; 18 19 struct CJS_DelayData; 20 21 class Document : public CJS_EmbedObj { 22 public: 23 explicit Document(CJS_Object* pJSObject); 24 ~Document() override; 25 26 CJS_Return get_ADBE(CJS_Runtime* pRuntime); 27 CJS_Return set_ADBE(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 28 29 CJS_Return get_author(CJS_Runtime* pRuntime); 30 CJS_Return set_author(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 31 32 CJS_Return get_base_URL(CJS_Runtime* pRuntime); 33 CJS_Return set_base_URL(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 34 35 CJS_Return get_bookmark_root(CJS_Runtime* pRuntime); 36 CJS_Return set_bookmark_root(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 37 38 CJS_Return get_calculate(CJS_Runtime* pRuntime); 39 CJS_Return set_calculate(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 40 41 CJS_Return get_collab(CJS_Runtime* pRuntime); 42 CJS_Return set_collab(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 43 44 CJS_Return get_creation_date(CJS_Runtime* pRuntime); 45 CJS_Return set_creation_date(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 46 47 CJS_Return get_creator(CJS_Runtime* pRuntime); 48 CJS_Return set_creator(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 49 50 CJS_Return get_delay(CJS_Runtime* pRuntime); 51 CJS_Return set_delay(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 52 53 CJS_Return get_dirty(CJS_Runtime* pRuntime); 54 CJS_Return set_dirty(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 55 56 CJS_Return get_document_file_name(CJS_Runtime* pRuntime); 57 CJS_Return set_document_file_name(CJS_Runtime* pRuntime, 58 v8::Local<v8::Value> vp); 59 60 CJS_Return get_external(CJS_Runtime* pRuntime); 61 CJS_Return set_external(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 62 63 CJS_Return get_filesize(CJS_Runtime* pRuntime); 64 CJS_Return set_filesize(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 65 66 CJS_Return get_icons(CJS_Runtime* pRuntime); 67 CJS_Return set_icons(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 68 69 CJS_Return get_info(CJS_Runtime* pRuntime); 70 CJS_Return set_info(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 71 72 CJS_Return get_keywords(CJS_Runtime* pRuntime); 73 CJS_Return set_keywords(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 74 75 CJS_Return get_layout(CJS_Runtime* pRuntime); 76 CJS_Return set_layout(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 77 78 CJS_Return get_media(CJS_Runtime* pRuntime); 79 CJS_Return set_media(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 80 81 CJS_Return get_mod_date(CJS_Runtime* pRuntime); 82 CJS_Return set_mod_date(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 83 84 CJS_Return get_mouse_x(CJS_Runtime* pRuntime); 85 CJS_Return set_mouse_x(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 86 87 CJS_Return get_mouse_y(CJS_Runtime* pRuntime); 88 CJS_Return set_mouse_y(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 89 90 CJS_Return get_num_fields(CJS_Runtime* pRuntime); 91 CJS_Return set_num_fields(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 92 93 CJS_Return get_num_pages(CJS_Runtime* pRuntime); 94 CJS_Return set_num_pages(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 95 96 CJS_Return get_page_num(CJS_Runtime* pRuntime); 97 CJS_Return set_page_num(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 98 99 CJS_Return get_page_window_rect(CJS_Runtime* pRuntime); 100 CJS_Return set_page_window_rect(CJS_Runtime* pRuntime, 101 v8::Local<v8::Value> vp); 102 103 CJS_Return get_path(CJS_Runtime* pRuntime); 104 CJS_Return set_path(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 105 106 CJS_Return get_producer(CJS_Runtime* pRuntime); 107 CJS_Return set_producer(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 108 109 CJS_Return get_subject(CJS_Runtime* pRuntime); 110 CJS_Return set_subject(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 111 112 CJS_Return get_title(CJS_Runtime* pRuntime); 113 CJS_Return set_title(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 114 115 CJS_Return get_zoom(CJS_Runtime* pRuntime); 116 CJS_Return set_zoom(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 117 118 CJS_Return get_zoom_type(CJS_Runtime* pRuntime); 119 CJS_Return set_zoom_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 120 121 CJS_Return get_URL(CJS_Runtime* pRuntime); 122 CJS_Return set_URL(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 123 124 CJS_Return addAnnot(CJS_Runtime* pRuntime, 125 const std::vector<v8::Local<v8::Value>>& params); 126 CJS_Return addField(CJS_Runtime* pRuntime, 127 const std::vector<v8::Local<v8::Value>>& params); 128 CJS_Return addLink(CJS_Runtime* pRuntime, 129 const std::vector<v8::Local<v8::Value>>& params); 130 CJS_Return addIcon(CJS_Runtime* pRuntime, 131 const std::vector<v8::Local<v8::Value>>& params); 132 CJS_Return calculateNow(CJS_Runtime* pRuntime, 133 const std::vector<v8::Local<v8::Value>>& params); 134 CJS_Return closeDoc(CJS_Runtime* pRuntime, 135 const std::vector<v8::Local<v8::Value>>& params); 136 CJS_Return createDataObject(CJS_Runtime* pRuntime, 137 const std::vector<v8::Local<v8::Value>>& params); 138 CJS_Return deletePages(CJS_Runtime* pRuntime, 139 const std::vector<v8::Local<v8::Value>>& params); 140 CJS_Return exportAsText(CJS_Runtime* pRuntime, 141 const std::vector<v8::Local<v8::Value>>& params); 142 CJS_Return exportAsFDF(CJS_Runtime* pRuntime, 143 const std::vector<v8::Local<v8::Value>>& params); 144 CJS_Return exportAsXFDF(CJS_Runtime* pRuntime, 145 const std::vector<v8::Local<v8::Value>>& params); 146 CJS_Return extractPages(CJS_Runtime* pRuntime, 147 const std::vector<v8::Local<v8::Value>>& params); 148 CJS_Return getAnnot(CJS_Runtime* pRuntime, 149 const std::vector<v8::Local<v8::Value>>& params); 150 CJS_Return getAnnots(CJS_Runtime* pRuntime, 151 const std::vector<v8::Local<v8::Value>>& params); 152 CJS_Return getAnnot3D(CJS_Runtime* pRuntime, 153 const std::vector<v8::Local<v8::Value>>& params); 154 CJS_Return getAnnots3D(CJS_Runtime* pRuntime, 155 const std::vector<v8::Local<v8::Value>>& params); 156 CJS_Return getField(CJS_Runtime* pRuntime, 157 const std::vector<v8::Local<v8::Value>>& params); 158 CJS_Return getIcon(CJS_Runtime* pRuntime, 159 const std::vector<v8::Local<v8::Value>>& params); 160 CJS_Return getLinks(CJS_Runtime* pRuntime, 161 const std::vector<v8::Local<v8::Value>>& params); 162 CJS_Return getNthFieldName(CJS_Runtime* pRuntime, 163 const std::vector<v8::Local<v8::Value>>& params); 164 CJS_Return getOCGs(CJS_Runtime* pRuntime, 165 const std::vector<v8::Local<v8::Value>>& params); 166 CJS_Return getPageBox(CJS_Runtime* pRuntime, 167 const std::vector<v8::Local<v8::Value>>& params); 168 CJS_Return getPageNthWord(CJS_Runtime* pRuntime, 169 const std::vector<v8::Local<v8::Value>>& params); 170 CJS_Return getPageNthWordQuads( 171 CJS_Runtime* pRuntime, 172 const std::vector<v8::Local<v8::Value>>& params); 173 CJS_Return getPageNumWords(CJS_Runtime* pRuntime, 174 const std::vector<v8::Local<v8::Value>>& params); 175 CJS_Return getPrintParams(CJS_Runtime* pRuntime, 176 const std::vector<v8::Local<v8::Value>>& params); 177 CJS_Return getURL(CJS_Runtime* pRuntime, 178 const std::vector<v8::Local<v8::Value>>& params); 179 CJS_Return gotoNamedDest(CJS_Runtime* pRuntime, 180 const std::vector<v8::Local<v8::Value>>& params); 181 CJS_Return importAnFDF(CJS_Runtime* pRuntime, 182 const std::vector<v8::Local<v8::Value>>& params); 183 CJS_Return importAnXFDF(CJS_Runtime* pRuntime, 184 const std::vector<v8::Local<v8::Value>>& params); 185 CJS_Return importTextData(CJS_Runtime* pRuntime, 186 const std::vector<v8::Local<v8::Value>>& params); 187 CJS_Return insertPages(CJS_Runtime* pRuntime, 188 const std::vector<v8::Local<v8::Value>>& params); 189 CJS_Return mailForm(CJS_Runtime* pRuntime, 190 const std::vector<v8::Local<v8::Value>>& params); 191 CJS_Return print(CJS_Runtime* pRuntime, 192 const std::vector<v8::Local<v8::Value>>& params); 193 CJS_Return removeField(CJS_Runtime* pRuntime, 194 const std::vector<v8::Local<v8::Value>>& params); 195 CJS_Return replacePages(CJS_Runtime* pRuntime, 196 const std::vector<v8::Local<v8::Value>>& params); 197 CJS_Return resetForm(CJS_Runtime* pRuntime, 198 const std::vector<v8::Local<v8::Value>>& params); 199 CJS_Return saveAs(CJS_Runtime* pRuntime, 200 const std::vector<v8::Local<v8::Value>>& params); 201 CJS_Return submitForm(CJS_Runtime* pRuntime, 202 const std::vector<v8::Local<v8::Value>>& params); 203 CJS_Return syncAnnotScan(CJS_Runtime* pRuntime, 204 const std::vector<v8::Local<v8::Value>>& params); 205 CJS_Return mailDoc(CJS_Runtime* pRuntime, 206 const std::vector<v8::Local<v8::Value>>& params); 207 CJS_Return removeIcon(CJS_Runtime* pRuntime, 208 const std::vector<v8::Local<v8::Value>>& params); 209 210 void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); GetFormFillEnv()211 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { 212 return m_pFormFillEnv.Get(); 213 } 214 void AddDelayData(CJS_DelayData* pData); 215 void DoFieldDelay(const WideString& sFieldName, int nControlIndex); 216 CJS_Document* GetCJSDoc() const; 217 218 private: 219 bool IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect); 220 int CountWords(CPDF_TextObject* pTextObj); 221 WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); 222 223 CJS_Return getPropertyInternal(CJS_Runtime* pRuntime, 224 const ByteString& propName); 225 CJS_Return setPropertyInternal(CJS_Runtime* pRuntime, 226 v8::Local<v8::Value> vp, 227 const ByteString& propName); 228 229 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; 230 WideString m_cwBaseURL; 231 std::list<std::unique_ptr<CJS_DelayData>> m_DelayData; 232 // Needs to be a std::list for iterator stability. 233 std::list<WideString> m_IconNames; 234 bool m_bDelay; 235 }; 236 237 class CJS_Document : public CJS_Object { 238 public: 239 static int GetObjDefnID(); 240 static void DefineJSObjects(CFXJS_Engine* pEngine); 241 CJS_Document(v8::Local<v8::Object> pObject)242 explicit CJS_Document(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Document()243 ~CJS_Document() override {} 244 245 // CJS_Object 246 void InitInstance(IJS_Runtime* pIRuntime) override; 247 248 JS_STATIC_PROP(ADBE, ADBE, Document); 249 JS_STATIC_PROP(author, author, Document); 250 JS_STATIC_PROP(baseURL, base_URL, Document); 251 JS_STATIC_PROP(bookmarkRoot, bookmark_root, Document); 252 JS_STATIC_PROP(calculate, calculate, Document); 253 JS_STATIC_PROP(Collab, collab, Document); 254 JS_STATIC_PROP(creationDate, creation_date, Document); 255 JS_STATIC_PROP(creator, creator, Document); 256 JS_STATIC_PROP(delay, delay, Document); 257 JS_STATIC_PROP(dirty, dirty, Document); 258 JS_STATIC_PROP(documentFileName, document_file_name, Document); 259 JS_STATIC_PROP(external, external, Document); 260 JS_STATIC_PROP(filesize, filesize, Document); 261 JS_STATIC_PROP(icons, icons, Document); 262 JS_STATIC_PROP(info, info, Document); 263 JS_STATIC_PROP(keywords, keywords, Document); 264 JS_STATIC_PROP(layout, layout, Document); 265 JS_STATIC_PROP(media, media, Document); 266 JS_STATIC_PROP(modDate, mod_date, Document); 267 JS_STATIC_PROP(mouseX, mouse_x, Document); 268 JS_STATIC_PROP(mouseY, mouse_y, Document); 269 JS_STATIC_PROP(numFields, num_fields, Document); 270 JS_STATIC_PROP(numPages, num_pages, Document); 271 JS_STATIC_PROP(pageNum, page_num, Document); 272 JS_STATIC_PROP(pageWindowRect, page_window_rect, Document); 273 JS_STATIC_PROP(path, path, Document); 274 JS_STATIC_PROP(producer, producer, Document); 275 JS_STATIC_PROP(subject, subject, Document); 276 JS_STATIC_PROP(title, title, Document); 277 JS_STATIC_PROP(URL, URL, Document); 278 JS_STATIC_PROP(zoom, zoom, Document); 279 JS_STATIC_PROP(zoomType, zoom_type, Document); 280 281 JS_STATIC_METHOD(addAnnot, Document); 282 JS_STATIC_METHOD(addField, Document); 283 JS_STATIC_METHOD(addLink, Document); 284 JS_STATIC_METHOD(addIcon, Document); 285 JS_STATIC_METHOD(calculateNow, Document); 286 JS_STATIC_METHOD(closeDoc, Document); 287 JS_STATIC_METHOD(createDataObject, Document); 288 JS_STATIC_METHOD(deletePages, Document); 289 JS_STATIC_METHOD(exportAsText, Document); 290 JS_STATIC_METHOD(exportAsFDF, Document); 291 JS_STATIC_METHOD(exportAsXFDF, Document); 292 JS_STATIC_METHOD(extractPages, Document); 293 JS_STATIC_METHOD(getAnnot, Document); 294 JS_STATIC_METHOD(getAnnots, Document); 295 JS_STATIC_METHOD(getAnnot3D, Document); 296 JS_STATIC_METHOD(getAnnots3D, Document); 297 JS_STATIC_METHOD(getField, Document); 298 JS_STATIC_METHOD(getIcon, Document); 299 JS_STATIC_METHOD(getLinks, Document); 300 JS_STATIC_METHOD(getNthFieldName, Document); 301 JS_STATIC_METHOD(getOCGs, Document); 302 JS_STATIC_METHOD(getPageBox, Document); 303 JS_STATIC_METHOD(getPageNthWord, Document); 304 JS_STATIC_METHOD(getPageNthWordQuads, Document); 305 JS_STATIC_METHOD(getPageNumWords, Document); 306 JS_STATIC_METHOD(getPrintParams, Document); 307 JS_STATIC_METHOD(getURL, Document); 308 JS_STATIC_METHOD(gotoNamedDest, Document); 309 JS_STATIC_METHOD(importAnFDF, Document); 310 JS_STATIC_METHOD(importAnXFDF, Document); 311 JS_STATIC_METHOD(importTextData, Document); 312 JS_STATIC_METHOD(insertPages, Document); 313 JS_STATIC_METHOD(mailForm, Document); 314 JS_STATIC_METHOD(print, Document); 315 JS_STATIC_METHOD(removeField, Document); 316 JS_STATIC_METHOD(replacePages, Document); 317 JS_STATIC_METHOD(removeIcon, Document); 318 JS_STATIC_METHOD(resetForm, Document); 319 JS_STATIC_METHOD(saveAs, Document); 320 JS_STATIC_METHOD(submitForm, Document); 321 JS_STATIC_METHOD(syncAnnotScan, Document); 322 JS_STATIC_METHOD(mailDoc, Document); 323 324 private: 325 static int ObjDefnID; 326 static const JSPropertySpec PropertySpecs[]; 327 static const JSMethodSpec MethodSpecs[]; 328 }; 329 330 #endif // FXJS_CJS_DOCUMENT_H_ 331