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