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 #include "extensions/renderer/script_context_set.h" | 5 #include "extensions/renderer/script_context_set.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "content/public/renderer/render_view.h" | 8 #include "content/public/renderer/render_view.h" |
9 #include "extensions/common/extension.h" | 9 #include "extensions/common/extension.h" |
10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 ScriptContextSet::ContextSet ScriptContextSet::GetAll() const { | 45 ScriptContextSet::ContextSet ScriptContextSet::GetAll() const { |
46 return contexts_; | 46 return contexts_; |
47 } | 47 } |
48 | 48 |
49 ScriptContext* ScriptContextSet::GetCurrent() const { | 49 ScriptContext* ScriptContextSet::GetCurrent() const { |
50 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 50 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
51 return isolate->InContext() ? GetByV8Context(isolate->GetCurrentContext()) | 51 return isolate->InContext() ? GetByV8Context(isolate->GetCurrentContext()) |
52 : NULL; | 52 : nullptr; |
53 } | 53 } |
54 | 54 |
55 ScriptContext* ScriptContextSet::GetCalling() const { | 55 ScriptContext* ScriptContextSet::GetCalling() const { |
56 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 56 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
57 v8::Local<v8::Context> calling = isolate->GetCallingContext(); | 57 v8::Local<v8::Context> calling = isolate->GetCallingContext(); |
58 return calling.IsEmpty() ? NULL : GetByV8Context(calling); | 58 return calling.IsEmpty() ? nullptr : GetByV8Context(calling); |
59 } | 59 } |
60 | 60 |
61 ScriptContext* ScriptContextSet::GetByV8Context( | 61 ScriptContext* ScriptContextSet::GetByV8Context( |
62 v8::Handle<v8::Context> v8_context) const { | 62 v8::Handle<v8::Context> v8_context) const { |
63 for (ContextSet::const_iterator iter = contexts_.begin(); | 63 for (ContextSet::const_iterator iter = contexts_.begin(); |
64 iter != contexts_.end(); | 64 iter != contexts_.end(); |
65 ++iter) { | 65 ++iter) { |
66 if ((*iter)->v8_context() == v8_context) | 66 if ((*iter)->v8_context() == v8_context) |
67 return *iter; | 67 return *iter; |
68 } | 68 } |
69 | 69 |
70 return NULL; | 70 return nullptr; |
71 } | 71 } |
72 | 72 |
73 void ScriptContextSet::ForEach( | 73 void ScriptContextSet::ForEach( |
74 const std::string& extension_id, | 74 const std::string& extension_id, |
75 content::RenderView* render_view, | 75 content::RenderView* render_view, |
76 const base::Callback<void(ScriptContext*)>& callback) const { | 76 const base::Callback<void(ScriptContext*)>& callback) const { |
77 // We copy the context list, because calling into javascript may modify it | 77 // We copy the context list, because calling into javascript may modify it |
78 // out from under us. | 78 // out from under us. |
79 ContextSet contexts = GetAll(); | 79 ContextSet contexts = GetAll(); |
80 | 80 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 (*it)->DispatchOnUnloadEvent(); | 115 (*it)->DispatchOnUnloadEvent(); |
116 removed.insert(*it); | 116 removed.insert(*it); |
117 Remove(*it); | 117 Remove(*it); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 return removed; | 121 return removed; |
122 } | 122 } |
123 | 123 |
124 } // namespace extensions | 124 } // namespace extensions |
OLD | NEW |