| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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_host.h" | 5 #include "chrome/browser/extensions/extension_host.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/debugger/devtools_manager.h" | 12 #include "chrome/browser/debugger/devtools_manager.h" |
| 13 #include "chrome/browser/extensions/extension_message_service.h" | 13 #include "chrome/browser/extensions/extension_message_service.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
| 17 #include "chrome/browser/renderer_host/render_widget_host.h" | 17 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 18 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 18 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 19 #include "chrome/browser/renderer_host/site_instance.h" | 19 #include "chrome/browser/renderer_host/site_instance.h" |
| 20 #include "chrome/browser/tab_contents/infobar_delegate.h" | 20 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "chrome/browser/tab_contents/tab_contents_view.h" | 22 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 23 #include "chrome/common/bindings_policy.h" |
| 23 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/pref_service.h" | 27 #include "chrome/common/pref_service.h" |
| 27 | 28 |
| 28 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
| 29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 30 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 31 | 32 |
| 32 #include "webkit/glue/context_menu.h" | 33 #include "webkit/glue/context_menu.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, | 80 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, |
| 80 const GURL& url) | 81 const GURL& url) |
| 81 : extension_(extension), | 82 : extension_(extension), |
| 82 profile_(site_instance->browsing_instance()->profile()), | 83 profile_(site_instance->browsing_instance()->profile()), |
| 83 did_stop_loading_(false), | 84 did_stop_loading_(false), |
| 84 url_(url) { | 85 url_(url) { |
| 85 render_view_host_ = new RenderViewHost( | 86 render_view_host_ = new RenderViewHost( |
| 86 site_instance, this, MSG_ROUTING_NONE, NULL); | 87 site_instance, this, MSG_ROUTING_NONE, NULL); |
| 87 render_view_host_->AllowExtensionBindings(); | 88 render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); |
| 88 } | 89 } |
| 89 | 90 |
| 90 ExtensionHost::~ExtensionHost() { | 91 ExtensionHost::~ExtensionHost() { |
| 91 NotificationService::current()->Notify( | 92 NotificationService::current()->Notify( |
| 92 NotificationType::EXTENSION_HOST_DESTROYED, | 93 NotificationType::EXTENSION_HOST_DESTROYED, |
| 93 Source<Profile>(profile_), | 94 Source<Profile>(profile_), |
| 94 Details<ExtensionHost>(this)); | 95 Details<ExtensionHost>(this)); |
| 95 render_view_host_->Shutdown(); // deletes render_view_host | 96 render_view_host_->Shutdown(); // deletes render_view_host |
| 96 } | 97 } |
| 97 | 98 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 did_stop_loading_ = true; | 190 did_stop_loading_ = true; |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ExtensionHost::DidInsertCSS() { | 193 void ExtensionHost::DidInsertCSS() { |
| 193 #if defined(TOOLKIT_VIEWS) | 194 #if defined(TOOLKIT_VIEWS) |
| 194 if (view_.get()) | 195 if (view_.get()) |
| 195 view_->SetDidInsertCSS(true); | 196 view_->SetDidInsertCSS(true); |
| 196 #endif | 197 #endif |
| 197 } | 198 } |
| 198 | 199 |
| 199 ExtensionFunctionDispatcher* ExtensionHost:: | |
| 200 CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host, | |
| 201 const std::string& extension_id) { | |
| 202 return new ExtensionFunctionDispatcher(render_view_host, this, extension_id); | |
| 203 } | |
| 204 | |
| 205 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() const { | 200 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() const { |
| 206 // TODO(erikkay) this is unfortunate. The interface declares that this method | 201 // TODO(erikkay) this is unfortunate. The interface declares that this method |
| 207 // must be const (no good reason for it as far as I can tell) which means you | 202 // must be const (no good reason for it as far as I can tell) which means you |
| 208 // can't return self without doing this const_cast. Either we need to change | 203 // can't return self without doing this const_cast. Either we need to change |
| 209 // the interface, or we need to split out the view delegate into another | 204 // the interface, or we need to split out the view delegate into another |
| 210 // object (which is how TabContents works). | 205 // object (which is how TabContents works). |
| 211 return const_cast<ExtensionHost*>(this); | 206 return const_cast<ExtensionHost*>(this); |
| 212 } | 207 } |
| 213 | 208 |
| 214 void ExtensionHost::CreateNewWindow(int route_id, | 209 void ExtensionHost::CreateNewWindow(int route_id, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 Browser* browser = BrowserList::GetLastActiveWithProfile( | 291 Browser* browser = BrowserList::GetLastActiveWithProfile( |
| 297 render_view_host()->process()->profile()); | 292 render_view_host()->process()->profile()); |
| 298 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, | 293 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
| 299 // a toolstrip or background_page onload chrome.tabs api call can make it | 294 // a toolstrip or background_page onload chrome.tabs api call can make it |
| 300 // into here before the browser is sufficiently initialized to return here. | 295 // into here before the browser is sufficiently initialized to return here. |
| 301 // A similar situation may arise during shutdown. | 296 // A similar situation may arise during shutdown. |
| 302 // TODO(rafaelw): Delay creation of background_page until the browser | 297 // TODO(rafaelw): Delay creation of background_page until the browser |
| 303 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 | 298 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 304 return browser; | 299 return browser; |
| 305 } | 300 } |
| 301 |
| 302 void ExtensionHost::ProcessDOMUIMessage(const std::string& message, |
| 303 const std::string& content, |
| 304 int request_id, |
| 305 bool has_callback) { |
| 306 extension_function_dispatcher_->HandleRequest(message, content, request_id, |
| 307 has_callback); |
| 308 } |
| 309 |
| 310 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { |
| 311 extension_function_dispatcher_.reset( |
| 312 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); |
| 313 } |
| OLD | NEW |