Commit bbaa913d authored by limasdf's avatar limasdf Committed by Commit bot

Cleanup/ Remove deprecated extension notification from ExtensionHost

Remove deprecated extension notification from ExtensionHost.
Use ExtensionRegistryObserver instead.

BUG=411568

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

Cr-Commit-Position: refs/heads/master@{#318803}
parent c9631120
......@@ -107,9 +107,9 @@ void ExtensionViewHost::LoadInitialURL() {
if (!ExtensionSystem::Get(browser_context())->
runtime_data()->IsBackgroundPageReady(extension())) {
// Make sure the background page loads before any others.
registrar()->Add(this,
extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::Source<Extension>(extension()));
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::Source<Extension>(extension()));
return;
}
......@@ -296,13 +296,11 @@ WebContents* ExtensionViewHost::GetVisibleWebContents() const {
void ExtensionViewHost::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY) {
DCHECK(ExtensionSystem::Get(browser_context())->
runtime_data()->IsBackgroundPageReady(extension()));
LoadInitialURL();
return;
}
ExtensionHost::Observe(type, source, details);
DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY);
DCHECK(ExtensionSystem::Get(browser_context())
->runtime_data()
->IsBackgroundPageReady(extension()));
LoadInitialURL();
}
} // namespace extensions
......@@ -9,6 +9,8 @@
#include "components/web_modal/popup_manager.h"
#include "components/web_modal/web_contents_modal_dialog_host.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 "extensions/browser/extension_host.h"
class Browser;
......@@ -29,7 +31,8 @@ class ExtensionView;
class ExtensionViewHost
: public ExtensionHost,
public web_modal::WebContentsModalDialogManagerDelegate,
public web_modal::WebContentsModalDialogHost {
public web_modal::WebContentsModalDialogHost,
public content::NotificationObserver {
public:
ExtensionViewHost(const Extension* extension,
content::SiteInstance* site_instance,
......@@ -127,6 +130,8 @@ class ExtensionViewHost
// a parent window.
scoped_ptr<web_modal::PopupManager> popup_manager_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost);
};
......
......@@ -13,8 +13,6 @@
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/native_web_keyboard_event.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_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
......@@ -25,6 +23,7 @@
#include "extensions/browser/extension_host_delegate.h"
#include "extensions/browser/extension_host_observer.h"
#include "extensions/browser/extension_host_queue.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/load_monitoring_extension_host_queue.h"
......@@ -77,15 +76,15 @@ ExtensionHost::ExtensionHost(const Extension* extension,
// Listen for when an extension is unloaded from the same profile, as it may
// be the same extension that this points to.
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<BrowserContext>(browser_context_));
ExtensionRegistry::Get(browser_context_)->AddObserver(this);
// Set up web contents observers and pref observers.
delegate_->OnExtensionHostCreated(host_contents());
}
ExtensionHost::~ExtensionHost() {
ExtensionRegistry::Get(browser_context_)->RemoveObserver(this);
if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) &&
load_start_.get()) {
......@@ -210,23 +209,15 @@ bool ExtensionHost::IsBackgroundPage() const {
return true;
}
void ExtensionHost::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
// The extension object will be deleted after this notification has been
// sent. Null it out so that dirty pointer issues don't arise in cases
// when multiple ExtensionHost objects pointing to the same Extension are
// present.
if (extension_ == content::Details<UnloadedExtensionInfo>(details)->
extension) {
extension_ = nullptr;
}
break;
default:
NOTREACHED() << "Unexpected notification sent.";
break;
void ExtensionHost::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
// The extension object will be deleted after this notification has been sent.
// Null it out so that dirty pointer issues don't arise in cases when multiple
// ExtensionHost objects pointing to the same Extension are present.
if (extension_ == extension) {
extension_ = nullptr;
}
}
......
......@@ -7,18 +7,16 @@
#include <set>
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/timer/elapsed_timer.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/deferred_start_render_host.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/stack_frame.h"
#include "extensions/common/view_type.h"
......@@ -49,7 +47,7 @@ class ExtensionHost : public DeferredStartRenderHost,
public content::WebContentsDelegate,
public content::WebContentsObserver,
public ExtensionFunctionDispatcher::Delegate,
public content::NotificationObserver {
public ExtensionRegistryObserver {
public:
ExtensionHost(const Extension* extension,
content::SiteInstance* site_instance,
......@@ -127,14 +125,12 @@ class ExtensionHost : public DeferredStartRenderHost,
content::MediaStreamType type) override;
bool IsNeverVisible(content::WebContents* web_contents) override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ExtensionRegistryObserver:
void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) override;
protected:
content::NotificationRegistrar* registrar() { return &registrar_; }
// Called after the extension page finishes loading but before the
// EXTENSION_HOST_DID_STOP_LOADING notification is sent.
virtual void OnDidStopLoading();
......@@ -191,8 +187,6 @@ class ExtensionHost : public DeferredStartRenderHost,
// Messages sent out to the renderer that have not been acknowledged yet.
std::set<int> unacked_messages_;
content::NotificationRegistrar registrar_;
ExtensionFunctionDispatcher extension_function_dispatcher_;
// The type of view being hosted.
......
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