Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: fpdfsdk/include/javascript/JS_Runtime.h

Issue 1352393003: Use std::set<> to track active event handlers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Simpler set manipulations Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fpdfsdk/src/javascript/JS_Context.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <utility>
12
10 #include "../../../third_party/base/nonstd_unique_ptr.h" 13 #include "../../../third_party/base/nonstd_unique_ptr.h"
11 #include "../../../core/include/fxcrt/fx_basic.h" 14 #include "../../../core/include/fxcrt/fx_basic.h"
12 #include "../jsapi/fxjs_v8.h" 15 #include "../jsapi/fxjs_v8.h"
13 #include "IJavaScript.h" 16 #include "IJavaScript.h"
14 #include "JS_EventHandler.h" 17 #include "JS_EventHandler.h"
15 18
16 class CJS_Context; 19 class CJS_Context;
17 20
18 class CJS_FieldEvent {
19 public:
20 CFX_WideString sTargetName;
21 JS_EVENT_T eEventType;
22 CJS_FieldEvent* pNext;
23 };
24
25 class CJS_Runtime : public IFXJS_Runtime { 21 class CJS_Runtime : public IFXJS_Runtime {
26 public: 22 public:
23 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>;
24
27 explicit CJS_Runtime(CPDFDoc_Environment* pApp); 25 explicit CJS_Runtime(CPDFDoc_Environment* pApp);
28 ~CJS_Runtime() override; 26 ~CJS_Runtime() override;
29 27
30 // IFXJS_Runtime 28 // IFXJS_Runtime
31 IFXJS_Context* NewContext() override; 29 IFXJS_Context* NewContext() override;
32 void ReleaseContext(IFXJS_Context* pContext) override; 30 void ReleaseContext(IFXJS_Context* pContext) override;
33 IFXJS_Context* GetCurrentContext() override; 31 IFXJS_Context* GetCurrentContext() override;
34 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; 32 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override;
35 CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; } 33 CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; }
36 34
37 CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } 35 CPDFDoc_Environment* GetReaderApp() const { return m_pApp; }
38 36
39 FX_BOOL AddEventToLoop(const CFX_WideString& sTargetName, 37 // Returns true if the event isn't already found in the set.
40 JS_EVENT_T eEventType); 38 bool AddEventToSet(const FieldEvent& event);
41 void RemoveEventInLoop(const CFX_WideString& sTargetName, 39 void RemoveEventFromSet(const FieldEvent& event);
42 JS_EVENT_T eEventType);
43 void RemoveEventsInLoop(CJS_FieldEvent* pStart);
44 40
45 void BeginBlock() { m_bBlocking = TRUE; } 41 void BeginBlock() { m_bBlocking = TRUE; }
46 void EndBlock() { m_bBlocking = FALSE; } 42 void EndBlock() { m_bBlocking = FALSE; }
47 FX_BOOL IsBlocking() const { return m_bBlocking; } 43 FX_BOOL IsBlocking() const { return m_bBlocking; }
48 44
49 v8::Isolate* GetIsolate() const { return m_isolate; } 45 v8::Isolate* GetIsolate() const { return m_isolate; }
50 v8::Local<v8::Context> NewJSContext(); 46 v8::Local<v8::Context> NewJSContext();
51 47
52 private: 48 private:
53 void DefineJSObjects(); 49 void DefineJSObjects();
54 50
55 CFX_ArrayTemplate<CJS_Context*> m_ContextArray; 51 CFX_ArrayTemplate<CJS_Context*> m_ContextArray;
56 CPDFDoc_Environment* m_pApp; 52 CPDFDoc_Environment* m_pApp;
57 CPDFSDK_Document* m_pDocument; 53 CPDFSDK_Document* m_pDocument;
58 FX_BOOL m_bBlocking; 54 FX_BOOL m_bBlocking;
59 CJS_FieldEvent* m_pFieldEventPath; 55 std::set<FieldEvent> m_FieldEventSet;
60 v8::Isolate* m_isolate; 56 v8::Isolate* m_isolate;
61 bool m_isolateManaged; 57 bool m_isolateManaged;
62 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; 58 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator;
63 v8::Global<v8::Context> m_context; 59 v8::Global<v8::Context> m_context;
64 }; 60 };
65 61
66 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ 62 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/src/javascript/JS_Context.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698