dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | bec7692 | 2016-09-29 16:52:30 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 8 | |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 9 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 10 | #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 11 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 14 | #include "fpdfsdk/cpdfsdk_pageview.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
| 16 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/javascript/ijs_runtime.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 18 | #include "xfa/fxfa/xfa_ffdocview.h" |
| 19 | #include "xfa/fxfa/xfa_ffwidget.h" |
| 20 | #include "xfa/fxfa/xfa_ffwidgethandler.h" |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 21 | |
| 22 | #define IDS_XFA_Validate_Input \ |
| 23 | "At least one required field was empty. Please fill in the required " \ |
| 24 | "fields\r\n(highlighted) before continuing." |
| 25 | |
| 26 | // submit |
| 27 | #define FXFA_CONFIG 0x00000001 |
| 28 | #define FXFA_TEMPLATE 0x00000010 |
| 29 | #define FXFA_LOCALESET 0x00000100 |
| 30 | #define FXFA_DATASETS 0x00001000 |
| 31 | #define FXFA_XMPMETA 0x00010000 |
| 32 | #define FXFA_XFDF 0x00100000 |
| 33 | #define FXFA_FORM 0x01000000 |
| 34 | #define FXFA_PDF 0x10000000 |
| 35 | #define FXFA_XFA_ALL 0x01111111 |
| 36 | |
| 37 | CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Document* doc) |
| 38 | : m_pDocument(doc), m_pJSContext(nullptr) { |
| 39 | ASSERT(m_pDocument); |
| 40 | } |
| 41 | |
| 42 | CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 43 | if (m_pJSContext && m_pDocument->GetFormFillEnv()) |
| 44 | m_pDocument->GetFormFillEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 48 | if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetFormFillEnv()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 49 | m_pDocument->GetFormFillEnv()->SetChangeMark(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView, |
| 53 | const CFX_RectF& rt, |
| 54 | uint32_t dwFlags /* = 0 */) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 55 | if (!m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 56 | return; |
| 57 | |
| 58 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) |
| 59 | return; |
| 60 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 61 | CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 62 | if (!pPage) |
| 63 | return; |
| 64 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 65 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 66 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 67 | return; |
| 68 | |
| 69 | CFX_FloatRect rcPage = CFX_FloatRect::FromCFXRectF(rt); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 70 | pFormFillEnv->Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, |
| 71 | rcPage.right, rcPage.top); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget, |
| 75 | FX_BOOL bVisible, |
| 76 | const CFX_RectF* pRtAnchor) { |
| 77 | if (!hWidget || !pRtAnchor || !m_pDocument->GetXFADoc() || |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 78 | !m_pDocument->GetFormFillEnv() || !m_pDocument->GetXFADocView()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 79 | return; |
| 80 | |
| 81 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) |
| 82 | return; |
| 83 | |
| 84 | CXFA_FFWidgetHandler* pWidgetHandler = |
| 85 | m_pDocument->GetXFADocView()->GetWidgetHandler(); |
| 86 | if (!pWidgetHandler) |
| 87 | return; |
| 88 | |
| 89 | CXFA_FFPageView* pPageView = hWidget->GetPageView(); |
| 90 | if (!pPageView) |
| 91 | return; |
| 92 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 93 | CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 94 | if (!pPage) |
| 95 | return; |
| 96 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 97 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 98 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 99 | return; |
| 100 | |
| 101 | CFX_FloatRect rcCaret = CFX_FloatRect::FromCFXRectF(*pRtAnchor); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 102 | pFormFillEnv->DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, |
| 103 | rcCaret.top, rcCaret.right, rcCaret.bottom); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | FX_BOOL CPDFXFA_DocEnvironment::GetPopupPos(CXFA_FFWidget* hWidget, |
| 107 | FX_FLOAT fMinPopup, |
| 108 | FX_FLOAT fMaxPopup, |
| 109 | const CFX_RectF& rtAnchor, |
| 110 | CFX_RectF& rtPopup) { |
| 111 | if (!hWidget) |
| 112 | return FALSE; |
| 113 | |
| 114 | CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 115 | if (!pXFAPageView) |
| 116 | return FALSE; |
| 117 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 118 | CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pXFAPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 119 | if (!pPage) |
| 120 | return FALSE; |
| 121 | |
| 122 | CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
| 123 | int nRotate = pWidgetAcc->GetRotate(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 124 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 125 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 126 | return FALSE; |
| 127 | |
| 128 | FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f}; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 129 | pFormFillEnv->GetPageViewRect(pPage, pageViewRect); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 130 | |
| 131 | int t1; |
| 132 | int t2; |
| 133 | CFX_FloatRect rcAnchor = CFX_FloatRect::FromCFXRectF(rtAnchor); |
| 134 | switch (nRotate) { |
| 135 | case 90: { |
| 136 | t1 = (int)(pageViewRect.right - rcAnchor.right); |
| 137 | t2 = (int)(rcAnchor.left - pageViewRect.left); |
| 138 | if (rcAnchor.bottom < pageViewRect.bottom) |
| 139 | rtPopup.left += rcAnchor.bottom - pageViewRect.bottom; |
| 140 | break; |
| 141 | } |
| 142 | case 180: { |
| 143 | t2 = (int)(pageViewRect.top - rcAnchor.top); |
| 144 | t1 = (int)(rcAnchor.bottom - pageViewRect.bottom); |
| 145 | if (rcAnchor.left < pageViewRect.left) |
| 146 | rtPopup.left += rcAnchor.left - pageViewRect.left; |
| 147 | break; |
| 148 | } |
| 149 | case 270: { |
| 150 | t1 = (int)(rcAnchor.left - pageViewRect.left); |
| 151 | t2 = (int)(pageViewRect.right - rcAnchor.right); |
| 152 | if (rcAnchor.top > pageViewRect.top) |
| 153 | rtPopup.left -= rcAnchor.top - pageViewRect.top; |
| 154 | break; |
| 155 | } |
| 156 | case 0: |
| 157 | default: { |
| 158 | t1 = (int)(pageViewRect.top - rcAnchor.top); |
| 159 | t2 = (int)(rcAnchor.bottom - pageViewRect.bottom); |
| 160 | if (rcAnchor.right > pageViewRect.right) |
| 161 | rtPopup.left -= rcAnchor.right - pageViewRect.right; |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | int t; |
| 167 | uint32_t dwPos; |
| 168 | if (t1 <= 0 && t2 <= 0) |
| 169 | return FALSE; |
| 170 | if (t1 <= 0) { |
| 171 | t = t2; |
| 172 | dwPos = 1; |
| 173 | } else if (t2 <= 0) { |
| 174 | t = t1; |
| 175 | dwPos = 0; |
| 176 | } else if (t1 > t2) { |
| 177 | t = t1; |
| 178 | dwPos = 0; |
| 179 | } else { |
| 180 | t = t2; |
| 181 | dwPos = 1; |
| 182 | } |
| 183 | |
| 184 | FX_FLOAT fPopupHeight; |
| 185 | if (t < fMinPopup) |
| 186 | fPopupHeight = fMinPopup; |
| 187 | else if (t > fMaxPopup) |
| 188 | fPopupHeight = fMaxPopup; |
| 189 | else |
| 190 | fPopupHeight = static_cast<FX_FLOAT>(t); |
| 191 | |
| 192 | switch (nRotate) { |
| 193 | case 0: |
| 194 | case 180: { |
| 195 | if (dwPos == 0) { |
| 196 | rtPopup.top = rtAnchor.height; |
| 197 | rtPopup.height = fPopupHeight; |
| 198 | } else { |
| 199 | rtPopup.top = -fPopupHeight; |
| 200 | rtPopup.height = fPopupHeight; |
| 201 | } |
| 202 | break; |
| 203 | } |
| 204 | case 90: |
| 205 | case 270: { |
| 206 | if (dwPos == 0) { |
| 207 | rtPopup.top = rtAnchor.width; |
| 208 | rtPopup.height = fPopupHeight; |
| 209 | } else { |
| 210 | rtPopup.top = -fPopupHeight; |
| 211 | rtPopup.height = fPopupHeight; |
| 212 | } |
| 213 | break; |
| 214 | } |
| 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | return TRUE; |
| 220 | } |
| 221 | |
| 222 | FX_BOOL CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget, |
| 223 | CFX_PointF ptPopup) { |
| 224 | if (!hWidget) |
| 225 | return FALSE; |
| 226 | |
| 227 | CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 228 | if (!pXFAPageView) |
| 229 | return FALSE; |
| 230 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 231 | CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pXFAPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 232 | if (!pPage) |
| 233 | return FALSE; |
| 234 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 235 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 236 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 237 | return FALSE; |
| 238 | |
| 239 | int menuFlag = 0; |
| 240 | if (hWidget->CanUndo()) |
| 241 | menuFlag |= FXFA_MENU_UNDO; |
| 242 | if (hWidget->CanRedo()) |
| 243 | menuFlag |= FXFA_MENU_REDO; |
| 244 | if (hWidget->CanPaste()) |
| 245 | menuFlag |= FXFA_MENU_PASTE; |
| 246 | if (hWidget->CanCopy()) |
| 247 | menuFlag |= FXFA_MENU_COPY; |
| 248 | if (hWidget->CanCut()) |
| 249 | menuFlag |= FXFA_MENU_CUT; |
| 250 | if (hWidget->CanSelectAll()) |
| 251 | menuFlag |= FXFA_MENU_SELECTALL; |
| 252 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 253 | return pFormFillEnv->PopupMenu(pPage, hWidget, menuFlag, ptPopup); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, |
| 257 | uint32_t dwFlags) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 258 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 259 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 260 | return; |
| 261 | |
| 262 | if (m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_LOADING || |
| 263 | m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING || |
| 264 | XFA_PAGEVIEWEVENT_StopLayout != dwFlags) |
| 265 | return; |
| 266 | |
| 267 | int nNewCount = m_pDocument->GetPageCount(); |
| 268 | if (nNewCount == m_pDocument->GetOriginalPageCount()) |
| 269 | return; |
| 270 | |
| 271 | CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); |
| 272 | if (!pXFADocView) |
| 273 | return; |
| 274 | |
| 275 | for (int iPageIter = 0; iPageIter < m_pDocument->GetOriginalPageCount(); |
| 276 | iPageIter++) { |
| 277 | CPDFXFA_Page* pPage = m_pDocument->GetXFAPageList()->GetAt(iPageIter); |
| 278 | if (!pPage) |
| 279 | continue; |
| 280 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 281 | m_pDocument->GetFormFillEnv()->RemovePageView(pPage); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 282 | pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); |
| 283 | } |
| 284 | |
| 285 | int flag = (nNewCount < m_pDocument->GetOriginalPageCount()) |
| 286 | ? FXFA_PAGEVIEWEVENT_POSTREMOVED |
| 287 | : FXFA_PAGEVIEWEVENT_POSTADDED; |
| 288 | int count = FXSYS_abs(nNewCount - m_pDocument->GetOriginalPageCount()); |
| 289 | m_pDocument->SetOriginalPageCount(nNewCount); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 290 | pFormFillEnv->PageEvent(count, flag); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget, |
| 294 | CXFA_WidgetAcc* pWidgetData) { |
| 295 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) |
| 296 | return; |
| 297 | |
| 298 | CXFA_FFPageView* pPageView = hWidget->GetPageView(); |
| 299 | if (!pPageView) |
| 300 | return; |
| 301 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 302 | CPDFXFA_Page* pXFAPage = m_pDocument->GetXFAPage(pPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 303 | if (!pXFAPage) |
| 304 | return; |
| 305 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 306 | m_pDocument->GetFormFillEnv() |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 307 | ->GetPageView(pXFAPage, true) |
| 308 | ->AddAnnot(hWidget); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget, |
| 312 | CXFA_WidgetAcc* pWidgetData) { |
| 313 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) |
| 314 | return; |
| 315 | |
| 316 | CXFA_FFPageView* pPageView = hWidget->GetPageView(); |
| 317 | if (!pPageView) |
| 318 | return; |
| 319 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 320 | CPDFXFA_Page* pXFAPage = m_pDocument->GetXFAPage(pPageView); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 321 | if (!pXFAPage) |
| 322 | return; |
| 323 | |
| 324 | CPDFSDK_PageView* pSdkPageView = |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 325 | m_pDocument->GetFormFillEnv()->GetPageView(pXFAPage, true); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 326 | if (CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget)) |
| 327 | pSdkPageView->DeleteAnnot(pAnnot); |
| 328 | } |
| 329 | |
| 330 | int32_t CPDFXFA_DocEnvironment::CountPages(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 331 | if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 332 | return m_pDocument->GetPageCount(); |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 337 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 338 | return -1; |
| 339 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) |
| 340 | return -1; |
| 341 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 342 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 343 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 344 | return -1; |
| 345 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 346 | return pFormFillEnv->GetCurrentPageIndex(this); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc, |
| 350 | int32_t iCurPage) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 351 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv() || |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 352 | m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 353 | iCurPage >= m_pDocument->GetFormFillEnv()->GetPageCount()) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 357 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 358 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 359 | return; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 360 | pFormFillEnv->SetCurrentPage(this, iCurPage); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | FX_BOOL CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 364 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 365 | return FALSE; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 366 | if (m_pDocument->GetFormFillEnv()->GetInterForm()) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 367 | return m_pDocument->GetFormFillEnv() |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 368 | ->GetInterForm() |
| 369 | ->IsXfaCalculateEnabled(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 370 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 371 | return FALSE; |
| 372 | } |
| 373 | |
| 374 | void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc, |
| 375 | FX_BOOL bEnabled) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 376 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 377 | return; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 378 | if (m_pDocument->GetFormFillEnv()->GetInterForm()) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 379 | m_pDocument->GetFormFillEnv() |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 380 | ->GetInterForm() |
| 381 | ->XfaEnableCalculate(bEnabled); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 382 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, |
| 386 | CFX_WideString& wsTitle) { |
| 387 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc()) |
| 388 | return; |
| 389 | |
| 390 | CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo(); |
| 391 | if (!pInfoDict) |
| 392 | return; |
| 393 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 394 | CFX_ByteString csTitle = pInfoDict->GetStringFor("Title"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 395 | wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength())); |
| 396 | csTitle.ReleaseBuffer(csTitle.GetLength()); |
| 397 | } |
| 398 | |
| 399 | void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc, |
| 400 | const CFX_WideString& wsTitle) { |
| 401 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc()) |
| 402 | return; |
| 403 | |
| 404 | if (CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 405 | pInfoDict->SetFor("Title", new CPDF_String(wsTitle)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, |
| 409 | const CFX_WideString& wsFilePath, |
| 410 | FX_BOOL bXDP) { |
| 411 | if (hDoc != m_pDocument->GetXFADoc()) |
| 412 | return; |
| 413 | |
| 414 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 415 | m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 416 | return; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 417 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 418 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 419 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 420 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 421 | return; |
| 422 | |
| 423 | int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; |
| 424 | CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); |
| 425 | if (wsFilePath.IsEmpty()) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 426 | if (!pFormFillEnv->GetFormFillInfo() || |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 427 | !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 428 | return; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 429 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 430 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 431 | CFX_WideString filepath = pFormFillEnv->JS_fieldBrowse(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 432 | bs = filepath.UTF16LE_Encode(); |
| 433 | } |
| 434 | int len = bs.GetLength(); |
| 435 | FPDF_FILEHANDLER* pFileHandler = |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 436 | pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, |
| 437 | (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 438 | bs.ReleaseBuffer(len); |
| 439 | if (!pFileHandler) |
| 440 | return; |
| 441 | |
| 442 | CFPDF_FileStream fileWrite(pFileHandler); |
| 443 | CFX_ByteString content; |
| 444 | if (fileType == FXFA_SAVEAS_XML) { |
| 445 | content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 446 | fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), |
| 447 | content.GetLength()); |
| 448 | m_pDocument->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, |
| 449 | &fileWrite, nullptr); |
| 450 | } else if (fileType == FXFA_SAVEAS_XDP) { |
| 451 | if (!m_pDocument->GetPDFDoc()) |
| 452 | return; |
| 453 | |
| 454 | CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot(); |
| 455 | if (!pRoot) |
| 456 | return; |
| 457 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 458 | CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 459 | if (!pAcroForm) |
| 460 | return; |
| 461 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 462 | CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 463 | if (!pArray) |
| 464 | return; |
| 465 | |
| 466 | int size = pArray->GetCount(); |
| 467 | for (int i = 1; i < size; i += 2) { |
| 468 | CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 469 | CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 470 | if (!pPrePDFObj->IsString()) |
| 471 | continue; |
| 472 | if (!pPDFObj->IsReference()) |
| 473 | continue; |
| 474 | |
| 475 | CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); |
| 476 | if (!pStream) |
| 477 | continue; |
| 478 | if (pPrePDFObj->GetString() == "form") { |
| 479 | m_pDocument->GetXFADocView()->GetDoc()->SavePackage( |
| 480 | XFA_HASHCODE_Form, &fileWrite, nullptr); |
| 481 | continue; |
| 482 | } |
| 483 | if (pPrePDFObj->GetString() == "datasets") { |
| 484 | m_pDocument->GetXFADocView()->GetDoc()->SavePackage( |
| 485 | XFA_HASHCODE_Datasets, &fileWrite, nullptr); |
| 486 | continue; |
| 487 | } |
| 488 | if (i == size - 1) { |
| 489 | CFX_WideString wPath = CFX_WideString::FromUTF16LE( |
| 490 | reinterpret_cast<const unsigned short*>(bs.c_str()), |
| 491 | bs.GetLength() / sizeof(unsigned short)); |
| 492 | CFX_ByteString bPath = wPath.UTF8Encode(); |
| 493 | const char* szFormat = |
| 494 | "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; |
| 495 | content.Format(szFormat, bPath.c_str()); |
| 496 | fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), |
| 497 | content.GetLength()); |
| 498 | } |
| 499 | std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); |
| 500 | pAcc->LoadAllData(pStream); |
| 501 | fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), |
| 502 | pAcc->GetSize()); |
| 503 | } |
| 504 | } |
| 505 | if (!fileWrite.Flush()) { |
| 506 | // Ignoring flush error. |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 511 | const CFX_WideString& bsURL) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 512 | if (hDoc != m_pDocument->GetXFADoc()) |
| 513 | return; |
| 514 | |
| 515 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) |
| 516 | return; |
| 517 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 518 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 519 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 520 | return; |
| 521 | |
| 522 | CFX_WideStringC str(bsURL.c_str()); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 523 | pFormFillEnv->GotoURL(this, str); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | FX_BOOL CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 527 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 528 | return FALSE; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 529 | if (m_pDocument->GetFormFillEnv()->GetInterForm()) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 530 | return m_pDocument->GetFormFillEnv() |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 531 | ->GetInterForm() |
| 532 | ->IsXfaValidationsEnabled(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 533 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 534 | return TRUE; |
| 535 | } |
| 536 | |
| 537 | void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc, |
| 538 | FX_BOOL bEnabled) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 539 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 540 | return; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 541 | if (m_pDocument->GetFormFillEnv()->GetInterForm()) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 542 | m_pDocument->GetFormFillEnv() |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 543 | ->GetInterForm() |
| 544 | ->XfaSetValidationsEnabled(bEnabled); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 545 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc, |
| 549 | CXFA_FFWidget* hWidget) { |
| 550 | if (hDoc != m_pDocument->GetXFADoc()) |
| 551 | return; |
| 552 | |
| 553 | if (!hWidget) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 554 | CPDFSDK_Annot::ObservedPtr pNull; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 555 | m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pNull); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 556 | return; |
| 557 | } |
| 558 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 559 | int pageViewCount = m_pDocument->GetFormFillEnv()->GetPageViewCount(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 560 | for (int i = 0; i < pageViewCount; i++) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 561 | CPDFSDK_PageView* pPageView = m_pDocument->GetFormFillEnv()->GetPageView(i); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 562 | if (!pPageView) |
| 563 | continue; |
| 564 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 565 | CPDFSDK_Annot::ObservedPtr pAnnot(pPageView->GetAnnotByXFAWidget(hWidget)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 566 | if (pAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 567 | m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pAnnot); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 568 | break; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void CPDFXFA_DocEnvironment::Print(CXFA_FFDoc* hDoc, |
| 574 | int32_t nStartPage, |
| 575 | int32_t nEndPage, |
| 576 | uint32_t dwOptions) { |
| 577 | if (hDoc != m_pDocument->GetXFADoc()) |
| 578 | return; |
| 579 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 580 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 581 | if (!pFormFillEnv || !pFormFillEnv->GetFormFillInfo() || |
| 582 | !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform || |
| 583 | !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 584 | return; |
| 585 | } |
| 586 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 587 | pFormFillEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print( |
| 588 | pFormFillEnv->GetFormFillInfo()->m_pJsPlatform, |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 589 | dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage, |
| 590 | dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage, |
| 591 | dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder, |
| 592 | dwOptions & XFA_PRINTOPT_PrintAnnot); |
| 593 | } |
| 594 | |
| 595 | FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor(CXFA_FFDoc* hDoc) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 596 | if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 597 | return 0; |
| 598 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 599 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetFormFillEnv()->GetInterForm(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 600 | if (!pInterForm) |
| 601 | return 0; |
| 602 | |
| 603 | return ArgbEncode(pInterForm->GetHighlightAlpha(), |
| 604 | pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA)); |
| 605 | } |
| 606 | |
| 607 | FX_BOOL CPDFXFA_DocEnvironment::NotifySubmit(FX_BOOL bPrevOrPost) { |
| 608 | if (bPrevOrPost) |
| 609 | return OnBeforeNotifySubmit(); |
| 610 | |
| 611 | OnAfterNotifySubmit(); |
| 612 | return TRUE; |
| 613 | } |
| 614 | |
| 615 | FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { |
| 616 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 617 | m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 618 | return TRUE; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 619 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 620 | |
| 621 | if (!m_pDocument->GetXFADocView()) |
| 622 | return TRUE; |
| 623 | |
| 624 | CXFA_FFWidgetHandler* pWidgetHandler = |
| 625 | m_pDocument->GetXFADocView()->GetWidgetHandler(); |
| 626 | if (!pWidgetHandler) |
| 627 | return TRUE; |
| 628 | |
| 629 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( |
| 630 | m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); |
| 631 | if (pWidgetAccIterator) { |
| 632 | CXFA_EventParam Param; |
| 633 | Param.m_eType = XFA_EVENT_PreSubmit; |
| 634 | while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) |
| 635 | pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 636 | } |
| 637 | |
| 638 | pWidgetAccIterator.reset( |
| 639 | m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); |
| 640 | if (!pWidgetAccIterator) |
| 641 | return TRUE; |
| 642 | |
| 643 | CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 644 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 645 | while (pWidgetAcc) { |
| 646 | int fRet = pWidgetAcc->ProcessValidate(-1); |
| 647 | if (fRet == XFA_EVENTERROR_Error) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 648 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 649 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 650 | return FALSE; |
| 651 | |
| 652 | CFX_WideString ws; |
| 653 | ws.FromLocal(IDS_XFA_Validate_Input); |
| 654 | CFX_ByteString bs = ws.UTF16LE_Encode(); |
| 655 | int len = bs.GetLength(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 656 | pFormFillEnv->Alert((FPDF_WIDESTRING)bs.GetBuffer(len), |
| 657 | (FPDF_WIDESTRING)L"", 0, 1); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 658 | bs.ReleaseBuffer(len); |
| 659 | return FALSE; |
| 660 | } |
| 661 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 662 | } |
| 663 | m_pDocument->GetXFADocView()->UpdateDocView(); |
| 664 | |
| 665 | return TRUE; |
| 666 | } |
| 667 | |
| 668 | void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() { |
| 669 | if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 670 | m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 671 | return; |
| 672 | |
| 673 | if (!m_pDocument->GetXFADocView()) |
| 674 | return; |
| 675 | |
| 676 | CXFA_FFWidgetHandler* pWidgetHandler = |
| 677 | m_pDocument->GetXFADocView()->GetWidgetHandler(); |
| 678 | if (!pWidgetHandler) |
| 679 | return; |
| 680 | |
| 681 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( |
| 682 | m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); |
| 683 | if (!pWidgetAccIterator) |
| 684 | return; |
| 685 | |
| 686 | CXFA_EventParam Param; |
| 687 | Param.m_eType = XFA_EVENT_PostSubmit; |
| 688 | CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 689 | while (pWidgetAcc) { |
| 690 | pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 691 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 692 | } |
| 693 | m_pDocument->GetXFADocView()->UpdateDocView(); |
| 694 | } |
| 695 | |
| 696 | FX_BOOL CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc, |
| 697 | CXFA_Submit submit) { |
| 698 | if (!NotifySubmit(TRUE) || !m_pDocument->GetXFADocView()) |
| 699 | return FALSE; |
| 700 | |
| 701 | m_pDocument->GetXFADocView()->UpdateDocView(); |
| 702 | FX_BOOL ret = SubmitDataInternal(hDoc, submit); |
| 703 | NotifySubmit(FALSE); |
| 704 | return ret; |
| 705 | } |
| 706 | |
tsepez | ad2441e | 2016-10-24 10:19:11 -0700 | [diff] [blame] | 707 | IFX_SeekableReadStream* CPDFXFA_DocEnvironment::OpenLinkedFile( |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 708 | CXFA_FFDoc* hDoc, |
| 709 | const CFX_WideString& wsLink) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 710 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 711 | if (!pFormFillEnv) |
tsepez | 04c1009 | 2016-10-25 15:16:40 -0700 | [diff] [blame^] | 712 | return nullptr; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 713 | |
| 714 | CFX_ByteString bs = wsLink.UTF16LE_Encode(); |
| 715 | int len = bs.GetLength(); |
| 716 | FPDF_FILEHANDLER* pFileHandler = |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 717 | pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 718 | bs.ReleaseBuffer(len); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 719 | if (!pFileHandler) |
| 720 | return nullptr; |
tsepez | 04c1009 | 2016-10-25 15:16:40 -0700 | [diff] [blame^] | 721 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 722 | return new CFPDF_FileStream(pFileHandler); |
| 723 | } |
| 724 | |
| 725 | FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, |
| 726 | int fileType, |
| 727 | FPDF_DWORD encodeType, |
| 728 | FPDF_DWORD flag) { |
| 729 | if (!m_pDocument->GetXFADocView()) |
| 730 | return FALSE; |
| 731 | |
| 732 | CFX_ByteString content; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 733 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 734 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 735 | return FALSE; |
| 736 | |
| 737 | CFPDF_FileStream fileStream(pFileHandler); |
| 738 | if (fileType == FXFA_SAVEAS_XML) { |
| 739 | const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 740 | fileStream.WriteBlock(kContent, 0, strlen(kContent)); |
| 741 | m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, &fileStream, |
| 742 | nullptr); |
| 743 | return TRUE; |
| 744 | } |
| 745 | |
| 746 | if (fileType != FXFA_SAVEAS_XDP) |
| 747 | return TRUE; |
| 748 | |
| 749 | if (!flag) { |
| 750 | flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 751 | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 752 | } |
| 753 | if (!m_pDocument->GetPDFDoc()) { |
| 754 | fileStream.Flush(); |
| 755 | return FALSE; |
| 756 | } |
| 757 | |
| 758 | CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot(); |
| 759 | if (!pRoot) { |
| 760 | fileStream.Flush(); |
| 761 | return FALSE; |
| 762 | } |
| 763 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 764 | CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 765 | if (!pAcroForm) { |
| 766 | fileStream.Flush(); |
| 767 | return FALSE; |
| 768 | } |
| 769 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 770 | CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 771 | if (!pArray) { |
| 772 | fileStream.Flush(); |
| 773 | return FALSE; |
| 774 | } |
| 775 | |
| 776 | int size = pArray->GetCount(); |
| 777 | for (int i = 1; i < size; i += 2) { |
| 778 | CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 779 | CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 780 | if (!pPrePDFObj->IsString()) |
| 781 | continue; |
| 782 | if (!pPDFObj->IsReference()) |
| 783 | continue; |
| 784 | |
| 785 | CPDF_Object* pDirectObj = pPDFObj->GetDirect(); |
| 786 | if (!pDirectObj->IsStream()) |
| 787 | continue; |
| 788 | if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) |
| 789 | continue; |
| 790 | if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) |
| 791 | continue; |
| 792 | if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) |
| 793 | continue; |
| 794 | if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) |
| 795 | continue; |
| 796 | if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) |
| 797 | continue; |
| 798 | if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) |
| 799 | continue; |
| 800 | if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) |
| 801 | continue; |
| 802 | if (pPrePDFObj->GetString() == "form") { |
| 803 | m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, &fileStream, |
| 804 | nullptr); |
| 805 | } else if (pPrePDFObj->GetString() == "datasets") { |
| 806 | m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, &fileStream, |
| 807 | nullptr); |
| 808 | } else { |
| 809 | // PDF,creator. |
| 810 | } |
| 811 | } |
| 812 | return TRUE; |
| 813 | } |
| 814 | |
| 815 | void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent, |
| 816 | FPDF_DWORD& flag) { |
| 817 | if (csSrcContent.Find(L" config ", 0) != -1) |
| 818 | flag |= FXFA_CONFIG; |
| 819 | if (csSrcContent.Find(L" template ", 0) != -1) |
| 820 | flag |= FXFA_TEMPLATE; |
| 821 | if (csSrcContent.Find(L" localeSet ", 0) != -1) |
| 822 | flag |= FXFA_LOCALESET; |
| 823 | if (csSrcContent.Find(L" datasets ", 0) != -1) |
| 824 | flag |= FXFA_DATASETS; |
| 825 | if (csSrcContent.Find(L" xmpmeta ", 0) != -1) |
| 826 | flag |= FXFA_XMPMETA; |
| 827 | if (csSrcContent.Find(L" xfdf ", 0) != -1) |
| 828 | flag |= FXFA_XFDF; |
| 829 | if (csSrcContent.Find(L" form ", 0) != -1) |
| 830 | flag |= FXFA_FORM; |
| 831 | if (flag == 0) { |
| 832 | flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 833 | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | FX_BOOL CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL, |
| 838 | CFX_WideString& csToAddress, |
| 839 | CFX_WideString& csCCAddress, |
| 840 | CFX_WideString& csBCCAddress, |
| 841 | CFX_WideString& csSubject, |
| 842 | CFX_WideString& csMsg) { |
| 843 | CFX_WideString srcURL = csURL; |
| 844 | srcURL.TrimLeft(); |
| 845 | if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0) |
| 846 | return FALSE; |
| 847 | |
| 848 | int pos = srcURL.Find(L'?', 0); |
| 849 | CFX_WideString tmp; |
| 850 | if (pos == -1) { |
| 851 | pos = srcURL.Find(L'@', 0); |
| 852 | if (pos == -1) |
| 853 | return FALSE; |
| 854 | |
| 855 | tmp = srcURL.Right(csURL.GetLength() - 7); |
| 856 | } else { |
| 857 | tmp = srcURL.Left(pos); |
| 858 | tmp = tmp.Right(tmp.GetLength() - 7); |
| 859 | } |
| 860 | tmp.TrimLeft(); |
| 861 | tmp.TrimRight(); |
| 862 | |
| 863 | csToAddress = tmp; |
| 864 | |
| 865 | srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); |
| 866 | while (!srcURL.IsEmpty()) { |
| 867 | srcURL.TrimLeft(); |
| 868 | srcURL.TrimRight(); |
| 869 | pos = srcURL.Find(L'&', 0); |
| 870 | |
| 871 | tmp = (pos == -1) ? srcURL : srcURL.Left(pos); |
| 872 | tmp.TrimLeft(); |
| 873 | tmp.TrimRight(); |
| 874 | if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) { |
| 875 | tmp = tmp.Right(tmp.GetLength() - 3); |
| 876 | if (!csCCAddress.IsEmpty()) |
| 877 | csCCAddress += L';'; |
| 878 | csCCAddress += tmp; |
| 879 | } else if (tmp.GetLength() >= 4 && |
| 880 | tmp.Left(4).CompareNoCase(L"bcc=") == 0) { |
| 881 | tmp = tmp.Right(tmp.GetLength() - 4); |
| 882 | if (!csBCCAddress.IsEmpty()) |
| 883 | csBCCAddress += L';'; |
| 884 | csBCCAddress += tmp; |
| 885 | } else if (tmp.GetLength() >= 8 && |
| 886 | tmp.Left(8).CompareNoCase(L"subject=") == 0) { |
| 887 | tmp = tmp.Right(tmp.GetLength() - 8); |
| 888 | csSubject += tmp; |
| 889 | } else if (tmp.GetLength() >= 5 && |
| 890 | tmp.Left(5).CompareNoCase(L"body=") == 0) { |
| 891 | tmp = tmp.Right(tmp.GetLength() - 5); |
| 892 | csMsg += tmp; |
| 893 | } |
| 894 | srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1)); |
| 895 | } |
| 896 | csToAddress.Replace(L",", L";"); |
| 897 | csCCAddress.Replace(L",", L";"); |
| 898 | csBCCAddress.Replace(L",", L";"); |
| 899 | return TRUE; |
| 900 | } |
| 901 | |
| 902 | FX_BOOL CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc, |
| 903 | CXFA_Submit submit) { |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 904 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
| 905 | if (!pFormFillEnv) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 906 | return FALSE; |
| 907 | |
| 908 | CFX_WideStringC csURLC; |
| 909 | submit.GetSubmitTarget(csURLC); |
| 910 | CFX_WideString csURL(csURLC); |
| 911 | if (csURL.IsEmpty()) { |
| 912 | CFX_WideString ws; |
| 913 | ws.FromLocal("Submit cancelled."); |
| 914 | CFX_ByteString bs = ws.UTF16LE_Encode(); |
| 915 | int len = bs.GetLength(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 916 | pFormFillEnv->Alert((FPDF_WIDESTRING)bs.GetBuffer(len), |
| 917 | (FPDF_WIDESTRING)L"", 0, 4); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 918 | bs.ReleaseBuffer(len); |
| 919 | return FALSE; |
| 920 | } |
| 921 | |
| 922 | FPDF_BOOL bRet = TRUE; |
| 923 | FPDF_FILEHANDLER* pFileHandler = nullptr; |
| 924 | int fileFlag = -1; |
| 925 | switch (submit.GetSubmitFormat()) { |
| 926 | case XFA_ATTRIBUTEENUM_Xdp: { |
| 927 | CFX_WideStringC csContentC; |
| 928 | submit.GetSubmitXDPContent(csContentC); |
| 929 | CFX_WideString csContent; |
| 930 | csContent = csContentC; |
| 931 | csContent.TrimLeft(); |
| 932 | csContent.TrimRight(); |
| 933 | CFX_WideString space; |
| 934 | space.FromLocal(" "); |
| 935 | csContent = space + csContent + space; |
| 936 | FPDF_DWORD flag = 0; |
| 937 | if (submit.IsSubmitEmbedPDF()) |
| 938 | flag |= FXFA_PDF; |
| 939 | |
| 940 | ToXFAContentFlags(csContent, flag); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 941 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 942 | fileFlag = FXFA_SAVEAS_XDP; |
| 943 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); |
| 944 | break; |
| 945 | } |
| 946 | case XFA_ATTRIBUTEENUM_Xml: |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 947 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 948 | fileFlag = FXFA_SAVEAS_XML; |
| 949 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); |
| 950 | break; |
| 951 | case XFA_ATTRIBUTEENUM_Pdf: |
| 952 | break; |
| 953 | case XFA_ATTRIBUTEENUM_Urlencoded: |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 954 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 955 | fileFlag = FXFA_SAVEAS_XML; |
| 956 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); |
| 957 | break; |
| 958 | default: |
| 959 | return false; |
| 960 | } |
| 961 | if (!pFileHandler) |
| 962 | return FALSE; |
| 963 | if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) { |
| 964 | CFX_WideString csToAddress; |
| 965 | CFX_WideString csCCAddress; |
| 966 | CFX_WideString csBCCAddress; |
| 967 | CFX_WideString csSubject; |
| 968 | CFX_WideString csMsg; |
| 969 | bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, |
| 970 | csMsg); |
| 971 | if (!bRet) |
| 972 | return FALSE; |
| 973 | |
| 974 | CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); |
| 975 | CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); |
| 976 | CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); |
| 977 | CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); |
| 978 | CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); |
| 979 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 980 | FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 981 | FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 982 | FPDF_WIDESTRING pSubject = |
| 983 | (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 984 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 985 | pFormFillEnv->EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 986 | bsTo.ReleaseBuffer(); |
| 987 | bsCC.ReleaseBuffer(); |
| 988 | bsBcc.ReleaseBuffer(); |
| 989 | bsSubject.ReleaseBuffer(); |
| 990 | bsMsg.ReleaseBuffer(); |
| 991 | } else { |
| 992 | // HTTP or FTP |
| 993 | CFX_WideString ws; |
| 994 | CFX_ByteString bs = csURL.UTF16LE_Encode(); |
| 995 | int len = bs.GetLength(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 996 | pFormFillEnv->UploadTo(pFileHandler, fileFlag, |
| 997 | (FPDF_WIDESTRING)bs.GetBuffer(len)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 998 | bs.ReleaseBuffer(len); |
| 999 | } |
| 1000 | return bRet; |
| 1001 | } |
| 1002 | |
| 1003 | FX_BOOL CPDFXFA_DocEnvironment::SetGlobalProperty( |
| 1004 | CXFA_FFDoc* hDoc, |
| 1005 | const CFX_ByteStringC& szPropName, |
| 1006 | CFXJSE_Value* pValue) { |
| 1007 | if (hDoc != m_pDocument->GetXFADoc()) |
| 1008 | return FALSE; |
| 1009 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1010 | if (m_pDocument->GetFormFillEnv() && |
| 1011 | m_pDocument->GetFormFillEnv()->GetJSRuntime()) { |
| 1012 | return m_pDocument->GetFormFillEnv()->GetJSRuntime()->SetValueByName( |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1013 | szPropName, pValue); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1014 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1015 | return FALSE; |
| 1016 | } |
| 1017 | |
| 1018 | FX_BOOL CPDFXFA_DocEnvironment::GetGlobalProperty( |
| 1019 | CXFA_FFDoc* hDoc, |
| 1020 | const CFX_ByteStringC& szPropName, |
| 1021 | CFXJSE_Value* pValue) { |
| 1022 | if (hDoc != m_pDocument->GetXFADoc()) |
| 1023 | return FALSE; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1024 | if (!m_pDocument->GetFormFillEnv() || |
| 1025 | !m_pDocument->GetFormFillEnv()->GetJSRuntime()) { |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1026 | return FALSE; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1027 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1028 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1029 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1030 | if (!m_pJSContext) |
| 1031 | m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1032 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 1033 | return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1034 | } |