diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc index 2b01864f79e7a..12b4ee3ee9938 100644 --- a/extensions/browser/app_window/app_window.cc +++ b/extensions/browser/app_window/app_window.cc @@ -16,6 +16,10 @@ #include "content/public/browser/browser_context.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_entry.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_types.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/web_contents.h" @@ -31,6 +35,7 @@ #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" #include "extensions/browser/extensions_browser_client.h" +#include "extensions/browser/notification_types.h" #include "extensions/browser/process_manager.h" #include "extensions/browser/suggest_permission_util.h" #include "extensions/browser/view_type_utils.h" @@ -307,7 +312,21 @@ void AppWindow::Init(const GURL& url, OnNativeWindowChanged(); - ExtensionRegistry::Get(browser_context_)->AddObserver(this); + // When the render view host is changed, the native window needs to know + // about it in case it has any setup to do to make the renderer appear + // properly. In particular, on Windows, the view's clickthrough region needs + // to be set. + ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); + registrar_.Add(this, + NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, + content::Source( + client->GetOriginalContext(browser_context_))); + // Update the app menu if an ephemeral app becomes installed. + registrar_.Add( + this, + NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, + content::Source( + client->GetOriginalContext(browser_context_))); // Close when the browser process is exiting. app_delegate_->SetTerminatingCallback( @@ -329,7 +348,6 @@ void AppWindow::Init(const GURL& url, } AppWindow::~AppWindow() { - ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); } void AppWindow::RequestMediaAccessPermission( @@ -923,22 +941,28 @@ bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source) return IsHtmlApiFullscreen(); } -void AppWindow::OnExtensionUnloaded(content::BrowserContext* browser_context, - const Extension* extension, - UnloadedExtensionInfo::Reason reason) { - if (extension_id_ == extension->id()) - native_app_window_->Close(); -} - -void AppWindow::OnExtensionWillBeInstalled( - content::BrowserContext* browser_context, - const Extension* extension, - bool is_update, - bool from_ephemeral, - const std::string& old_name) { - // Update the app menu if an ephemeral app becomes installed. - if (extension_id_ == extension->id()) - native_app_window_->UpdateShelfMenu(); +void AppWindow::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { + const Extension* unloaded_extension = + content::Details(details)->extension; + if (extension_id_ == unloaded_extension->id()) + native_app_window_->Close(); + break; + } + case NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { + const Extension* installed_extension = + content::Details(details)->extension; + DCHECK(installed_extension); + if (installed_extension->id() == extension_id()) + native_app_window_->UpdateShelfMenu(); + break; + } + default: + NOTREACHED() << "Received unexpected notification"; + } } void AppWindow::SetWebContentsBlocked(content::WebContents* web_contents, diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h index 3cef2ed4f6e66..7cad2abbc9f92 100644 --- a/extensions/browser/app_window/app_window.h +++ b/extensions/browser/app_window/app_window.h @@ -13,10 +13,11 @@ #include "components/sessions/session_id.h" #include "components/web_modal/popup_manager.h" #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "extensions/browser/extension_icon_image.h" -#include "extensions/browser/extension_registry_observer.h" #include "ui/base/ui_base_types.h" // WindowShowState #include "ui/gfx/image/image.h" #include "ui/gfx/rect.h" @@ -42,7 +43,6 @@ namespace extensions { class AppDelegate; class AppWebContentsHelper; class Extension; -class ExtensionRegistry; class NativeAppWindow; class PlatformAppBrowserTest; class WindowController; @@ -82,11 +82,11 @@ class AppWindowContents { // AppWindow is the type of window used by platform apps. App windows // have a WebContents but none of the chrome of normal browser windows. -class AppWindow : public content::WebContentsDelegate, +class AppWindow : public content::NotificationObserver, + public content::WebContentsDelegate, public content::WebContentsObserver, public web_modal::WebContentsModalDialogManagerDelegate, - public IconImage::Observer, - public ExtensionRegistryObserver { + public IconImage::Observer { public: enum WindowType { WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. @@ -412,17 +412,10 @@ class AppWindow : public content::WebContentsDelegate, // content::WebContentsObserver implementation. virtual void DidFirstVisuallyNonEmptyPaint() OVERRIDE; - // ExtensionRegistryObserver implementation. - virtual void OnExtensionUnloaded( - content::BrowserContext* browser_context, - const Extension* extension, - UnloadedExtensionInfo::Reason reason) OVERRIDE; - virtual void OnExtensionWillBeInstalled( - content::BrowserContext* browser_context, - const Extension* extension, - bool is_update, - bool from_ephemeral, - const std::string& old_name) OVERRIDE; + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; // web_modal::WebContentsModalDialogManagerDelegate implementation. virtual void SetWebContentsBlocked(content::WebContents* web_contents, @@ -492,6 +485,7 @@ class AppWindow : public content::WebContentsDelegate, const SessionID session_id_; WindowType window_type_; + content::NotificationRegistrar registrar_; // Icon shown in the task bar. gfx::Image app_icon_;