| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_extension_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/content_settings_details.h" | |
| 8 #include "chrome/browser/extensions/extension_content_settings_store.h" | 7 #include "chrome/browser/extensions/extension_content_settings_store.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "content/common/notification_details.h" | |
| 12 #include "content/common/notification_service.h" | |
| 13 #include "content/common/notification_source.h" | |
| 14 | 10 |
| 15 namespace content_settings { | 11 namespace content_settings { |
| 16 | 12 |
| 17 ExtensionProvider::ExtensionProvider( | 13 ExtensionProvider::ExtensionProvider( |
| 18 HostContentSettingsMap* map, | |
| 19 ExtensionContentSettingsStore* extensions_settings, | 14 ExtensionContentSettingsStore* extensions_settings, |
| 20 bool incognito) | 15 bool incognito) |
| 21 : map_(map), | 16 : incognito_(incognito), |
| 22 incognito_(incognito), | |
| 23 extensions_settings_(extensions_settings) { | 17 extensions_settings_(extensions_settings) { |
| 24 extensions_settings_->AddObserver(this); | 18 extensions_settings_->AddObserver(this); |
| 25 } | 19 } |
| 26 | 20 |
| 27 ExtensionProvider::~ExtensionProvider() { | 21 ExtensionProvider::~ExtensionProvider() { |
| 28 DCHECK(!map_); | |
| 29 } | 22 } |
| 30 | 23 |
| 31 ContentSetting ExtensionProvider::GetContentSetting( | 24 ContentSetting ExtensionProvider::GetContentSetting( |
| 32 const GURL& embedded_url, | 25 const GURL& embedded_url, |
| 33 const GURL& top_level_url, | 26 const GURL& top_level_url, |
| 34 ContentSettingsType content_type, | 27 ContentSettingsType content_type, |
| 35 const ResourceIdentifier& resource_identifier) const { | 28 const ResourceIdentifier& resource_identifier) const { |
| 36 // TODO(markusheintz): Instead of getting the effective setting every time | 29 // TODO(markusheintz): Instead of getting the effective setting every time |
| 37 // effective patterns could be cached in here. | 30 // effective patterns could be cached in here. |
| 38 DCHECK(extensions_settings_); | 31 DCHECK(extensions_settings_); |
| 39 return extensions_settings_->GetEffectiveContentSetting( | 32 return extensions_settings_->GetEffectiveContentSetting( |
| 40 embedded_url, | 33 embedded_url, |
| 41 top_level_url, | 34 top_level_url, |
| 42 content_type, | 35 content_type, |
| 43 resource_identifier, | 36 resource_identifier, |
| 44 incognito_); | 37 incognito_); |
| 45 } | 38 } |
| 46 | 39 |
| 47 void ExtensionProvider::GetAllContentSettingsRules( | 40 void ExtensionProvider::GetAllContentSettingsRules( |
| 48 ContentSettingsType content_type, | 41 ContentSettingsType content_type, |
| 49 const ResourceIdentifier& resource_identifier, | 42 const ResourceIdentifier& resource_identifier, |
| 50 Rules* content_setting_rules) const { | 43 Rules* content_setting_rules) const { |
| 51 return extensions_settings_->GetContentSettingsForContentType( | 44 return extensions_settings_->GetContentSettingsForContentType( |
| 52 content_type, resource_identifier, incognito_, content_setting_rules); | 45 content_type, resource_identifier, incognito_, content_setting_rules); |
| 53 } | 46 } |
| 54 | 47 |
| 55 void ExtensionProvider::ShutdownOnUIThread() { | 48 void ExtensionProvider::ShutdownOnUIThread() { |
| 49 RemoveAllObservers(); |
| 56 extensions_settings_->RemoveObserver(this); | 50 extensions_settings_->RemoveObserver(this); |
| 57 map_ = NULL; | |
| 58 } | |
| 59 | |
| 60 void ExtensionProvider::NotifyObservers( | |
| 61 const ContentSettingsDetails& details) { | |
| 62 DCHECK(map_); | |
| 63 NotificationService::current()->Notify( | |
| 64 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | |
| 65 Source<HostContentSettingsMap>(map_), | |
| 66 Details<const ContentSettingsDetails>(&details)); | |
| 67 } | 51 } |
| 68 | 52 |
| 69 void ExtensionProvider::OnContentSettingChanged( | 53 void ExtensionProvider::OnContentSettingChanged( |
| 70 const std::string& extension_id, | 54 const std::string& extension_id, |
| 71 bool incognito) { | 55 bool incognito) { |
| 72 if (incognito_ != incognito) | 56 if (incognito_ != incognito) |
| 73 return; | 57 return; |
| 74 // TODO(markusheintz): Be more concise. | 58 // TODO(markusheintz): Be more concise. |
| 75 ContentSettingsDetails details(ContentSettingsPattern(), | 59 NotifyObservers(ContentSettingsPattern(), |
| 76 ContentSettingsPattern(), | 60 ContentSettingsPattern(), |
| 77 CONTENT_SETTINGS_TYPE_DEFAULT, | 61 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 78 std::string()); | 62 std::string()); |
| 79 NotifyObservers(details); | |
| 80 } | 63 } |
| 81 | 64 |
| 82 } // namespace content_settings | 65 } // namespace content_settings |
| OLD | NEW |