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