Commit 45116080 authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Update permission indicator if the user changes the setting

Bug: 875521
Change-Id: I4d5a0930e090b6720646352d8e537e90faedc004
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132413
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756390}
parent 48b66f4b
...@@ -684,25 +684,58 @@ void TabSpecificContentSettings::OnContentSettingChanged( ...@@ -684,25 +684,58 @@ void TabSpecificContentSettings::OnContentSettingChanged(
return; return;
} }
if (content_type == ContentSettingsType::MEDIASTREAM_MIC || ContentSettingsStatus& status = content_settings_status_[content_type];
content_type == ContentSettingsType::MEDIASTREAM_CAMERA) { switch (content_type) {
const GURL media_origin = media_stream_access_origin(); case ContentSettingsType::MEDIASTREAM_MIC:
ContentSetting setting = map_->GetContentSetting( case ContentSettingsType::MEDIASTREAM_CAMERA: {
media_origin, media_origin, content_type, std::string()); const GURL media_origin = media_stream_access_origin();
ContentSettingsStatus& status = content_settings_status_[content_type]; ContentSetting setting = map_->GetContentSetting(
media_origin, media_origin, content_type, std::string());
if (content_type == ContentSettingsType::MEDIASTREAM_MIC &&
setting == CONTENT_SETTING_ALLOW) { if (content_type == ContentSettingsType::MEDIASTREAM_MIC &&
mic_was_just_granted_on_site_level_ = true; setting == CONTENT_SETTING_ALLOW) {
mic_was_just_granted_on_site_level_ = true;
}
if (content_type == ContentSettingsType::MEDIASTREAM_CAMERA &&
setting == CONTENT_SETTING_ALLOW) {
camera_was_just_granted_on_site_level_ = true;
}
status.allowed = setting == CONTENT_SETTING_ALLOW;
status.blocked = setting == CONTENT_SETTING_BLOCK;
break;
} }
case ContentSettingsType::IMAGES:
if (content_type == ContentSettingsType::MEDIASTREAM_CAMERA && case ContentSettingsType::JAVASCRIPT:
setting == CONTENT_SETTING_ALLOW) { case ContentSettingsType::PLUGINS:
camera_was_just_granted_on_site_level_ = true; case ContentSettingsType::COOKIES:
case ContentSettingsType::POPUPS:
case ContentSettingsType::MIXEDSCRIPT:
case ContentSettingsType::PPAPI_BROKER:
case ContentSettingsType::MIDI_SYSEX:
case ContentSettingsType::ADS:
case ContentSettingsType::SOUND:
case ContentSettingsType::CLIPBOARD_READ_WRITE:
case ContentSettingsType::SENSORS: {
ContentSetting setting = map_->GetContentSetting(
web_contents()->GetVisibleURL(), web_contents()->GetVisibleURL(),
content_type, std::string());
// If an indicator is shown and the content settings has changed, swap the
// indicator for the one with the opposite meaning (allowed <=> blocked).
if (setting == CONTENT_SETTING_BLOCK && status.allowed) {
status.blocked = false;
status.allowed = false;
OnContentBlocked(content_type);
} else if (setting == CONTENT_SETTING_ALLOW && status.blocked) {
status.blocked = false;
status.allowed = false;
OnContentAllowed(content_type);
}
break;
} }
default:
status.allowed = setting == CONTENT_SETTING_ALLOW; break;
status.blocked = setting == CONTENT_SETTING_BLOCK;
} }
if (!ShouldSendUpdatedContentSettingsRulesToRenderer(content_type)) if (!ShouldSendUpdatedContentSettingsRulesToRenderer(content_type))
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/content_settings/host_content_settings_map_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/core/browser/host_content_settings_map.h"
#include "net/cookies/canonical_cookie.h" #include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h" #include "net/cookies/cookie_options.h"
#include "net/cookies/parsed_cookie.h" #include "net/cookies/parsed_cookie.h"
...@@ -320,3 +322,45 @@ TEST_F(TabSpecificContentSettingsTest, LocalSharedObjectsContainerCookie) { ...@@ -320,3 +322,45 @@ TEST_F(TabSpecificContentSettingsTest, LocalSharedObjectsContainerCookie) {
EXPECT_EQ(5u, objects.GetObjectCountForDomain(GURL("http://google.com"))); EXPECT_EQ(5u, objects.GetObjectCountForDomain(GURL("http://google.com")));
EXPECT_EQ(1u, objects.GetDomainCount()); EXPECT_EQ(1u, objects.GetDomainCount());
} }
TEST_F(TabSpecificContentSettingsTest, IndicatorChangedOnContentSettingChange) {
NavigateAndCommit(GURL("http://google.com"));
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
// First trigger OnContentBlocked.
EXPECT_FALSE(content_settings->IsContentBlocked(
ContentSettingsType::CLIPBOARD_READ_WRITE));
content_settings->OnContentBlocked(ContentSettingsType::CLIPBOARD_READ_WRITE);
EXPECT_TRUE(content_settings->IsContentBlocked(
ContentSettingsType::CLIPBOARD_READ_WRITE));
// Simulate the user modifying the setting.
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(browser_context());
ContentSettingsPattern pattern =
ContentSettingsPattern::FromURL(web_contents()->GetVisibleURL());
map->SetWebsiteSettingCustomScope(
pattern, pattern, ContentSettingsType::CLIPBOARD_READ_WRITE,
std::string(), std::make_unique<base::Value>(CONTENT_SETTING_ALLOW));
// Now the indicator is set to allowed.
EXPECT_TRUE(content_settings->IsContentAllowed(
ContentSettingsType::CLIPBOARD_READ_WRITE));
EXPECT_FALSE(content_settings->IsContentBlocked(
ContentSettingsType::CLIPBOARD_READ_WRITE));
// Simulate the user modifying the setting back to blocked.
map->SetWebsiteSettingCustomScope(
pattern, pattern, ContentSettingsType::CLIPBOARD_READ_WRITE,
std::string(), std::make_unique<base::Value>(CONTENT_SETTING_BLOCK));
// Now the indicator is set to allowed.
EXPECT_TRUE(content_settings->IsContentBlocked(
ContentSettingsType::CLIPBOARD_READ_WRITE));
EXPECT_FALSE(content_settings->IsContentAllowed(
ContentSettingsType::CLIPBOARD_READ_WRITE));
}
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