| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 | |
| 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_JS_RUNTIME_H_ | |
| 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_RUNTIME_H_ | |
| 9 | |
| 10 #include <set> | |
| 11 #include <map> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "core/include/fxcrt/fx_basic.h" | |
| 16 #include "fpdfsdk/include/javascript/IJavaScript.h" | |
| 17 #include "fpdfsdk/include/jsapi/fxjs_v8.h" | |
| 18 #include "fpdfsdk/src/javascript/JS_EventHandler.h" | |
| 19 | |
| 20 class CJS_Context; | |
| 21 | |
| 22 class CJS_Runtime : public IJS_Runtime { | |
| 23 public: | |
| 24 class Observer { | |
| 25 public: | |
| 26 virtual void OnDestroyed() = 0; | |
| 27 | |
| 28 protected: | |
| 29 virtual ~Observer() {} | |
| 30 }; | |
| 31 | |
| 32 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; | |
| 33 | |
| 34 static CJS_Runtime* FromContext(const IJS_Context* cc); | |
| 35 | |
| 36 explicit CJS_Runtime(CPDFDoc_Environment* pApp); | |
| 37 ~CJS_Runtime() override; | |
| 38 | |
| 39 // IJS_Runtime | |
| 40 IJS_Context* NewContext() override; | |
| 41 void ReleaseContext(IJS_Context* pContext) override; | |
| 42 IJS_Context* GetCurrentContext() override; | |
| 43 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; | |
| 44 CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; } | |
| 45 int Execute(IJS_Context* cc, | |
| 46 const wchar_t* script, | |
| 47 CFX_WideString* info) override; | |
| 48 | |
| 49 CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } | |
| 50 | |
| 51 // Returns true if the event isn't already found in the set. | |
| 52 bool AddEventToSet(const FieldEvent& event); | |
| 53 void RemoveEventFromSet(const FieldEvent& event); | |
| 54 | |
| 55 void BeginBlock() { m_bBlocking = TRUE; } | |
| 56 void EndBlock() { m_bBlocking = FALSE; } | |
| 57 FX_BOOL IsBlocking() const { return m_bBlocking; } | |
| 58 | |
| 59 v8::Isolate* GetIsolate() const { return m_isolate; } | |
| 60 v8::Local<v8::Context> NewJSContext(); | |
| 61 | |
| 62 void SetConstArray(const CFX_WideString& name, v8::Local<v8::Array> array); | |
| 63 v8::Local<v8::Array> GetConstArray(const CFX_WideString& name); | |
| 64 | |
| 65 #ifdef PDF_ENABLE_XFA | |
| 66 FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, | |
| 67 FXJSE_HVALUE hValue) override; | |
| 68 FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, | |
| 69 FXJSE_HVALUE hValue) override; | |
| 70 #endif // PDF_ENABLE_XFA | |
| 71 | |
| 72 void AddObserver(Observer* observer); | |
| 73 void RemoveObserver(Observer* observer); | |
| 74 | |
| 75 private: | |
| 76 void DefineJSObjects(); | |
| 77 | |
| 78 CFX_ArrayTemplate<CJS_Context*> m_ContextArray; | |
| 79 CPDFDoc_Environment* m_pApp; | |
| 80 CPDFSDK_Document* m_pDocument; | |
| 81 FX_BOOL m_bBlocking; | |
| 82 std::set<FieldEvent> m_FieldEventSet; | |
| 83 v8::Isolate* m_isolate; | |
| 84 bool m_isolateManaged; | |
| 85 v8::Global<v8::Context> m_context; | |
| 86 std::vector<v8::Global<v8::Object>*> m_StaticObjects; | |
| 87 std::map<CFX_WideString, v8::Global<v8::Array>> m_ConstArrays; | |
| 88 std::set<Observer*> m_observers; | |
| 89 }; | |
| 90 | |
| 91 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_RUNTIME_H_ | |
| OLD | NEW |