OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/chrome_v8_context_set.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 contexts_.insert(context); | 73 contexts_.insert(context); |
74 } | 74 } |
75 | 75 |
76 void ChromeV8ContextSet::Remove(ChromeV8Context* context) { | 76 void ChromeV8ContextSet::Remove(ChromeV8Context* context) { |
77 if (contexts_.erase(context)) { | 77 if (contexts_.erase(context)) { |
78 context->clear_web_frame(); | 78 context->clear_web_frame(); |
79 MessageLoop::current()->DeleteSoon(FROM_HERE, context); | 79 MessageLoop::current()->DeleteSoon(FROM_HERE, context); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll() | 83 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll() const { |
84 const { | |
85 return contexts_; | 84 return contexts_; |
86 } | 85 } |
87 | 86 |
88 ChromeV8Context* ChromeV8ContextSet::GetCurrent() const { | 87 ChromeV8Context* ChromeV8ContextSet::GetCurrent() const { |
89 if (!v8::Context::InContext()) | 88 if (!v8::Context::InContext()) |
90 return NULL; | 89 return NULL; |
91 else | 90 else |
92 return GetByV8Context(v8::Context::GetCurrent()); | 91 return GetByV8Context(v8::Context::GetCurrent()); |
93 } | 92 } |
94 | 93 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 CHECK(arguments.Get(i, &item)); | 143 CHECK(arguments.Get(i, &item)); |
145 v8_arguments.push_back(converter->ToV8Value(item, context)); | 144 v8_arguments.push_back(converter->ToV8Value(item, context)); |
146 } | 145 } |
147 | 146 |
148 v8::Handle<v8::Value> retval; | 147 v8::Handle<v8::Value> retval; |
149 (*it)->CallChromeHiddenMethod( | 148 (*it)->CallChromeHiddenMethod( |
150 method_name, v8_arguments.size(), &v8_arguments[0], &retval); | 149 method_name, v8_arguments.size(), &v8_arguments[0], &retval); |
151 } | 150 } |
152 } | 151 } |
153 | 152 |
| 153 void ChromeV8ContextSet::OnExtensionUnloaded(const std::string& extension_id) { |
| 154 ContextSet contexts = GetAll(); |
| 155 |
| 156 // Clean up contexts belonging to the unloaded extension. This is done so |
| 157 // that content scripts (which remain injected into the page) don't continue |
| 158 // receiving events and sending messages. |
| 159 for (ContextSet::iterator it = contexts.begin(); it != contexts.end(); |
| 160 ++it) { |
| 161 if ((*it)->extension() && (*it)->extension()->id() == extension_id) { |
| 162 (*it)->DispatchOnUnloadEvent(); |
| 163 Remove(*it); |
| 164 } |
| 165 } |
| 166 } |
| 167 |
154 } // namespace extensions | 168 } // namespace extensions |
OLD | NEW |