OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #ifndef ScriptState_h | 5 #ifndef ScriptState_h |
6 #define ScriptState_h | 6 #define ScriptState_h |
7 | 7 |
8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
9 #include "bindings/core/v8/V8PerContextData.h" | 9 #include "bindings/core/v8/V8PerContextData.h" |
10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 m_context->Enter(); | 37 m_context->Enter(); |
38 } | 38 } |
39 | 39 |
40 ~Scope() | 40 ~Scope() |
41 { | 41 { |
42 m_context->Exit(); | 42 m_context->Exit(); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 v8::HandleScope m_handleScope; | 46 v8::HandleScope m_handleScope; |
47 v8::Handle<v8::Context> m_context; | 47 v8::Local<v8::Context> m_context; |
48 }; | 48 }; |
49 | 49 |
50 static PassRefPtr<ScriptState> create(v8::Handle<v8::Context>, PassRefPtr<DO
MWrapperWorld>); | 50 static PassRefPtr<ScriptState> create(v8::Local<v8::Context>, PassRefPtr<DOM
WrapperWorld>); |
51 virtual ~ScriptState(); | 51 virtual ~ScriptState(); |
52 | 52 |
53 static ScriptState* current(v8::Isolate* isolate) | 53 static ScriptState* current(v8::Isolate* isolate) |
54 { | 54 { |
55 return from(isolate->GetCurrentContext()); | 55 return from(isolate->GetCurrentContext()); |
56 } | 56 } |
57 | 57 |
58 static ScriptState* from(v8::Handle<v8::Context> context) | 58 static ScriptState* from(v8::Local<v8::Context> context) |
59 { | 59 { |
60 ASSERT(!context.IsEmpty()); | 60 ASSERT(!context.IsEmpty()); |
61 ScriptState* scriptState = static_cast<ScriptState*>(context->GetAligned
PointerFromEmbedderData(v8ContextPerContextDataIndex)); | 61 ScriptState* scriptState = static_cast<ScriptState*>(context->GetAligned
PointerFromEmbedderData(v8ContextPerContextDataIndex)); |
62 // ScriptState::from() must not be called for a context that does not ha
ve | 62 // ScriptState::from() must not be called for a context that does not ha
ve |
63 // valid embedder data in the embedder field. | 63 // valid embedder data in the embedder field. |
64 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState); | 64 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState); |
65 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == conte
xt); | 65 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == conte
xt); |
66 return scriptState; | 66 return scriptState; |
67 } | 67 } |
68 | 68 |
69 static ScriptState* forMainWorld(LocalFrame*); | 69 static ScriptState* forMainWorld(LocalFrame*); |
70 | 70 |
71 v8::Isolate* isolate() const { return m_isolate; } | 71 v8::Isolate* isolate() const { return m_isolate; } |
72 DOMWrapperWorld& world() const { return *m_world; } | 72 DOMWrapperWorld& world() const { return *m_world; } |
73 LocalDOMWindow* domWindow() const; | 73 LocalDOMWindow* domWindow() const; |
74 virtual ExecutionContext* executionContext() const; | 74 virtual ExecutionContext* executionContext() const; |
75 virtual void setExecutionContext(ExecutionContext*); | 75 virtual void setExecutionContext(ExecutionContext*); |
76 | 76 |
77 // This can return an empty handle if the v8::Context is gone. | 77 // This can return an empty handle if the v8::Context is gone. |
78 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } | 78 v8::Local<v8::Context> context() const { return m_context.newLocal(m_isolate
); } |
79 bool contextIsValid() const { return !m_context.isEmpty() && m_perContextDat
a; } | 79 bool contextIsValid() const { return !m_context.isEmpty() && m_perContextDat
a; } |
80 void detachGlobalObject(); | 80 void detachGlobalObject(); |
81 void clearContext() { return m_context.clear(); } | 81 void clearContext() { return m_context.clear(); } |
82 #if ENABLE(ASSERT) | 82 #if ENABLE(ASSERT) |
83 bool isGlobalObjectDetached() const { return m_globalObjectDetached; } | 83 bool isGlobalObjectDetached() const { return m_globalObjectDetached; } |
84 #endif | 84 #endif |
85 | 85 |
86 V8PerContextData* perContextData() const { return m_perContextData.get(); } | 86 V8PerContextData* perContextData() const { return m_perContextData.get(); } |
87 void disposePerContextData(); | 87 void disposePerContextData(); |
88 | 88 |
89 class Observer { | 89 class Observer { |
90 public: | 90 public: |
91 virtual ~Observer() { } | 91 virtual ~Observer() { } |
92 virtual void willDisposeScriptState(ScriptState*) = 0; | 92 virtual void willDisposeScriptState(ScriptState*) = 0; |
93 }; | 93 }; |
94 void addObserver(Observer*); | 94 void addObserver(Observer*); |
95 void removeObserver(Observer*); | 95 void removeObserver(Observer*); |
96 | 96 |
97 bool evalEnabled() const; | 97 bool evalEnabled() const; |
98 void setEvalEnabled(bool); | 98 void setEvalEnabled(bool); |
99 ScriptValue getFromGlobalObject(const char* name); | 99 ScriptValue getFromGlobalObject(const char* name); |
100 | 100 |
101 protected: | 101 protected: |
102 ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 102 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
103 | 103 |
104 private: | 104 private: |
105 v8::Isolate* m_isolate; | 105 v8::Isolate* m_isolate; |
106 // This persistent handle is weak. | 106 // This persistent handle is weak. |
107 ScopedPersistent<v8::Context> m_context; | 107 ScopedPersistent<v8::Context> m_context; |
108 | 108 |
109 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. | 109 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. |
110 RefPtr<DOMWrapperWorld> m_world; | 110 RefPtr<DOMWrapperWorld> m_world; |
111 | 111 |
112 // This OwnPtr causes a cycle: | 112 // This OwnPtr causes a cycle: |
(...skipping 29 matching lines...) Expand all Loading... |
142 } | 142 } |
143 | 143 |
144 private: | 144 private: |
145 RefPtr<ScriptState> m_scriptState; | 145 RefPtr<ScriptState> m_scriptState; |
146 ScopedPersistent<v8::Context> m_context; | 146 ScopedPersistent<v8::Context> m_context; |
147 }; | 147 }; |
148 | 148 |
149 } | 149 } |
150 | 150 |
151 #endif // ScriptState_h | 151 #endif // ScriptState_h |
OLD | NEW |