Chromium Code Reviews| 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/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_(NULL) { | |
| 30 // Whitelist all extensions loaded so far. | 33 // Whitelist all extensions loaded so far. |
| 31 const extensions::ExtensionSet* extensions = extension_service->extensions(); | 34 const extensions::ExtensionSet* extensions = extension_service->extensions(); |
| 32 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 35 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
| 33 it != extensions->end(); ++it) { | 36 it != extensions->end(); ++it) { |
| 34 if (extensions::PluginInfo::HasPlugins(it->get())) | 37 if (extensions::PluginInfo::HasPlugins(it->get())) |
| 35 SetContentSettingForExtension(it->get(), CONTENT_SETTING_ALLOW); | 38 SetContentSettingForExtension(it->get(), CONTENT_SETTING_ALLOW); |
| 36 } | 39 } |
| 37 Profile* profile = extension_service->profile(); | 40 Profile* profile = extension_service->profile(); |
| 38 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 41 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 39 content::Source<Profile>(profile)); | 42 content::Source<Profile>(profile)); |
| 40 registrar_->Add(this, | 43 extension_registry_ = extensions::ExtensionRegistry::Get(profile); |
|
Bernhard Bauer
2014/06/10 08:57:05
Could you initialize this in the initializer list
limasdf
2014/06/10 09:29:51
Done.
| |
| 41 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 44 extension_registry_->AddObserver(this); |
| 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 if (extension_registry_) { | |
|
Bernhard Bauer
2014/06/10 08:57:05
When can it happen that |extension_registry_| is N
limasdf
2014/06/10 09:29:51
Hm, it seems doesn't necessary. Removed if stateme
| |
| 89 extension_registry_->RemoveObserver(this); | |
| 90 extension_registry_ = NULL; | |
| 91 } | |
| 92 } | |
| 93 | |
| 70 void InternalExtensionProvider::Observe(int type, | 94 void InternalExtensionProvider::Observe(int type, |
| 71 const content::NotificationSource& source, | 95 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) { | 96 const content::NotificationDetails& details) { |
| 73 switch (type) { | 97 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_HOST_CREATED, type); |
| 74 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: { | 98 const extensions::ExtensionHost* host = |
| 75 const extensions::ExtensionHost* host = | 99 content::Details<extensions::ExtensionHost>(details).ptr(); |
| 76 content::Details<extensions::ExtensionHost>(details).ptr(); | 100 if (host->extension()->is_platform_app()) { |
| 77 if (host->extension()->is_platform_app()) { | 101 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK); |
| 78 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK); | |
| 79 | 102 |
| 80 // White-list CRD's v2 app, until crbug.com/134216 is complete. | 103 // White-list CRD's v2 app, until crbug.com/134216 is complete. |
| 81 const char* kAppWhitelist[] = { | 104 const char* kAppWhitelist[] = {"2775E568AC98F9578791F1EAB65A1BF5F8CEF414", |
| 82 "2775E568AC98F9578791F1EAB65A1BF5F8CEF414", | 105 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169", |
| 83 "4AA3C5D69A4AECBD236CAD7884502209F0F5C169", | 106 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2", |
| 84 "97B23E01B2AA064E8332EE43A7A85C628AADC3F2", | 107 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6", |
| 85 "9E930B2B5EABA6243AE6C710F126E54688E8FAF6", | 108 "C449A798C495E6CF7D6AF10162113D564E67AD12", |
| 86 "C449A798C495E6CF7D6AF10162113D564E67AD12", | 109 "E410CDAB2C6E6DD408D731016CECF2444000A912", |
| 87 "E410CDAB2C6E6DD408D731016CECF2444000A912", | 110 "EBA908206905323CECE6DC4B276A58A0F4AC573F", |
| 88 "EBA908206905323CECE6DC4B276A58A0F4AC573F", | |
| 89 | 111 |
| 90 // http://crbug.com/327507 | 112 // http://crbug.com/327507 |
| 91 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E", | 113 "FAFE8EFDD2D6AE2EEB277AFEB91C870C79064D9E", |
| 92 "3B52D273A271D4E2348233E322426DBAE854B567", | 114 "3B52D273A271D4E2348233E322426DBAE854B567", |
| 93 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059", | 115 "5DF6ADC8708DF59FCFDDBF16AFBFB451380C2059", |
| 94 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1", | 116 "1037DEF5F6B06EA46153AD87B6C5C37440E3F2D1", |
| 95 "F5815DAFEB8C53B078DD1853B2059E087C42F139", | 117 "F5815DAFEB8C53B078DD1853B2059E087C42F139", |
| 96 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513", | 118 "6A08EFFF9C16E090D6DCC7EC55A01CADAE840513", |
| 97 | 119 |
| 98 // http://crbug.com/354258 | 120 // http://crbug.com/354258 |
| 99 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4", | 121 "C32D6D93E12F5401DAA3A723E0C3CC5F25429BA4", |
| 100 "9099782647D39C778E15C8C6E0D23C88F5CDE170", | 122 "9099782647D39C778E15C8C6E0D23C88F5CDE170", |
| 101 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0", | 123 "B7D5B52D1E5B106288BD7F278CAFA5E8D76108B0", |
| 102 "89349DBAA2C4022FB244AA50182AB60934EB41EE", | 124 "89349DBAA2C4022FB244AA50182AB60934EB41EE", |
| 103 "CB593E510640572A995CB1B6D41BD85ED51E63F8", | 125 "CB593E510640572A995CB1B6D41BD85ED51E63F8", |
| 104 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612", | 126 "1AD1AC86C87969CD3434FA08D99DBA6840AEA612", |
| 105 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D", | 127 "9C2EA21D7975BDF2B3C01C3A454EE44854067A6D", |
| 106 "D2C488C80C3C90C3E01A991112A05E37831E17D0", | 128 "D2C488C80C3C90C3E01A991112A05E37831E17D0", |
| 107 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F", | 129 "6EEC061C0E74B46C7B5BE2EEFA49436368F4988F", |
| 108 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777", | 130 "8B344D9E8A4C505EF82A0DBBC25B8BD1F984E777", |
| 109 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868" | 131 "E06AFCB1EB0EFD237824CC4AC8FDD3D43E8BC868"}; |
| 110 }; | 132 if (extensions::SimpleFeature::IsIdInList( |
| 111 if (extensions::SimpleFeature::IsIdInList( | 133 host->extension()->id(), |
| 112 host->extension()->id(), | 134 std::set<std::string>(kAppWhitelist, |
| 113 std::set<std::string>( | 135 kAppWhitelist + arraysize(kAppWhitelist)))) { |
| 114 kAppWhitelist, kAppWhitelist + arraysize(kAppWhitelist)))) { | 136 SetContentSettingForExtensionAndResource( |
| 115 SetContentSettingForExtensionAndResource( | 137 host->extension(), |
| 116 host->extension(), | 138 ChromeContentClient::kRemotingViewerPluginPath, |
| 117 ChromeContentClient::kRemotingViewerPluginPath, | 139 CONTENT_SETTING_ALLOW); |
| 118 CONTENT_SETTING_ALLOW); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 break; | |
| 123 } | 140 } |
| 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 } | 141 } |
| 141 } | 142 } |
| 142 | 143 |
| 143 void InternalExtensionProvider::ShutdownOnUIThread() { | 144 void InternalExtensionProvider::ShutdownOnUIThread() { |
| 144 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 145 RemoveAllObservers(); | 146 RemoveAllObservers(); |
| 146 registrar_.reset(); | 147 registrar_.reset(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void InternalExtensionProvider::SetContentSettingForExtension( | 150 void InternalExtensionProvider::SetContentSettingForExtension( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 180 base::Value::CreateIntegerValue(setting)); | 181 base::Value::CreateIntegerValue(setting)); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 NotifyObservers(primary_pattern, | 184 NotifyObservers(primary_pattern, |
| 184 secondary_pattern, | 185 secondary_pattern, |
| 185 CONTENT_SETTINGS_TYPE_PLUGINS, | 186 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 186 resource); | 187 resource); |
| 187 } | 188 } |
| 188 | 189 |
| 189 } // namespace content_settings | 190 } // namespace content_settings |
| OLD | NEW |