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 @@ ...@@ -6,6 +6,7 @@
#include "chrome/browser/content_settings/content_settings_rule.h" #include "chrome/browser/content_settings/content_settings_rule.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/extensions/api/plugins/plugins_handler.h" #include "chrome/common/extensions/api/plugins/plugins_handler.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/notification_types.h" #include "extensions/browser/notification_types.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -26,7 +28,9 @@ namespace content_settings { ...@@ -26,7 +28,9 @@ namespace content_settings {
InternalExtensionProvider::InternalExtensionProvider( InternalExtensionProvider::InternalExtensionProvider(
ExtensionService* extension_service) 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. // Whitelist all extensions loaded so far.
const extensions::ExtensionSet* extensions = extension_service->extensions(); const extensions::ExtensionSet* extensions = extension_service->extensions();
for (extensions::ExtensionSet::const_iterator it = extensions->begin(); for (extensions::ExtensionSet::const_iterator it = extensions->begin();
...@@ -38,12 +42,8 @@ InternalExtensionProvider::InternalExtensionProvider( ...@@ -38,12 +42,8 @@ InternalExtensionProvider::InternalExtensionProvider(
registrar_->Add(this, registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_CREATED, extensions::NOTIFICATION_EXTENSION_HOST_CREATED,
content::Source<Profile>(profile)); content::Source<Profile>(profile));
registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, extension_registry_->AddObserver(this);
content::Source<Profile>(profile));
registrar_->Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile));
} }
InternalExtensionProvider::~InternalExtensionProvider() { InternalExtensionProvider::~InternalExtensionProvider() {
...@@ -72,92 +72,85 @@ void InternalExtensionProvider::ClearAllContentSettingsRules( ...@@ -72,92 +72,85 @@ void InternalExtensionProvider::ClearAllContentSettingsRules(
void InternalExtensionProvider::Observe(int type, void InternalExtensionProvider::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_CREATED, type);
case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: { const extensions::ExtensionHost* host =
const extensions::ExtensionHost* host = content::Details<extensions::ExtensionHost>(details).ptr();
content::Details<extensions::ExtensionHost>(details).ptr(); if (host->extension()->is_platform_app()) {
if (host->extension()->is_platform_app()) { SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
// White-list CRD's v2 app, until crbug.com/134216 is complete.
// White-list CRD's v2 app, until crbug.com/134216 is complete. const char* kAppWhitelist[] = {"2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
const char* kAppWhitelist[] = { "4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
"2775E568AC98F9578791F1EAB65A1BF5F8CEF414", "97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
"4AA3C5D69A4AECBD236CAD7884502209F0F5C169", "9E930B2B5EABA6243AE6C710F126E54688E8FAF6",
"97B23E01B2AA064E8332EE43A7A85C628AADC3F2", "C449A798C495E6CF7D6AF10162113D564E67AD12",
"9E930B2B5EABA6243AE6C710F126E54688E8FAF6", "E410CDAB2C6E6DD408D731016CECF2444000A912",
"C449A798C495E6CF7D6AF10162113D564E67AD12", "EBA908206905323CECE6DC4B276A58A0F4AC573F",
"E410CDAB2C6E6DD408D731016CECF2444000A912",
"EBA908206905323CECE6DC4B276A58A0F4AC573F", // http://crbug.com/327507
"FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E",
// http://crbug.com/327507 "3B52D273A271D4E2348233E322426DBAE854B567",
"FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E", "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059",
"3B52D273A271D4E2348233E322426DBAE854B567", "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1",
"5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059", "F5815DAFEB8C53B078DD1853B2059E087C42F139",
"1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1", "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513",
"F5815DAFEB8C53B078DD1853B2059E087C42F139",
"6A08EFFF9C16E090D6DCC7EC55A01CADAE840513", // http://crbug.com/354258
"C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4",
// http://crbug.com/354258 "9099782647D39C778E15C8C6E0D23C88F5CDE170",
"C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4", "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0",
"9099782647D39C778E15C8C6E0D23C88F5CDE170", "89349DBAA2C4022FB244AA50182AB60934EB41EE",
"B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0", "CB593E510640572A995CB1B6D41BD85ED51E63F8",
"89349DBAA2C4022FB244AA50182AB60934EB41EE", "1AD1AC86C87969CD3434FA08D99DBA6840AEA612",
"CB593E510640572A995CB1B6D41BD85ED51E63F8", "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D",
"1AD1AC86C87969CD3434FA08D99DBA6840AEA612", "D2C488C80C3C90C3E01A991112A05E37831E17D0",
"9C2EA21D7975BDF2B3C01C3A454EE44854067A6D", "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F",
"D2C488C80C3C90C3E01A991112A05E37831E17D0", "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777",
"6EEC061C0E74B46C7B5BE2EEFA49436368F4988F", "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868",
"8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777",
"E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868", // http://crbug.com/386324
"F76F43EFFF56BF17A9868A5243F339BA28746632",
// http://crbug.com/386324 "C6EA52B92F80878515F94137020F01519357E5B5",
"F76F43EFFF56BF17A9868A5243F339BA28746632", "E466389F058ABD73FF6FDD06F768A351FCBF8532",
"C6EA52B92F80878515F94137020F01519357E5B5", "40063F1CF7B68BA847A26FA6620DDF156171D23C",
"E466389F058ABD73FF6FDD06F768A351FCBF8532", "A6FD8E15353CF1F5C3D0A7B20E1D10AEA4DD3E6A",
"40063F1CF7B68BA847A26FA6620DDF156171D23C", "57AC4D9E6BD8A2D0A70056B5FAC2378CAA588912",
"A6FD8E15353CF1F5C3D0A7B20E1D10AEA4DD3E6A", "02037314DA4D913640DCF0E296A7D01F4FD793EC",
"57AC4D9E6BD8A2D0A70056B5FAC2378CAA588912", "B6EC0809BC63E10B431C5E4AA3645232CA86B2A5",
"02037314DA4D913640DCF0E296A7D01F4FD793EC", "48CA541313139786F056DBCB504A1025CFF5D2E3",
"B6EC0809BC63E10B431C5E4AA3645232CA86B2A5", "05106136AE7F08A3C181D4648E5438350B1D2B4F"};
"48CA541313139786F056DBCB504A1025CFF5D2E3", if (extensions::SimpleFeature::IsIdInList(
"05106136AE7F08A3C181D4648E5438350B1D2B4F" host->extension()->id(),
}; std::set<std::string>(kAppWhitelist,
if (extensions::SimpleFeature::IsIdInList( kAppWhitelist + arraysize(kAppWhitelist)))) {
host->extension()->id(), SetContentSettingForExtensionAndResource(
std::set<std::string>( host->extension(),
kAppWhitelist, kAppWhitelist + arraysize(kAppWhitelist)))) { ChromeContentClient::kRemotingViewerPluginPath,
SetContentSettingForExtensionAndResource( CONTENT_SETTING_ALLOW);
host->extension(),
ChromeContentClient::kRemotingViewerPluginPath,
CONTENT_SETTING_ALLOW);
}
}
break;
}
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const extensions::Extension* extension =
content::Details<extensions::Extension>(details).ptr();
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::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
if (extensions::PluginInfo::HasPlugins(extension))
SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
}
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() { void InternalExtensionProvider::ShutdownOnUIThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
RemoveAllObservers(); RemoveAllObservers();
registrar_.reset(); registrar_.reset();
extension_registry_->RemoveObserver(this);
} }
void InternalExtensionProvider::SetContentSettingForExtension( void InternalExtensionProvider::SetContentSettingForExtension(
......
...@@ -12,18 +12,21 @@ ...@@ -12,18 +12,21 @@
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class ExtensionService; class ExtensionService;
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionRegistry;
} }
namespace content_settings { namespace content_settings {
// A content settings provider which disables certain plugins for platform apps. // A content settings provider which disables certain plugins for platform apps.
class InternalExtensionProvider : public ObservableProvider, class InternalExtensionProvider : public ObservableProvider,
public content::NotificationObserver { public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public: public:
explicit InternalExtensionProvider(ExtensionService* extension_service); explicit InternalExtensionProvider(ExtensionService* extension_service);
...@@ -51,6 +54,16 @@ class InternalExtensionProvider : public ObservableProvider, ...@@ -51,6 +54,16 @@ class InternalExtensionProvider : public ObservableProvider,
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; 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: private:
void SetContentSettingForExtension(const extensions::Extension* extension, void SetContentSettingForExtension(const extensions::Extension* extension,
ContentSetting setting); ContentSetting setting);
...@@ -65,6 +78,8 @@ class InternalExtensionProvider : public ObservableProvider, ...@@ -65,6 +78,8 @@ class InternalExtensionProvider : public ObservableProvider,
mutable base::Lock lock_; mutable base::Lock lock_;
scoped_ptr<content::NotificationRegistrar> registrar_; scoped_ptr<content::NotificationRegistrar> registrar_;
extensions::ExtensionRegistry* extension_registry_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(InternalExtensionProvider); 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