Commit 76ad5848 authored by limasdf's avatar limasdf Committed by Commit bot

remove deprecated extension notification from content_settings.

Use ExtensionRegistryObserver instead.

R=bauerb@chromium.org
BUG=354046, 354458
TEST=unit_tests

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

Cr-Commit-Position: refs/heads/master@{#294768}
parent 761d1b2a
......@@ -6,6 +6,7 @@
#include "chrome/browser/content_settings/content_settings_rule.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/extensions/api/plugins/plugins_handler.h"
#include "components/content_settings/core/common/content_settings.h"
......@@ -14,6 +15,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
......@@ -26,7 +28,9 @@ namespace content_settings {
InternalExtensionProvider::InternalExtensionProvider(
ExtensionService* extension_service)
: registrar_(new content::NotificationRegistrar) {
: registrar_(new content::NotificationRegistrar),
extension_registry_(
extensions::ExtensionRegistry::Get(extension_service->profile())) {
// Whitelist all extensions loaded so far.
const extensions::ExtensionSet* extensions = extension_service->extensions();
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
......@@ -38,12 +42,8 @@ InternalExtensionProvider::InternalExtensionProvider(
registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_CREATED,
content::Source<Profile>(profile));
registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile));
registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile));
extension_registry_->AddObserver(this);
}
InternalExtensionProvider::~InternalExtensionProvider() {
......@@ -72,16 +72,14 @@ void InternalExtensionProvider::ClearAllContentSettingsRules(
void InternalExtensionProvider::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: {
DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_CREATED, type);
const extensions::ExtensionHost* host =
content::Details<extensions::ExtensionHost>(details).ptr();
if (host->extension()->is_platform_app()) {
SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
// White-list CRD's v2 app, until crbug.com/134216 is complete.
const char* kAppWhitelist[] = {
"2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
const char* kAppWhitelist[] = {"2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
"4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
"97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
"9E930B2B5EABA6243AE6C710F126E54688E8FAF6",
......@@ -120,44 +118,39 @@ void InternalExtensionProvider::Observe(int type,
"02037314DA4D913640DCF0E296A7D01F4FD793EC",
"B6EC0809BC63E10B431C5E4AA3645232CA86B2A5",
"48CA541313139786F056DBCB504A1025CFF5D2E3",
"05106136AE7F08A3C181D4648E5438350B1D2B4F"
};
"05106136AE7F08A3C181D4648E5438350B1D2B4F"};
if (extensions::SimpleFeature::IsIdInList(
host->extension()->id(),
std::set<std::string>(
kAppWhitelist, kAppWhitelist + arraysize(kAppWhitelist)))) {
std::set<std::string>(kAppWhitelist,
kAppWhitelist + arraysize(kAppWhitelist)))) {
SetContentSettingForExtensionAndResource(
host->extension(),
ChromeContentClient::kRemotingViewerPluginPath,
CONTENT_SETTING_ALLOW);
}
}
}
break;
}
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const extensions::Extension* extension =
content::Details<extensions::Extension>(details).ptr();
void InternalExtensionProvider::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
if (extensions::PluginInfo::HasPlugins(extension))
SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
break;
}
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const UnloadedExtensionInfo& info =
*(content::Details<UnloadedExtensionInfo>(details).ptr());
if (extensions::PluginInfo::HasPlugins(info.extension))
SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT);
break;
}
default:
NOTREACHED();
}
}
void InternalExtensionProvider::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (extensions::PluginInfo::HasPlugins(extension))
SetContentSettingForExtension(extension, CONTENT_SETTING_DEFAULT);
}
void InternalExtensionProvider::ShutdownOnUIThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
RemoveAllObservers();
registrar_.reset();
extension_registry_->RemoveObserver(this);
}
void InternalExtensionProvider::SetContentSettingForExtension(
......
......@@ -12,18 +12,21 @@
#include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class ExtensionService;
namespace extensions {
class Extension;
class ExtensionRegistry;
}
namespace content_settings {
// A content settings provider which disables certain plugins for platform apps.
class InternalExtensionProvider : public ObservableProvider,
public content::NotificationObserver {
public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
explicit InternalExtensionProvider(ExtensionService* extension_service);
......@@ -51,6 +54,16 @@ class InternalExtensionProvider : public ObservableProvider,
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
private:
void SetContentSettingForExtension(const extensions::Extension* extension,
ContentSetting setting);
......@@ -65,6 +78,8 @@ class InternalExtensionProvider : public ObservableProvider,
mutable base::Lock lock_;
scoped_ptr<content::NotificationRegistrar> registrar_;
extensions::ExtensionRegistry* extension_registry_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(InternalExtensionProvider);
};
......
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