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 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 9 | #include <utility> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
dsinclair | 166bc16 | 2016-09-29 11:58:38 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/fpdf_font/cpdf_font.h" |
dsinclair | 8a752ab | 2016-09-29 11:59:54 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_page/cpdf_page.h" |
dsinclair | c6c425a | 2016-09-29 12:01:30 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_parser/cpdf_array.h" |
| 15 | #include "core/fpdfapi/fpdf_parser/cpdf_document.h" |
| 16 | #include "core/fpdfapi/fpdf_parser/fpdf_parser_decode.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 17 | #include "core/fpdfdoc/cpdf_interform.h" |
| 18 | #include "core/fpdfdoc/cpdf_nametree.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame^] | 19 | #include "fpdfsdk/cpdfsdk_annotiterator.h" |
| 20 | #include "fpdfsdk/cpdfsdk_document.h" |
| 21 | #include "fpdfsdk/cpdfsdk_environment.h" |
| 22 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 23 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 24 | #include "fpdfsdk/cpdfsdk_widget.h" |
tonikitoo | 618cb1f | 2016-08-18 20:10:17 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/javascript/Annot.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 26 | #include "fpdfsdk/javascript/Field.h" |
| 27 | #include "fpdfsdk/javascript/Icon.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 28 | #include "fpdfsdk/javascript/JS_Define.h" |
| 29 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 30 | #include "fpdfsdk/javascript/JS_Object.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 31 | #include "fpdfsdk/javascript/JS_Value.h" |
| 32 | #include "fpdfsdk/javascript/app.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/javascript/cjs_context.h" |
| 34 | #include "fpdfsdk/javascript/cjs_runtime.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 35 | #include "fpdfsdk/javascript/resource.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 36 | #include "third_party/base/numerics/safe_math.h" |
Chris Palmer | 9108ad2 | 2014-06-26 16:01:46 -0700 | [diff] [blame] | 37 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) |
| 39 | END_JS_STATIC_CONST() |
| 40 | |
| 41 | BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
| 42 | END_JS_STATIC_PROP() |
| 43 | |
| 44 | BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
| 45 | END_JS_STATIC_METHOD() |
| 46 | |
| 47 | IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) |
| 48 | |
| 49 | PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | : CJS_EmbedObj(pJSObject) { |
| 51 | bUI = TRUE; |
| 52 | nStart = 0; |
| 53 | nEnd = 0; |
| 54 | bSilent = FALSE; |
| 55 | bShrinkToFit = FALSE; |
| 56 | bPrintAsImage = FALSE; |
| 57 | bReverse = FALSE; |
| 58 | bAnnotations = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | #define MINWIDTH 5.0f |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | #define MINHEIGHT 5.0f |
| 63 | |
| 64 | BEGIN_JS_STATIC_CONST(CJS_Document) |
| 65 | END_JS_STATIC_CONST() |
| 66 | |
| 67 | BEGIN_JS_STATIC_PROP(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | JS_STATIC_PROP_ENTRY(ADBE) |
| 69 | JS_STATIC_PROP_ENTRY(author) |
| 70 | JS_STATIC_PROP_ENTRY(baseURL) |
| 71 | JS_STATIC_PROP_ENTRY(bookmarkRoot) |
| 72 | JS_STATIC_PROP_ENTRY(calculate) |
| 73 | JS_STATIC_PROP_ENTRY(Collab) |
| 74 | JS_STATIC_PROP_ENTRY(creationDate) |
| 75 | JS_STATIC_PROP_ENTRY(creator) |
| 76 | JS_STATIC_PROP_ENTRY(delay) |
| 77 | JS_STATIC_PROP_ENTRY(dirty) |
| 78 | JS_STATIC_PROP_ENTRY(documentFileName) |
| 79 | JS_STATIC_PROP_ENTRY(external) |
| 80 | JS_STATIC_PROP_ENTRY(filesize) |
| 81 | JS_STATIC_PROP_ENTRY(icons) |
| 82 | JS_STATIC_PROP_ENTRY(info) |
| 83 | JS_STATIC_PROP_ENTRY(keywords) |
| 84 | JS_STATIC_PROP_ENTRY(layout) |
| 85 | JS_STATIC_PROP_ENTRY(media) |
| 86 | JS_STATIC_PROP_ENTRY(modDate) |
| 87 | JS_STATIC_PROP_ENTRY(mouseX) |
| 88 | JS_STATIC_PROP_ENTRY(mouseY) |
| 89 | JS_STATIC_PROP_ENTRY(numFields) |
| 90 | JS_STATIC_PROP_ENTRY(numPages) |
| 91 | JS_STATIC_PROP_ENTRY(pageNum) |
| 92 | JS_STATIC_PROP_ENTRY(pageWindowRect) |
| 93 | JS_STATIC_PROP_ENTRY(path) |
| 94 | JS_STATIC_PROP_ENTRY(producer) |
| 95 | JS_STATIC_PROP_ENTRY(subject) |
| 96 | JS_STATIC_PROP_ENTRY(title) |
tonikitoo | 33c4cdb | 2016-08-08 10:52:51 -0700 | [diff] [blame] | 97 | JS_STATIC_PROP_ENTRY(URL) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | JS_STATIC_PROP_ENTRY(zoom) |
| 99 | JS_STATIC_PROP_ENTRY(zoomType) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | END_JS_STATIC_PROP() |
| 101 | |
| 102 | BEGIN_JS_STATIC_METHOD(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | JS_STATIC_METHOD_ENTRY(addAnnot) |
| 104 | JS_STATIC_METHOD_ENTRY(addField) |
| 105 | JS_STATIC_METHOD_ENTRY(addLink) |
| 106 | JS_STATIC_METHOD_ENTRY(addIcon) |
| 107 | JS_STATIC_METHOD_ENTRY(calculateNow) |
| 108 | JS_STATIC_METHOD_ENTRY(closeDoc) |
| 109 | JS_STATIC_METHOD_ENTRY(createDataObject) |
| 110 | JS_STATIC_METHOD_ENTRY(deletePages) |
| 111 | JS_STATIC_METHOD_ENTRY(exportAsText) |
| 112 | JS_STATIC_METHOD_ENTRY(exportAsFDF) |
| 113 | JS_STATIC_METHOD_ENTRY(exportAsXFDF) |
| 114 | JS_STATIC_METHOD_ENTRY(extractPages) |
| 115 | JS_STATIC_METHOD_ENTRY(getAnnot) |
| 116 | JS_STATIC_METHOD_ENTRY(getAnnots) |
| 117 | JS_STATIC_METHOD_ENTRY(getAnnot3D) |
| 118 | JS_STATIC_METHOD_ENTRY(getAnnots3D) |
| 119 | JS_STATIC_METHOD_ENTRY(getField) |
| 120 | JS_STATIC_METHOD_ENTRY(getIcon) |
| 121 | JS_STATIC_METHOD_ENTRY(getLinks) |
| 122 | JS_STATIC_METHOD_ENTRY(getNthFieldName) |
| 123 | JS_STATIC_METHOD_ENTRY(getOCGs) |
| 124 | JS_STATIC_METHOD_ENTRY(getPageBox) |
| 125 | JS_STATIC_METHOD_ENTRY(getPageNthWord) |
| 126 | JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) |
| 127 | JS_STATIC_METHOD_ENTRY(getPageNumWords) |
| 128 | JS_STATIC_METHOD_ENTRY(getPrintParams) |
| 129 | JS_STATIC_METHOD_ENTRY(getURL) |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 130 | JS_STATIC_METHOD_ENTRY(gotoNamedDest) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | JS_STATIC_METHOD_ENTRY(importAnFDF) |
| 132 | JS_STATIC_METHOD_ENTRY(importAnXFDF) |
| 133 | JS_STATIC_METHOD_ENTRY(importTextData) |
| 134 | JS_STATIC_METHOD_ENTRY(insertPages) |
| 135 | JS_STATIC_METHOD_ENTRY(mailForm) |
| 136 | JS_STATIC_METHOD_ENTRY(print) |
| 137 | JS_STATIC_METHOD_ENTRY(removeField) |
| 138 | JS_STATIC_METHOD_ENTRY(replacePages) |
| 139 | JS_STATIC_METHOD_ENTRY(resetForm) |
| 140 | JS_STATIC_METHOD_ENTRY(removeIcon) |
| 141 | JS_STATIC_METHOD_ENTRY(saveAs) |
| 142 | JS_STATIC_METHOD_ENTRY(submitForm) |
tonikitoo | bb5fa04 | 2016-08-19 11:18:29 -0700 | [diff] [blame] | 143 | JS_STATIC_METHOD_ENTRY(syncAnnotScan) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 144 | JS_STATIC_METHOD_ENTRY(mailDoc) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | END_JS_STATIC_METHOD() |
| 146 | |
| 147 | IMPLEMENT_JS_CLASS(CJS_Document, Document) |
| 148 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 149 | void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| 150 | CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 151 | Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
| 152 | pDoc->AttachDoc(pRuntime->GetReaderDocument()); |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 153 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | Document::Document(CJS_Object* pJSObject) |
| 156 | : CJS_EmbedObj(pJSObject), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 157 | m_pDocument(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 158 | m_cwBaseURL(L""), |
| 159 | m_bDelay(FALSE) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | Document::~Document() { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | // the total number of fileds in document. |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 165 | FX_BOOL Document::numFields(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | CJS_PropValue& vp, |
| 167 | CFX_WideString& sError) { |
| 168 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 169 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 170 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | } |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 172 | if (!m_pDocument) { |
| 173 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 174 | return FALSE; |
| 175 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 177 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 178 | vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 182 | FX_BOOL Document::dirty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | CJS_PropValue& vp, |
| 184 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 185 | if (!m_pDocument) { |
| 186 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 187 | return FALSE; |
| 188 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | if (vp.IsGetting()) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 190 | vp << !!m_pDocument->GetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | } else { |
| 192 | bool bChanged = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | vp >> bChanged; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | if (bChanged) |
| 196 | m_pDocument->SetChangeMark(); |
| 197 | else |
| 198 | m_pDocument->ClearChangeMark(); |
| 199 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 203 | FX_BOOL Document::ADBE(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | CJS_PropValue& vp, |
| 205 | CFX_WideString& sError) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 206 | if (vp.IsGetting()) |
| 207 | vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | |
| 209 | return TRUE; |
| 210 | } |
| 211 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 212 | FX_BOOL Document::pageNum(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | CJS_PropValue& vp, |
| 214 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 215 | if (!m_pDocument) { |
| 216 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 217 | return FALSE; |
| 218 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | if (vp.IsGetting()) { |
| 220 | if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { |
| 221 | vp << pPageView->GetPageIndex(); |
| 222 | } |
| 223 | } else { |
| 224 | int iPageCount = m_pDocument->GetPageCount(); |
| 225 | int iPageNum = 0; |
| 226 | vp >> iPageNum; |
| 227 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 228 | CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | if (iPageNum >= 0 && iPageNum < iPageCount) { |
| 230 | pEnv->JS_docgotoPage(iPageNum); |
| 231 | } else if (iPageNum >= iPageCount) { |
| 232 | pEnv->JS_docgotoPage(iPageCount - 1); |
| 233 | } else if (iPageNum < 0) { |
| 234 | pEnv->JS_docgotoPage(0); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | return TRUE; |
| 239 | } |
| 240 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 241 | FX_BOOL Document::addAnnot(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 242 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | CJS_Value& vRet, |
| 244 | CFX_WideString& sError) { |
| 245 | // Not supported. |
| 246 | return TRUE; |
| 247 | } |
| 248 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 249 | FX_BOOL Document::addField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 250 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | CJS_Value& vRet, |
| 252 | CFX_WideString& sError) { |
| 253 | // Not supported. |
| 254 | return TRUE; |
| 255 | } |
| 256 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 257 | FX_BOOL Document::exportAsText(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 258 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | CJS_Value& vRet, |
| 260 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 261 | // Unsafe, not supported. |
| 262 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 265 | FX_BOOL Document::exportAsFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 266 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | CJS_Value& vRet, |
| 268 | CFX_WideString& sError) { |
| 269 | // Unsafe, not supported. |
| 270 | return TRUE; |
| 271 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 272 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 273 | FX_BOOL Document::exportAsXFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 274 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | CJS_Value& vRet, |
| 276 | CFX_WideString& sError) { |
| 277 | // Unsafe, not supported. |
| 278 | return TRUE; |
| 279 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 280 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | // Maps a field object in PDF document to a JavaScript variable |
| 282 | // comment: |
| 283 | // note: the paremter cName, this is clue how to treat if the cName is not a |
| 284 | // valiable filed name in this document |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 285 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 286 | FX_BOOL Document::getField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 287 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | CJS_Value& vRet, |
| 289 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | if (params.size() < 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 291 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 292 | return FALSE; |
| 293 | } |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 294 | if (!m_pDocument) { |
| 295 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 296 | return FALSE; |
| 297 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 298 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 299 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 300 | CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 302 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 303 | if (pPDFForm->CountFields(wideName) <= 0) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 304 | vRet.SetNull(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | return TRUE; |
| 306 | } |
| 307 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 308 | v8::Local<v8::Object> pFieldObj = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 309 | pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 310 | CJS_Field* pJSField = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 311 | static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 312 | Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | pField->AttachField(this, wideName); |
| 314 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 315 | vRet = CJS_Value(pRuntime, pJSField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | return TRUE; |
| 317 | } |
| 318 | |
| 319 | // Gets the name of the nth field in the document |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 320 | FX_BOOL Document::getNthFieldName(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 321 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | CJS_Value& vRet, |
| 323 | CFX_WideString& sError) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 324 | if (params.size() != 1) { |
| 325 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 326 | return FALSE; |
| 327 | } |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 328 | if (!m_pDocument) { |
| 329 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 330 | return FALSE; |
| 331 | } |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 332 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 333 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 334 | int nIndex = params[0].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | if (nIndex < 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 336 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | return FALSE; |
| 338 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 339 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 340 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 341 | CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 342 | if (!pField) |
| 343 | return FALSE; |
| 344 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 345 | vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | return TRUE; |
| 347 | } |
| 348 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 349 | FX_BOOL Document::importAnFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 350 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 351 | CJS_Value& vRet, |
| 352 | CFX_WideString& sError) { |
| 353 | // Unsafe, not supported. |
| 354 | return TRUE; |
| 355 | } |
| 356 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 357 | FX_BOOL Document::importAnXFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 358 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | CJS_Value& vRet, |
| 360 | CFX_WideString& sError) { |
| 361 | // Unsafe, not supported. |
| 362 | return TRUE; |
| 363 | } |
| 364 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 365 | FX_BOOL Document::importTextData(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 366 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | CJS_Value& vRet, |
| 368 | CFX_WideString& sError) { |
| 369 | // Unsafe, not supported. |
| 370 | return TRUE; |
| 371 | } |
| 372 | |
| 373 | // exports the form data and mails the resulting fdf file as an attachment to |
| 374 | // all recipients. |
| 375 | // comment: need reader supports |
| 376 | // note: |
| 377 | // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string |
| 378 | // cbcc,string cSubject,string cms); |
| 379 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 380 | FX_BOOL Document::mailForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 381 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | CJS_Value& vRet, |
| 383 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 384 | if (!m_pDocument) { |
| 385 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 386 | return FALSE; |
| 387 | } |
| 388 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 389 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 390 | return FALSE; |
| 391 | } |
| 392 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 393 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 394 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 395 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | int iLength = params.size(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 397 | FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; |
| 398 | CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 399 | CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 400 | CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 401 | CFX_WideString cSubject = |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 402 | iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 403 | CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 405 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 406 | CFX_ByteTextBuf textBuf; |
| 407 | if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 408 | return FALSE; |
| 409 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | pRuntime->BeginBlock(); |
dsinclair | 8e0638b | 2016-09-22 11:06:02 -0700 | [diff] [blame] | 411 | CPDFSDK_Environment* pEnv = pContext->GetReaderEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 412 | pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 413 | cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 414 | cMsg.c_str()); |
| 415 | pRuntime->EndBlock(); |
| 416 | return TRUE; |
| 417 | } |
| 418 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 419 | FX_BOOL Document::print(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 420 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | CJS_Value& vRet, |
| 422 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 423 | if (!m_pDocument) { |
| 424 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 425 | return FALSE; |
| 426 | } |
| 427 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 428 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 429 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 430 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 431 | FX_BOOL bUI = TRUE; |
| 432 | int nStart = 0; |
| 433 | int nEnd = 0; |
| 434 | FX_BOOL bSilent = FALSE; |
| 435 | FX_BOOL bShrinkToFit = FALSE; |
| 436 | FX_BOOL bPrintAsImage = FALSE; |
| 437 | FX_BOOL bReverse = FALSE; |
| 438 | FX_BOOL bAnnotations = FALSE; |
| 439 | |
| 440 | int nlength = params.size(); |
| 441 | if (nlength == 9) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 442 | if (params[8].GetType() == CJS_Value::VT_object) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 443 | v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); |
| 444 | if (CFXJS_Engine::GetObjDefnID(pObj) == |
| 445 | CJS_PrintParamsObj::g_nObjDefnID) { |
| 446 | if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 447 | if (PrintParamsObj* pprintparamsObj = |
| 448 | static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { |
| 449 | bUI = pprintparamsObj->bUI; |
| 450 | nStart = pprintparamsObj->nStart; |
| 451 | nEnd = pprintparamsObj->nEnd; |
| 452 | bSilent = pprintparamsObj->bSilent; |
| 453 | bShrinkToFit = pprintparamsObj->bShrinkToFit; |
| 454 | bPrintAsImage = pprintparamsObj->bPrintAsImage; |
| 455 | bReverse = pprintparamsObj->bReverse; |
| 456 | bAnnotations = pprintparamsObj->bAnnotations; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 458 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } else { |
| 462 | if (nlength >= 1) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 463 | bUI = params[0].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 464 | if (nlength >= 2) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 465 | nStart = params[1].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | if (nlength >= 3) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 467 | nEnd = params[2].ToInt(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | if (nlength >= 4) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 469 | bSilent = params[3].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | if (nlength >= 5) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 471 | bShrinkToFit = params[4].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | if (nlength >= 6) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 473 | bPrintAsImage = params[5].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | if (nlength >= 7) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 475 | bReverse = params[6].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | if (nlength >= 8) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 477 | bAnnotations = params[7].ToBool(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | } |
| 479 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 480 | if (CPDFSDK_Environment* pEnv = m_pDocument->GetEnv()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, |
| 482 | bReverse, bAnnotations); |
| 483 | return TRUE; |
| 484 | } |
| 485 | return FALSE; |
| 486 | } |
| 487 | |
| 488 | // removes the specified field from the document. |
| 489 | // comment: |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 490 | // 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] | 491 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 492 | FX_BOOL Document::removeField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 493 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | CJS_Value& vRet, |
| 495 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 496 | if (params.size() != 1) { |
| 497 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 498 | return FALSE; |
| 499 | } |
| 500 | if (!m_pDocument) { |
| 501 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 502 | return FALSE; |
| 503 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 504 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 505 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
| 506 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | return FALSE; |
| 508 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 509 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 510 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 511 | CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 512 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 513 | std::vector<CPDFSDK_Widget*> widgets; |
| 514 | pInterForm->GetWidgets(sFieldName, &widgets); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 515 | if (widgets.empty()) |
| 516 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 518 | for (CPDFSDK_Widget* pWidget : widgets) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 519 | CFX_FloatRect rcAnnot = pWidget->GetRect(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 520 | --rcAnnot.left; |
| 521 | --rcAnnot.bottom; |
| 522 | ++rcAnnot.right; |
| 523 | ++rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 525 | std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 526 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 527 | ASSERT(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | |
dsinclair | 1897bdc | 2016-09-06 14:18:57 -0700 | [diff] [blame] | 529 | // If there is currently no pageview associated with the page being used |
| 530 | // do not create one. We may be in the process of tearing down the document |
| 531 | // and creating a new pageview at this point will cause bad things. |
| 532 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); |
| 533 | if (pPageView) { |
| 534 | pPageView->DeleteAnnot(pWidget); |
| 535 | pPageView->UpdateRects(aRefresh); |
| 536 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 538 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | |
| 540 | return TRUE; |
| 541 | } |
| 542 | |
| 543 | // reset filed values within a document. |
| 544 | // comment: |
| 545 | // note: if the fields names r not rational, aodbe is dumb for it. |
| 546 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 547 | FX_BOOL Document::resetForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 548 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 549 | CJS_Value& vRet, |
| 550 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 551 | if (!m_pDocument) { |
| 552 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 553 | return FALSE; |
| 554 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 556 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 557 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 558 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | return FALSE; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 560 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 562 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 563 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 564 | CJS_Array aName; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 566 | if (params.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 567 | pPDFForm->ResetForm(TRUE); |
| 568 | m_pDocument->SetChangeMark(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 569 | return TRUE; |
| 570 | } |
| 571 | |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 572 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 573 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 574 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 575 | switch (params[0].GetType()) { |
| 576 | default: |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 577 | aName.Attach(params[0].ToV8Array(pRuntime)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 578 | break; |
| 579 | case CJS_Value::VT_string: |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 580 | aName.SetElement(pRuntime, 0, params[0]); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 581 | break; |
| 582 | } |
| 583 | |
| 584 | std::vector<CPDF_FormField*> aFields; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 585 | for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 586 | CJS_Value valElement(pRuntime); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 587 | aName.GetElement(pRuntime, i, valElement); |
| 588 | CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 589 | for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 590 | aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 591 | } |
| 592 | |
| 593 | if (!aFields.empty()) { |
| 594 | pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 595 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | return TRUE; |
| 599 | } |
| 600 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 601 | FX_BOOL Document::saveAs(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 602 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | CJS_Value& vRet, |
| 604 | CFX_WideString& sError) { |
| 605 | // Unsafe, not supported. |
| 606 | return TRUE; |
| 607 | } |
| 608 | |
tonikitoo | bb5fa04 | 2016-08-19 11:18:29 -0700 | [diff] [blame] | 609 | FX_BOOL Document::syncAnnotScan(IJS_Context* cc, |
| 610 | const std::vector<CJS_Value>& params, |
| 611 | CJS_Value& vRet, |
| 612 | CFX_WideString& sError) { |
| 613 | return TRUE; |
| 614 | } |
| 615 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 616 | FX_BOOL Document::submitForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 617 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | CJS_Value& vRet, |
| 619 | CFX_WideString& sError) { |
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) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1237 | if (params.size() != 2) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1238 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1239 | return FALSE; |
| 1240 | } |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1241 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1242 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1243 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1244 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1245 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1246 | if (params[1].GetType() != CJS_Value::VT_object) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1247 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1248 | return FALSE; |
| 1249 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1250 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1251 | v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
| 1252 | if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1253 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1254 | return FALSE; |
| 1255 | } |
| 1256 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1257 | CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1258 | if (!pEmbedObj) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1259 | sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1260 | return FALSE; |
| 1261 | } |
| 1262 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1263 | m_IconList.push_back(std::unique_ptr<IconElement>( |
| 1264 | new IconElement(swIconName, (Icon*)pEmbedObj))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1265 | return TRUE; |
| 1266 | } |
| 1267 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1268 | FX_BOOL Document::icons(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1269 | CJS_PropValue& vp, |
| 1270 | CFX_WideString& sError) { |
| 1271 | if (vp.IsSetting()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1272 | sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1273 | return FALSE; |
| 1274 | } |
| 1275 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1276 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1277 | if (m_IconList.empty()) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1278 | vp.GetJSValue()->SetNull(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1279 | return TRUE; |
| 1280 | } |
| 1281 | |
tsepez | e5aff74 | 2016-08-08 09:49:42 -0700 | [diff] [blame] | 1282 | CJS_Array Icons; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1283 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1284 | int i = 0; |
| 1285 | for (const auto& pIconElement : m_IconList) { |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1286 | v8::Local<v8::Object> pObj = |
| 1287 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | if (pObj.IsEmpty()) |
| 1289 | return FALSE; |
| 1290 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1291 | CJS_Icon* pJS_Icon = |
| 1292 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | if (!pJS_Icon) |
| 1294 | return FALSE; |
| 1295 | |
| 1296 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1297 | if (!pIcon) |
| 1298 | return FALSE; |
| 1299 | |
| 1300 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1301 | pIcon->SetIconName(pIconElement->IconName); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1302 | Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | vp << Icons; |
| 1306 | return TRUE; |
| 1307 | } |
| 1308 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1309 | FX_BOOL Document::getIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1310 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1311 | CJS_Value& vRet, |
| 1312 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1313 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1314 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1315 | return FALSE; |
| 1316 | } |
| 1317 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1318 | if (m_IconList.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1319 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1320 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1321 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1322 | CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1323 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1324 | for (const auto& pIconElement : m_IconList) { |
| 1325 | if (pIconElement->IconName == swIconName) { |
| 1326 | Icon* pRetIcon = pIconElement->IconStream; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1327 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1328 | v8::Local<v8::Object> pObj = |
| 1329 | pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1330 | if (pObj.IsEmpty()) |
| 1331 | return FALSE; |
| 1332 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1333 | CJS_Icon* pJS_Icon = |
| 1334 | static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1335 | if (!pJS_Icon) |
| 1336 | return FALSE; |
| 1337 | |
| 1338 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1339 | if (!pIcon) |
| 1340 | return FALSE; |
| 1341 | |
| 1342 | pIcon->SetIconName(swIconName); |
| 1343 | pIcon->SetStream(pRetIcon->GetStream()); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1344 | vRet = CJS_Value(pRuntime, pJS_Icon); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1345 | return TRUE; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | return FALSE; |
| 1350 | } |
| 1351 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1352 | FX_BOOL Document::removeIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1353 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1354 | CJS_Value& vRet, |
| 1355 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1356 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1357 | return TRUE; |
| 1358 | } |
| 1359 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1360 | FX_BOOL Document::createDataObject(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1361 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1362 | CJS_Value& vRet, |
| 1363 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1364 | // Unsafe, not implemented. |
| 1365 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1368 | FX_BOOL Document::media(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1369 | CJS_PropValue& vp, |
| 1370 | CFX_WideString& sError) { |
| 1371 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1374 | FX_BOOL Document::calculateNow(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1375 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1376 | CJS_Value& vRet, |
| 1377 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1378 | if (!m_pDocument) { |
| 1379 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1380 | return FALSE; |
| 1381 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1382 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1383 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1384 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 1385 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1386 | return FALSE; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1387 | } |
| 1388 | m_pDocument->GetInterForm()->OnCalculate(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1389 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1392 | FX_BOOL Document::Collab(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1393 | CJS_PropValue& vp, |
| 1394 | CFX_WideString& sError) { |
| 1395 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1398 | FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1399 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1400 | CJS_Value& vRet, |
| 1401 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1402 | if (!m_pDocument) { |
| 1403 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1404 | return FALSE; |
| 1405 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1406 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1407 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | return FALSE; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1409 | } |
| 1410 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1411 | |
| 1412 | // TODO(tsepez): check maximum allowable params. |
| 1413 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1414 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1415 | int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1416 | bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1417 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1418 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1419 | if (!pDocument) |
| 1420 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1421 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1422 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1423 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1424 | return FALSE; |
| 1425 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1426 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1427 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1428 | if (!pPageDict) |
| 1429 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1430 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1431 | CPDF_Page page(pDocument, pPageDict, true); |
| 1432 | page.ParseContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1433 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1434 | int nWords = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1435 | CFX_WideString swRet; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1436 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1437 | if (pPageObj->IsText()) { |
| 1438 | CPDF_TextObject* pTextObj = pPageObj->AsText(); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1439 | int nObjWords = CountWords(pTextObj); |
| 1440 | if (nWords + nObjWords >= nWordNo) { |
| 1441 | swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1442 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1443 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1444 | nWords += nObjWords; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1445 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1446 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1447 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1448 | if (bStrip) { |
| 1449 | swRet.TrimLeft(); |
| 1450 | swRet.TrimRight(); |
| 1451 | } |
| 1452 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1453 | vRet = CJS_Value(pRuntime, swRet.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1454 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1457 | FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1458 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1459 | CJS_Value& vRet, |
| 1460 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1461 | if (!m_pDocument) { |
| 1462 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1463 | return FALSE; |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1464 | } |
| 1465 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1466 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1467 | return FALSE; |
| 1468 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1469 | return FALSE; |
| 1470 | } |
| 1471 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1472 | FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1473 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1474 | CJS_Value& vRet, |
| 1475 | CFX_WideString& sError) { |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1476 | if (!m_pDocument) { |
| 1477 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1478 | return FALSE; |
| 1479 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1480 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1481 | sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1482 | return FALSE; |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1483 | } |
| 1484 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1485 | int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1486 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1487 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1488 | sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1489 | return FALSE; |
| 1490 | } |
| 1491 | |
| 1492 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1493 | if (!pPageDict) |
| 1494 | return FALSE; |
| 1495 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 1496 | CPDF_Page page(pDocument, pPageDict, true); |
| 1497 | page.ParseContent(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1498 | |
| 1499 | int nWords = 0; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1500 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1501 | if (pPageObj->IsText()) |
| 1502 | nWords += CountWords(pPageObj->AsText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1505 | vRet = CJS_Value(pRuntime, nWords); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1506 | return TRUE; |
| 1507 | } |
| 1508 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1509 | FX_BOOL Document::getPrintParams(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1510 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1511 | CJS_Value& vRet, |
| 1512 | CFX_WideString& sError) { |
| 1513 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1514 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1515 | v8::Local<v8::Object> pRetObj = |
| 1516 | pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1517 | |
| 1518 | // Not implemented yet. |
| 1519 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1520 | vRet = CJS_Value(pRuntime, pRetObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1521 | return TRUE; |
| 1522 | } |
| 1523 | |
| 1524 | #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1525 | |
| 1526 | int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1527 | if (!pTextObj) |
| 1528 | return 0; |
| 1529 | |
| 1530 | int nWords = 0; |
| 1531 | |
| 1532 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1533 | if (!pFont) |
| 1534 | return 0; |
| 1535 | |
| 1536 | FX_BOOL bIsLatin = FALSE; |
| 1537 | |
| 1538 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1539 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1540 | FX_FLOAT kerning; |
| 1541 | |
| 1542 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1543 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1544 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1545 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1546 | if (swUnicode.GetLength() > 0) |
| 1547 | unicode = swUnicode[0]; |
| 1548 | |
| 1549 | if (ISLATINWORD(unicode) && bIsLatin) |
| 1550 | continue; |
| 1551 | |
| 1552 | bIsLatin = ISLATINWORD(unicode); |
| 1553 | if (unicode != 0x20) |
| 1554 | nWords++; |
| 1555 | } |
| 1556 | |
| 1557 | return nWords; |
| 1558 | } |
| 1559 | |
| 1560 | CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1561 | int nWordIndex) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1562 | CFX_WideString swRet; |
| 1563 | |
| 1564 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1565 | if (!pFont) |
| 1566 | return L""; |
| 1567 | |
| 1568 | int nWords = 0; |
| 1569 | FX_BOOL bIsLatin = FALSE; |
| 1570 | |
| 1571 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1572 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1573 | FX_FLOAT kerning; |
| 1574 | |
| 1575 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1576 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1577 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1578 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1579 | if (swUnicode.GetLength() > 0) |
| 1580 | unicode = swUnicode[0]; |
| 1581 | |
| 1582 | if (ISLATINWORD(unicode) && bIsLatin) { |
| 1583 | } else { |
| 1584 | bIsLatin = ISLATINWORD(unicode); |
| 1585 | if (unicode != 0x20) |
| 1586 | nWords++; |
| 1587 | } |
| 1588 | |
| 1589 | if (nWords - 1 == nWordIndex) |
| 1590 | swRet += unicode; |
| 1591 | } |
| 1592 | |
| 1593 | return swRet; |
| 1594 | } |
| 1595 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1596 | FX_BOOL Document::zoom(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1597 | CJS_PropValue& vp, |
| 1598 | CFX_WideString& sError) { |
| 1599 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | /** |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1603 | (none, NoVary) |
| 1604 | (fitP, FitPage) |
| 1605 | (fitW, FitWidth) |
| 1606 | (fitH, FitHeight) |
| 1607 | (fitV, FitVisibleWidth) |
| 1608 | (pref, Preferred) |
| 1609 | (refW, ReflowWidth) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1610 | */ |
| 1611 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1612 | FX_BOOL Document::zoomType(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1613 | CJS_PropValue& vp, |
| 1614 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1615 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1618 | FX_BOOL Document::deletePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1619 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1620 | CJS_Value& vRet, |
| 1621 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1622 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1623 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1624 | } |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1625 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1626 | FX_BOOL Document::extractPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1627 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1628 | CJS_Value& vRet, |
| 1629 | CFX_WideString& sError) { |
| 1630 | // Unsafe, not supported. |
| 1631 | return TRUE; |
| 1632 | } |
| 1633 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1634 | FX_BOOL Document::insertPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1635 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1636 | CJS_Value& vRet, |
| 1637 | CFX_WideString& sError) { |
| 1638 | // Unsafe, not supported. |
| 1639 | return TRUE; |
| 1640 | } |
| 1641 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1642 | FX_BOOL Document::replacePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1643 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1644 | CJS_Value& vRet, |
| 1645 | CFX_WideString& sError) { |
| 1646 | // Unsafe, not supported. |
| 1647 | return TRUE; |
| 1648 | } |
| 1649 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1650 | FX_BOOL Document::getURL(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1651 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1652 | CJS_Value& vRet, |
| 1653 | CFX_WideString& sError) { |
| 1654 | // Unsafe, not supported. |
| 1655 | return TRUE; |
| 1656 | } |
| 1657 | |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1658 | FX_BOOL Document::gotoNamedDest(IJS_Context* cc, |
| 1659 | const std::vector<CJS_Value>& params, |
| 1660 | CJS_Value& vRet, |
| 1661 | CFX_WideString& sError) { |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1662 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1663 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1664 | return FALSE; |
| 1665 | } |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1666 | if (!m_pDocument) { |
| 1667 | sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1668 | return FALSE; |
| 1669 | } |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 1670 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1671 | CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 1672 | CFX_ByteString utf8Name = wideName.UTF8Encode(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1673 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1674 | if (!pDocument) |
| 1675 | return FALSE; |
| 1676 | |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1677 | CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1678 | CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1679 | if (!destArray) |
| 1680 | return FALSE; |
| 1681 | |
| 1682 | CPDF_Dest dest(destArray); |
| 1683 | const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1684 | |
| 1685 | std::unique_ptr<float[]> scrollPositionArray; |
| 1686 | int scrollPositionArraySize = 0; |
| 1687 | |
| 1688 | if (arrayObject) { |
| 1689 | scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1690 | int j = 0; |
| 1691 | for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1692 | scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1693 | scrollPositionArraySize = j; |
| 1694 | } |
| 1695 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1696 | pRuntime->BeginBlock(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1697 | CPDFSDK_Environment* pApp = m_pDocument->GetEnv(); |
dsinclair | 1f24890 | 2016-09-14 10:38:17 -0700 | [diff] [blame] | 1698 | pApp->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1699 | scrollPositionArray.get(), scrollPositionArraySize); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 1700 | pRuntime->EndBlock(); |
tonikitoo | 1c83675 | 2016-08-08 16:14:05 -0700 | [diff] [blame] | 1701 | |
| 1702 | return TRUE; |
| 1703 | } |
| 1704 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1705 | void Document::AddDelayData(CJS_DelayData* pData) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1706 | m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1710 | int nControlIndex) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1711 | std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1712 | auto iter = m_DelayData.begin(); |
| 1713 | while (iter != m_DelayData.end()) { |
| 1714 | auto old = iter++; |
| 1715 | if ((*old)->sFieldName == sFieldName && |
| 1716 | (*old)->nControlIndex == nControlIndex) { |
| 1717 | DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1718 | m_DelayData.erase(old); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1722 | for (const auto& pData : DelayDataForFieldAndControlIndex) |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 1723 | Field::DoDelay(m_pDocument.Get(), pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1726 | CJS_Document* Document::GetCJSDoc() const { |
| 1727 | return static_cast<CJS_Document*>(m_pJSObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1728 | } |