| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "chrome/browser/content_settings/content_settings_platform_app_provider
.h" | |
| 6 | |
| 7 #include "chrome/browser/content_settings/content_settings_rule.h" | |
| 8 #include "chrome/browser/extensions/extension_host.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/common/chrome_notification_types.h" | |
| 11 #include "chrome/common/content_settings.h" | |
| 12 #include "chrome/common/content_settings_pattern.h" | |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 #include "chrome/common/extensions/extension_set.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/browser/notification_details.h" | |
| 18 #include "content/public/browser/notification_service.h" | |
| 19 | |
| 20 using extensions::UnloadedExtensionInfo; | |
| 21 | |
| 22 namespace content_settings { | |
| 23 | |
| 24 PlatformAppProvider::PlatformAppProvider(ExtensionService* extension_service) | |
| 25 : registrar_(new content::NotificationRegistrar) { | |
| 26 // Whitelist all extensions loaded so far. | |
| 27 const ExtensionSet* extensions = extension_service->extensions(); | |
| 28 for (ExtensionSet::const_iterator it = extensions->begin(); | |
| 29 it != extensions->end(); ++it) { | |
| 30 if ((*it)->plugins().size() > 0) | |
| 31 SetContentSettingForExtension(*it, CONTENT_SETTING_ALLOW); | |
| 32 } | |
| 33 Profile* profile = extension_service->profile(); | |
| 34 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | |
| 35 content::Source<Profile>(profile)); | |
| 36 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 37 content::Source<Profile>(profile)); | |
| 38 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
| 39 content::Source<Profile>(profile)); | |
| 40 } | |
| 41 | |
| 42 PlatformAppProvider::~PlatformAppProvider() { | |
| 43 DCHECK(!registrar_.get()); | |
| 44 } | |
| 45 | |
| 46 RuleIterator* PlatformAppProvider::GetRuleIterator( | |
| 47 ContentSettingsType content_type, | |
| 48 const ResourceIdentifier& resource_identifier, | |
| 49 bool incognito) const { | |
| 50 return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_); | |
| 51 } | |
| 52 | |
| 53 bool PlatformAppProvider::SetWebsiteSetting( | |
| 54 const ContentSettingsPattern& primary_pattern, | |
| 55 const ContentSettingsPattern& secondary_pattern, | |
| 56 ContentSettingsType content_type, | |
| 57 const ResourceIdentifier& resource_identifier, | |
| 58 Value* value) { | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 62 void PlatformAppProvider::ClearAllContentSettingsRules( | |
| 63 ContentSettingsType content_type) {} | |
| 64 | |
| 65 void PlatformAppProvider::Observe(int type, | |
| 66 const content::NotificationSource& source, | |
| 67 const content::NotificationDetails& details) { | |
| 68 switch (type) { | |
| 69 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: { | |
| 70 const extensions::ExtensionHost* host = | |
| 71 content::Details<extensions::ExtensionHost>(details).ptr(); | |
| 72 if (host->extension()->is_platform_app()) | |
| 73 SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK); | |
| 74 break; | |
| 75 } | |
| 76 case chrome::NOTIFICATION_EXTENSION_LOADED: { | |
| 77 const extensions::Extension* extension = | |
| 78 content::Details<extensions::Extension>(details).ptr(); | |
| 79 if (extension->plugins().size() > 0) | |
| 80 SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW); | |
| 81 break; | |
| 82 } | |
| 83 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | |
| 84 const UnloadedExtensionInfo& info = | |
| 85 *(content::Details<UnloadedExtensionInfo>(details).ptr()); | |
| 86 if (info.extension->plugins().size() > 0) | |
| 87 SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT); | |
| 88 break; | |
| 89 } | |
| 90 default: | |
| 91 NOTREACHED(); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void PlatformAppProvider::ShutdownOnUIThread() { | |
| 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 97 RemoveAllObservers(); | |
| 98 registrar_.reset(); | |
| 99 } | |
| 100 | |
| 101 void PlatformAppProvider::SetContentSettingForExtension( | |
| 102 const extensions::Extension* extension, | |
| 103 ContentSetting setting) { | |
| 104 scoped_ptr<ContentSettingsPattern::BuilderInterface> pattern_builder( | |
| 105 ContentSettingsPattern::CreateBuilder(false)); | |
| 106 pattern_builder->WithScheme(chrome::kExtensionScheme); | |
| 107 pattern_builder->WithHost(extension->id()); | |
| 108 pattern_builder->WithPathWildcard(); | |
| 109 | |
| 110 ContentSettingsPattern primary_pattern = pattern_builder->Build(); | |
| 111 ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard(); | |
| 112 { | |
| 113 base::AutoLock lock(lock_); | |
| 114 if (setting == CONTENT_SETTING_DEFAULT) { | |
| 115 value_map_.DeleteValue(primary_pattern, | |
| 116 secondary_pattern, | |
| 117 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 118 ResourceIdentifier("")); | |
| 119 } else { | |
| 120 value_map_.SetValue(primary_pattern, | |
| 121 secondary_pattern, | |
| 122 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 123 ResourceIdentifier(""), | |
| 124 Value::CreateIntegerValue(setting)); | |
| 125 } | |
| 126 } | |
| 127 NotifyObservers(primary_pattern, | |
| 128 secondary_pattern, | |
| 129 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 130 ResourceIdentifier("")); | |
| 131 } | |
| 132 | |
| 133 } // namespace content_settings | |
| OLD | NEW |