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