diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc index 4e791ef50440f..3218a2496425d 100644 --- a/extensions/browser/app_window/app_window.cc +++ b/extensions/browser/app_window/app_window.cc @@ -16,10 +16,6 @@ #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" @@ -35,7 +31,6 @@ #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" @@ -312,21 +307,7 @@ void AppWindow::Init(const GURL& url, OnNativeWindowChanged(); - // 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_))); + ExtensionRegistry::Get(browser_context_)->AddObserver(this); // Close when the browser process is exiting. app_delegate_->SetTerminatingCallback( @@ -351,6 +332,8 @@ AppWindow::~AppWindow() { // Unregister now to prevent getting notified if we're the last window open. app_delegate_->SetTerminatingCallback(base::Closure()); + ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); + // Remove shutdown prevention. AppsClient::Get()->DecrementKeepAliveCount(); } @@ -935,28 +918,22 @@ bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source) return IsHtmlApiFullscreen(); } -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::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::SetWebContentsBlocked(content::WebContents* web_contents, diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h index a7378bd7323a2..7b84ed7eaea9c 100644 --- a/extensions/browser/app_window/app_window.h +++ b/extensions/browser/app_window/app_window.h @@ -13,11 +13,10 @@ #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" @@ -43,6 +42,7 @@ 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::NotificationObserver, - public content::WebContentsDelegate, +class AppWindow : public content::WebContentsDelegate, public content::WebContentsObserver, public web_modal::WebContentsModalDialogManagerDelegate, - public IconImage::Observer { + public IconImage::Observer, + public ExtensionRegistryObserver { public: enum WindowType { WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. @@ -408,10 +408,17 @@ class AppWindow : public content::NotificationObserver, // content::WebContentsObserver implementation. virtual void DidFirstVisuallyNonEmptyPaint() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) 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; // web_modal::WebContentsModalDialogManagerDelegate implementation. virtual void SetWebContentsBlocked(content::WebContents* web_contents, @@ -481,7 +488,6 @@ class AppWindow : public content::NotificationObserver, const SessionID session_id_; WindowType window_type_; - content::NotificationRegistrar registrar_; // Icon shown in the task bar. gfx::Image app_icon_;