| 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 #ifndef FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
| 8 #define FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ | 8 #define FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "core/fxcrt/include/cfx_observable.h" |
| 16 #include "core/fxcrt/include/fx_basic.h" | 17 #include "core/fxcrt/include/fx_basic.h" |
| 17 #include "fpdfsdk/javascript/JS_EventHandler.h" | 18 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 18 #include "fpdfsdk/javascript/ijs_runtime.h" | 19 #include "fpdfsdk/javascript/ijs_runtime.h" |
| 19 #include "fxjs/include/fxjs_v8.h" | 20 #include "fxjs/include/fxjs_v8.h" |
| 20 | 21 |
| 21 class CJS_Context; | 22 class CJS_Context; |
| 22 | 23 |
| 23 class CJS_Runtime : public IJS_Runtime, public CFXJS_Engine { | 24 class CJS_Runtime : public IJS_Runtime, |
| 25 public CFXJS_Engine, |
| 26 public CFX_Observable<CJS_Runtime> { |
| 24 public: | 27 public: |
| 25 class Observer { | |
| 26 public: | |
| 27 virtual void OnDestroyed() = 0; | |
| 28 | |
| 29 protected: | |
| 30 virtual ~Observer() {} | |
| 31 }; | |
| 32 | |
| 33 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; | 28 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; |
| 34 | 29 |
| 35 static CJS_Runtime* FromContext(const IJS_Context* cc); | 30 static CJS_Runtime* FromContext(const IJS_Context* cc); |
| 36 static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); | 31 static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); |
| 37 | 32 |
| 38 explicit CJS_Runtime(CPDFDoc_Environment* pApp); | 33 explicit CJS_Runtime(CPDFDoc_Environment* pApp); |
| 39 ~CJS_Runtime() override; | 34 ~CJS_Runtime() override; |
| 40 | 35 |
| 41 // IJS_Runtime | 36 // IJS_Runtime |
| 42 IJS_Context* NewContext() override; | 37 IJS_Context* NewContext() override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 void EndBlock() { m_bBlocking = FALSE; } | 52 void EndBlock() { m_bBlocking = FALSE; } |
| 58 FX_BOOL IsBlocking() const { return m_bBlocking; } | 53 FX_BOOL IsBlocking() const { return m_bBlocking; } |
| 59 | 54 |
| 60 #ifdef PDF_ENABLE_XFA | 55 #ifdef PDF_ENABLE_XFA |
| 61 FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, | 56 FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, |
| 62 CFXJSE_Value* pValue) override; | 57 CFXJSE_Value* pValue) override; |
| 63 FX_BOOL SetValueByName(const CFX_ByteStringC& utf8Name, | 58 FX_BOOL SetValueByName(const CFX_ByteStringC& utf8Name, |
| 64 CFXJSE_Value* pValue) override; | 59 CFXJSE_Value* pValue) override; |
| 65 #endif // PDF_ENABLE_XFA | 60 #endif // PDF_ENABLE_XFA |
| 66 | 61 |
| 67 void AddObserver(Observer* observer); | |
| 68 void RemoveObserver(Observer* observer); | |
| 69 | |
| 70 private: | 62 private: |
| 71 void DefineJSObjects(); | 63 void DefineJSObjects(); |
| 72 | 64 |
| 73 std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; | 65 std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; |
| 74 CPDFDoc_Environment* const m_pApp; | 66 CPDFDoc_Environment* const m_pApp; |
| 75 CPDFSDK_Document* m_pDocument; | 67 CPDFSDK_Document* m_pDocument; |
| 76 bool m_bBlocking; | 68 bool m_bBlocking; |
| 77 bool m_isolateManaged; | 69 bool m_isolateManaged; |
| 78 std::set<FieldEvent> m_FieldEventSet; | 70 std::set<FieldEvent> m_FieldEventSet; |
| 79 std::set<Observer*> m_observers; | |
| 80 }; | 71 }; |
| 81 | 72 |
| 82 #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ | 73 #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
| OLD | NEW |