Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_internal_extension_provider.cc
blobae8161d7cc7b99bc5bfc9647d2218ec095592736
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
3 // found in the LICENSE file.
5 #include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
7 #include "chrome/browser/pdf/pdf_extension_util.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/chrome_content_client.h"
10 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
11 #include "components/content_settings/core/browser/content_settings_rule.h"
12 #include "components/content_settings/core/common/content_settings.h"
13 #include "components/content_settings/core/common/content_settings_pattern.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h"
16 #include "extensions/browser/extension_host.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/notification_types.h"
19 #include "extensions/common/constants.h"
20 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_set.h"
22 #include "extensions/common/features/simple_feature.h"
24 using extensions::UnloadedExtensionInfo;
26 namespace content_settings {
28 namespace {
30 // This is the set of extensions that are allowed to access the internal
31 // remoting viewer plugin.
32 const char* const kRemotingViewerWhitelist[] = {
33 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
34 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
35 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
36 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
39 } // namespace
42 InternalExtensionProvider::InternalExtensionProvider(Profile* profile)
43 : registrar_(new content::NotificationRegistrar) {
44 for (size_t i = 0; i < arraysize(kRemotingViewerWhitelist); ++i)
45 chrome_remote_desktop_.insert(kRemotingViewerWhitelist[i]);
47 // Whitelist all extensions loaded so far.
48 for (const scoped_refptr<const extensions::Extension>& extension :
49 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
50 ApplyPluginContentSettingsForExtension(extension.get(),
51 CONTENT_SETTING_ALLOW);
53 registrar_->Add(this,
54 extensions::NOTIFICATION_EXTENSION_HOST_CREATED,
55 content::Source<Profile>(profile));
56 registrar_->Add(this,
57 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
58 content::Source<Profile>(profile));
59 registrar_->Add(this,
60 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
61 content::Source<Profile>(profile));
64 InternalExtensionProvider::~InternalExtensionProvider() {
65 DCHECK(!registrar_.get());
68 RuleIterator* InternalExtensionProvider::GetRuleIterator(
69 ContentSettingsType content_type,
70 const ResourceIdentifier& resource_identifier,
71 bool incognito) const {
72 return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_);
75 bool InternalExtensionProvider::SetWebsiteSetting(
76 const ContentSettingsPattern& primary_pattern,
77 const ContentSettingsPattern& secondary_pattern,
78 ContentSettingsType content_type,
79 const ResourceIdentifier& resource_identifier,
80 base::Value* value) {
81 return false;
84 void InternalExtensionProvider::ClearAllContentSettingsRules(
85 ContentSettingsType content_type) {}
87 void InternalExtensionProvider::Observe(
88 int type,
89 const content::NotificationSource& source,
90 const content::NotificationDetails& details) {
91 switch (type) {
92 case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: {
93 const extensions::ExtensionHost* host =
94 content::Details<extensions::ExtensionHost>(details).ptr();
95 if (host->extension()->is_platform_app()) {
96 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
98 // White-list CRD's v2 app, until crbug.com/134216 is complete.
99 const char* const kAppWhitelist[] = {
100 "2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
101 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
102 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
103 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6",
104 "C449A798C495E6CF7D6AF10162113D564E67AD12",
105 "E410CDAB2C6E6DD408D731016CECF2444000A912",
106 "EBA908206905323CECE6DC4B276A58A0F4AC573F",
108 // http://crbug.com/327507
109 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E",
110 "3B52D273A271D4E2348233E322426DBAE854B567",
111 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059",
112 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1",
113 "F5815DAFEB8C53B078DD1853B2059E087C42F139",
114 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513",
116 // http://crbug.com/354258
117 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4",
118 "9099782647D39C778E15C8C6E0D23C88F5CDE170",
119 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0",
120 "89349DBAA2C4022FB244AA50182AB60934EB41EE",
121 "CB593E510640572A995CB1B6D41BD85ED51E63F8",
122 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612",
123 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D",
124 "D2C488C80C3C90C3E01A991112A05E37831E17D0",
125 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F",
126 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777",
127 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868",
129 // http://crbug.com/386324
130 "F76F43EFFF56BF17A9868A5243F339BA28746632",
131 "C6EA52B92F80878515F94137020F01519357E5B5",
132 "E466389F058ABD73FF6FDD06F768A351FCBF8532",
133 "40063F1CF7B68BA847A26FA6620DDF156171D23C",
134 "A6FD8E15353CF1F5C3D0A7B20E1D10AEA4DD3E6A",
135 "57AC4D9E6BD8A2D0A70056B5FAC2378CAA588912",
136 "02037314DA4D913640DCF0E296A7D01F4FD793EC",
137 "B6EC0809BC63E10B431C5E4AA3645232CA86B2A5",
138 "48CA541313139786F056DBCB504A1025CFF5D2E3",
139 "05106136AE7F08A3C181D4648E5438350B1D2B4F"
141 if (extensions::SimpleFeature::IsIdInArray(
142 host->extension()->id(),
143 kAppWhitelist,
144 arraysize(kAppWhitelist))) {
145 SetContentSettingForExtensionAndResource(
146 host->extension(),
147 ChromeContentClient::kRemotingViewerPluginPath,
148 CONTENT_SETTING_ALLOW);
152 break;
154 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
155 const extensions::Extension* extension =
156 content::Details<extensions::Extension>(details).ptr();
157 ApplyPluginContentSettingsForExtension(extension, CONTENT_SETTING_ALLOW);
158 break;
160 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
161 const UnloadedExtensionInfo& info =
162 *(content::Details<UnloadedExtensionInfo>(details).ptr());
163 ApplyPluginContentSettingsForExtension(info.extension,
164 CONTENT_SETTING_DEFAULT);
165 break;
167 default:
168 NOTREACHED();
172 void InternalExtensionProvider::ShutdownOnUIThread() {
173 DCHECK(CalledOnValidThread());
174 RemoveAllObservers();
175 registrar_.reset();
178 void InternalExtensionProvider::ApplyPluginContentSettingsForExtension(
179 const extensions::Extension* extension,
180 ContentSetting setting) {
181 if (extensions::PluginInfo::HasPlugins(extension))
182 SetContentSettingForExtension(extension, setting);
184 // Chrome Remove Desktop relies on the remoting viewer plugin. The
185 // above check does not catch this, as the plugin is a builtin plugin.
186 if (chrome_remote_desktop_.find(extension->id()) !=
187 chrome_remote_desktop_.end()) {
188 SetContentSettingForExtensionAndResource(
189 extension, ChromeContentClient::kRemotingViewerPluginPath, setting);
192 // The PDF viewer extension relies on the out of process PDF plugin.
193 if (extension->id() == extension_misc::kPdfExtensionId) {
194 SetContentSettingForExtensionAndResource(
195 extension, pdf_extension_util::kPdfResourceIdentifier, setting);
199 void InternalExtensionProvider::SetContentSettingForExtension(
200 const extensions::Extension* extension,
201 ContentSetting setting) {
202 SetContentSettingForExtensionAndResource(
203 extension, ResourceIdentifier(), setting);
206 void InternalExtensionProvider::SetContentSettingForExtensionAndResource(
207 const extensions::Extension* extension,
208 const ResourceIdentifier& resource,
209 ContentSetting setting) {
210 scoped_ptr<ContentSettingsPattern::BuilderInterface> pattern_builder(
211 ContentSettingsPattern::CreateBuilder(false));
212 pattern_builder->WithScheme(extensions::kExtensionScheme);
213 pattern_builder->WithHost(extension->id());
214 pattern_builder->WithPathWildcard();
216 ContentSettingsPattern primary_pattern = pattern_builder->Build();
217 ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard();
219 base::AutoLock lock(lock_);
220 if (setting == CONTENT_SETTING_DEFAULT) {
221 value_map_.DeleteValue(primary_pattern,
222 secondary_pattern,
223 CONTENT_SETTINGS_TYPE_PLUGINS,
224 resource);
225 } else {
226 value_map_.SetValue(primary_pattern,
227 secondary_pattern,
228 CONTENT_SETTINGS_TYPE_PLUGINS,
229 resource,
230 new base::FundamentalValue(setting));
233 NotifyObservers(primary_pattern,
234 secondary_pattern,
235 CONTENT_SETTINGS_TYPE_PLUGINS,
236 resource);
239 } // namespace content_settings