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