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 | 04f50cf | 2018-01-22 21:11:17 +0000 | [diff] [blame^] | 24 | #include "xfa/fxfa/cxfa_widgetacc.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 25 | #include "xfa/fxfa/cxfa_widgetacciterator.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 | |
Tom Sepez | 40badde | 2017-05-01 13:21:39 -0700 | [diff] [blame] | 623 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = |
Dan Sinclair | b7e315c | 2018-01-04 15:43:00 -0500 | [diff] [blame] | 624 | docView->CreateWidgetAccIterator(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 625 | if (pWidgetAccIterator) { |
| 626 | CXFA_EventParam Param; |
| 627 | Param.m_eType = XFA_EVENT_PreSubmit; |
| 628 | while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) |
| 629 | pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 630 | } |
| 631 | |
Dan Sinclair | b7e315c | 2018-01-04 15:43:00 -0500 | [diff] [blame] | 632 | pWidgetAccIterator = docView->CreateWidgetAccIterator(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 633 | if (!pWidgetAccIterator) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 634 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 635 | |
| 636 | CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 637 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 638 | while (pWidgetAcc) { |
Dan Sinclair | 9dfcdd2 | 2018-01-08 17:00:20 -0500 | [diff] [blame] | 639 | int fRet = pWidgetAcc->GetNode()->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 | } |
| 653 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 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 | |
Tom Sepez | 40badde | 2017-05-01 13:21:39 -0700 | [diff] [blame] | 672 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = |
| 673 | m_pContext->GetXFADocView()->CreateWidgetAccIterator(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 674 | if (!pWidgetAccIterator) |
| 675 | return; |
| 676 | |
| 677 | CXFA_EventParam Param; |
| 678 | Param.m_eType = XFA_EVENT_PostSubmit; |
| 679 | CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 680 | while (pWidgetAcc) { |
| 681 | pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 682 | pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 683 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 684 | m_pContext->GetXFADocView()->UpdateDocView(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 687 | bool CPDFXFA_DocEnvironment::Submit(CXFA_FFDoc* hDoc, CXFA_Submit* submit) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 688 | if (!NotifySubmit(true) || !m_pContext->GetXFADocView()) |
| 689 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 690 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 691 | m_pContext->GetXFADocView()->UpdateDocView(); |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 692 | bool ret = SubmitInternal(hDoc, submit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 693 | NotifySubmit(false); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 694 | return ret; |
| 695 | } |
| 696 | |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 697 | RetainPtr<IFX_SeekableReadStream> CPDFXFA_DocEnvironment::OpenLinkedFile( |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 698 | CXFA_FFDoc* hDoc, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 699 | const WideString& wsLink) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 700 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 701 | if (!pFormFillEnv) |
tsepez | 04c1009 | 2016-10-25 15:16:40 -0700 | [diff] [blame] | 702 | return nullptr; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 703 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 704 | ByteString bs = wsLink.UTF16LE_Encode(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 705 | int len = bs.GetLength(); |
| 706 | FPDF_FILEHANDLER* pFileHandler = |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 707 | pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 708 | bs.ReleaseBuffer(len); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 709 | if (!pFileHandler) |
| 710 | return nullptr; |
tsepez | 04c1009 | 2016-10-25 15:16:40 -0700 | [diff] [blame] | 711 | |
tsepez | fa89a20 | 2016-12-02 09:48:30 -0800 | [diff] [blame] | 712 | return MakeSeekableStream(pFileHandler); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 713 | } |
| 714 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 715 | bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, |
| 716 | int fileType, |
| 717 | FPDF_DWORD encodeType, |
| 718 | FPDF_DWORD flag) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 719 | if (!m_pContext->GetXFADocView()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 720 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 721 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 722 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 723 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 724 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 725 | |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 726 | CXFA_FFDoc* ffdoc = m_pContext->GetXFADocView()->GetDoc(); |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 727 | RetainPtr<IFX_SeekableStream> fileStream = MakeSeekableStream(pFileHandler); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 728 | if (fileType == FXFA_SAVEAS_XML) { |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 729 | static constexpr char kContent[] = |
| 730 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
tsepez | fa89a20 | 2016-12-02 09:48:30 -0800 | [diff] [blame] | 731 | fileStream->WriteBlock(kContent, 0, strlen(kContent)); |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 732 | |
| 733 | ffdoc->SavePackage( |
| 734 | ToNode(ffdoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Data)), fileStream, |
| 735 | nullptr); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 736 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | if (fileType != FXFA_SAVEAS_XDP) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 740 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 741 | |
| 742 | if (!flag) { |
| 743 | flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 744 | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 745 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 746 | if (!m_pContext->GetPDFDoc()) { |
tsepez | fa89a20 | 2016-12-02 09:48:30 -0800 | [diff] [blame] | 747 | fileStream->Flush(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 748 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 751 | const CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 752 | if (!pRoot) { |
tsepez | fa89a20 | 2016-12-02 09:48:30 -0800 | [diff] [blame] | 753 | fileStream->Flush(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 754 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 755 | } |
| 756 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 757 | CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 758 | if (!pAcroForm) { |
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_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 764 | if (!pArray) { |
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 | |
| 769 | int size = pArray->GetCount(); |
| 770 | for (int i = 1; i < size; i += 2) { |
| 771 | CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 772 | CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 773 | if (!pPrePDFObj->IsString()) |
| 774 | continue; |
| 775 | if (!pPDFObj->IsReference()) |
| 776 | continue; |
| 777 | |
| 778 | CPDF_Object* pDirectObj = pPDFObj->GetDirect(); |
| 779 | if (!pDirectObj->IsStream()) |
| 780 | continue; |
| 781 | if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) |
| 782 | continue; |
| 783 | if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) |
| 784 | continue; |
| 785 | if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) |
| 786 | continue; |
| 787 | if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) |
| 788 | continue; |
| 789 | if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) |
| 790 | continue; |
| 791 | if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) |
| 792 | continue; |
| 793 | if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) |
| 794 | continue; |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 795 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 796 | if (pPrePDFObj->GetString() == "form") { |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 797 | ffdoc->SavePackage( |
| 798 | ToNode(ffdoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form)), |
| 799 | fileStream, nullptr); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 800 | } else if (pPrePDFObj->GetString() == "datasets") { |
Dan Sinclair | f96dfed | 2017-11-08 19:57:00 +0000 | [diff] [blame] | 801 | ffdoc->SavePackage( |
| 802 | ToNode(ffdoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Datasets)), |
| 803 | fileStream, nullptr); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 806 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 809 | void CPDFXFA_DocEnvironment::ToXFAContentFlags(WideString csSrcContent, |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 810 | FPDF_DWORD& flag) { |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 811 | if (csSrcContent.Contains(L" config ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 812 | flag |= FXFA_CONFIG; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 813 | if (csSrcContent.Contains(L" template ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 814 | flag |= FXFA_TEMPLATE; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 815 | if (csSrcContent.Contains(L" localeSet ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 816 | flag |= FXFA_LOCALESET; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 817 | if (csSrcContent.Contains(L" datasets ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 818 | flag |= FXFA_DATASETS; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 819 | if (csSrcContent.Contains(L" xmpmeta ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 820 | flag |= FXFA_XMPMETA; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 821 | if (csSrcContent.Contains(L" xfdf ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 822 | flag |= FXFA_XFDF; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 823 | if (csSrcContent.Contains(L" form ")) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 824 | flag |= FXFA_FORM; |
| 825 | if (flag == 0) { |
| 826 | flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 827 | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 828 | } |
| 829 | } |
| 830 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 831 | bool CPDFXFA_DocEnvironment::MailToInfo(WideString& csURL, |
| 832 | WideString& csToAddress, |
| 833 | WideString& csCCAddress, |
| 834 | WideString& csBCCAddress, |
| 835 | WideString& csSubject, |
| 836 | WideString& csMsg) { |
| 837 | WideString srcURL = csURL; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 838 | srcURL.TrimLeft(); |
| 839 | if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 840 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 841 | |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 842 | auto pos = srcURL.Find(L'?'); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 843 | WideString tmp; |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 844 | if (!pos.has_value()) { |
| 845 | pos = srcURL.Find(L'@'); |
| 846 | if (!pos.has_value()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 847 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 848 | |
| 849 | tmp = srcURL.Right(csURL.GetLength() - 7); |
| 850 | } else { |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 851 | tmp = srcURL.Left(pos.value()); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 852 | tmp = tmp.Right(tmp.GetLength() - 7); |
| 853 | } |
Lei Zhang | 135c660 | 2017-11-21 18:07:00 +0000 | [diff] [blame] | 854 | tmp.Trim(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 855 | |
| 856 | csToAddress = tmp; |
| 857 | |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 858 | srcURL = srcURL.Right(srcURL.GetLength() - (pos.value() + 1)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 859 | while (!srcURL.IsEmpty()) { |
Lei Zhang | 135c660 | 2017-11-21 18:07:00 +0000 | [diff] [blame] | 860 | srcURL.Trim(); |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 861 | pos = srcURL.Find(L'&'); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 862 | |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 863 | tmp = (!pos.has_value()) ? srcURL : srcURL.Left(pos.value()); |
Lei Zhang | 135c660 | 2017-11-21 18:07:00 +0000 | [diff] [blame] | 864 | tmp.Trim(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 865 | if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) { |
| 866 | tmp = tmp.Right(tmp.GetLength() - 3); |
| 867 | if (!csCCAddress.IsEmpty()) |
| 868 | csCCAddress += L';'; |
| 869 | csCCAddress += tmp; |
| 870 | } else if (tmp.GetLength() >= 4 && |
| 871 | tmp.Left(4).CompareNoCase(L"bcc=") == 0) { |
| 872 | tmp = tmp.Right(tmp.GetLength() - 4); |
| 873 | if (!csBCCAddress.IsEmpty()) |
| 874 | csBCCAddress += L';'; |
| 875 | csBCCAddress += tmp; |
| 876 | } else if (tmp.GetLength() >= 8 && |
| 877 | tmp.Left(8).CompareNoCase(L"subject=") == 0) { |
| 878 | tmp = tmp.Right(tmp.GetLength() - 8); |
| 879 | csSubject += tmp; |
| 880 | } else if (tmp.GetLength() >= 5 && |
| 881 | tmp.Left(5).CompareNoCase(L"body=") == 0) { |
| 882 | tmp = tmp.Right(tmp.GetLength() - 5); |
| 883 | csMsg += tmp; |
| 884 | } |
Ryan Harrison | 12db751 | 2017-08-23 10:39:35 -0400 | [diff] [blame] | 885 | srcURL = !pos.has_value() |
| 886 | ? L"" |
| 887 | : srcURL.Right(csURL.GetLength() - (pos.value() + 1)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 888 | } |
| 889 | csToAddress.Replace(L",", L";"); |
| 890 | csCCAddress.Replace(L",", L";"); |
| 891 | csBCCAddress.Replace(L",", L";"); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 892 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 895 | bool CPDFXFA_DocEnvironment::SubmitInternal(CXFA_FFDoc* hDoc, |
| 896 | CXFA_Submit* submit) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 897 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 898 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 899 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 900 | |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 901 | WideString csURL = submit->GetSubmitTarget(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 902 | if (csURL.IsEmpty()) { |
Henrique Nakashima | ce6979f | 2017-12-07 22:19:53 +0000 | [diff] [blame] | 903 | WideString ws = WideString::FromLocal("Submit cancelled."); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 904 | ByteString bs = ws.UTF16LE_Encode(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 905 | int len = bs.GetLength(); |
Dan Sinclair | aee2869 | 2017-11-14 21:19:44 +0000 | [diff] [blame] | 906 | pFormFillEnv->Alert(reinterpret_cast<FPDF_WIDESTRING>(bs.GetBuffer(len)), |
| 907 | reinterpret_cast<FPDF_WIDESTRING>(L""), 0, 4); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 908 | bs.ReleaseBuffer(len); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 909 | return false; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 910 | } |
| 911 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 912 | FPDF_FILEHANDLER* pFileHandler = nullptr; |
| 913 | int fileFlag = -1; |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 914 | switch (submit->GetSubmitFormat()) { |
Dan Sinclair | d02c4d8 | 2017-11-30 22:06:40 +0000 | [diff] [blame] | 915 | case XFA_AttributeEnum::Xdp: { |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 916 | WideString csContent = submit->GetSubmitXDPContent(); |
Lei Zhang | 135c660 | 2017-11-21 18:07:00 +0000 | [diff] [blame] | 917 | csContent.Trim(); |
Dan Sinclair | ebe865d | 2017-11-21 22:05:40 +0000 | [diff] [blame] | 918 | |
Henrique Nakashima | ce6979f | 2017-12-07 22:19:53 +0000 | [diff] [blame] | 919 | WideString space = WideString::FromLocal(" "); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 920 | csContent = space + csContent + space; |
| 921 | FPDF_DWORD flag = 0; |
Dan Sinclair | c5e0f66 | 2017-12-14 20:20:33 +0000 | [diff] [blame] | 922 | if (submit->IsSubmitEmbedPDF()) |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 923 | flag |= FXFA_PDF; |
| 924 | |
| 925 | ToXFAContentFlags(csContent, flag); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 926 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 927 | fileFlag = FXFA_SAVEAS_XDP; |
| 928 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); |
| 929 | break; |
| 930 | } |
Dan Sinclair | d02c4d8 | 2017-11-30 22:06:40 +0000 | [diff] [blame] | 931 | case XFA_AttributeEnum::Xml: |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 932 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 933 | fileFlag = FXFA_SAVEAS_XML; |
| 934 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); |
| 935 | break; |
Dan Sinclair | d02c4d8 | 2017-11-30 22:06:40 +0000 | [diff] [blame] | 936 | case XFA_AttributeEnum::Pdf: |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 937 | break; |
Dan Sinclair | d02c4d8 | 2017-11-30 22:06:40 +0000 | [diff] [blame] | 938 | case XFA_AttributeEnum::Urlencoded: |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 939 | pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 940 | fileFlag = FXFA_SAVEAS_XML; |
| 941 | ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); |
| 942 | break; |
| 943 | default: |
| 944 | return false; |
| 945 | } |
| 946 | if (!pFileHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 947 | return false; |
Dan Sinclair | ebe865d | 2017-11-21 22:05:40 +0000 | [diff] [blame] | 948 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 949 | if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 950 | WideString csToAddress; |
| 951 | WideString csCCAddress; |
| 952 | WideString csBCCAddress; |
| 953 | WideString csSubject; |
| 954 | WideString csMsg; |
tsepez | 16b703c | 2016-10-26 08:45:31 -0700 | [diff] [blame] | 955 | if (!MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, |
| 956 | csMsg)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 957 | return false; |
tsepez | 16b703c | 2016-10-26 08:45:31 -0700 | [diff] [blame] | 958 | } |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 959 | ByteString bsTo = WideString(csToAddress).UTF16LE_Encode(); |
| 960 | ByteString bsCC = WideString(csCCAddress).UTF16LE_Encode(); |
| 961 | ByteString bsBcc = WideString(csBCCAddress).UTF16LE_Encode(); |
| 962 | ByteString bsSubject = WideString(csSubject).UTF16LE_Encode(); |
| 963 | ByteString bsMsg = WideString(csMsg).UTF16LE_Encode(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 964 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 965 | FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 966 | FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 967 | FPDF_WIDESTRING pSubject = |
| 968 | (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 969 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 970 | pFormFillEnv->EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); |
Ryan Harrison | 0186c18 | 2017-08-01 16:20:40 -0400 | [diff] [blame] | 971 | bsTo.ReleaseBuffer(bsTo.GetStringLength()); |
| 972 | bsCC.ReleaseBuffer(bsCC.GetStringLength()); |
| 973 | bsBcc.ReleaseBuffer(bsBcc.GetStringLength()); |
| 974 | bsSubject.ReleaseBuffer(bsSubject.GetStringLength()); |
| 975 | bsMsg.ReleaseBuffer(bsMsg.GetStringLength()); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 976 | } else { |
| 977 | // HTTP or FTP |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 978 | WideString ws; |
| 979 | ByteString bs = csURL.UTF16LE_Encode(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 980 | int len = bs.GetLength(); |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 981 | pFormFillEnv->UploadTo(pFileHandler, fileFlag, |
| 982 | (FPDF_WIDESTRING)bs.GetBuffer(len)); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 983 | bs.ReleaseBuffer(len); |
| 984 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 985 | return true; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 988 | bool CPDFXFA_DocEnvironment::SetGlobalProperty(CXFA_FFDoc* hDoc, |
| 989 | const ByteStringView& szPropName, |
| 990 | CFXJSE_Value* pValue) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 991 | if (hDoc != m_pContext->GetXFADoc()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 992 | return false; |
Tom Sepez | 7dc9fe5 | 2017-05-18 09:51:57 -0700 | [diff] [blame] | 993 | if (!m_pContext->GetFormFillEnv() || |
| 994 | !m_pContext->GetFormFillEnv()->GetJSRuntime()) { |
| 995 | return false; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 996 | } |
Tom Sepez | 7dc9fe5 | 2017-05-18 09:51:57 -0700 | [diff] [blame] | 997 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
| 998 | IJS_EventContext* pContext = pFormFillEnv->GetJSRuntime()->NewEventContext(); |
| 999 | bool bRet = pFormFillEnv->GetJSRuntime()->SetValueByName(szPropName, pValue); |
| 1000 | pFormFillEnv->GetJSRuntime()->ReleaseEventContext(pContext); |
| 1001 | return bRet; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1004 | bool CPDFXFA_DocEnvironment::GetGlobalProperty(CXFA_FFDoc* hDoc, |
| 1005 | const ByteStringView& szPropName, |
| 1006 | CFXJSE_Value* pValue) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1007 | if (hDoc != m_pContext->GetXFADoc()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1008 | return false; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1009 | if (!m_pContext->GetFormFillEnv() || |
| 1010 | !m_pContext->GetFormFillEnv()->GetJSRuntime()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1011 | return false; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 1012 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1013 | CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
Tom Sepez | 7dc9fe5 | 2017-05-18 09:51:57 -0700 | [diff] [blame] | 1014 | IJS_EventContext* pContext = pFormFillEnv->GetJSRuntime()->NewEventContext(); |
| 1015 | bool bRet = pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); |
| 1016 | pFormFillEnv->GetJSRuntime()->ReleaseEventContext(pContext); |
| 1017 | return bRet; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1018 | } |