| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
| 8 #include "base/singleton.h" | 8 #include "base/singleton.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 10 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 bool ExtensionFunctionDispatcher::OverrideFunction( | 162 bool ExtensionFunctionDispatcher::OverrideFunction( |
| 163 const std::string& name, ExtensionFunctionFactory factory) { | 163 const std::string& name, ExtensionFunctionFactory factory) { |
| 164 return FactoryRegistry::instance()->OverrideFunction(name, factory); | 164 return FactoryRegistry::instance()->OverrideFunction(name, factory); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ExtensionFunctionDispatcher::ResetFunctions() { | 167 void ExtensionFunctionDispatcher::ResetFunctions() { |
| 168 FactoryRegistry::instance()->ResetFunctions(); | 168 FactoryRegistry::instance()->ResetFunctions(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 std::set<ExtensionFunctionDispatcher*>* |
| 172 ExtensionFunctionDispatcher::all_instances() { |
| 173 static std::set<ExtensionFunctionDispatcher*> instances; |
| 174 return &instances; |
| 175 } |
| 176 |
| 171 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( | 177 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( |
| 172 RenderViewHost* render_view_host, | 178 RenderViewHost* render_view_host, |
| 173 Delegate* delegate, | 179 Delegate* delegate, |
| 174 const std::string& extension_id) | 180 const GURL& url) |
| 175 : render_view_host_(render_view_host), | 181 : render_view_host_(render_view_host), |
| 176 delegate_(delegate), | 182 delegate_(delegate), |
| 177 extension_id_(extension_id), | 183 url_(url), |
| 178 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { | 184 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { |
| 185 all_instances()->insert(this); |
| 179 RenderProcessHost* process = render_view_host_->process(); | 186 RenderProcessHost* process = render_view_host_->process(); |
| 180 ExtensionMessageService* message_service = | 187 ExtensionMessageService* message_service = |
| 181 ExtensionMessageService::GetInstance(profile()->GetRequestContext()); | 188 ExtensionMessageService::GetInstance(profile()->GetRequestContext()); |
| 182 DCHECK(process); | 189 DCHECK(process); |
| 183 DCHECK(message_service); | 190 DCHECK(message_service); |
| 184 message_service->RegisterExtension(extension_id, process->pid()); | 191 message_service->RegisterExtension(extension_id(), process->pid()); |
| 185 } | 192 } |
| 186 | 193 |
| 187 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { | 194 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
| 195 all_instances()->erase(this); |
| 188 peer_->dispatcher_ = NULL; | 196 peer_->dispatcher_ = NULL; |
| 189 } | 197 } |
| 190 | 198 |
| 191 Browser* ExtensionFunctionDispatcher::GetBrowser() { | 199 Browser* ExtensionFunctionDispatcher::GetBrowser() { |
| 192 DCHECK(delegate_); | 200 DCHECK(delegate_); |
| 193 | 201 |
| 194 Browser* retval = delegate_->GetBrowser(); | 202 Browser* retval = delegate_->GetBrowser(); |
| 195 return retval; | 203 return retval; |
| 196 } | 204 } |
| 197 | 205 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 } else { | 231 } else { |
| 224 NOTREACHED(); | 232 NOTREACHED(); |
| 225 base::KillProcess(render_view_host_->process()->process().handle(), | 233 base::KillProcess(render_view_host_->process()->process().handle(), |
| 226 ResultCodes::KILLED_BAD_MESSAGE, false); | 234 ResultCodes::KILLED_BAD_MESSAGE, false); |
| 227 } | 235 } |
| 228 } | 236 } |
| 229 | 237 |
| 230 Profile* ExtensionFunctionDispatcher::profile() { | 238 Profile* ExtensionFunctionDispatcher::profile() { |
| 231 return render_view_host_->process()->profile(); | 239 return render_view_host_->process()->profile(); |
| 232 } | 240 } |
| OLD | NEW |