| 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/v8/ScopedPersistent.h" | 8 #include "bindings/v8/ScopedPersistent.h" |
| 9 #include "bindings/v8/V8PerContextData.h" | 9 #include "bindings/v8/V8PerContextData.h" |
| 10 #include "wtf/RefCounted.h" | 10 #include "wtf/RefCounted.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == conte
xt); | 63 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == conte
xt); |
| 64 return scriptState; | 64 return scriptState; |
| 65 } | 65 } |
| 66 | 66 |
| 67 static ScriptState* forMainWorld(LocalFrame*); | 67 static ScriptState* forMainWorld(LocalFrame*); |
| 68 | 68 |
| 69 v8::Isolate* isolate() const { return m_isolate; } | 69 v8::Isolate* isolate() const { return m_isolate; } |
| 70 DOMWrapperWorld& world() const { return *m_world; } | 70 DOMWrapperWorld& world() const { return *m_world; } |
| 71 DOMWindow* domWindow() const; | 71 DOMWindow* domWindow() const; |
| 72 virtual ExecutionContext* executionContext() const; | 72 virtual ExecutionContext* executionContext() const; |
| 73 virtual void setExecutionContext(PassRefPtr<ExecutionContext>); | 73 virtual void setExecutionContext(ExecutionContext*); |
| 74 | 74 |
| 75 // This can return an empty handle if the v8::Context is gone. | 75 // This can return an empty handle if the v8::Context is gone. |
| 76 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } | 76 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } |
| 77 bool contextIsEmpty() const { return m_context.isEmpty(); } | 77 bool contextIsEmpty() const { return m_context.isEmpty(); } |
| 78 void clearContext() { return m_context.clear(); } | 78 void clearContext() { return m_context.clear(); } |
| 79 | 79 |
| 80 V8PerContextData* perContextData() const { return m_perContextData.get(); } | 80 V8PerContextData* perContextData() const { return m_perContextData.get(); } |
| 81 void disposePerContextData() { m_perContextData = nullptr; } | 81 void disposePerContextData() { m_perContextData = nullptr; } |
| 82 | 82 |
| 83 bool evalEnabled() const; | 83 bool evalEnabled() const; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 100 // So you must explicitly clear the OwnPtr by calling disposePerContextData(
) | 100 // So you must explicitly clear the OwnPtr by calling disposePerContextData(
) |
| 101 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. | 101 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. |
| 102 OwnPtr<V8PerContextData> m_perContextData; | 102 OwnPtr<V8PerContextData> m_perContextData; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 class ScriptStateForTesting : public ScriptState { | 105 class ScriptStateForTesting : public ScriptState { |
| 106 public: | 106 public: |
| 107 static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, Pas
sRefPtr<DOMWrapperWorld>); | 107 static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, Pas
sRefPtr<DOMWrapperWorld>); |
| 108 | 108 |
| 109 virtual ExecutionContext* executionContext() const OVERRIDE; | 109 virtual ExecutionContext* executionContext() const OVERRIDE; |
| 110 virtual void setExecutionContext(PassRefPtr<ExecutionContext>) OVERRIDE; | 110 virtual void setExecutionContext(ExecutionContext*) OVERRIDE; |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 ScriptStateForTesting(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 113 ScriptStateForTesting(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
| 114 | 114 |
| 115 RefPtr<ExecutionContext> m_executionContext; | 115 ExecutionContext* m_executionContext; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. | 118 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. |
| 119 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. | 119 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. |
| 120 class ScriptStateProtectingContext { | 120 class ScriptStateProtectingContext { |
| 121 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); | 121 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); |
| 122 public: | 122 public: |
| 123 ScriptStateProtectingContext(ScriptState* scriptState) | 123 ScriptStateProtectingContext(ScriptState* scriptState) |
| 124 : m_scriptState(scriptState) | 124 : m_scriptState(scriptState) |
| 125 { | 125 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 RefPtr<ScriptState> m_scriptState; | 139 RefPtr<ScriptState> m_scriptState; |
| 140 ScopedPersistent<v8::Context> m_context; | 140 ScopedPersistent<v8::Context> m_context; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 } | 143 } |
| 144 | 144 |
| 145 #endif // ScriptState_h | 145 #endif // ScriptState_h |
| OLD | NEW |