| 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> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 public: | 26 public: |
| 27 virtual void OnDestroyed() = 0; | 27 virtual void OnDestroyed() = 0; |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 virtual ~Observer() {} | 30 virtual ~Observer() {} |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; | 33 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; |
| 34 | 34 |
| 35 static CJS_Runtime* FromContext(const IJS_Context* cc); | 35 static CJS_Runtime* FromContext(const IJS_Context* cc); |
| 36 static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); |
| 36 | 37 |
| 37 explicit CJS_Runtime(CPDFDoc_Environment* pApp); | 38 explicit CJS_Runtime(CPDFDoc_Environment* pApp); |
| 38 ~CJS_Runtime() override; | 39 ~CJS_Runtime() override; |
| 39 | 40 |
| 40 // IJS_Runtime | 41 // IJS_Runtime |
| 41 IJS_Context* NewContext() override; | 42 IJS_Context* NewContext() override; |
| 42 void ReleaseContext(IJS_Context* pContext) override; | 43 void ReleaseContext(IJS_Context* pContext) override; |
| 43 IJS_Context* GetCurrentContext() override; | 44 IJS_Context* GetCurrentContext() override; |
| 44 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; | 45 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; |
| 45 CPDFSDK_Document* GetReaderDocument() override; | 46 CPDFSDK_Document* GetReaderDocument() override; |
| 46 int Execute(const CFX_WideString& script, CFX_WideString* info) override; | 47 int ExecuteScript(const CFX_WideString& script, |
| 48 CFX_WideString* info) override; |
| 47 | 49 |
| 48 CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } | 50 CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } |
| 49 | 51 |
| 50 // Returns true if the event isn't already found in the set. | 52 // Returns true if the event isn't already found in the set. |
| 51 bool AddEventToSet(const FieldEvent& event); | 53 bool AddEventToSet(const FieldEvent& event); |
| 52 void RemoveEventFromSet(const FieldEvent& event); | 54 void RemoveEventFromSet(const FieldEvent& event); |
| 53 | 55 |
| 54 void BeginBlock() { m_bBlocking = TRUE; } | 56 void BeginBlock() { m_bBlocking = TRUE; } |
| 55 void EndBlock() { m_bBlocking = FALSE; } | 57 void EndBlock() { m_bBlocking = FALSE; } |
| 56 FX_BOOL IsBlocking() const { return m_bBlocking; } | 58 FX_BOOL IsBlocking() const { return m_bBlocking; } |
| 57 | 59 |
| 58 v8::Isolate* GetIsolate() const { return m_isolate; } | |
| 59 v8::Local<v8::Context> NewJSContext(); | |
| 60 | |
| 61 void SetConstArray(const CFX_WideString& name, v8::Local<v8::Array> array); | |
| 62 v8::Local<v8::Array> GetConstArray(const CFX_WideString& name); | |
| 63 | |
| 64 #ifdef PDF_ENABLE_XFA | 60 #ifdef PDF_ENABLE_XFA |
| 65 FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, | 61 FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, |
| 66 CFXJSE_Value* pValue) override; | 62 CFXJSE_Value* pValue) override; |
| 67 FX_BOOL SetValueByName(const CFX_ByteStringC& utf8Name, | 63 FX_BOOL SetValueByName(const CFX_ByteStringC& utf8Name, |
| 68 CFXJSE_Value* pValue) override; | 64 CFXJSE_Value* pValue) override; |
| 69 #endif // PDF_ENABLE_XFA | 65 #endif // PDF_ENABLE_XFA |
| 70 | 66 |
| 71 void AddObserver(Observer* observer); | 67 void AddObserver(Observer* observer); |
| 72 void RemoveObserver(Observer* observer); | 68 void RemoveObserver(Observer* observer); |
| 73 | 69 |
| 74 private: | 70 private: |
| 75 void DefineJSObjects(); | 71 void DefineJSObjects(); |
| 76 | 72 |
| 77 std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; | 73 std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; |
| 78 CPDFDoc_Environment* const m_pApp; | 74 CPDFDoc_Environment* const m_pApp; |
| 79 CPDFSDK_Document* m_pDocument; | 75 CPDFSDK_Document* m_pDocument; |
| 80 bool m_bBlocking; | 76 bool m_bBlocking; |
| 81 bool m_isolateManaged; | 77 bool m_isolateManaged; |
| 82 std::set<FieldEvent> m_FieldEventSet; | 78 std::set<FieldEvent> m_FieldEventSet; |
| 83 std::set<Observer*> m_observers; | 79 std::set<Observer*> m_observers; |
| 84 }; | 80 }; |
| 85 | 81 |
| 86 #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ | 82 #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
| OLD | NEW |