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