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

Side by Side Diff: Source/bindings/v8/ScriptState.h

Issue 257803006: Fixing wrong extension ID in Activity Log entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: ActivityLogger moved to ScriptState Created 6 years, 7 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
OLDNEW
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"
11 #include <v8.h> 11 #include <v8.h>
12 12
13 namespace WebCore { 13 namespace WebCore {
14 14
15 class DOMWindow; 15 class DOMWindow;
16 class DOMWrapperWorld; 16 class DOMWrapperWorld;
17 class ExecutionContext; 17 class ExecutionContext;
18 class LocalFrame; 18 class LocalFrame;
19 class V8DOMActivityLogger;
19 20
20 // ScriptState is created when v8::Context is created. 21 // ScriptState is created when v8::Context is created.
21 // ScriptState is destroyed when v8::Context is garbage-collected and 22 // ScriptState is destroyed when v8::Context is garbage-collected and
22 // all V8 proxy objects that have references to the ScriptState are destructed. 23 // all V8 proxy objects that have references to the ScriptState are destructed.
23 class ScriptState : public RefCounted<ScriptState> { 24 class ScriptState : public RefCounted<ScriptState> {
24 WTF_MAKE_NONCOPYABLE(ScriptState); 25 WTF_MAKE_NONCOPYABLE(ScriptState);
25 public: 26 public:
26 class Scope { 27 class Scope {
27 public: 28 public:
28 // You need to make sure that scriptState->context() is not empty before creating a Scope. 29 // You need to make sure that scriptState->context() is not empty before creating a Scope.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat e); } 75 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat e); }
75 bool contextIsEmpty() const { return m_context.isEmpty(); } 76 bool contextIsEmpty() const { return m_context.isEmpty(); }
76 void clearContext() { return m_context.clear(); } 77 void clearContext() { return m_context.clear(); }
77 78
78 V8PerContextData* perContextData() const { return m_perContextData.get(); } 79 V8PerContextData* perContextData() const { return m_perContextData.get(); }
79 void disposePerContextData() { m_perContextData = nullptr; } 80 void disposePerContextData() { m_perContextData = nullptr; }
80 81
81 bool evalEnabled() const; 82 bool evalEnabled() const;
82 void setEvalEnabled(bool); 83 void setEvalEnabled(bool);
83 84
85 V8DOMActivityLogger* activityLogger() const { return m_activityLogger; }
86 void setActivityLogger(V8DOMActivityLogger* activityLogger) { m_activityLogg er = activityLogger; }
87
84 private: 88 private:
85 ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); 89 ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
86 90
87 v8::Isolate* m_isolate; 91 v8::Isolate* m_isolate;
88 // This persistent handle is weak. 92 // This persistent handle is weak.
89 ScopedPersistent<v8::Context> m_context; 93 ScopedPersistent<v8::Context> m_context;
90 94
91 // This RefPtr doesn't cause a cycle because all persistent handles that DOM WrapperWorld holds are weak. 95 // This RefPtr doesn't cause a cycle because all persistent handles that DOM WrapperWorld holds are weak.
92 RefPtr<DOMWrapperWorld> m_world; 96 RefPtr<DOMWrapperWorld> m_world;
93 97
94 // This OwnPtr causes a cycle: 98 // This OwnPtr causes a cycle:
95 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState --(OwnPtr)--> V8PerContextData 99 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState --(OwnPtr)--> V8PerContextData
96 // So you must explicitly clear the OwnPtr by calling disposePerContextData( ) 100 // So you must explicitly clear the OwnPtr by calling disposePerContextData( )
97 // 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.
98 OwnPtr<V8PerContextData> m_perContextData; 102 OwnPtr<V8PerContextData> m_perContextData;
103 // This is owned by a static hash map in V8DOMActivityLogger.
104 V8DOMActivityLogger* m_activityLogger;
99 }; 105 };
100 106
101 // ScriptStateProtectingContext keeps the context associated with the ScriptStat e alive. 107 // ScriptStateProtectingContext keeps the context associated with the ScriptStat e alive.
102 // You need to call clear() once you no longer need the context. Otherwise, the context will leak. 108 // You need to call clear() once you no longer need the context. Otherwise, the context will leak.
103 class ScriptStateProtectingContext { 109 class ScriptStateProtectingContext {
104 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); 110 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
105 public: 111 public:
106 ScriptStateProtectingContext(ScriptState* scriptState) 112 ScriptStateProtectingContext(ScriptState* scriptState)
107 : m_scriptState(scriptState) 113 : m_scriptState(scriptState)
108 { 114 {
(...skipping 10 matching lines...) Expand all
119 } 125 }
120 126
121 private: 127 private:
122 RefPtr<ScriptState> m_scriptState; 128 RefPtr<ScriptState> m_scriptState;
123 ScopedPersistent<v8::Context> m_context; 129 ScopedPersistent<v8::Context> m_context;
124 }; 130 };
125 131
126 } 132 }
127 133
128 #endif // ScriptState_h 134 #endif // ScriptState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698