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