diff options
author | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 00:37:31 +0000 |
---|---|---|
committer | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 00:37:31 +0000 |
commit | 1c1c77a5021be0b902240a4f78009a8d8f71d1ac (patch) | |
tree | c1afb46b67de923afaac68340ddb0113b7306193 /chrome/browser/extensions/extension_host.cc | |
parent | 23b3f6c67270a6aff5020c9a7279f4ed84192a02 (diff) | |
download | chromium_src-1c1c77a5021be0b902240a4f78009a8d8f71d1ac.zip chromium_src-1c1c77a5021be0b902240a4f78009a8d8f71d1ac.tar.gz chromium_src-1c1c77a5021be0b902240a4f78009a8d8f71d1ac.tar.bz2 |
Submitting change from http://codereview.chromium.org/276029/show
BUG=none
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_host.cc')
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 2f94612..9435913 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -18,12 +18,16 @@ #include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/extensions/extension_popup_api.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/site_instance.h" +#if defined(TOOLKIT_VIEWS) +#include "chrome/browser/views/extensions/extension_popup.h" +#endif #include "chrome/common/bindings_policy.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" @@ -111,14 +115,25 @@ ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, did_stop_loading_(false), document_element_available_(false), url_(url), +#if defined(TOOLKIT_VIEWS) + child_popup_(NULL), +#endif extension_host_type_(host_type) { render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE); render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); if (enable_dom_automation_) render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION); + +#if defined(TOOLKIT_VIEWS) + // Listen for view close requests, so that we can dismiss a hosted pop-up + // view, if necessary. + registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, + Source<Profile>(profile_)); +#endif } ExtensionHost::~ExtensionHost() { + DismissPopup(); NotificationService::current()->Notify( NotificationType::EXTENSION_HOST_DESTROYED, Source<Profile>(profile_), @@ -208,6 +223,15 @@ void ExtensionHost::Observe(NotificationType type, NavigateToURL(url_); } else if (type == NotificationType::BROWSER_THEME_CHANGED) { InsertThemeCSS(); +#if defined(TOOLKIT_VIEWS) + } else if (type == NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE) { + // If we aren't the host of the popup, then disregard the notification. + if (!child_popup_ || + Details<ExtensionHost>(child_popup_->host()) != details) + return; + + DismissPopup(); +#endif } else { NOTREACHED(); } @@ -294,6 +318,38 @@ void ExtensionHost::InsertThemeCSS() { render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS"); } +void ExtensionHost::DismissPopup() { +#if defined(TOOLKIT_VIEWS) + if (child_popup_) { + child_popup_->Hide(); + child_popup_->DetachFromBrowser(); + delete child_popup_; + child_popup_ = NULL; + + PopupEventRouter::OnPopupClosed(GetBrowser()->profile(), + view()->render_view_host()->routing_id()); + } +#endif +} + +#if defined(TOOLKIT_VIEWS) +void ExtensionHost::BubbleBrowserWindowMoved(BrowserBubble* bubble) { + DismissPopup(); +} +void ExtensionHost::BubbleBrowserWindowClosing(BrowserBubble* bubble) { + DismissPopup(); +} + +void ExtensionHost::BubbleGotFocus(BrowserBubble* bubble) { +} + +void ExtensionHost::BubbleLostFocus(BrowserBubble* bubble) { + // TODO(twiz): Dismiss the pop-up upon loss of focus of the bubble, but not + // if the focus is transitioning to the host which owns the popup! + // DismissPopup(); +} +#endif // defined(TOOLKIT_VIEWS) + void ExtensionHost::DidStopLoading() { bool notify = !did_stop_loading_; did_stop_loading_ = true; @@ -325,6 +381,13 @@ void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, NotificationService::AllSources()); } + + if (ViewType::EXTENSION_POPUP == GetRenderViewType()) { + NotificationService::current()->Notify( + NotificationType::EXTENSION_POPUP_VIEW_READY, + Source<Profile>(profile_), + Details<ExtensionHost>(this)); + } } void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, |