| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/cjs_context.h" | 7 #include "fpdfsdk/javascript/cjs_context.h" |
| 8 | 8 |
| 9 #include "fpdfsdk/javascript/JS_EventHandler.h" | 9 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 10 #include "fpdfsdk/javascript/cjs_runtime.h" | 10 #include "fpdfsdk/javascript/cjs_runtime.h" |
| 11 #include "fpdfsdk/javascript/resource.h" | 11 #include "fpdfsdk/javascript/resource.h" |
| 12 | 12 |
| 13 CJS_Context::CJS_Context(CJS_Runtime* pRuntime) | 13 CJS_Context::CJS_Context(CJS_Runtime* pRuntime) |
| 14 : m_pRuntime(pRuntime), | 14 : m_pRuntime(pRuntime), |
| 15 m_pEventHandler(new CJS_EventHandler(this)), | 15 m_pEventHandler(new CJS_EventHandler(this)), |
| 16 m_bBusy(FALSE) {} | 16 m_bBusy(false) {} |
| 17 | 17 |
| 18 CJS_Context::~CJS_Context() {} | 18 CJS_Context::~CJS_Context() {} |
| 19 | 19 |
| 20 CPDFSDK_FormFillEnvironment* CJS_Context::GetFormFillEnv() { | 20 CPDFSDK_FormFillEnvironment* CJS_Context::GetFormFillEnv() { |
| 21 return m_pRuntime->GetFormFillEnv(); | 21 return m_pRuntime->GetFormFillEnv(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, | 24 bool CJS_Context::RunScript(const CFX_WideString& script, |
| 25 CFX_WideString* info) { | 25 CFX_WideString* info) { |
| 26 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); | 26 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); |
| 27 v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); | 27 v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); |
| 28 v8::Local<v8::Context> context = m_pRuntime->NewLocalContext(); | 28 v8::Local<v8::Context> context = m_pRuntime->NewLocalContext(); |
| 29 v8::Context::Scope context_scope(context); | 29 v8::Context::Scope context_scope(context); |
| 30 | 30 |
| 31 if (m_bBusy) { | 31 if (m_bBusy) { |
| 32 *info = JSGetStringFromID(IDS_STRING_JSBUSY); | 32 *info = JSGetStringFromID(IDS_STRING_JSBUSY); |
| 33 return FALSE; | 33 return false; |
| 34 } | 34 } |
| 35 m_bBusy = TRUE; | 35 m_bBusy = true; |
| 36 | 36 |
| 37 ASSERT(m_pEventHandler->IsValid()); | 37 ASSERT(m_pEventHandler->IsValid()); |
| 38 CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(), | 38 CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(), |
| 39 m_pEventHandler->EventType()); | 39 m_pEventHandler->EventType()); |
| 40 if (!m_pRuntime->AddEventToSet(event)) { | 40 if (!m_pRuntime->AddEventToSet(event)) { |
| 41 *info = JSGetStringFromID(IDS_STRING_JSEVENT); | 41 *info = JSGetStringFromID(IDS_STRING_JSEVENT); |
| 42 return FALSE; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| 45 CFX_WideString sErrorMessage; | 45 CFX_WideString sErrorMessage; |
| 46 int nRet = 0; | 46 int nRet = 0; |
| 47 if (script.GetLength() > 0) { | 47 if (script.GetLength() > 0) { |
| 48 nRet = m_pRuntime->ExecuteScript(script.c_str(), &sErrorMessage); | 48 nRet = m_pRuntime->ExecuteScript(script.c_str(), &sErrorMessage); |
| 49 } | 49 } |
| 50 | 50 |
| 51 if (nRet < 0) { | 51 if (nRet < 0) { |
| 52 *info += sErrorMessage; | 52 *info += sErrorMessage; |
| 53 } else { | 53 } else { |
| 54 *info = JSGetStringFromID(IDS_STRING_RUN); | 54 *info = JSGetStringFromID(IDS_STRING_RUN); |
| 55 } | 55 } |
| 56 | 56 |
| 57 m_pRuntime->RemoveEventFromSet(event); | 57 m_pRuntime->RemoveEventFromSet(event); |
| 58 m_pEventHandler->Destroy(); | 58 m_pEventHandler->Destroy(); |
| 59 m_bBusy = FALSE; | 59 m_bBusy = false; |
| 60 | 60 |
| 61 return nRet >= 0; | 61 return nRet >= 0; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CJS_Context::OnApp_Init() { | 64 void CJS_Context::OnApp_Init() { |
| 65 m_pEventHandler->OnApp_Init(); | 65 m_pEventHandler->OnApp_Init(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void CJS_Context::OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 68 void CJS_Context::OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 69 const CFX_WideString& strTargetName) { | 69 const CFX_WideString& strTargetName) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CJS_Context::OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | 101 void CJS_Context::OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 102 m_pEventHandler->OnPage_InView(pFormFillEnv); | 102 m_pEventHandler->OnPage_InView(pFormFillEnv); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void CJS_Context::OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | 105 void CJS_Context::OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 106 m_pEventHandler->OnPage_OutView(pFormFillEnv); | 106 m_pEventHandler->OnPage_OutView(pFormFillEnv); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, | 109 void CJS_Context::OnField_MouseDown(bool bModifier, |
| 110 FX_BOOL bShift, | 110 bool bShift, |
| 111 CPDF_FormField* pTarget) { | 111 CPDF_FormField* pTarget) { |
| 112 m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget); | 112 m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, | 115 void CJS_Context::OnField_MouseEnter(bool bModifier, |
| 116 FX_BOOL bShift, | 116 bool bShift, |
| 117 CPDF_FormField* pTarget) { | 117 CPDF_FormField* pTarget) { |
| 118 m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget); | 118 m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, | 121 void CJS_Context::OnField_MouseExit(bool bModifier, |
| 122 FX_BOOL bShift, | 122 bool bShift, |
| 123 CPDF_FormField* pTarget) { | 123 CPDF_FormField* pTarget) { |
| 124 m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget); | 124 m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, | 127 void CJS_Context::OnField_MouseUp(bool bModifier, |
| 128 FX_BOOL bShift, | 128 bool bShift, |
| 129 CPDF_FormField* pTarget) { | 129 CPDF_FormField* pTarget) { |
| 130 m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget); | 130 m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void CJS_Context::OnField_Focus(FX_BOOL bModifier, | 133 void CJS_Context::OnField_Focus(bool bModifier, |
| 134 FX_BOOL bShift, | 134 bool bShift, |
| 135 CPDF_FormField* pTarget, | 135 CPDF_FormField* pTarget, |
| 136 const CFX_WideString& Value) { | 136 const CFX_WideString& Value) { |
| 137 m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value); | 137 m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void CJS_Context::OnField_Blur(FX_BOOL bModifier, | 140 void CJS_Context::OnField_Blur(bool bModifier, |
| 141 FX_BOOL bShift, | 141 bool bShift, |
| 142 CPDF_FormField* pTarget, | 142 CPDF_FormField* pTarget, |
| 143 const CFX_WideString& Value) { | 143 const CFX_WideString& Value) { |
| 144 m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value); | 144 m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, | 147 void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, |
| 148 CPDF_FormField* pTarget, | 148 CPDF_FormField* pTarget, |
| 149 CFX_WideString& Value, | 149 CFX_WideString& Value, |
| 150 FX_BOOL& bRc) { | 150 bool& bRc) { |
| 151 m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc); | 151 m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CJS_Context::OnField_Format(CPDF_FormField* pTarget, | 154 void CJS_Context::OnField_Format(CPDF_FormField* pTarget, |
| 155 CFX_WideString& Value, | 155 CFX_WideString& Value, |
| 156 FX_BOOL bWillCommit) { | 156 bool bWillCommit) { |
| 157 m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit); | 157 m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void CJS_Context::OnField_Keystroke(CFX_WideString& strChange, | 160 void CJS_Context::OnField_Keystroke(CFX_WideString& strChange, |
| 161 const CFX_WideString& strChangeEx, | 161 const CFX_WideString& strChangeEx, |
| 162 FX_BOOL bKeyDown, | 162 bool bKeyDown, |
| 163 FX_BOOL bModifier, | 163 bool bModifier, |
| 164 int& nSelEnd, | 164 int& nSelEnd, |
| 165 int& nSelStart, | 165 int& nSelStart, |
| 166 FX_BOOL bShift, | 166 bool bShift, |
| 167 CPDF_FormField* pTarget, | 167 CPDF_FormField* pTarget, |
| 168 CFX_WideString& Value, | 168 CFX_WideString& Value, |
| 169 FX_BOOL bWillCommit, | 169 bool bWillCommit, |
| 170 FX_BOOL bFieldFull, | 170 bool bFieldFull, |
| 171 FX_BOOL& bRc) { | 171 bool& bRc) { |
| 172 m_pEventHandler->OnField_Keystroke( | 172 m_pEventHandler->OnField_Keystroke( |
| 173 strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart, bShift, | 173 strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart, bShift, |
| 174 pTarget, Value, bWillCommit, bFieldFull, bRc); | 174 pTarget, Value, bWillCommit, bFieldFull, bRc); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void CJS_Context::OnField_Validate(CFX_WideString& strChange, | 177 void CJS_Context::OnField_Validate(CFX_WideString& strChange, |
| 178 const CFX_WideString& strChangeEx, | 178 const CFX_WideString& strChangeEx, |
| 179 FX_BOOL bKeyDown, | 179 bool bKeyDown, |
| 180 FX_BOOL bModifier, | 180 bool bModifier, |
| 181 FX_BOOL bShift, | 181 bool bShift, |
| 182 CPDF_FormField* pTarget, | 182 CPDF_FormField* pTarget, |
| 183 CFX_WideString& Value, | 183 CFX_WideString& Value, |
| 184 FX_BOOL& bRc) { | 184 bool& bRc) { |
| 185 m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, | 185 m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, |
| 186 bShift, pTarget, Value, bRc); | 186 bShift, pTarget, Value, bRc); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, | 189 void CJS_Context::OnScreen_Focus(bool bModifier, |
| 190 FX_BOOL bShift, | 190 bool bShift, |
| 191 CPDFSDK_Annot* pScreen) { | 191 CPDFSDK_Annot* pScreen) { |
| 192 m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen); | 192 m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, | 195 void CJS_Context::OnScreen_Blur(bool bModifier, |
| 196 FX_BOOL bShift, | 196 bool bShift, |
| 197 CPDFSDK_Annot* pScreen) { | 197 CPDFSDK_Annot* pScreen) { |
| 198 m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen); | 198 m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void CJS_Context::OnScreen_Open(FX_BOOL bModifier, | 201 void CJS_Context::OnScreen_Open(bool bModifier, |
| 202 FX_BOOL bShift, | 202 bool bShift, |
| 203 CPDFSDK_Annot* pScreen) { | 203 CPDFSDK_Annot* pScreen) { |
| 204 m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen); | 204 m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CJS_Context::OnScreen_Close(FX_BOOL bModifier, | 207 void CJS_Context::OnScreen_Close(bool bModifier, |
| 208 FX_BOOL bShift, | 208 bool bShift, |
| 209 CPDFSDK_Annot* pScreen) { | 209 CPDFSDK_Annot* pScreen) { |
| 210 m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen); | 210 m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, | 213 void CJS_Context::OnScreen_MouseDown(bool bModifier, |
| 214 FX_BOOL bShift, | 214 bool bShift, |
| 215 CPDFSDK_Annot* pScreen) { | 215 CPDFSDK_Annot* pScreen) { |
| 216 m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen); | 216 m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, | 219 void CJS_Context::OnScreen_MouseUp(bool bModifier, |
| 220 FX_BOOL bShift, | 220 bool bShift, |
| 221 CPDFSDK_Annot* pScreen) { | 221 CPDFSDK_Annot* pScreen) { |
| 222 m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen); | 222 m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, | 225 void CJS_Context::OnScreen_MouseEnter(bool bModifier, |
| 226 FX_BOOL bShift, | 226 bool bShift, |
| 227 CPDFSDK_Annot* pScreen) { | 227 CPDFSDK_Annot* pScreen) { |
| 228 m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen); | 228 m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, | 231 void CJS_Context::OnScreen_MouseExit(bool bModifier, |
| 232 FX_BOOL bShift, | 232 bool bShift, |
| 233 CPDFSDK_Annot* pScreen) { | 233 CPDFSDK_Annot* pScreen) { |
| 234 m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen); | 234 m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void CJS_Context::OnScreen_InView(FX_BOOL bModifier, | 237 void CJS_Context::OnScreen_InView(bool bModifier, |
| 238 FX_BOOL bShift, | 238 bool bShift, |
| 239 CPDFSDK_Annot* pScreen) { | 239 CPDFSDK_Annot* pScreen) { |
| 240 m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen); | 240 m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, | 243 void CJS_Context::OnScreen_OutView(bool bModifier, |
| 244 FX_BOOL bShift, | 244 bool bShift, |
| 245 CPDFSDK_Annot* pScreen) { | 245 CPDFSDK_Annot* pScreen) { |
| 246 m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen); | 246 m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) { | 249 void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) { |
| 250 m_pEventHandler->OnBookmark_MouseUp(pBookMark); | 250 m_pEventHandler->OnBookmark_MouseUp(pBookMark); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void CJS_Context::OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | 253 void CJS_Context::OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 254 m_pEventHandler->OnLink_MouseUp(pFormFillEnv); | 254 m_pEventHandler->OnLink_MouseUp(pFormFillEnv); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void CJS_Context::OnConsole_Exec() { | 257 void CJS_Context::OnConsole_Exec() { |
| 258 m_pEventHandler->OnConsole_Exec(); | 258 m_pEventHandler->OnConsole_Exec(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void CJS_Context::OnExternal_Exec() { | 261 void CJS_Context::OnExternal_Exec() { |
| 262 m_pEventHandler->OnExternal_Exec(); | 262 m_pEventHandler->OnExternal_Exec(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void CJS_Context::OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | 265 void CJS_Context::OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 266 m_pEventHandler->OnBatchExec(pFormFillEnv); | 266 m_pEventHandler->OnBatchExec(pFormFillEnv); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void CJS_Context::OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 269 void CJS_Context::OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 270 const CFX_WideString& strTargetName) { | 270 const CFX_WideString& strTargetName) { |
| 271 m_pEventHandler->OnMenu_Exec(pFormFillEnv, strTargetName); | 271 m_pEventHandler->OnMenu_Exec(pFormFillEnv, strTargetName); |
| 272 } | 272 } |
| OLD | NEW |