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,12 +684,13 @@ void TabSpecificContentSettings::OnContentSettingChanged(
return;
}
if (content_type == ContentSettingsType::MEDIASTREAM_MIC ||
content_type == ContentSettingsType::MEDIASTREAM_CAMERA) {
ContentSettingsStatus& status = content_settings_status_[content_type];
switch (content_type) {
case ContentSettingsType::MEDIASTREAM_MIC:
case ContentSettingsType::MEDIASTREAM_CAMERA: {
const GURL media_origin = media_stream_access_origin();
ContentSetting setting = map_->GetContentSetting(
media_origin, media_origin, content_type, std::string());
ContentSettingsStatus& status = content_settings_status_[content_type];
if (content_type == ContentSettingsType::MEDIASTREAM_MIC &&
setting == CONTENT_SETTING_ALLOW) {
......@@ -703,6 +704,38 @@ void TabSpecificContentSettings::OnContentSettingChanged(
status.allowed = setting == CONTENT_SETTING_ALLOW;
status.blocked = setting == CONTENT_SETTING_BLOCK;
break;
}
case ContentSettingsType::IMAGES:
case ContentSettingsType::JAVASCRIPT:
case ContentSettingsType::PLUGINS:
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:
break;
}
if (!ShouldSendUpdatedContentSettingsRulesToRenderer(content_type))
......
......@@ -8,8 +8,10 @@
#include "base/optional.h"
#include "base/strings/string16.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/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/parsed_cookie.h"
......@@ -320,3 +322,45 @@ TEST_F(TabSpecificContentSettingsTest, LocalSharedObjectsContainerCookie) {
EXPECT_EQ(5u, objects.GetObjectCountForDomain(GURL("http://google.com")));
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