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