Chromium Code Reviews| 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/extensions/extension_content_settings_store.h" | 7 #include "chrome/browser/extensions/extension_content_settings_store.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
| 10 | 10 |
| 11 namespace content_settings { | 11 namespace content_settings { |
| 12 | 12 |
| 13 ExtensionProvider::ExtensionProvider( | 13 ExtensionProvider::ExtensionProvider( |
| 14 ExtensionContentSettingsStore* extensions_settings, | 14 ExtensionContentSettingsStore* extensions_settings, |
| 15 bool incognito) | 15 bool incognito) |
| 16 : incognito_(incognito), | 16 : incognito_(incognito), |
| 17 extensions_settings_(extensions_settings) { | 17 extensions_settings_(extensions_settings) { |
| 18 extensions_settings_->AddObserver(this); | 18 extensions_settings_->AddObserver(this); |
| 19 } | 19 } |
| 20 | 20 |
| 21 ExtensionProvider::~ExtensionProvider() { | 21 ExtensionProvider::~ExtensionProvider() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 ContentSetting ExtensionProvider::GetContentSetting( | 24 ContentSetting ExtensionProvider::GetContentSetting( |
| 25 const GURL& embedded_url, | 25 const GURL& primary_url, |
| 26 const GURL& top_level_url, | 26 const GURL& secondary_url, |
| 27 ContentSettingsType content_type, | 27 ContentSettingsType content_type, |
| 28 const ResourceIdentifier& resource_identifier) const { | 28 const ResourceIdentifier& resource_identifier) const { |
| 29 // TODO(markusheintz): Instead of getting the effective setting every time | 29 // TODO(markusheintz): Instead of getting the effective setting every time |
| 30 // effective patterns could be cached in here. | 30 // effective patterns could be cached in here. |
| 31 DCHECK(extensions_settings_); | 31 DCHECK(extensions_settings_); |
| 32 return extensions_settings_->GetEffectiveContentSetting( | 32 return extensions_settings_->GetEffectiveContentSetting( |
| 33 embedded_url, | 33 primary_url, |
| 34 top_level_url, | 34 secondary_url, |
| 35 content_type, | 35 content_type, |
| 36 resource_identifier, | 36 resource_identifier, |
| 37 incognito_); | 37 incognito_); |
| 38 } | 38 } |
| 39 | 39 |
| 40 Value* ExtensionProvider::GetContentSettingValue( | |
| 41 const GURL& primary_url, | |
| 42 const GURL& secondary_url, | |
| 43 ContentSettingsType content_type, | |
| 44 const ResourceIdentifier& resource_identifier) const { | |
| 45 // TODO(markusheintz): Change the ExtensionSettingsStore to use the | |
| 46 // OriginIdentifierValueMap to allow arbitray |Value|s to be stored inseted of | |
|
Pam (message me for reviews)
2011/09/02 10:50:16
typo "instead"
markusheintz_
2011/09/02 15:22:21
Done.
| |
| 47 // |ContentSetting|s. | |
| 48 ContentSetting setting = GetContentSetting( | |
| 49 primary_url, | |
| 50 secondary_url, | |
| 51 content_type, | |
| 52 resource_identifier); | |
| 53 if (setting == CONTENT_SETTING_DEFAULT) | |
| 54 return NULL; | |
| 55 return Value::CreateIntegerValue(setting); | |
| 56 } | |
| 57 | |
| 58 | |
| 40 void ExtensionProvider::GetAllContentSettingsRules( | 59 void ExtensionProvider::GetAllContentSettingsRules( |
| 41 ContentSettingsType content_type, | 60 ContentSettingsType content_type, |
| 42 const ResourceIdentifier& resource_identifier, | 61 const ResourceIdentifier& resource_identifier, |
| 43 Rules* content_setting_rules) const { | 62 Rules* content_setting_rules) const { |
| 44 return extensions_settings_->GetContentSettingsForContentType( | 63 return extensions_settings_->GetContentSettingsForContentType( |
| 45 content_type, resource_identifier, incognito_, content_setting_rules); | 64 content_type, resource_identifier, incognito_, content_setting_rules); |
| 46 } | 65 } |
| 47 | 66 |
| 48 void ExtensionProvider::ShutdownOnUIThread() { | 67 void ExtensionProvider::ShutdownOnUIThread() { |
| 49 RemoveAllObservers(); | 68 RemoveAllObservers(); |
| 50 extensions_settings_->RemoveObserver(this); | 69 extensions_settings_->RemoveObserver(this); |
| 51 } | 70 } |
| 52 | 71 |
| 53 void ExtensionProvider::OnContentSettingChanged( | 72 void ExtensionProvider::OnContentSettingChanged( |
| 54 const std::string& extension_id, | 73 const std::string& extension_id, |
| 55 bool incognito) { | 74 bool incognito) { |
| 56 if (incognito_ != incognito) | 75 if (incognito_ != incognito) |
| 57 return; | 76 return; |
| 58 // TODO(markusheintz): Be more concise. | 77 // TODO(markusheintz): Be more concise. |
| 59 NotifyObservers(ContentSettingsPattern(), | 78 NotifyObservers(ContentSettingsPattern(), |
| 60 ContentSettingsPattern(), | 79 ContentSettingsPattern(), |
| 61 CONTENT_SETTINGS_TYPE_DEFAULT, | 80 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 62 std::string()); | 81 std::string()); |
| 63 } | 82 } |
| 64 | 83 |
| 65 } // namespace content_settings | 84 } // namespace content_settings |
| OLD | NEW |