| 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_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ | 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |
| 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ | 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "../../../third_party/base/nonstd_unique_ptr.h" | 13 #include "../../../third_party/base/nonstd_unique_ptr.h" |
| 14 #include "../../../core/include/fxcrt/fx_basic.h" | 14 #include "../../../core/include/fxcrt/fx_basic.h" |
| 15 #include "../jsapi/fxjs_v8.h" | 15 #include "../jsapi/fxjs_v8.h" |
| 16 #include "IJavaScript.h" | 16 #include "IJavaScript.h" |
| 17 #include "JS_EventHandler.h" | 17 #include "JS_EventHandler.h" |
| 18 | 18 |
| 19 class CJS_Context; | 19 class CJS_Context; |
| 20 | 20 |
| 21 class CJS_Runtime : public IFXJS_Runtime { | 21 class CJS_Runtime : public IFXJS_Runtime { |
| 22 public: | 22 public: |
| 23 class Observer { |
| 24 public: |
| 25 virtual void OnDestroyed() = 0; |
| 26 |
| 27 protected: |
| 28 virtual ~Observer() {} |
| 29 }; |
| 30 |
| 23 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; | 31 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; |
| 24 | 32 |
| 25 explicit CJS_Runtime(CPDFDoc_Environment* pApp); | 33 explicit CJS_Runtime(CPDFDoc_Environment* pApp); |
| 26 ~CJS_Runtime() override; | 34 ~CJS_Runtime() override; |
| 27 | 35 |
| 28 // IFXJS_Runtime | 36 // IFXJS_Runtime |
| 29 IFXJS_Context* NewContext() override; | 37 IFXJS_Context* NewContext() override; |
| 30 void ReleaseContext(IFXJS_Context* pContext) override; | 38 void ReleaseContext(IFXJS_Context* pContext) override; |
| 31 IFXJS_Context* GetCurrentContext() override; | 39 IFXJS_Context* GetCurrentContext() override; |
| 32 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; | 40 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 FX_BOOL IsBlocking() const { return m_bBlocking; } | 51 FX_BOOL IsBlocking() const { return m_bBlocking; } |
| 44 | 52 |
| 45 v8::Isolate* GetIsolate() const { return m_isolate; } | 53 v8::Isolate* GetIsolate() const { return m_isolate; } |
| 46 v8::Local<v8::Context> NewJSContext(); | 54 v8::Local<v8::Context> NewJSContext(); |
| 47 | 55 |
| 48 virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, | 56 virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 49 FXJSE_HVALUE hValue); | 57 FXJSE_HVALUE hValue); |
| 50 virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, | 58 virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, |
| 51 FXJSE_HVALUE hValue); | 59 FXJSE_HVALUE hValue); |
| 52 | 60 |
| 61 void AddObserver(Observer* observer); |
| 62 void RemoveObserver(Observer* observer); |
| 63 |
| 53 private: | 64 private: |
| 54 void DefineJSObjects(); | 65 void DefineJSObjects(); |
| 55 | 66 |
| 56 CFX_ArrayTemplate<CJS_Context*> m_ContextArray; | 67 CFX_ArrayTemplate<CJS_Context*> m_ContextArray; |
| 57 CPDFDoc_Environment* m_pApp; | 68 CPDFDoc_Environment* m_pApp; |
| 58 CPDFSDK_Document* m_pDocument; | 69 CPDFSDK_Document* m_pDocument; |
| 59 FX_BOOL m_bBlocking; | 70 FX_BOOL m_bBlocking; |
| 60 std::set<FieldEvent> m_FieldEventSet; | 71 std::set<FieldEvent> m_FieldEventSet; |
| 61 v8::Isolate* m_isolate; | 72 v8::Isolate* m_isolate; |
| 62 bool m_isolateManaged; | 73 bool m_isolateManaged; |
| 63 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; | 74 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; |
| 64 v8::Global<v8::Context> m_context; | 75 v8::Global<v8::Context> m_context; |
| 76 std::set<Observer*> m_observers; |
| 65 }; | 77 }; |
| 66 | 78 |
| 67 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ | 79 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |
| OLD | NEW |