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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_DOCUMENT_H_ 8 #define FPDFSDK_SRC_JAVASCRIPT_DOCUMENT_H_ 9 10 #include <list> 11 #include <memory> 12 13 #include "JS_Define.h" 14 15 class PrintParamsObj : public CJS_EmbedObj { 16 public: 17 PrintParamsObj(CJS_Object* pJSObject); 18 ~PrintParamsObj() override {} 19 20 public: 21 FX_BOOL bUI; 22 int nStart; 23 int nEnd; 24 FX_BOOL bSilent; 25 FX_BOOL bShrinkToFit; 26 FX_BOOL bPrintAsImage; 27 FX_BOOL bReverse; 28 FX_BOOL bAnnotations; 29 }; 30 31 class CJS_PrintParamsObj : public CJS_Object { 32 public: 33 CJS_PrintParamsObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} 34 ~CJS_PrintParamsObj() override {} 35 36 DECLARE_JS_CLASS(); 37 }; 38 39 class Icon; 40 class Field; 41 42 struct IconElement { 43 IconElement(const CFX_WideString& name, Icon* stream) 44 : IconName(name), IconStream(stream) {} 45 46 CFX_WideString IconName; 47 Icon* IconStream; 48 }; 49 50 struct CJS_DelayData; 51 struct CJS_DelayAnnot; 52 struct CJS_AnnotObj; 53 54 class Document : public CJS_EmbedObj { 55 public: 56 Document(CJS_Object* pJSObject); 57 ~Document() override; 58 59 FX_BOOL ADBE(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 60 FX_BOOL author(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 61 FX_BOOL baseURL(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 62 FX_BOOL bookmarkRoot(IJS_Context* cc, 63 CJS_PropValue& vp, 64 CFX_WideString& sError); 65 FX_BOOL calculate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 66 FX_BOOL Collab(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 67 FX_BOOL creationDate(IJS_Context* cc, 68 CJS_PropValue& vp, 69 CFX_WideString& sError); 70 FX_BOOL creator(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 71 FX_BOOL delay(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 72 FX_BOOL dirty(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 73 FX_BOOL documentFileName(IJS_Context* cc, 74 CJS_PropValue& vp, 75 CFX_WideString& sError); 76 FX_BOOL external(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 77 FX_BOOL filesize(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 78 FX_BOOL icons(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 79 FX_BOOL info(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 80 FX_BOOL keywords(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 81 FX_BOOL layout(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 82 FX_BOOL media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 83 FX_BOOL modDate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 84 FX_BOOL mouseX(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 85 FX_BOOL mouseY(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 86 FX_BOOL numFields(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 87 FX_BOOL numPages(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 88 FX_BOOL pageNum(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 89 FX_BOOL pageWindowRect(IJS_Context* cc, 90 CJS_PropValue& vp, 91 CFX_WideString& sError); 92 FX_BOOL path(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 93 FX_BOOL producer(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 94 FX_BOOL subject(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 95 FX_BOOL title(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 96 FX_BOOL zoom(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 97 FX_BOOL zoomType(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 98 99 FX_BOOL addAnnot(IJS_Context* cc, 100 const std::vector<CJS_Value>& params, 101 CJS_Value& vRet, 102 CFX_WideString& sError); 103 FX_BOOL addField(IJS_Context* cc, 104 const std::vector<CJS_Value>& params, 105 CJS_Value& vRet, 106 CFX_WideString& sError); 107 FX_BOOL addLink(IJS_Context* cc, 108 const std::vector<CJS_Value>& params, 109 CJS_Value& vRet, 110 CFX_WideString& sError); 111 FX_BOOL addIcon(IJS_Context* cc, 112 const std::vector<CJS_Value>& params, 113 CJS_Value& vRet, 114 CFX_WideString& sError); 115 FX_BOOL calculateNow(IJS_Context* cc, 116 const std::vector<CJS_Value>& params, 117 CJS_Value& vRet, 118 CFX_WideString& sError); 119 FX_BOOL closeDoc(IJS_Context* cc, 120 const std::vector<CJS_Value>& params, 121 CJS_Value& vRet, 122 CFX_WideString& sError); 123 FX_BOOL createDataObject(IJS_Context* cc, 124 const std::vector<CJS_Value>& params, 125 CJS_Value& vRet, 126 CFX_WideString& sError); 127 FX_BOOL deletePages(IJS_Context* cc, 128 const std::vector<CJS_Value>& params, 129 CJS_Value& vRet, 130 CFX_WideString& sError); 131 FX_BOOL exportAsText(IJS_Context* cc, 132 const std::vector<CJS_Value>& params, 133 CJS_Value& vRet, 134 CFX_WideString& sError); 135 FX_BOOL exportAsFDF(IJS_Context* cc, 136 const std::vector<CJS_Value>& params, 137 CJS_Value& vRet, 138 CFX_WideString& sError); 139 FX_BOOL exportAsXFDF(IJS_Context* cc, 140 const std::vector<CJS_Value>& params, 141 CJS_Value& vRet, 142 CFX_WideString& sError); 143 FX_BOOL extractPages(IJS_Context* cc, 144 const std::vector<CJS_Value>& params, 145 CJS_Value& vRet, 146 CFX_WideString& sError); 147 FX_BOOL getAnnot(IJS_Context* cc, 148 const std::vector<CJS_Value>& params, 149 CJS_Value& vRet, 150 CFX_WideString& sError); 151 FX_BOOL getAnnots(IJS_Context* cc, 152 const std::vector<CJS_Value>& params, 153 CJS_Value& vRet, 154 CFX_WideString& sError); 155 FX_BOOL getAnnot3D(IJS_Context* cc, 156 const std::vector<CJS_Value>& params, 157 CJS_Value& vRet, 158 CFX_WideString& sError); 159 FX_BOOL getAnnots3D(IJS_Context* cc, 160 const std::vector<CJS_Value>& params, 161 CJS_Value& vRet, 162 CFX_WideString& sError); 163 FX_BOOL getField(IJS_Context* cc, 164 const std::vector<CJS_Value>& params, 165 CJS_Value& vRet, 166 CFX_WideString& sError); 167 FX_BOOL getIcon(IJS_Context* cc, 168 const std::vector<CJS_Value>& params, 169 CJS_Value& vRet, 170 CFX_WideString& sError); 171 FX_BOOL getLinks(IJS_Context* cc, 172 const std::vector<CJS_Value>& params, 173 CJS_Value& vRet, 174 CFX_WideString& sError); 175 FX_BOOL getNthFieldName(IJS_Context* cc, 176 const std::vector<CJS_Value>& params, 177 CJS_Value& vRet, 178 CFX_WideString& sError); 179 FX_BOOL getOCGs(IJS_Context* cc, 180 const std::vector<CJS_Value>& params, 181 CJS_Value& vRet, 182 CFX_WideString& sError); 183 FX_BOOL getPageBox(IJS_Context* cc, 184 const std::vector<CJS_Value>& params, 185 CJS_Value& vRet, 186 CFX_WideString& sError); 187 FX_BOOL getPageNthWord(IJS_Context* cc, 188 const std::vector<CJS_Value>& params, 189 CJS_Value& vRet, 190 CFX_WideString& sError); 191 FX_BOOL getPageNthWordQuads(IJS_Context* cc, 192 const std::vector<CJS_Value>& params, 193 CJS_Value& vRet, 194 CFX_WideString& sError); 195 FX_BOOL getPageNumWords(IJS_Context* cc, 196 const std::vector<CJS_Value>& params, 197 CJS_Value& vRet, 198 CFX_WideString& sError); 199 FX_BOOL getPrintParams(IJS_Context* cc, 200 const std::vector<CJS_Value>& params, 201 CJS_Value& vRet, 202 CFX_WideString& sError); 203 FX_BOOL getURL(IJS_Context* cc, 204 const std::vector<CJS_Value>& params, 205 CJS_Value& vRet, 206 CFX_WideString& sError); 207 FX_BOOL importAnFDF(IJS_Context* cc, 208 const std::vector<CJS_Value>& params, 209 CJS_Value& vRet, 210 CFX_WideString& sError); 211 FX_BOOL importAnXFDF(IJS_Context* cc, 212 const std::vector<CJS_Value>& params, 213 CJS_Value& vRet, 214 CFX_WideString& sError); 215 FX_BOOL importTextData(IJS_Context* cc, 216 const std::vector<CJS_Value>& params, 217 CJS_Value& vRet, 218 CFX_WideString& sError); 219 FX_BOOL insertPages(IJS_Context* cc, 220 const std::vector<CJS_Value>& params, 221 CJS_Value& vRet, 222 CFX_WideString& sError); 223 FX_BOOL mailForm(IJS_Context* cc, 224 const std::vector<CJS_Value>& params, 225 CJS_Value& vRet, 226 CFX_WideString& sError); 227 FX_BOOL print(IJS_Context* cc, 228 const std::vector<CJS_Value>& params, 229 CJS_Value& vRet, 230 CFX_WideString& sError); 231 FX_BOOL removeField(IJS_Context* cc, 232 const std::vector<CJS_Value>& params, 233 CJS_Value& vRet, 234 CFX_WideString& sError); 235 FX_BOOL replacePages(IJS_Context* cc, 236 const std::vector<CJS_Value>& params, 237 CJS_Value& vRet, 238 CFX_WideString& sError); 239 FX_BOOL resetForm(IJS_Context* cc, 240 const std::vector<CJS_Value>& params, 241 CJS_Value& vRet, 242 CFX_WideString& sError); 243 FX_BOOL saveAs(IJS_Context* cc, 244 const std::vector<CJS_Value>& params, 245 CJS_Value& vRet, 246 CFX_WideString& sError); 247 FX_BOOL submitForm(IJS_Context* cc, 248 const std::vector<CJS_Value>& params, 249 CJS_Value& vRet, 250 CFX_WideString& sError); 251 FX_BOOL mailDoc(IJS_Context* cc, 252 const std::vector<CJS_Value>& params, 253 CJS_Value& vRet, 254 CFX_WideString& sError); 255 FX_BOOL removeIcon(IJS_Context* cc, 256 const std::vector<CJS_Value>& params, 257 CJS_Value& vRet, 258 CFX_WideString& sError); 259 260 void AttachDoc(CPDFSDK_Document* pDoc); 261 CPDFSDK_Document* GetReaderDoc(); 262 void AddDelayData(CJS_DelayData* pData); 263 void DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex); 264 void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } 265 CJS_Document* GetCJSDoc() const; 266 267 private: 268 bool IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect); 269 int CountWords(CPDF_TextObject* pTextObj); 270 CFX_WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); 271 272 v8::Isolate* m_isolate; 273 std::list<std::unique_ptr<IconElement>> m_IconList; 274 CPDFSDK_Document* m_pDocument; 275 CFX_WideString m_cwBaseURL; 276 bool m_bDelay; 277 CFX_ArrayTemplate<CJS_DelayData*> m_DelayData; 278 }; 279 280 class CJS_Document : public CJS_Object { 281 public: 282 explicit CJS_Document(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} 283 ~CJS_Document() override {} 284 285 // CJS_Object 286 void InitInstance(IJS_Runtime* pIRuntime) override; 287 288 DECLARE_JS_CLASS(); 289 290 JS_STATIC_PROP(ADBE, Document); 291 JS_STATIC_PROP(author, Document); 292 JS_STATIC_PROP(baseURL, Document); 293 JS_STATIC_PROP(bookmarkRoot, Document); 294 JS_STATIC_PROP(calculate, Document); 295 JS_STATIC_PROP(Collab, Document); 296 JS_STATIC_PROP(creationDate, Document); 297 JS_STATIC_PROP(creator, Document); 298 JS_STATIC_PROP(delay, Document); 299 JS_STATIC_PROP(dirty, Document); 300 JS_STATIC_PROP(documentFileName, Document); 301 JS_STATIC_PROP(external, Document); 302 JS_STATIC_PROP(filesize, Document); 303 JS_STATIC_PROP(icons, Document); 304 JS_STATIC_PROP(info, Document); 305 JS_STATIC_PROP(keywords, Document); 306 JS_STATIC_PROP(layout, Document); 307 JS_STATIC_PROP(media, Document); 308 JS_STATIC_PROP(modDate, Document); 309 JS_STATIC_PROP(mouseX, Document); 310 JS_STATIC_PROP(mouseY, Document); 311 JS_STATIC_PROP(numFields, Document); 312 JS_STATIC_PROP(numPages, Document); 313 JS_STATIC_PROP(pageNum, Document); 314 JS_STATIC_PROP(pageWindowRect, Document); 315 JS_STATIC_PROP(path, Document); 316 JS_STATIC_PROP(producer, Document); 317 JS_STATIC_PROP(subject, Document); 318 JS_STATIC_PROP(title, Document); 319 JS_STATIC_PROP(zoom, Document); 320 JS_STATIC_PROP(zoomType, Document); 321 322 JS_STATIC_METHOD(addAnnot, Document); 323 JS_STATIC_METHOD(addField, Document); 324 JS_STATIC_METHOD(addLink, Document); 325 JS_STATIC_METHOD(addIcon, Document); 326 JS_STATIC_METHOD(calculateNow, Document); 327 JS_STATIC_METHOD(closeDoc, Document); 328 JS_STATIC_METHOD(createDataObject, Document); 329 JS_STATIC_METHOD(deletePages, Document); 330 JS_STATIC_METHOD(exportAsText, Document); 331 JS_STATIC_METHOD(exportAsFDF, Document); 332 JS_STATIC_METHOD(exportAsXFDF, Document); 333 JS_STATIC_METHOD(extractPages, Document); 334 JS_STATIC_METHOD(getAnnot, Document); 335 JS_STATIC_METHOD(getAnnots, Document); 336 JS_STATIC_METHOD(getAnnot3D, Document); 337 JS_STATIC_METHOD(getAnnots3D, Document); 338 JS_STATIC_METHOD(getField, Document); 339 JS_STATIC_METHOD(getIcon, Document); 340 JS_STATIC_METHOD(getLinks, Document); 341 JS_STATIC_METHOD(getNthFieldName, Document); 342 JS_STATIC_METHOD(getOCGs, Document); 343 JS_STATIC_METHOD(getPageBox, Document); 344 JS_STATIC_METHOD(getPageNthWord, Document); 345 JS_STATIC_METHOD(getPageNthWordQuads, Document); 346 JS_STATIC_METHOD(getPageNumWords, Document); 347 JS_STATIC_METHOD(getPrintParams, Document); 348 JS_STATIC_METHOD(getURL, Document); 349 JS_STATIC_METHOD(importAnFDF, Document); 350 JS_STATIC_METHOD(importAnXFDF, Document); 351 JS_STATIC_METHOD(importTextData, Document); 352 JS_STATIC_METHOD(insertPages, Document); 353 JS_STATIC_METHOD(mailForm, Document); 354 JS_STATIC_METHOD(print, Document); 355 JS_STATIC_METHOD(removeField, Document); 356 JS_STATIC_METHOD(replacePages, Document); 357 JS_STATIC_METHOD(removeIcon, Document); 358 JS_STATIC_METHOD(resetForm, Document); 359 JS_STATIC_METHOD(saveAs, Document); 360 JS_STATIC_METHOD(submitForm, Document); 361 JS_STATIC_METHOD(mailDoc, Document); 362 }; 363 364 #endif // FPDFSDK_SRC_JAVASCRIPT_DOCUMENT_H_ 365