Commit 018ce4f8 authored by Illia Klimov's avatar Illia Klimov Committed by Commit Bot

Hide misleading string in ContentSettingsBubble.

This patch adds TabSpecificContentSettings::Delegate into
ContentSettingsUsagesState. ContentSettingsUsagesState::GetDetailedInfo
verifies if ContentSettings is under embargo so that the dialog no
longer incorrectly claims that the setting will be cleared after the
page is reloaded.
Added method TabSpecificContentSettings::Delegate::GetEmbargoSetting to
get ContentSetting of embargoed origin.

Bug: 1068162
Change-Id: I6cbd3cfedff0072b16b2c2ae07188e2564b1d69e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2165744
Commit-Queue: Illia Klimov <elklm@google.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770664}
parent eb96794b
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "chrome/common/renderer_configuration.mojom.h" #include "chrome/common/renderer_configuration.mojom.h"
#include "components/content_settings/browser/tab_specific_content_settings.h" #include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -74,6 +76,15 @@ HostContentSettingsMap* TabSpecificContentSettingsDelegate::GetSettingsMap() { ...@@ -74,6 +76,15 @@ HostContentSettingsMap* TabSpecificContentSettingsDelegate::GetSettingsMap() {
Profile::FromBrowserContext(web_contents()->GetBrowserContext())); Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
} }
ContentSetting TabSpecificContentSettingsDelegate::GetEmbargoSetting(
const GURL& request_origin,
ContentSettingsType permission) {
return PermissionDecisionAutoBlockerFactory::GetForProfile(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()))
->GetEmbargoResult(request_origin, permission)
.content_setting;
}
std::vector<storage::FileSystemType> std::vector<storage::FileSystemType>
TabSpecificContentSettingsDelegate::GetAdditionalFileSystemTypes() { TabSpecificContentSettingsDelegate::GetAdditionalFileSystemTypes() {
return browsing_data_file_system_util::GetAdditionalFileSystemTypes(); return browsing_data_file_system_util::GetAdditionalFileSystemTypes();
......
...@@ -66,6 +66,8 @@ class TabSpecificContentSettingsDelegate ...@@ -66,6 +66,8 @@ class TabSpecificContentSettingsDelegate
const RendererContentSettingRules& rules) override; const RendererContentSettingRules& rules) override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
HostContentSettingsMap* GetSettingsMap() override; HostContentSettingsMap* GetSettingsMap() override;
ContentSetting GetEmbargoSetting(const GURL& request_origin,
ContentSettingsType permission) override;
std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override; std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override;
browsing_data::CookieHelper::IsDeletionDisabledCallback browsing_data::CookieHelper::IsDeletionDisabledCallback
GetIsDeletionDisabledCallback() override; GetIsDeletionDisabledCallback() override;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "chrome/browser/permissions/permission_manager_factory.h" #include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/browser/tab_specific_content_settings.h" #include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/permission_manager.h" #include "components/permissions/permission_manager.h"
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h" #include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h"
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h" #include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "chrome/browser/permissions/quiet_notification_permission_ui_config.h" #include "chrome/browser/permissions/quiet_notification_permission_ui_config.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/plugins/plugin_utils.h" #include "chrome/browser/plugins/plugin_utils.h"
...@@ -43,15 +44,18 @@ ...@@ -43,15 +44,18 @@
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/browser/tab_specific_content_settings.h" #include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/content_settings/common/content_settings_agent.mojom.h" #include "components/content_settings/common/content_settings_agent.mojom.h"
#include "components/content_settings/core/browser/content_settings_utils.h" #include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h" #include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_utils.h" #include "components/content_settings/core/common/content_settings_utils.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/permissions/permission_request_manager.h" #include "components/permissions/permission_request_manager.h"
#include "components/permissions/permission_uma_util.h" #include "components/permissions/permission_uma_util.h"
#include "components/permissions/permission_util.h" #include "components/permissions/permission_util.h"
#include "components/permissions/permissions_client.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/subresource_filter/core/browser/subresource_filter_constants.h" #include "components/subresource_filter/core/browser/subresource_filter_constants.h"
...@@ -566,6 +570,8 @@ void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() { ...@@ -566,6 +570,8 @@ void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() {
content_settings->midi_usages_state().state_map(); content_settings->midi_usages_state().state_map();
HostContentSettingsMap* map = HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(GetProfile()); HostContentSettingsMapFactory::GetForProfile(GetProfile());
auto* auto_blocker =
PermissionDecisionAutoBlockerFactory::GetForProfile(GetProfile());
for (const std::pair<const GURL, ContentSetting>& map_entry : state_map) { for (const std::pair<const GURL, ContentSetting>& map_entry : state_map) {
permissions::PermissionUmaUtil::ScopedRevocationReporter( permissions::PermissionUmaUtil::ScopedRevocationReporter(
GetProfile(), map_entry.first, embedder_url, GetProfile(), map_entry.first, embedder_url,
...@@ -574,6 +580,8 @@ void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() { ...@@ -574,6 +580,8 @@ void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() {
map->SetContentSettingDefaultScope(map_entry.first, embedder_url, map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
ContentSettingsType::MIDI_SYSEX, ContentSettingsType::MIDI_SYSEX,
std::string(), CONTENT_SETTING_DEFAULT); std::string(), CONTENT_SETTING_DEFAULT);
auto_blocker->RemoveEmbargoAndResetCounts(map_entry.first,
ContentSettingsType::MIDI_SYSEX);
} }
} }
...@@ -655,6 +663,8 @@ void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() { ...@@ -655,6 +663,8 @@ void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
content_settings->geolocation_usages_state().state_map(); content_settings->geolocation_usages_state().state_map();
HostContentSettingsMap* map = HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(GetProfile()); HostContentSettingsMapFactory::GetForProfile(GetProfile());
auto* auto_blocker =
PermissionDecisionAutoBlockerFactory::GetForProfile(GetProfile());
for (const std::pair<const GURL, ContentSetting>& map_entry : state_map) { for (const std::pair<const GURL, ContentSetting>& map_entry : state_map) {
permissions::PermissionUmaUtil::ScopedRevocationReporter( permissions::PermissionUmaUtil::ScopedRevocationReporter(
GetProfile(), map_entry.first, embedder_url, GetProfile(), map_entry.first, embedder_url,
...@@ -663,6 +673,8 @@ void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() { ...@@ -663,6 +673,8 @@ void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
map->SetContentSettingDefaultScope(map_entry.first, embedder_url, map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
ContentSettingsType::GEOLOCATION, ContentSettingsType::GEOLOCATION,
std::string(), CONTENT_SETTING_DEFAULT); std::string(), CONTENT_SETTING_DEFAULT);
auto_blocker->RemoveEmbargoAndResetCounts(map_entry.first,
ContentSettingsType::GEOLOCATION);
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/popup_blocker.h" #include "chrome/browser/ui/blocked_content/popup_blocker.h"
#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
...@@ -32,6 +33,8 @@ ...@@ -32,6 +33,8 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/permissions/permission_result.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
...@@ -823,6 +826,68 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) { ...@@ -823,6 +826,68 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
CheckGeolocationBubble(2, true, false); CheckGeolocationBubble(2, true, false);
} }
TEST_F(ContentSettingBubbleModelTest, GeolocationEmbargo) {
GURL origin_to_embargo("http://example.com/");
// Verify that |origin_to_embargo| is not blocked.
{
auto* content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile());
const ContentSetting saved_setting =
content_settings_map->GetContentSetting(
origin_to_embargo, origin_to_embargo,
ContentSettingsType::GEOLOCATION, std::string());
ASSERT_EQ(CONTENT_SETTING_ASK, saved_setting);
}
NavigateAndCommit(origin_to_embargo);
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
content_settings->OnGeolocationPermissionSet(origin_to_embargo, false);
// |origin_to_embargo| is not blocked or embargoed. Verify no clear link
// shown.
CheckGeolocationBubble(1, /*expect_clear_link*/ false,
/*expect_reload_hint*/ true);
{
auto* auto_blocker =
PermissionDecisionAutoBlockerFactory::GetForProfile(profile());
for (int i = 0; i < 3; ++i)
auto_blocker->RecordDismissAndEmbargo(
origin_to_embargo, ContentSettingsType::GEOLOCATION, false);
}
// |origin_to_embargo| is not blocked but under embargo. Verify clear link is
// shown.
CheckGeolocationBubble(1, /*expect_clear_link*/ true,
/*expect_reload_hint*/ false);
// Reset ContentSettings and embargo state by pressing on Custom Link.
{
std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
ContentSettingBubbleModel::CreateContentSettingBubbleModel(
nullptr, web_contents(), ContentSettingsType::GEOLOCATION));
content_setting_bubble_model->OnCustomLinkClicked();
}
// Verify |origin_to_embargo| is no longer under embargo.
{
auto* auto_blocker =
PermissionDecisionAutoBlockerFactory::GetForProfile(profile());
permissions::PermissionResult result = auto_blocker->GetEmbargoResult(
origin_to_embargo, ContentSettingsType::GEOLOCATION);
ASSERT_EQ(CONTENT_SETTING_ASK, result.content_setting);
}
// |origin_to_embargo| returned to default state, not blocked or embargoed.
// Verify no clear link shown.
CheckGeolocationBubble(1, /*expect_clear_link*/ false,
/*expect_reload_hint*/ true);
}
TEST_F(ContentSettingBubbleModelTest, FileURL) { TEST_F(ContentSettingBubbleModelTest, FileURL) {
std::string file_url("file:///tmp/test.html"); std::string file_url("file:///tmp/test.html");
NavigateAndCommit(GURL(file_url)); NavigateAndCommit(GURL(file_url));
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/browser/tab_specific_content_settings.h" #include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/content_settings/core/browser/cookie_settings.h" #include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/usb/usb_tab_helper.h" #include "chrome/browser/usb/usb_tab_helper.h"
#include "chrome/browser/vr/vr_tab_helper.h" #include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/vr/win/vr_browser_renderer_thread_win.h" #include "chrome/browser/vr/win/vr_browser_renderer_thread_win.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/browser/tab_specific_content_settings.h" #include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/permissions/permission_manager.h" #include "components/permissions/permission_manager.h"
#include "components/permissions/permission_result.h" #include "components/permissions/permission_result.h"
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
ContentSettingsUsagesState::ContentSettingsUsagesState( ContentSettingsUsagesState::ContentSettingsUsagesState(
HostContentSettingsMap* host_content_settings_map, content_settings::TabSpecificContentSettings::Delegate* delegate_,
ContentSettingsType type) ContentSettingsType type)
: host_content_settings_map_(host_content_settings_map), type_(type) {} : delegate_(delegate_), type_(type) {}
ContentSettingsUsagesState::~ContentSettingsUsagesState() {} ContentSettingsUsagesState::~ContentSettingsUsagesState() {}
...@@ -48,39 +48,62 @@ void ContentSettingsUsagesState::GetDetailedInfo( ...@@ -48,39 +48,62 @@ void ContentSettingsUsagesState::GetDetailedInfo(
unsigned int* tab_state_flags) const { unsigned int* tab_state_flags) const {
DCHECK(tab_state_flags); DCHECK(tab_state_flags);
DCHECK(embedder_url_.is_valid()); DCHECK(embedder_url_.is_valid());
// This logic is used only for |ContentSettingsType::GEOLOCATION| and
// |ContentSettingsType::MIDI_SYSEX|.
DCHECK(type_ == ContentSettingsType::GEOLOCATION ||
type_ == ContentSettingsType::MIDI_SYSEX);
ContentSetting default_setting = ContentSetting default_setting =
host_content_settings_map_->GetDefaultContentSetting(type_, nullptr); delegate_->GetSettingsMap()->GetDefaultContentSetting(type_, nullptr);
std::set<std::string> formatted_hosts; std::set<std::string> formatted_hosts;
std::set<std::string> repeated_formatted_hosts; std::set<std::string> repeated_formatted_hosts;
// Build a set of repeated formatted hosts // Build a set of repeated formatted hosts.
for (auto i(state_map_.begin()); i != state_map_.end(); ++i) { for (const auto& i : state_map_) {
std::string formatted_host = GURLToFormattedHost(i->first); std::string formatted_host = GURLToFormattedHost(i.first);
if (!formatted_hosts.insert(formatted_host).second) { if (!formatted_hosts.insert(formatted_host).second) {
repeated_formatted_hosts.insert(formatted_host); repeated_formatted_hosts.insert(formatted_host);
} }
} }
for (auto i(state_map_.begin()); i != state_map_.end(); ++i) { for (const auto& i : state_map_) {
if (i->second == CONTENT_SETTING_ALLOW) const GURL& origin = i.first;
// The setting that was applied when the corresponding capability was last
// requested.
const ContentSetting& effective_setting = i.second;
if (effective_setting == CONTENT_SETTING_ALLOW)
*tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED; *tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED;
if (formatted_hosts_per_state) { if (formatted_hosts_per_state) {
std::string formatted_host = GURLToFormattedHost(i->first); std::string formatted_host = GURLToFormattedHost(origin);
std::string final_formatted_host = std::string final_formatted_host =
repeated_formatted_hosts.find(formatted_host) == repeated_formatted_hosts.find(formatted_host) ==
repeated_formatted_hosts.end() repeated_formatted_hosts.end()
? formatted_host ? formatted_host
: i->first.spec(); : origin.spec();
(*formatted_hosts_per_state)[i->second].insert(final_formatted_host); (*formatted_hosts_per_state)[effective_setting].insert(
final_formatted_host);
} }
const ContentSetting saved_setting = ContentSetting saved_setting =
host_content_settings_map_->GetContentSetting(i->first, embedder_url_, delegate_->GetSettingsMap()->GetContentSetting(origin, embedder_url_,
type_, std::string()); type_, std::string());
ContentSetting embargo_setting =
delegate_->GetEmbargoSetting(origin, type_);
// |embargo_setting| can be only CONTENT_SETTING_ASK or
// CONTENT_SETTING_BLOCK. If |saved_setting| is CONTENT_SETTING_ASK then
// the |embargo_setting| takes effect.
if (saved_setting == CONTENT_SETTING_ASK)
saved_setting = embargo_setting;
// |effective_setting| can be only CONTENT_SETTING_ALLOW or
// CONTENT_SETTING_BLOCK.
if (saved_setting != effective_setting)
*tab_state_flags |= TABSTATE_HAS_CHANGED;
if (saved_setting != default_setting) if (saved_setting != default_setting)
*tab_state_flags |= TABSTATE_HAS_EXCEPTION; *tab_state_flags |= TABSTATE_HAS_EXCEPTION;
if (saved_setting != i->second)
*tab_state_flags |= TABSTATE_HAS_CHANGED;
if (saved_setting != CONTENT_SETTING_ASK) if (saved_setting != CONTENT_SETTING_ASK)
*tab_state_flags |= TABSTATE_HAS_ANY_ICON; *tab_state_flags |= TABSTATE_HAS_ANY_ICON;
} }
......
...@@ -9,19 +9,20 @@ ...@@ -9,19 +9,20 @@
#include <set> #include <set>
#include "base/macros.h" #include "base/macros.h"
#include "components/content_settings/browser/tab_specific_content_settings.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "url/gurl.h" #include "url/gurl.h"
class HostContentSettingsMap;
// This class manages a content setting state per tab for a given // This class manages a content setting state per tab for a given
// |ContentSettingsType|, and provides information and presentation data about // |ContentSettingsType|, and provides information and presentation data about
// the content setting usage. // the content setting usage.
class ContentSettingsUsagesState { class ContentSettingsUsagesState {
public: public:
ContentSettingsUsagesState(HostContentSettingsMap* host_content_settings_map, ContentSettingsUsagesState(
ContentSettingsType type); content_settings::TabSpecificContentSettings::Delegate* delegate_,
ContentSettingsType type);
~ContentSettingsUsagesState(); ~ContentSettingsUsagesState();
typedef std::map<GURL, ContentSetting> StateMap; typedef std::map<GURL, ContentSetting> StateMap;
...@@ -57,8 +58,7 @@ class ContentSettingsUsagesState { ...@@ -57,8 +58,7 @@ class ContentSettingsUsagesState {
private: private:
std::string GURLToFormattedHost(const GURL& url) const; std::string GURLToFormattedHost(const GURL& url) const;
content_settings::TabSpecificContentSettings::Delegate* delegate_;
HostContentSettingsMap* const host_content_settings_map_;
ContentSettingsType type_; ContentSettingsType type_;
StateMap state_map_; StateMap state_map_;
GURL embedder_url_; GURL embedder_url_;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/browsing_data/content/local_storage_helper.h" #include "components/browsing_data/content/local_storage_helper.h"
#include "components/browsing_data/content/service_worker_helper.h" #include "components/browsing_data/content/service_worker_helper.h"
#include "components/browsing_data/content/shared_worker_helper.h" #include "components/browsing_data/content/shared_worker_helper.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/common/content_settings_agent.mojom.h" #include "components/content_settings/common/content_settings_agent.mojom.h"
#include "components/content_settings/core/browser/content_settings_details.h" #include "components/content_settings/core/browser/content_settings_details.h"
#include "components/content_settings/core/browser/content_settings_info.h" #include "components/content_settings/core/browser/content_settings_info.h"
...@@ -91,8 +92,12 @@ TabSpecificContentSettings::TabSpecificContentSettings( ...@@ -91,8 +92,12 @@ TabSpecificContentSettings::TabSpecificContentSettings(
blocked_local_shared_objects_(tab->GetBrowserContext(), blocked_local_shared_objects_(tab->GetBrowserContext(),
delegate_->GetAdditionalFileSystemTypes(), delegate_->GetAdditionalFileSystemTypes(),
delegate_->GetIsDeletionDisabledCallback()), delegate_->GetIsDeletionDisabledCallback()),
geolocation_usages_state_(map_, ContentSettingsType::GEOLOCATION), geolocation_usages_state_(std::make_unique<ContentSettingsUsagesState>(
midi_usages_state_(map_, ContentSettingsType::MIDI_SYSEX), delegate_.get(),
ContentSettingsType::GEOLOCATION)),
midi_usages_state_(std::make_unique<ContentSettingsUsagesState>(
delegate_.get(),
ContentSettingsType::MIDI_SYSEX)),
load_plugins_link_enabled_(true), load_plugins_link_enabled_(true),
microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED) { microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED) {
ClearContentSettingsExceptForNavigationRelatedSettings(); ClearContentSettingsExceptForNavigationRelatedSettings();
...@@ -488,7 +493,7 @@ void TabSpecificContentSettings::OnFileSystemAccessed(const GURL& url, ...@@ -488,7 +493,7 @@ void TabSpecificContentSettings::OnFileSystemAccessed(const GURL& url,
void TabSpecificContentSettings::OnGeolocationPermissionSet( void TabSpecificContentSettings::OnGeolocationPermissionSet(
const GURL& requesting_origin, const GURL& requesting_origin,
bool allowed) { bool allowed) {
geolocation_usages_state_.OnPermissionSet(requesting_origin, allowed); geolocation_usages_state_->OnPermissionSet(requesting_origin, allowed);
delegate_->UpdateLocationBar(); delegate_->UpdateLocationBar();
} }
...@@ -564,13 +569,13 @@ void TabSpecificContentSettings::OnMediaStreamPermissionSet( ...@@ -564,13 +569,13 @@ void TabSpecificContentSettings::OnMediaStreamPermissionSet(
void TabSpecificContentSettings::OnMidiSysExAccessed( void TabSpecificContentSettings::OnMidiSysExAccessed(
const GURL& requesting_origin) { const GURL& requesting_origin) {
midi_usages_state_.OnPermissionSet(requesting_origin, true); midi_usages_state_->OnPermissionSet(requesting_origin, true);
OnContentAllowed(ContentSettingsType::MIDI_SYSEX); OnContentAllowed(ContentSettingsType::MIDI_SYSEX);
} }
void TabSpecificContentSettings::OnMidiSysExAccessBlocked( void TabSpecificContentSettings::OnMidiSysExAccessBlocked(
const GURL& requesting_origin) { const GURL& requesting_origin) {
midi_usages_state_.OnPermissionSet(requesting_origin, false); midi_usages_state_->OnPermissionSet(requesting_origin, false);
OnContentBlocked(ContentSettingsType::MIDI_SYSEX); OnContentBlocked(ContentSettingsType::MIDI_SYSEX);
} }
...@@ -808,16 +813,16 @@ void TabSpecificContentSettings::ClearContentSettingsChangedViaPageInfo() { ...@@ -808,16 +813,16 @@ void TabSpecificContentSettings::ClearContentSettingsChangedViaPageInfo() {
void TabSpecificContentSettings::GeolocationDidNavigate( void TabSpecificContentSettings::GeolocationDidNavigate(
content::NavigationHandle* navigation_handle) { content::NavigationHandle* navigation_handle) {
geolocation_usages_state_.ClearStateMap(); geolocation_usages_state_->ClearStateMap();
geolocation_usages_state_.DidNavigate(navigation_handle->GetURL(), geolocation_usages_state_->DidNavigate(navigation_handle->GetURL(),
navigation_handle->GetPreviousURL()); navigation_handle->GetPreviousURL());
} }
void TabSpecificContentSettings::MidiDidNavigate( void TabSpecificContentSettings::MidiDidNavigate(
content::NavigationHandle* navigation_handle) { content::NavigationHandle* navigation_handle) {
midi_usages_state_.ClearStateMap(); midi_usages_state_->ClearStateMap();
midi_usages_state_.DidNavigate(navigation_handle->GetURL(), midi_usages_state_->DidNavigate(navigation_handle->GetURL(),
navigation_handle->GetPreviousURL()); navigation_handle->GetPreviousURL());
} }
void TabSpecificContentSettings::BlockAllContentForTesting() { void TabSpecificContentSettings::BlockAllContentForTesting() {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/browsing_data/content/cookie_helper.h" #include "components/browsing_data/content/cookie_helper.h"
#include "components/browsing_data/content/local_shared_objects_container.h" #include "components/browsing_data/content/local_shared_objects_container.h"
#include "components/content_settings/browser/content_settings_usages_state.h"
#include "components/content_settings/core/browser/content_settings_observer.h" #include "components/content_settings/core/browser/content_settings_observer.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
...@@ -36,6 +35,8 @@ namespace url { ...@@ -36,6 +35,8 @@ namespace url {
class Origin; class Origin;
} // namespace url } // namespace url
class ContentSettingsUsagesState;
namespace content_settings { namespace content_settings {
// TODO(msramek): Media is storing their state in TabSpecificContentSettings: // TODO(msramek): Media is storing their state in TabSpecificContentSettings:
...@@ -85,6 +86,10 @@ class TabSpecificContentSettings ...@@ -85,6 +86,10 @@ class TabSpecificContentSettings
// Gets the settings map for the current web contents. // Gets the settings map for the current web contents.
virtual HostContentSettingsMap* GetSettingsMap() = 0; virtual HostContentSettingsMap* GetSettingsMap() = 0;
virtual ContentSetting GetEmbargoSetting(
const GURL& request_origin,
ContentSettingsType permission) = 0;
// Gets any additional file system types which should be used when // Gets any additional file system types which should be used when
// constructing a browsing_data::FileSystemHelper. // constructing a browsing_data::FileSystemHelper.
virtual std::vector<storage::FileSystemType> virtual std::vector<storage::FileSystemType>
...@@ -259,13 +264,13 @@ class TabSpecificContentSettings ...@@ -259,13 +264,13 @@ class TabSpecificContentSettings
// Returns the ContentSettingsUsagesState that controls the // Returns the ContentSettingsUsagesState that controls the
// geolocation API usage on this page. // geolocation API usage on this page.
const ContentSettingsUsagesState& geolocation_usages_state() const { const ContentSettingsUsagesState& geolocation_usages_state() const {
return geolocation_usages_state_; return *geolocation_usages_state_;
} }
// Returns the ContentSettingsUsageState that controls the MIDI usage on // Returns the ContentSettingsUsageState that controls the MIDI usage on
// this page. // this page.
const ContentSettingsUsagesState& midi_usages_state() const { const ContentSettingsUsagesState& midi_usages_state() const {
return midi_usages_state_; return *midi_usages_state_;
} }
// Returns the |LocalSharedObjectsContainer| instances corresponding to all // Returns the |LocalSharedObjectsContainer| instances corresponding to all
...@@ -427,10 +432,10 @@ class TabSpecificContentSettings ...@@ -427,10 +432,10 @@ class TabSpecificContentSettings
browsing_data::LocalSharedObjectsContainer blocked_local_shared_objects_; browsing_data::LocalSharedObjectsContainer blocked_local_shared_objects_;
// Manages information about Geolocation API usage in this page. // Manages information about Geolocation API usage in this page.
ContentSettingsUsagesState geolocation_usages_state_; std::unique_ptr<ContentSettingsUsagesState> geolocation_usages_state_;
// Manages information about MIDI usages in this page. // Manages information about MIDI usages in this page.
ContentSettingsUsagesState midi_usages_state_; std::unique_ptr<ContentSettingsUsagesState> midi_usages_state_;
// Stores whether the user can load blocked plugins on this page. // Stores whether the user can load blocked plugins on this page.
bool load_plugins_link_enabled_; bool load_plugins_link_enabled_;
......
...@@ -76,6 +76,11 @@ class TabSpecificContentSettingsTest ...@@ -76,6 +76,11 @@ class TabSpecificContentSettingsTest
return test_->settings_map_.get(); return test_->settings_map_.get();
} }
ContentSetting GetEmbargoSetting(const GURL& request_origin,
ContentSettingsType permission) override {
return ContentSetting::CONTENT_SETTING_ASK;
}
std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes()
override { override {
return {}; return {};
......
...@@ -123,7 +123,6 @@ class TestTabSpecificContentSettingsDelegate ...@@ -123,7 +123,6 @@ class TestTabSpecificContentSettingsDelegate
content::BrowserContext* browser_context) content::BrowserContext* browser_context)
: browser_context_(browser_context) {} : browser_context_(browser_context) {}
// content_settings::TabSpecificContentSettings::Delegate:
void UpdateLocationBar() override {} void UpdateLocationBar() override {}
void SetContentSettingRules( void SetContentSettingRules(
...@@ -136,6 +135,11 @@ class TestTabSpecificContentSettingsDelegate ...@@ -136,6 +135,11 @@ class TestTabSpecificContentSettingsDelegate
return PermissionsClient::Get()->GetSettingsMap(browser_context_); return PermissionsClient::Get()->GetSettingsMap(browser_context_);
} }
ContentSetting GetEmbargoSetting(const GURL& request_origin,
ContentSettingsType permission) override {
return ContentSetting::CONTENT_SETTING_ASK;
}
std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override { std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override {
return {}; return {};
} }
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "weblayer/browser/browser_context_impl.h" #include "weblayer/browser/browser_context_impl.h"
#include "weblayer/browser/host_content_settings_map_factory.h" #include "weblayer/browser/host_content_settings_map_factory.h"
#include "weblayer/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "weblayer/common/renderer_configuration.mojom.h" #include "weblayer/common/renderer_configuration.mojom.h"
namespace weblayer { namespace weblayer {
...@@ -59,6 +61,15 @@ HostContentSettingsMap* TabSpecificContentSettingsDelegate::GetSettingsMap() { ...@@ -59,6 +61,15 @@ HostContentSettingsMap* TabSpecificContentSettingsDelegate::GetSettingsMap() {
web_contents_->GetBrowserContext()); web_contents_->GetBrowserContext());
} }
ContentSetting TabSpecificContentSettingsDelegate::GetEmbargoSetting(
const GURL& request_origin,
ContentSettingsType permission) {
return PermissionDecisionAutoBlockerFactory::GetForBrowserContext(
web_contents_->GetBrowserContext())
->GetEmbargoResult(request_origin, permission)
.content_setting;
}
std::vector<storage::FileSystemType> std::vector<storage::FileSystemType>
TabSpecificContentSettingsDelegate::GetAdditionalFileSystemTypes() { TabSpecificContentSettingsDelegate::GetAdditionalFileSystemTypes() {
return {}; return {};
......
...@@ -32,6 +32,8 @@ class TabSpecificContentSettingsDelegate ...@@ -32,6 +32,8 @@ class TabSpecificContentSettingsDelegate
const RendererContentSettingRules& rules) override; const RendererContentSettingRules& rules) override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
HostContentSettingsMap* GetSettingsMap() override; HostContentSettingsMap* GetSettingsMap() override;
ContentSetting GetEmbargoSetting(const GURL& request_origin,
ContentSettingsType permission) override;
std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override; std::vector<storage::FileSystemType> GetAdditionalFileSystemTypes() override;
browsing_data::CookieHelper::IsDeletionDisabledCallback browsing_data::CookieHelper::IsDeletionDisabledCallback
GetIsDeletionDisabledCallback() override; GetIsDeletionDisabledCallback() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment