Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Remove deprecated extension notification from AppWindow
Browse files Browse the repository at this point in the history
and use ExtensionRegistryObserver instead.

BUG=411568

Review URL: https://codereview.chromium.org/573223002

Cr-Commit-Position: refs/heads/master@{#295372}
  • Loading branch information
sunglim authored and Commit bot committed Sep 17, 2014
1 parent 690253e commit 49c3dc9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 52 deletions.
61 changes: 19 additions & 42 deletions extensions/browser/app_window/app_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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<content::BrowserContext>(
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<content::BrowserContext>(
client->GetOriginalContext(browser_context_)));
ExtensionRegistry::Get(browser_context_)->AddObserver(this);

// Close when the browser process is exiting.
app_delegate_->SetTerminatingCallback(
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<UnloadedExtensionInfo>(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<const InstalledExtensionInfo>(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,
Expand Down
26 changes: 16 additions & 10 deletions extensions/browser/app_window/app_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -43,6 +42,7 @@ namespace extensions {
class AppDelegate;
class AppWebContentsHelper;
class Extension;
class ExtensionRegistry;
class NativeAppWindow;
class PlatformAppBrowserTest;
class WindowController;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit 49c3dc9

Please sign in to comment.