Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: chrome/browser/content_settings/content_settings_internal_extension_provider.cc

Issue 276573011: Remove deprecated extension notification from content_settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/content_settings/content_settings_internal_extension_pr ovider.h" 5 #include "chrome/browser/content_settings/content_settings_internal_extension_pr ovider.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/content_settings/content_settings_rule.h" 8 #include "chrome/browser/content_settings/content_settings_rule.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_content_client.h" 11 #include "chrome/common/chrome_content_client.h"
11 #include "chrome/common/content_settings.h" 12 #include "chrome/common/content_settings.h"
12 #include "chrome/common/content_settings_pattern.h" 13 #include "chrome/common/content_settings_pattern.h"
13 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 14 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "extensions/browser/extension_host.h" 18 #include "extensions/browser/extension_host.h"
19 #include "extensions/browser/extension_registry.h"
18 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
19 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h" 22 #include "extensions/common/extension_set.h"
21 #include "extensions/common/features/simple_feature.h" 23 #include "extensions/common/features/simple_feature.h"
22 24
23 using extensions::UnloadedExtensionInfo; 25 using extensions::UnloadedExtensionInfo;
24 26
25 namespace content_settings { 27 namespace content_settings {
26 28
27 InternalExtensionProvider::InternalExtensionProvider( 29 InternalExtensionProvider::InternalExtensionProvider(
28 ExtensionService* extension_service) 30 ExtensionService* extension_service)
29 : registrar_(new content::NotificationRegistrar) { 31 : registrar_(new content::NotificationRegistrar),
32 extension_registry_(
33 extensions::ExtensionRegistry::Get(extension_service->profile())) {
30 // Whitelist all extensions loaded so far. 34 // Whitelist all extensions loaded so far.
31 const extensions::ExtensionSet* extensions = extension_service->extensions(); 35 const extensions::ExtensionSet* extensions = extension_service->extensions();
32 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); 36 for (extensions::ExtensionSet::const_iterator it = extensions->begin();
33 it != extensions->end(); ++it) { 37 it != extensions->end(); ++it) {
34 if (extensions::PluginInfo::HasPlugins(it->get())) 38 if (extensions::PluginInfo::HasPlugins(it->get()))
35 SetContentSettingForExtension(it->get(), CONTENT_SETTING_ALLOW); 39 SetContentSettingForExtension(it->get(), CONTENT_SETTING_ALLOW);
36 } 40 }
37 Profile* profile = extension_service->profile(); 41 Profile* profile = extension_service->profile();
38 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 42 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
39 content::Source<Profile>(profile)); 43 content::Source<Profile>(profile));
40 registrar_->Add(this, 44 extension_registry_->AddObserver(this);
41 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
42 content::Source<Profile>(profile));
43 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
44 content::Source<Profile>(profile));
45 } 45 }
46 46
47 InternalExtensionProvider::~InternalExtensionProvider() { 47 InternalExtensionProvider::~InternalExtensionProvider() {
48 DCHECK(!registrar_.get()); 48 DCHECK(!registrar_.get());
49 } 49 }
50 50
51 RuleIterator* InternalExtensionProvider::GetRuleIterator( 51 RuleIterator* InternalExtensionProvider::GetRuleIterator(
52 ContentSettingsType content_type, 52 ContentSettingsType content_type,
53 const ResourceIdentifier& resource_identifier, 53 const ResourceIdentifier& resource_identifier,
54 bool incognito) const { 54 bool incognito) const {
55 return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_); 55 return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_);
56 } 56 }
57 57
58 bool InternalExtensionProvider::SetWebsiteSetting( 58 bool InternalExtensionProvider::SetWebsiteSetting(
59 const ContentSettingsPattern& primary_pattern, 59 const ContentSettingsPattern& primary_pattern,
60 const ContentSettingsPattern& secondary_pattern, 60 const ContentSettingsPattern& secondary_pattern,
61 ContentSettingsType content_type, 61 ContentSettingsType content_type,
62 const ResourceIdentifier& resource_identifier, 62 const ResourceIdentifier& resource_identifier,
63 base::Value* value) { 63 base::Value* value) {
64 return false; 64 return false;
65 } 65 }
66 66
67 void InternalExtensionProvider::ClearAllContentSettingsRules( 67 void InternalExtensionProvider::ClearAllContentSettingsRules(
68 ContentSettingsType content_type) {} 68 ContentSettingsType content_type) {}
69 69
70 void InternalExtensionProvider::OnExtensionLoaded(
71 content::BrowserContext* browser_context,
72 const extensions::Extension* extension) {
73 if (extensions::PluginInfo::HasPlugins(extension))
74 SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
75 }
76
77 void InternalExtensionProvider::OnExtensionUnloaded(
78 content::BrowserContext* browser_context,
79 const extensions::Extension* extension,
80 extensions::UnloadedExtensionInfo::Reason reason) {
81 if (extensions::PluginInfo::HasPlugins(extension))
82 SetContentSettingForExtension(extension, CONTENT_SETTING_DEFAULT);
83 }
84
85 void InternalExtensionProvider::OnShutdown(
86 extensions::ExtensionRegistry* registry) {
87 DCHECK_EQ(extension_registry_, registry);
88 extension_registry_->RemoveObserver(this);
89 extension_registry_ = NULL;
90 }
91
70 void InternalExtensionProvider::Observe(int type, 92 void InternalExtensionProvider::Observe(int type,
71 const content::NotificationSource& source, 93 const content::NotificationSource& source,
72 const content::NotificationDetails& details) { 94 const content::NotificationDetails& details) {
73 switch (type) { 95 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_HOST_CREATED, type);
74 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: { 96 const extensions::ExtensionHost* host =
75 const extensions::ExtensionHost* host = 97 content::Details<extensions::ExtensionHost>(details).ptr();
76 content::Details<extensions::ExtensionHost>(details).ptr(); 98 if (host->extension()->is_platform_app()) {
77 if (host->extension()->is_platform_app()) { 99 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
78 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
79 100
80 // White-list CRD's v2 app, until crbug.com/134216 is complete. 101 // White-list CRD's v2 app, until crbug.com/134216 is complete.
81 const char* kAppWhitelist[] = { 102 const char* kAppWhitelist[] = {"2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
82 "2775E568AC98F9578791F1EAB65A1BF5F8CEF414", 103 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
83 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169", 104 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
84 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2", 105 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6",
85 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6", 106 "C449A798C495E6CF7D6AF10162113D564E67AD12",
86 "C449A798C495E6CF7D6AF10162113D564E67AD12", 107 "E410CDAB2C6E6DD408D731016CECF2444000A912",
87 "E410CDAB2C6E6DD408D731016CECF2444000A912", 108 "EBA908206905323CECE6DC4B276A58A0F4AC573F",
88 "EBA908206905323CECE6DC4B276A58A0F4AC573F",
89 109
90 // http://crbug.com/327507 110 // http://crbug.com/327507
91 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E", 111 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E",
92 "3B52D273A271D4E2348233E322426DBAE854B567", 112 "3B52D273A271D4E2348233E322426DBAE854B567",
93 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059", 113 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059",
94 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1", 114 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1",
95 "F5815DAFEB8C53B078DD1853B2059E087C42F139", 115 "F5815DAFEB8C53B078DD1853B2059E087C42F139",
96 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513", 116 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513",
97 117
98 // http://crbug.com/354258 118 // http://crbug.com/354258
99 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4", 119 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4",
100 "9099782647D39C778E15C8C6E0D23C88F5CDE170", 120 "9099782647D39C778E15C8C6E0D23C88F5CDE170",
101 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0", 121 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0",
102 "89349DBAA2C4022FB244AA50182AB60934EB41EE", 122 "89349DBAA2C4022FB244AA50182AB60934EB41EE",
103 "CB593E510640572A995CB1B6D41BD85ED51E63F8", 123 "CB593E510640572A995CB1B6D41BD85ED51E63F8",
104 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612", 124 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612",
105 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D", 125 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D",
106 "D2C488C80C3C90C3E01A991112A05E37831E17D0", 126 "D2C488C80C3C90C3E01A991112A05E37831E17D0",
107 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F", 127 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F",
108 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777", 128 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777",
109 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868" 129 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868"};
110 }; 130 if (extensions::SimpleFeature::IsIdInList(
111 if (extensions::SimpleFeature::IsIdInList( 131 host->extension()->id(),
112 host->extension()->id(), 132 std::set<std::string>(kAppWhitelist,
113 std::set<std::string>( 133 kAppWhitelist + arraysize(kAppWhitelist)))) {
114 kAppWhitelist, kAppWhitelist + arraysize(kAppWhitelist)))) { 134 SetContentSettingForExtensionAndResource(
115 SetContentSettingForExtensionAndResource( 135 host->extension(),
116 host->extension(), 136 ChromeContentClient::kRemotingViewerPluginPath,
117 ChromeContentClient::kRemotingViewerPluginPath, 137 CONTENT_SETTING_ALLOW);
118 CONTENT_SETTING_ALLOW);
119 }
120 }
121
122 break;
123 } 138 }
124 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
125 const extensions::Extension* extension =
126 content::Details<extensions::Extension>(details).ptr();
127 if (extensions::PluginInfo::HasPlugins(extension))
128 SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
129 break;
130 }
131 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
132 const UnloadedExtensionInfo& info =
133 *(content::Details<UnloadedExtensionInfo>(details).ptr());
134 if (extensions::PluginInfo::HasPlugins(info.extension))
135 SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT);
136 break;
137 }
138 default:
139 NOTREACHED();
140 } 139 }
141 } 140 }
142 141
143 void InternalExtensionProvider::ShutdownOnUIThread() { 142 void InternalExtensionProvider::ShutdownOnUIThread() {
144 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 143 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
145 RemoveAllObservers(); 144 RemoveAllObservers();
146 registrar_.reset(); 145 registrar_.reset();
147 } 146 }
148 147
149 void InternalExtensionProvider::SetContentSettingForExtension( 148 void InternalExtensionProvider::SetContentSettingForExtension(
(...skipping 30 matching lines...) Expand all
180 base::Value::CreateIntegerValue(setting)); 179 base::Value::CreateIntegerValue(setting));
181 } 180 }
182 } 181 }
183 NotifyObservers(primary_pattern, 182 NotifyObservers(primary_pattern,
184 secondary_pattern, 183 secondary_pattern,
185 CONTENT_SETTINGS_TYPE_PLUGINS, 184 CONTENT_SETTINGS_TYPE_PLUGINS,
186 resource); 185 resource);
187 } 186 }
188 187
189 } // namespace content_settings 188 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698