Commit 89740fc0 authored by limasdf@gmail.com's avatar limasdf@gmail.com

Use ExtensionRegistryObserver instead of DEPRECATED extension notify.

BUG=354458

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284725 0039d316-1c4b-4281-b951-d872f2087c98
parent 008a278f
......@@ -33,6 +33,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/image_loader.h"
#include "extensions/common/constants.h"
......@@ -439,11 +440,6 @@ void Panel::Observe(int type,
case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED:
ConfigureAutoResize(content::Source<content::WebContents>(source).ptr());
break;
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
if (content::Details<extensions::UnloadedExtensionInfo>(
details)->extension->id() == extension_id())
Close();
break;
case chrome::NOTIFICATION_APP_TERMINATING:
Close();
break;
......@@ -452,6 +448,14 @@ void Panel::Observe(int type,
}
}
void Panel::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (extension->id() == extension_id())
Close();
}
void Panel::OnTitlebarClicked(panel::ClickModifier modifier) {
if (collection_)
collection_->OnPanelTitlebarClicked(this, modifier);
......@@ -532,8 +536,8 @@ void Panel::Initialize(const GURL& url,
native_panel_->AttachWebContents(web_contents);
// Close when the extension is unloaded or the browser is exiting.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile_));
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
......@@ -815,6 +819,7 @@ Panel::Panel(Profile* profile, const std::string& app_name,
attention_mode_(USE_PANEL_ATTENTION),
expansion_state_(EXPANDED),
command_updater_(this),
extension_registry_observer_(this),
image_loader_ptr_factory_(this) {
}
......
......@@ -10,6 +10,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/command_updater_delegate.h"
......@@ -17,6 +18,7 @@
#include "chrome/browser/ui/panels/panel_constants.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
#include "ui/base/base_window.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
......@@ -36,6 +38,7 @@ struct NativeWebKeyboardEvent;
namespace extensions {
class Extension;
class ExtensionRegistry;
class WindowController;
}
......@@ -50,7 +53,8 @@ class WindowController;
// other Panels. For example deleting a panel would rearrange other panels.
class Panel : public ui::BaseWindow,
public CommandUpdaterDelegate,
public content::NotificationObserver {
public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
enum ExpansionState {
// The panel is fully expanded with both title-bar and the client-area.
......@@ -145,6 +149,12 @@ class Panel : public ui::BaseWindow,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver implementation.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
// Construct a native panel implementation.
static NativePanel* CreateNativePanel(Panel* panel,
const gfx::Rect& bounds,
......@@ -392,6 +402,11 @@ class Panel : public ui::BaseWindow,
scoped_ptr<extensions::WindowController> extension_window_controller_;
scoped_ptr<PanelHost> panel_host_;
// Listen to extension unloaded notification.
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
// Icon showed in the task bar.
gfx::Image app_icon_;
......
......@@ -37,6 +37,7 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -1418,12 +1419,12 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
content::Source<Panel>(panel1));
// Send unload notification on the first extension.
extensions::UnloadedExtensionInfo details(
extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser()->profile()),
content::Details<extensions::UnloadedExtensionInfo>(&details));
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(browser()->profile());
registry->RemoveEnabled(extension->id());
registry->TriggerOnUnloaded(
extension.get(),
extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
// Wait for the panels opened by the first extension to close.
signal.Wait();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment