| Index: chrome/browser/extensions/extension_content_settings_provider.cc
|
| diff --git a/chrome/browser/extensions/extension_content_settings_provider.cc b/chrome/browser/extensions/extension_content_settings_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3015b3855dbca43e182c5089cb654aa116d162ff
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/extension_content_settings_provider.cc
|
| @@ -0,0 +1,155 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/extensions/extension_content_settings_provider.h"
|
| +
|
| +#include "chrome/browser/content_settings/content_settings_details.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "content/common/notification_service.h"
|
| +#include "content/common/notification_source.h"
|
| +
|
| +// ////////////////////////////////////////////////////////////////////////////
|
| +// class ExtensionDefaultContentSettingsProvider
|
| +//
|
| +ExtensionDefaultContentSettingsProvider
|
| + ::ExtensionDefaultContentSettingsProvider(
|
| + Profile* profile,
|
| + ExtensionContentSettingsStore* extensions_settings,
|
| + bool incognito)
|
| + : profile_(profile),
|
| + incognito_(incognito),
|
| + extensions_settings_(extensions_settings) {
|
| + extensions_settings_->AddObserver(this);
|
| +}
|
| +
|
| +ExtensionDefaultContentSettingsProvider
|
| + ::~ExtensionDefaultContentSettingsProvider() {
|
| +}
|
| +
|
| +ContentSetting ExtensionDefaultContentSettingsProvider::ProvideDefaultSetting(
|
| + ContentSettingsType content_type) const {
|
| + return extensions_settings_->GetEffectiveDefaultContentSetting(
|
| + content_type);
|
| +}
|
| +
|
| +bool ExtensionDefaultContentSettingsProvider::DefaultSettingIsManaged(
|
| + ContentSettingsType content_type) const {
|
| + return false;
|
| +}
|
| +
|
| +void ExtensionDefaultContentSettingsProvider::OnDefaultContentSettingChanged(
|
| + const ContentSettingsType& type,
|
| + ContentSetting setting,
|
| + bool incognito) {
|
| + if (incognito_ != incognito)
|
| + return;
|
| + NotifyObservers(ContentSettingsDetails(
|
| + ContentSettingsPattern(), type, ""));
|
| +}
|
| +
|
| +void ExtensionDefaultContentSettingsProvider::OnContentSettingChanged(
|
| + const ContentSettingsPattern& pattern,
|
| + const ContentSettingsPattern& embedder_pattern,
|
| + const ContentSettingsType& type,
|
| + const content_settings::ResourceIdentifier& identifier,
|
| + ContentSetting setting,
|
| + bool incognito) {
|
| +}
|
| +
|
| +void ExtensionDefaultContentSettingsProvider::OnDestruction() {
|
| + CHECK(extensions_settings_);
|
| + extensions_settings_->RemoveObserver(this);
|
| + extensions_settings_ = NULL;
|
| +}
|
| +
|
| +void ExtensionDefaultContentSettingsProvider::NotifyObservers(
|
| + const ContentSettingsDetails& details) {
|
| + if (profile_ == NULL)
|
| + return;
|
| + NotificationService::current()->Notify(
|
| + NotificationType::CONTENT_SETTINGS_CHANGED,
|
| + Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()),
|
| + Details<const ContentSettingsDetails>(&details));
|
| +}
|
| +
|
| +// ////////////////////////////////////////////////////////////////////////////
|
| +// class ExtensionContentSettingsProvider
|
| +//
|
| +ExtensionContentSettingsProvider::ExtensionContentSettingsProvider(
|
| + Profile* profile,
|
| + ExtensionContentSettingsStore* extensions_settings,
|
| + bool incognito)
|
| + : profile_(profile),
|
| + incognito_(incognito),
|
| + extensions_settings_(extensions_settings) {
|
| + extensions_settings_->AddObserver(this);
|
| +}
|
| +
|
| +ExtensionContentSettingsProvider::~ExtensionContentSettingsProvider() {
|
| +}
|
| +
|
| +bool ExtensionContentSettingsProvider::ContentSettingsTypeIsManaged(
|
| + ContentSettingsType content_type) {
|
| + // TODO(markusheintz): Maybe an extension should be able to specify
|
| + // whether it wants to manage a certain content type or not.
|
| + return false;
|
| +}
|
| +
|
| +ContentSetting ExtensionContentSettingsProvider::GetContentSetting(
|
| + const GURL& requesting_url,
|
| + const GURL& embedding_url,
|
| + ContentSettingsType content_type,
|
| + const content_settings::ResourceIdentifier& resource_identifier) const {
|
| + // TODO(markusheintz): Instead of getting the Effective setting every time
|
| + // effective patterns could be cached in here.
|
| + return extensions_settings_->GetEffectiveContentSetting(
|
| + requesting_url,
|
| + embedding_url,
|
| + content_type,
|
| + resource_identifier,
|
| + incognito_);
|
| +}
|
| +
|
| +void ExtensionContentSettingsProvider::GetAllContentSettingsRules(
|
| + ContentSettingsType content_type,
|
| + const content_settings::ResourceIdentifier& resource_identifier,
|
| + Rules* content_setting_rules) const {
|
| + // TODO(markusheintz): Implement get all effective patterns.
|
| +}
|
| +
|
| +void ExtensionContentSettingsProvider::NotifyObservers(
|
| + const ContentSettingsDetails& details) {
|
| + if (profile_ == NULL)
|
| + return;
|
| + NotificationService::current()->Notify(
|
| + NotificationType::CONTENT_SETTINGS_CHANGED,
|
| + Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()),
|
| + Details<const ContentSettingsDetails>(&details));
|
| +}
|
| +
|
| +void ExtensionContentSettingsProvider::OnDefaultContentSettingChanged(
|
| + const ContentSettingsType& type,
|
| + ContentSetting setting,
|
| + bool incognito) {
|
| +}
|
| +
|
| +void ExtensionContentSettingsProvider::OnContentSettingChanged(
|
| + const ContentSettingsPattern& pattern,
|
| + const ContentSettingsPattern& embedder_pattern,
|
| + const ContentSettingsType& type,
|
| + const content_settings::ResourceIdentifier& identifier,
|
| + ContentSetting setting,
|
| + bool incognito) {
|
| + if (incognito_ != incognito)
|
| + return;
|
| + // TODO(markusheintz): Be more consise.
|
| + NotifyObservers(ContentSettingsDetails(
|
| + ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, ""));
|
| +}
|
| +
|
| +void ExtensionContentSettingsProvider::OnDestruction() {
|
| + CHECK(extensions_settings_);
|
| + extensions_settings_->RemoveObserver(this);
|
| + extensions_settings_ = NULL;
|
| +}
|
|
|