OLD | NEW |
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/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/common/chrome_content_client.h" | 8 #include "chrome/common/chrome_content_client.h" |
9 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 9 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
10 #include "components/content_settings/core/browser/content_settings_rule.h" | 10 #include "components/content_settings/core/browser/content_settings_rule.h" |
11 #include "components/content_settings/core/common/content_settings.h" | 11 #include "components/content_settings/core/common/content_settings.h" |
12 #include "components/content_settings/core/common/content_settings_pattern.h" | 12 #include "components/content_settings/core/common/content_settings_pattern.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "extensions/browser/extension_host.h" | 15 #include "extensions/browser/extension_host.h" |
16 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/browser/notification_types.h" | 17 #include "extensions/browser/notification_types.h" |
18 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
20 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
21 #include "extensions/common/features/simple_feature.h" | 21 #include "extensions/common/features/simple_feature.h" |
22 | 22 |
23 using extensions::UnloadedExtensionInfo; | 23 using extensions::UnloadedExtensionInfo; |
24 | 24 |
25 namespace content_settings { | 25 namespace content_settings { |
26 | 26 |
| 27 namespace { |
| 28 |
| 29 // This is the set of extensions that are allowed to access the internal |
| 30 // remoting viewer plugin. |
| 31 const char* kRemotingViewerWhitelist[] = { |
| 32 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 33 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 34 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
| 35 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
| 36 }; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 |
27 InternalExtensionProvider::InternalExtensionProvider(Profile* profile) | 41 InternalExtensionProvider::InternalExtensionProvider(Profile* profile) |
28 : registrar_(new content::NotificationRegistrar) { | 42 : registrar_(new content::NotificationRegistrar) { |
| 43 for (size_t i = 0; i < arraysize(kRemotingViewerWhitelist); ++i) |
| 44 chrome_remote_desktop_.insert(kRemotingViewerWhitelist[i]); |
| 45 |
29 // Whitelist all extensions loaded so far. | 46 // Whitelist all extensions loaded so far. |
30 for (const scoped_refptr<const extensions::Extension>& extension : | 47 for (const scoped_refptr<const extensions::Extension>& extension : |
31 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { | 48 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { |
32 if (extensions::PluginInfo::HasPlugins(extension.get())) | 49 ApplyPluginContentSettingsForExtension(extension.get(), |
33 SetContentSettingForExtension(extension.get(), CONTENT_SETTING_ALLOW); | 50 CONTENT_SETTING_ALLOW); |
34 } | 51 } |
35 registrar_->Add(this, | 52 registrar_->Add(this, |
36 extensions::NOTIFICATION_EXTENSION_HOST_CREATED, | 53 extensions::NOTIFICATION_EXTENSION_HOST_CREATED, |
37 content::Source<Profile>(profile)); | 54 content::Source<Profile>(profile)); |
38 registrar_->Add(this, | 55 registrar_->Add(this, |
39 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 56 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
40 content::Source<Profile>(profile)); | 57 content::Source<Profile>(profile)); |
41 registrar_->Add(this, | 58 registrar_->Add(this, |
42 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 59 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
43 content::Source<Profile>(profile)); | 60 content::Source<Profile>(profile)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ChromeContentClient::kRemotingViewerPluginPath, | 145 ChromeContentClient::kRemotingViewerPluginPath, |
129 CONTENT_SETTING_ALLOW); | 146 CONTENT_SETTING_ALLOW); |
130 } | 147 } |
131 } | 148 } |
132 | 149 |
133 break; | 150 break; |
134 } | 151 } |
135 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 152 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
136 const extensions::Extension* extension = | 153 const extensions::Extension* extension = |
137 content::Details<extensions::Extension>(details).ptr(); | 154 content::Details<extensions::Extension>(details).ptr(); |
138 if (extensions::PluginInfo::HasPlugins(extension)) | 155 ApplyPluginContentSettingsForExtension(extension, CONTENT_SETTING_ALLOW); |
139 SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW); | |
140 break; | 156 break; |
141 } | 157 } |
142 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 158 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
143 const UnloadedExtensionInfo& info = | 159 const UnloadedExtensionInfo& info = |
144 *(content::Details<UnloadedExtensionInfo>(details).ptr()); | 160 *(content::Details<UnloadedExtensionInfo>(details).ptr()); |
145 if (extensions::PluginInfo::HasPlugins(info.extension)) | 161 ApplyPluginContentSettingsForExtension(info.extension, |
146 SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT); | 162 CONTENT_SETTING_DEFAULT); |
147 break; | 163 break; |
148 } | 164 } |
149 default: | 165 default: |
150 NOTREACHED(); | 166 NOTREACHED(); |
151 } | 167 } |
152 } | 168 } |
153 | 169 |
154 void InternalExtensionProvider::ShutdownOnUIThread() { | 170 void InternalExtensionProvider::ShutdownOnUIThread() { |
155 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
156 RemoveAllObservers(); | 172 RemoveAllObservers(); |
157 registrar_.reset(); | 173 registrar_.reset(); |
158 } | 174 } |
159 | 175 |
| 176 void InternalExtensionProvider::ApplyPluginContentSettingsForExtension( |
| 177 const extensions::Extension* extension, |
| 178 ContentSetting setting) { |
| 179 if (extensions::PluginInfo::HasPlugins(extension)) |
| 180 SetContentSettingForExtension(extension, setting); |
| 181 |
| 182 // Chrome Remove Desktop relies on the remoting viewer plugin. The |
| 183 // above check does not catch this, as the plugin is a builtin plugin. |
| 184 if (chrome_remote_desktop_.find(extension->id()) != |
| 185 chrome_remote_desktop_.end()) { |
| 186 SetContentSettingForExtensionAndResource( |
| 187 extension, ChromeContentClient::kRemotingViewerPluginPath, setting); |
| 188 } |
| 189 } |
| 190 |
160 void InternalExtensionProvider::SetContentSettingForExtension( | 191 void InternalExtensionProvider::SetContentSettingForExtension( |
161 const extensions::Extension* extension, | 192 const extensions::Extension* extension, |
162 ContentSetting setting) { | 193 ContentSetting setting) { |
163 SetContentSettingForExtensionAndResource( | 194 SetContentSettingForExtensionAndResource( |
164 extension, ResourceIdentifier(), setting); | 195 extension, ResourceIdentifier(), setting); |
165 } | 196 } |
166 | 197 |
167 void InternalExtensionProvider::SetContentSettingForExtensionAndResource( | 198 void InternalExtensionProvider::SetContentSettingForExtensionAndResource( |
168 const extensions::Extension* extension, | 199 const extensions::Extension* extension, |
169 const ResourceIdentifier& resource, | 200 const ResourceIdentifier& resource, |
(...skipping 21 matching lines...) Expand all Loading... |
191 new base::FundamentalValue(setting)); | 222 new base::FundamentalValue(setting)); |
192 } | 223 } |
193 } | 224 } |
194 NotifyObservers(primary_pattern, | 225 NotifyObservers(primary_pattern, |
195 secondary_pattern, | 226 secondary_pattern, |
196 CONTENT_SETTINGS_TYPE_PLUGINS, | 227 CONTENT_SETTINGS_TYPE_PLUGINS, |
197 resource); | 228 resource); |
198 } | 229 } |
199 | 230 |
200 } // namespace content_settings | 231 } // namespace content_settings |
OLD | NEW |