Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_internal_extension_provider.cc
blob68d970bce34b548db5d8bcdcf54a098120306248
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/profiles/profile.h"
8 #include "chrome/common/chrome_content_client.h"
9 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
10 #include "components/content_settings/core/browser/content_settings_rule.h"
11 #include "components/content_settings/core/common/content_settings.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
15 #include "extensions/browser/extension_host.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/notification_types.h"
18 #include "extensions/common/constants.h"
19 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h"
21 #include "extensions/common/features/simple_feature.h"
23 using extensions::UnloadedExtensionInfo;
25 namespace content_settings {
27 InternalExtensionProvider::InternalExtensionProvider(Profile* profile)
28 : registrar_(new content::NotificationRegistrar) {
29 // Whitelist all extensions loaded so far.
30 for (const scoped_refptr<const extensions::Extension>& extension :
31 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
32 if (extensions::PluginInfo::HasPlugins(extension.get()))
33 SetContentSettingForExtension(extension.get(), CONTENT_SETTING_ALLOW);
35 registrar_->Add(this,
36 extensions::NOTIFICATION_EXTENSION_HOST_CREATED,
37 content::Source<Profile>(profile));
38 registrar_->Add(this,
39 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
40 content::Source<Profile>(profile));
41 registrar_->Add(this,
42 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
43 content::Source<Profile>(profile));
46 InternalExtensionProvider::~InternalExtensionProvider() {
47 DCHECK(!registrar_.get());
50 RuleIterator* InternalExtensionProvider::GetRuleIterator(
51 ContentSettingsType content_type,
52 const ResourceIdentifier& resource_identifier,
53 bool incognito) const {
54 return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_);
57 bool InternalExtensionProvider::SetWebsiteSetting(
58 const ContentSettingsPattern& primary_pattern,
59 const ContentSettingsPattern& secondary_pattern,
60 ContentSettingsType content_type,
61 const ResourceIdentifier& resource_identifier,
62 base::Value* value) {
63 return false;
66 void InternalExtensionProvider::ClearAllContentSettingsRules(
67 ContentSettingsType content_type) {}
69 void InternalExtensionProvider::Observe(int type,
70 const content::NotificationSource& source,
71 const content::NotificationDetails& details) {
72 switch (type) {
73 case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: {
74 const extensions::ExtensionHost* host =
75 content::Details<extensions::ExtensionHost>(details).ptr();
76 if (host->extension()->is_platform_app()) {
77 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
79 // White-list CRD's v2 app, until crbug.com/134216 is complete.
80 const char* kAppWhitelist[] = {
81 "2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
82 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
83 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
84 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6",
85 "C449A798C495E6CF7D6AF10162113D564E67AD12",
86 "E410CDAB2C6E6DD408D731016CECF2444000A912",
87 "EBA908206905323CECE6DC4B276A58A0F4AC573F",
89 // http://crbug.com/327507
90 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E",
91 "3B52D273A271D4E2348233E322426DBAE854B567",
92 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059",
93 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1",
94 "F5815DAFEB8C53B078DD1853B2059E087C42F139",
95 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513",
97 // http://crbug.com/354258
98 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4",
99 "9099782647D39C778E15C8C6E0D23C88F5CDE170",
100 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0",
101 "89349DBAA2C4022FB244AA50182AB60934EB41EE",
102 "CB593E510640572A995CB1B6D41BD85ED51E63F8",
103 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612",
104 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D",
105 "D2C488C80C3C90C3E01A991112A05E37831E17D0",
106 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F",
107 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777",
108 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868",
110 // http://crbug.com/386324
111 "F76F43EFFF56BF17A9868A5243F339BA28746632",
112 "C6EA52B92F80878515F94137020F01519357E5B5",
113 "E466389F058ABD73FF6FDD06F768A351FCBF8532",
114 "40063F1CF7B68BA847A26FA6620DDF156171D23C",
115 "A6FD8E15353CF1F5C3D0A7B20E1D10AEA4DD3E6A",
116 "57AC4D9E6BD8A2D0A70056B5FAC2378CAA588912",
117 "02037314DA4D913640DCF0E296A7D01F4FD793EC",
118 "B6EC0809BC63E10B431C5E4AA3645232CA86B2A5",
119 "48CA541313139786F056DBCB504A1025CFF5D2E3",
120 "05106136AE7F08A3C181D4648E5438350B1D2B4F"
122 if (extensions::SimpleFeature::IsIdInList(
123 host->extension()->id(),
124 std::set<std::string>(
125 kAppWhitelist, kAppWhitelist + arraysize(kAppWhitelist)))) {
126 SetContentSettingForExtensionAndResource(
127 host->extension(),
128 ChromeContentClient::kRemotingViewerPluginPath,
129 CONTENT_SETTING_ALLOW);
133 break;
135 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
136 const extensions::Extension* extension =
137 content::Details<extensions::Extension>(details).ptr();
138 if (extensions::PluginInfo::HasPlugins(extension))
139 SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
140 break;
142 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
143 const UnloadedExtensionInfo& info =
144 *(content::Details<UnloadedExtensionInfo>(details).ptr());
145 if (extensions::PluginInfo::HasPlugins(info.extension))
146 SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT);
147 break;
149 default:
150 NOTREACHED();
154 void InternalExtensionProvider::ShutdownOnUIThread() {
155 DCHECK(CalledOnValidThread());
156 RemoveAllObservers();
157 registrar_.reset();
160 void InternalExtensionProvider::SetContentSettingForExtension(
161 const extensions::Extension* extension,
162 ContentSetting setting) {
163 SetContentSettingForExtensionAndResource(
164 extension, ResourceIdentifier(), setting);
167 void InternalExtensionProvider::SetContentSettingForExtensionAndResource(
168 const extensions::Extension* extension,
169 const ResourceIdentifier& resource,
170 ContentSetting setting) {
171 scoped_ptr<ContentSettingsPattern::BuilderInterface> pattern_builder(
172 ContentSettingsPattern::CreateBuilder(false));
173 pattern_builder->WithScheme(extensions::kExtensionScheme);
174 pattern_builder->WithHost(extension->id());
175 pattern_builder->WithPathWildcard();
177 ContentSettingsPattern primary_pattern = pattern_builder->Build();
178 ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard();
180 base::AutoLock lock(lock_);
181 if (setting == CONTENT_SETTING_DEFAULT) {
182 value_map_.DeleteValue(primary_pattern,
183 secondary_pattern,
184 CONTENT_SETTINGS_TYPE_PLUGINS,
185 resource);
186 } else {
187 value_map_.SetValue(primary_pattern,
188 secondary_pattern,
189 CONTENT_SETTINGS_TYPE_PLUGINS,
190 resource,
191 new base::FundamentalValue(setting));
194 NotifyObservers(primary_pattern,
195 secondary_pattern,
196 CONTENT_SETTINGS_TYPE_PLUGINS,
197 resource);
200 } // namespace content_settings