OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/extensions/extension_content_settings_provider.h" |
| 6 |
| 7 #include "chrome/browser/content_settings/content_settings_details.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "content/common/notification_service.h" |
| 10 #include "content/common/notification_source.h" |
| 11 |
| 12 // //////////////////////////////////////////////////////////////////////////// |
| 13 // class ExtensionDefaultContentSettingsProvider |
| 14 // |
| 15 ExtensionDefaultContentSettingsProvider |
| 16 ::ExtensionDefaultContentSettingsProvider( |
| 17 Profile* profile, |
| 18 ExtensionContentSettingsStore* extensions_settings, |
| 19 bool incognito) |
| 20 : profile_(profile), |
| 21 incognito_(incognito), |
| 22 extensions_settings_(extensions_settings) { |
| 23 extensions_settings_->AddObserver(this); |
| 24 } |
| 25 |
| 26 ExtensionDefaultContentSettingsProvider |
| 27 ::~ExtensionDefaultContentSettingsProvider() { |
| 28 } |
| 29 |
| 30 ContentSetting ExtensionDefaultContentSettingsProvider::ProvideDefaultSetting( |
| 31 ContentSettingsType content_type) const { |
| 32 return extensions_settings_->GetEffectiveDefaultContentSetting( |
| 33 content_type); |
| 34 } |
| 35 |
| 36 bool ExtensionDefaultContentSettingsProvider::DefaultSettingIsManaged( |
| 37 ContentSettingsType content_type) const { |
| 38 return false; |
| 39 } |
| 40 |
| 41 void ExtensionDefaultContentSettingsProvider::OnDefaultContentSettingChanged( |
| 42 const ContentSettingsType& type, |
| 43 ContentSetting setting, |
| 44 bool incognito) { |
| 45 if (incognito_ != incognito) |
| 46 return; |
| 47 NotifyObservers(ContentSettingsDetails( |
| 48 ContentSettingsPattern(), type, "")); |
| 49 } |
| 50 |
| 51 void ExtensionDefaultContentSettingsProvider::OnContentSettingChanged( |
| 52 const ContentSettingsPattern& pattern, |
| 53 const ContentSettingsPattern& embedder_pattern, |
| 54 const ContentSettingsType& type, |
| 55 const content_settings::ResourceIdentifier& identifier, |
| 56 ContentSetting setting, |
| 57 bool incognito) { |
| 58 } |
| 59 |
| 60 void ExtensionDefaultContentSettingsProvider::OnDestruction() { |
| 61 CHECK(extensions_settings_); |
| 62 extensions_settings_->RemoveObserver(this); |
| 63 extensions_settings_ = NULL; |
| 64 } |
| 65 |
| 66 void ExtensionDefaultContentSettingsProvider::NotifyObservers( |
| 67 const ContentSettingsDetails& details) { |
| 68 if (profile_ == NULL) |
| 69 return; |
| 70 NotificationService::current()->Notify( |
| 71 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 72 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
| 73 Details<const ContentSettingsDetails>(&details)); |
| 74 } |
| 75 |
| 76 // //////////////////////////////////////////////////////////////////////////// |
| 77 // class ExtensionContentSettingsProvider |
| 78 // |
| 79 ExtensionContentSettingsProvider::ExtensionContentSettingsProvider( |
| 80 Profile* profile, |
| 81 ExtensionContentSettingsStore* extensions_settings, |
| 82 bool incognito) |
| 83 : profile_(profile), |
| 84 incognito_(incognito), |
| 85 extensions_settings_(extensions_settings) { |
| 86 extensions_settings_->AddObserver(this); |
| 87 } |
| 88 |
| 89 ExtensionContentSettingsProvider::~ExtensionContentSettingsProvider() { |
| 90 } |
| 91 |
| 92 bool ExtensionContentSettingsProvider::ContentSettingsTypeIsManaged( |
| 93 ContentSettingsType content_type) { |
| 94 // TODO(markusheintz): Maybe an extension should be able to specify |
| 95 // whether it wants to manage a certain content type or not. |
| 96 return false; |
| 97 } |
| 98 |
| 99 ContentSetting ExtensionContentSettingsProvider::GetContentSetting( |
| 100 const GURL& requesting_url, |
| 101 const GURL& embedding_url, |
| 102 ContentSettingsType content_type, |
| 103 const content_settings::ResourceIdentifier& resource_identifier) const { |
| 104 // TODO(markusheintz): Instead of getting the Effective setting every time |
| 105 // effective patterns could be cached in here. |
| 106 return extensions_settings_->GetEffectiveContentSetting( |
| 107 requesting_url, |
| 108 embedding_url, |
| 109 content_type, |
| 110 resource_identifier, |
| 111 incognito_); |
| 112 } |
| 113 |
| 114 void ExtensionContentSettingsProvider::GetAllContentSettingsRules( |
| 115 ContentSettingsType content_type, |
| 116 const content_settings::ResourceIdentifier& resource_identifier, |
| 117 Rules* content_setting_rules) const { |
| 118 // TODO(markusheintz): Implement get all effective patterns. |
| 119 } |
| 120 |
| 121 void ExtensionContentSettingsProvider::NotifyObservers( |
| 122 const ContentSettingsDetails& details) { |
| 123 if (profile_ == NULL) |
| 124 return; |
| 125 NotificationService::current()->Notify( |
| 126 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 127 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
| 128 Details<const ContentSettingsDetails>(&details)); |
| 129 } |
| 130 |
| 131 void ExtensionContentSettingsProvider::OnDefaultContentSettingChanged( |
| 132 const ContentSettingsType& type, |
| 133 ContentSetting setting, |
| 134 bool incognito) { |
| 135 } |
| 136 |
| 137 void ExtensionContentSettingsProvider::OnContentSettingChanged( |
| 138 const ContentSettingsPattern& pattern, |
| 139 const ContentSettingsPattern& embedder_pattern, |
| 140 const ContentSettingsType& type, |
| 141 const content_settings::ResourceIdentifier& identifier, |
| 142 ContentSetting setting, |
| 143 bool incognito) { |
| 144 if (incognito_ != incognito) |
| 145 return; |
| 146 // TODO(markusheintz): Be more consise. |
| 147 NotifyObservers(ContentSettingsDetails( |
| 148 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); |
| 149 } |
| 150 |
| 151 void ExtensionContentSettingsProvider::OnDestruction() { |
| 152 CHECK(extensions_settings_); |
| 153 extensions_settings_->RemoveObserver(this); |
| 154 extensions_settings_ = NULL; |
| 155 } |
OLD | NEW |