Commit 567984c5 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Fix formatting/lint issues in content setting model files.

Fixes include:
- Include what you use
- Running "git cl format"
- Reordering classes to be consistent

Change-Id: I197eb04cb84babe0f91aa47a7f4792c6289d92ee
Reviewed-on: https://chromium-review.googlesource.com/780019
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521145}
parent fa26960a
......@@ -6,6 +6,9 @@
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/macros.h"
......@@ -76,14 +79,6 @@ using content_settings::SETTING_SOURCE_NONE;
namespace {
// These states must match the order of appearance of the radio buttons
// in the XIB file for the Mac port.
enum RPHState {
RPH_ALLOW = 0,
RPH_BLOCK,
RPH_IGNORE,
};
struct ContentSettingsTypeIdEntry {
ContentSettingsType type;
int id;
......@@ -99,25 +94,14 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
return 0;
}
const content::MediaStreamDevice& GetMediaDeviceById(
const std::string& device_id,
const content::MediaStreamDevices& devices) {
DCHECK(!devices.empty());
for (const content::MediaStreamDevice& device : devices) {
if (device.id == device_id)
return device;
}
// A device with the |device_id| was not found. It is likely that the device
// has been unplugged from the OS. Return the first device as the default
// device.
return *devices.begin();
void SetAllowRunningInsecureContent(content::RenderFrameHost* frame) {
chrome::mojom::InsecureContentRendererPtr renderer;
frame->GetRemoteInterfaces()->GetInterface(&renderer);
renderer->SetAllowRunningInsecureContent();
}
} // namespace
const int ContentSettingBubbleModel::kAllowButtonIndex = 0;
// ContentSettingSimpleBubbleModel ---------------------------------------------
ContentSettingSimpleBubbleModel::ContentSettingSimpleBubbleModel(
......@@ -240,222 +224,418 @@ void ContentSettingSimpleBubbleModel::SetCustomLink() {
void ContentSettingSimpleBubbleModel::OnCustomLinkClicked() {
}
// ContentSettingSingleRadioGroup ----------------------------------------------
// ContentSettingMixedScriptBubbleModel ----------------------------------------
class ContentSettingSingleRadioGroup : public ContentSettingSimpleBubbleModel {
class ContentSettingMixedScriptBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingSingleRadioGroup(Delegate* delegate,
ContentSettingMixedScriptBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
~ContentSettingSingleRadioGroup() override;
Profile* profile);
protected:
bool settings_changed() const;
int selected_item() const { return selected_item_; }
~ContentSettingMixedScriptBubbleModel() override {}
private:
void SetRadioGroup();
void SetNarrowestContentSetting(ContentSetting setting);
void OnRadioClicked(int radio_index) override;
void SetManageText();
ContentSetting block_setting_;
int selected_item_;
// ContentSettingBubbleModel:
void OnLearnMoreClicked() override;
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSingleRadioGroup);
DISALLOW_COPY_AND_ASSIGN(ContentSettingMixedScriptBubbleModel);
};
ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup(
ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
Profile* profile)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
content_type),
block_setting_(CONTENT_SETTING_BLOCK),
selected_item_(0) {
SetRadioGroup();
CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_BUBBLE);
set_custom_link_enabled(true);
set_show_learn_more(true);
SetManageText();
}
ContentSettingSingleRadioGroup::~ContentSettingSingleRadioGroup() {
if (settings_changed()) {
ContentSetting setting =
selected_item_ == kAllowButtonIndex ?
CONTENT_SETTING_ALLOW :
block_setting_;
SetNarrowestContentSetting(setting);
}
}
void ContentSettingMixedScriptBubbleModel::OnLearnMoreClicked() {
if (delegate())
delegate()->ShowLearnMorePage(content_type());
bool ContentSettingSingleRadioGroup::settings_changed() const {
return selected_item_ != bubble_content().radio_group.default_item;
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_CLICKED_LEARN_MORE);
}
// Initialize the radio group by setting the appropriate labels for the
// content type and setting the default value based on the content setting.
void ContentSettingSingleRadioGroup::SetRadioGroup() {
GURL url = web_contents()->GetURL();
base::string16 display_host =
url_formatter::FormatUrlForSecurityDisplay(url);
if (display_host.empty())
display_host = base::ASCIIToUTF16(url.spec());
void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
DCHECK(rappor_service());
if (!web_contents())
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
bool allowed = !content_settings->IsContentBlocked(content_type());
DCHECK(!allowed || content_settings->IsContentAllowed(content_type()));
MixedContentSettingsTabHelper* mixed_content_settings =
MixedContentSettingsTabHelper::FromWebContents(web_contents());
if (mixed_content_settings) {
// Update browser side settings to allow active mixed content.
mixed_content_settings->AllowRunningOfInsecureContent();
}
RadioGroup radio_group;
radio_group.url = url;
// Update renderer side settings to allow active mixed content.
web_contents()->ForEachFrame(
base::BindRepeating(&::SetAllowRunningInsecureContent));
static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
{CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
{CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK},
{CONTENT_SETTINGS_TYPE_SOUND, IDS_BLOCKED_SOUND_UNBLOCK},
};
// Fields as for kBlockedAllowIDs, above.
static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION},
};
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_CLICKED_ALLOW);
base::string16 radio_allow_label;
if (allowed) {
int resource_id = GetIdForContentType(kAllowedAllowIDs,
arraysize(kAllowedAllowIDs),
content_type());
radio_allow_label = l10n_util::GetStringUTF16(resource_id);
} else {
radio_allow_label = l10n_util::GetStringFUTF16(
GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs),
content_type()),
display_host);
}
rappor::SampleDomainAndRegistryFromGURL(
rappor_service(), "ContentSettings.MixedScript.UserClickedAllow",
web_contents()->GetLastCommittedURL());
}
static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
{CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION},
{CONTENT_SETTINGS_TYPE_SOUND, IDS_BLOCKED_SOUND_NO_ACTION},
};
static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_BLOCK},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK},
};
// Don't set any manage text since none is displayed.
void ContentSettingMixedScriptBubbleModel::SetManageText() {
set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
}
base::string16 radio_block_label;
if (allowed) {
int resource_id = GetIdForContentType(
kAllowedBlockIDs, arraysize(kAllowedBlockIDs), content_type());
radio_block_label = l10n_util::GetStringFUTF16(resource_id, display_host);
} else {
radio_block_label = l10n_util::GetStringUTF16(GetIdForContentType(
kBlockedBlockIDs, arraysize(kBlockedBlockIDs), content_type()));
}
// ContentSettingRPHBubbleModel ------------------------------------------------
radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_block_label);
ContentSetting setting;
SettingSource setting_source = SETTING_SOURCE_NONE;
namespace {
if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
content_settings::CookieSettings* cookie_settings =
CookieSettingsFactory::GetForProfile(profile()).get();
cookie_settings->GetCookieSetting(url, url, &setting_source, &setting);
// These states must match the order of appearance of the radio buttons
// in the XIB file for the Mac port.
enum RPHState {
RPH_ALLOW = 0,
RPH_BLOCK,
RPH_IGNORE,
};
} // namespace
ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ProtocolHandlerRegistry* registry)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS),
selected_item_(0),
interacted_(false),
registry_(registry),
pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
pending_handler_ = content_settings->pending_protocol_handler();
previous_handler_ = content_settings->previous_protocol_handler();
base::string16 protocol;
if (pending_handler_.protocol() == "mailto") {
protocol =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
} else if (pending_handler_.protocol() == "webcal") {
protocol =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
} else {
SettingInfo info;
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
std::unique_ptr<base::Value> value =
map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
setting = content_settings::ValueToContentSetting(value.get());
setting_source = info.source;
protocol = base::UTF8ToUTF16(pending_handler_.protocol());
}
if (setting == CONTENT_SETTING_ALLOW) {
radio_group.default_item = kAllowButtonIndex;
// |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
// Note that we ignore the |title| parameter.
if (previous_handler_.IsEmpty()) {
set_title(l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
base::UTF8ToUTF16(pending_handler_.url().host()), protocol));
} else {
radio_group.default_item = 1;
block_setting_ = setting;
set_title(l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
base::UTF8ToUTF16(pending_handler_.url().host()), protocol,
base::UTF8ToUTF16(previous_handler_.url().host())));
}
const auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
// Prevent creation of content settings for illegal urls like about:blank
bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type());
base::string16 radio_allow_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT);
base::string16 radio_deny_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
base::string16 radio_ignore_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
set_radio_group_enabled(is_valid && setting_source == SETTING_SOURCE_USER);
const GURL& url = web_contents->GetURL();
RadioGroup radio_group;
radio_group.url = url;
radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_deny_label);
radio_group.radio_items.push_back(radio_ignore_label);
ContentSetting setting = content_settings->pending_protocol_handler_setting();
if (setting == CONTENT_SETTING_ALLOW)
radio_group.default_item = RPH_ALLOW;
else if (setting == CONTENT_SETTING_BLOCK)
radio_group.default_item = RPH_BLOCK;
else
radio_group.default_item = RPH_IGNORE;
selected_item_ = radio_group.default_item;
set_radio_group_enabled(true);
set_radio_group(radio_group);
}
void ContentSettingSingleRadioGroup::SetNarrowestContentSetting(
ContentSetting setting) {
if (!profile())
ContentSettingRPHBubbleModel::~ContentSettingRPHBubbleModel() {
if (!web_contents() || !interacted_)
return;
auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
map->SetNarrowestContentSetting(bubble_content().radio_group.url,
bubble_content().radio_group.url,
content_type(), setting);
}
void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) {
selected_item_ = radio_index;
// The user has one chance to deal with the RPH content setting UI,
// then we remove it.
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->ClearPendingProtocolHandler();
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::Source<WebContents>(web_contents()),
content::NotificationService::NoDetails());
}
// ContentSettingCookiesBubbleModel --------------------------------------------
void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
if (selected_item_ == radio_index)
return;
class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
interacted_ = true;
selected_item_ = radio_index;
if (radio_index == RPH_ALLOW)
RegisterProtocolHandler();
else if (radio_index == RPH_BLOCK)
UnregisterProtocolHandler();
else if (radio_index == RPH_IGNORE)
IgnoreProtocolHandler();
else
NOTREACHED();
}
void ContentSettingRPHBubbleModel::OnDoneClicked() {
interacted_ = true;
}
void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
if (!web_contents())
return;
// A no-op if the handler hasn't been ignored, but needed in case the user
// selects sequences like register/ignore/register.
registry_->RemoveIgnoredHandler(pending_handler_);
registry_->OnAcceptRegisterProtocolHandler(pending_handler_);
TabSpecificContentSettings::FromWebContents(web_contents())
->set_pending_protocol_handler_setting(CONTENT_SETTING_ALLOW);
}
void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
if (!web_contents())
return;
registry_->OnDenyRegisterProtocolHandler(pending_handler_);
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_BLOCK);
ClearOrSetPreviousHandler();
}
void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
if (!web_contents())
return;
registry_->OnIgnoreRegisterProtocolHandler(pending_handler_);
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_DEFAULT);
ClearOrSetPreviousHandler();
}
void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
if (previous_handler_.IsEmpty()) {
registry_->ClearDefault(pending_handler_.protocol());
} else {
registry_->OnAcceptRegisterProtocolHandler(previous_handler_);
}
}
// ContentSettingMidiSysExBubbleModel ------------------------------------------
class ContentSettingMidiSysExBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingCookiesBubbleModel(Delegate* delegate,
ContentSettingMidiSysExBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingCookiesBubbleModel() override;
~ContentSettingMidiSysExBubbleModel() override {}
private:
void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
void SetDomainsAndCustomLink();
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingCookiesBubbleModel);
DISALLOW_COPY_AND_ASSIGN(ContentSettingMidiSysExBubbleModel);
};
ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel(
ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile)
: ContentSettingSingleRadioGroup(delegate,
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_COOKIES) {
CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
SetDomainsAndCustomLink();
}
void ContentSettingMidiSysExBubbleModel::MaybeAddDomainList(
const std::set<std::string>& hosts,
int title_id) {
if (!hosts.empty()) {
DomainList domain_list;
domain_list.title = l10n_util::GetStringUTF16(title_id);
domain_list.hosts = hosts;
add_domain_list(domain_list);
}
}
void ContentSettingMidiSysExBubbleModel::SetDomainsAndCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState& usages_state =
content_settings->midi_usages_state();
ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state;
unsigned int tab_state_flags = 0;
usages_state.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
// Divide the tab's current MIDI sysex users into sets according to their
// permission state.
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
IDS_MIDI_SYSEX_BUBBLE_ALLOWED);
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
IDS_MIDI_SYSEX_BUBBLE_DENIED);
if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_MIDI_SYSEX_BUBBLE_CLEAR_LINK));
set_custom_link_enabled(true);
} else if (tab_state_flags &
ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) {
set_custom_link(l10n_util::GetStringUTF16(
IDS_MIDI_SYSEX_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
}
}
ContentSettingCookiesBubbleModel::~ContentSettingCookiesBubbleModel() {
// On some plattforms e.g. MacOS X it is possible to close a tab while the
// cookies settings bubble is open. This resets the web contents to NULL.
if (settings_changed() && web_contents()) {
CollectedCookiesInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents()));
void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() {
if (!web_contents())
return;
// Reset this embedder's entry to default for each of the requesting
// origins currently on the page.
const GURL& embedder_url = web_contents()->GetURL();
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState::StateMap& state_map =
content_settings->midi_usages_state().state_map();
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
PermissionUtil::ScopedRevocationReporter(
profile(), map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
std::string(), CONTENT_SETTING_DEFAULT);
}
}
void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() {
// ContentSettingDomainListBubbleModel -----------------------------------------
class ContentSettingDomainListBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingDomainListBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
~ContentSettingDomainListBubbleModel() override {}
private:
void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
void SetDomainsAndCustomLink();
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingDomainListBubbleModel);
};
ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
content_type) {
DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type)
<< "SetDomains currently only supports geolocation content type";
SetDomainsAndCustomLink();
}
void ContentSettingDomainListBubbleModel::MaybeAddDomainList(
const std::set<std::string>& hosts,
int title_id) {
if (!hosts.empty()) {
DomainList domain_list;
domain_list.title = l10n_util::GetStringUTF16(title_id);
domain_list.hosts = hosts;
add_domain_list(domain_list);
}
}
void ContentSettingDomainListBubbleModel::SetDomainsAndCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState& usages =
content_settings->geolocation_usages_state();
ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state;
unsigned int tab_state_flags = 0;
usages.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
// Divide the tab's current geolocation users into sets according to their
// permission state.
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
set_custom_link_enabled(true);
} else if (tab_state_flags &
ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) {
set_custom_link(l10n_util::GetStringUTF16(
IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
}
}
void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
if (!web_contents())
return;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
content::Source<TabSpecificContentSettings>(
TabSpecificContentSettings::FromWebContents(web_contents())),
content::NotificationService::NoDetails());
delegate()->ShowCollectedCookiesDialog(web_contents());
// Reset this embedder's entry to default for each of the requesting
// origins currently on the page.
const GURL& embedder_url = web_contents()->GetURL();
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState::StateMap& state_map =
content_settings->geolocation_usages_state().state_map();
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
PermissionUtil::ScopedRevocationReporter(
profile(), map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string(), CONTENT_SETTING_DEFAULT);
}
}
// ContentSettingPluginBubbleModel ---------------------------------------------
......@@ -550,20 +730,235 @@ void ContentSettingPluginBubbleModel::RunPluginsOnPage() {
->set_load_plugins_link_enabled(false);
}
// ContentSettingPopupBubbleModel ----------------------------------------------
// ContentSettingSingleRadioGroup ----------------------------------------------
class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup,
public PopupBlockerTabHelper::Observer {
class ContentSettingSingleRadioGroup : public ContentSettingSimpleBubbleModel {
public:
ContentSettingPopupBubbleModel(Delegate* delegate,
ContentSettingSingleRadioGroup(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingPopupBubbleModel() override;
// PopupBlockerTabHelper::Observer:
void BlockedPopupAdded(int32_t id, const GURL& url) override;
Profile* profile,
ContentSettingsType content_type);
~ContentSettingSingleRadioGroup() override;
// content::NotificationObserver:
protected:
bool settings_changed() const;
int selected_item() const { return selected_item_; }
private:
void SetRadioGroup();
void SetNarrowestContentSetting(ContentSetting setting);
void OnRadioClicked(int radio_index) override;
ContentSetting block_setting_;
int selected_item_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSingleRadioGroup);
};
ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
content_type),
block_setting_(CONTENT_SETTING_BLOCK),
selected_item_(0) {
SetRadioGroup();
}
ContentSettingSingleRadioGroup::~ContentSettingSingleRadioGroup() {
if (settings_changed()) {
ContentSetting setting = selected_item_ == kAllowButtonIndex
? CONTENT_SETTING_ALLOW
: block_setting_;
SetNarrowestContentSetting(setting);
}
}
bool ContentSettingSingleRadioGroup::settings_changed() const {
return selected_item_ != bubble_content().radio_group.default_item;
}
// Initialize the radio group by setting the appropriate labels for the
// content type and setting the default value based on the content setting.
void ContentSettingSingleRadioGroup::SetRadioGroup() {
GURL url = web_contents()->GetURL();
base::string16 display_host = url_formatter::FormatUrlForSecurityDisplay(url);
if (display_host.empty())
display_host = base::ASCIIToUTF16(url.spec());
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
bool allowed = !content_settings->IsContentBlocked(content_type());
DCHECK(!allowed || content_settings->IsContentAllowed(content_type()));
RadioGroup radio_group;
radio_group.url = url;
static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
{CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
{CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK},
{CONTENT_SETTINGS_TYPE_SOUND, IDS_BLOCKED_SOUND_UNBLOCK},
};
// Fields as for kBlockedAllowIDs, above.
static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION},
};
base::string16 radio_allow_label;
if (allowed) {
int resource_id = GetIdForContentType(
kAllowedAllowIDs, arraysize(kAllowedAllowIDs), content_type());
radio_allow_label = l10n_util::GetStringUTF16(resource_id);
} else {
radio_allow_label = l10n_util::GetStringFUTF16(
GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs),
content_type()),
display_host);
}
static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
{CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
{CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION},
{CONTENT_SETTINGS_TYPE_SOUND, IDS_BLOCKED_SOUND_NO_ACTION},
};
static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_BLOCK},
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK},
};
base::string16 radio_block_label;
if (allowed) {
int resource_id = GetIdForContentType(
kAllowedBlockIDs, arraysize(kAllowedBlockIDs), content_type());
radio_block_label = l10n_util::GetStringFUTF16(resource_id, display_host);
} else {
radio_block_label = l10n_util::GetStringUTF16(GetIdForContentType(
kBlockedBlockIDs, arraysize(kBlockedBlockIDs), content_type()));
}
radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_block_label);
ContentSetting setting;
SettingSource setting_source = SETTING_SOURCE_NONE;
if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
content_settings::CookieSettings* cookie_settings =
CookieSettingsFactory::GetForProfile(profile()).get();
cookie_settings->GetCookieSetting(url, url, &setting_source, &setting);
} else {
SettingInfo info;
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
std::unique_ptr<base::Value> value =
map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
setting = content_settings::ValueToContentSetting(value.get());
setting_source = info.source;
}
if (setting == CONTENT_SETTING_ALLOW) {
radio_group.default_item = kAllowButtonIndex;
// |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
} else {
radio_group.default_item = 1;
block_setting_ = setting;
}
const auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
// Prevent creation of content settings for illegal urls like about:blank
bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type());
set_radio_group_enabled(is_valid && setting_source == SETTING_SOURCE_USER);
selected_item_ = radio_group.default_item;
set_radio_group(radio_group);
}
void ContentSettingSingleRadioGroup::SetNarrowestContentSetting(
ContentSetting setting) {
if (!profile())
return;
auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
map->SetNarrowestContentSetting(bubble_content().radio_group.url,
bubble_content().radio_group.url,
content_type(), setting);
}
void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) {
selected_item_ = radio_index;
}
// ContentSettingCookiesBubbleModel --------------------------------------------
class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingCookiesBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingCookiesBubbleModel() override;
private:
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingCookiesBubbleModel);
};
ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile)
: ContentSettingSingleRadioGroup(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_COOKIES) {
set_custom_link_enabled(true);
}
ContentSettingCookiesBubbleModel::~ContentSettingCookiesBubbleModel() {
// On some plattforms e.g. MacOS X it is possible to close a tab while the
// cookies settings bubble is open. This resets the web contents to NULL.
if (settings_changed() && web_contents()) {
CollectedCookiesInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents()));
}
}
void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() {
if (!web_contents())
return;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
content::Source<TabSpecificContentSettings>(
TabSpecificContentSettings::FromWebContents(web_contents())),
content::NotificationService::NoDetails());
delegate()->ShowCollectedCookiesDialog(web_contents());
}
// ContentSettingPopupBubbleModel ----------------------------------------------
class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup,
public PopupBlockerTabHelper::Observer {
public:
ContentSettingPopupBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingPopupBubbleModel() override;
// PopupBlockerTabHelper::Observer:
void BlockedPopupAdded(int32_t id, const GURL& url) override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
......@@ -655,7 +1050,7 @@ void ContentSettingPopupBubbleModel::OnListItemClicked(int index,
}
}
ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel(){
ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel() {
// User selected to always allow pop-ups from.
if (settings_changed() && selected_item() == kAllowButtonIndex) {
// Increases the counter.
......@@ -671,6 +1066,25 @@ ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel(){
// ContentSettingMediaStreamBubbleModel ----------------------------------------
namespace {
const content::MediaStreamDevice& GetMediaDeviceById(
const std::string& device_id,
const content::MediaStreamDevices& devices) {
DCHECK(!devices.empty());
for (const content::MediaStreamDevice& device : devices) {
if (device.id == device_id)
return device;
}
// A device with the |device_id| was not found. It is likely that the device
// has been unplugged from the OS. Return the first device as the default
// device.
return *devices.begin();
}
} // namespace
ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
Delegate* delegate,
WebContents* web_contents,
......@@ -720,7 +1134,7 @@ ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
}
ContentSettingMediaStreamBubbleModel*
ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() {
ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() {
return this;
}
......@@ -731,8 +1145,8 @@ void ContentSettingMediaStreamBubbleModel::OnManageButtonClicked() {
if (MicrophoneAccessed() && CameraAccessed()) {
delegate()->ShowMediaSettingsPage();
} else {
delegate()->ShowContentSettingsPage(CameraAccessed()
? CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
delegate()->ShowContentSettingsPage(
CameraAccessed() ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
: CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
}
}
......@@ -813,21 +1227,21 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW;
if (MicrophoneAccessed())
radio_allow_label_id = CameraAccessed() ?
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW :
IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW;
radio_allow_label_id =
CameraAccessed() ? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW
: IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW;
} else {
radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK;
if (MicrophoneAccessed())
radio_allow_label_id = CameraAccessed() ?
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK :
IDS_BLOCKED_MEDIASTREAM_MIC_ASK;
radio_allow_label_id = CameraAccessed()
? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK
: IDS_BLOCKED_MEDIASTREAM_MIC_ASK;
}
radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION;
if (MicrophoneAccessed())
radio_block_label_id = CameraAccessed() ?
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION :
IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION;
radio_block_label_id =
CameraAccessed() ? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION
: IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION;
} else {
if (MicrophoneAccessed() && CameraAccessed()) {
radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
......@@ -843,8 +1257,11 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
selected_item_ =
(MicrophoneAccessed() && content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) ||
(CameraAccessed() && content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) ? 1 : 0;
(CameraAccessed() &&
content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA))
? 1
: 0;
base::string16 radio_allow_label =
l10n_util::GetStringFUTF16(radio_allow_label_id, display_host);
......@@ -854,474 +1271,151 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
radio_group.default_item = selected_item_;
radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_block_label);
set_radio_group(radio_group);
set_radio_group_enabled(true);
}
void ContentSettingMediaStreamBubbleModel::UpdateSettings(
ContentSetting setting) {
if (!profile())
return;
TabSpecificContentSettings* tab_content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
// The same urls must be used as in other places (e.g. the infobar) in
// order to override the existing rule. Otherwise a new rule is created.
// TODO(markusheintz): Extract to a helper so that there is only a single
// place to touch.
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
if (MicrophoneAccessed()) {
PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
profile(), tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(
tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
}
if (CameraAccessed()) {
PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
profile(), tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(
tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
}
}
void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
content::MediaStreamType type,
const std::string& device) {
PrefService* prefs = profile()->GetPrefs();
if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
prefs->SetString(prefs::kDefaultAudioCaptureDevice, device);
} else {
DCHECK_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, type);
prefs->SetString(prefs::kDefaultVideoCaptureDevice, device);
}
}
void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const std::string& requested_microphone =
content_settings->media_stream_requested_audio_device();
const std::string& requested_camera =
content_settings->media_stream_requested_video_device();
// Add microphone menu.
PrefService* prefs = profile()->GetPrefs();
MediaCaptureDevicesDispatcher* dispatcher =
MediaCaptureDevicesDispatcher::GetInstance();
const content::MediaStreamDevices& microphones =
dispatcher->GetAudioCaptureDevices();
if (MicrophoneAccessed()) {
MediaMenu mic_menu;
mic_menu.label = l10n_util::GetStringUTF16(IDS_MEDIA_SELECTED_MIC_LABEL);
if (!microphones.empty()) {
std::string preferred_mic;
if (requested_microphone.empty()) {
preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice);
mic_menu.disabled = false;
} else {
// Set the |disabled| to true in order to disable the device selection
// menu on the media settings bubble. This must be done if the website
// manages the microphone devices itself.
preferred_mic = requested_microphone;
mic_menu.disabled = true;
}
mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
mic_menu.selected_device = mic_menu.default_device;
}
add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
}
if (CameraAccessed()) {
const content::MediaStreamDevices& cameras =
dispatcher->GetVideoCaptureDevices();
MediaMenu camera_menu;
camera_menu.label =
l10n_util::GetStringUTF16(IDS_MEDIA_SELECTED_CAMERA_LABEL);
if (!cameras.empty()) {
std::string preferred_camera;
if (requested_camera.empty()) {
preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
camera_menu.disabled = false;
} else {
// Disable the menu since the website is managing the camera devices
// itself.
preferred_camera = requested_camera;
camera_menu.disabled = true;
}
camera_menu.default_device =
GetMediaDeviceById(preferred_camera, cameras);
camera_menu.selected_device = camera_menu.default_device;
}
add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
}
}
void ContentSettingMediaStreamBubbleModel::SetManageText() {
DCHECK(CameraAccessed() || MicrophoneAccessed());
set_manage_text(l10n_util::GetStringUTF16(IDS_MANAGE));
}
void ContentSettingMediaStreamBubbleModel::SetCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
if (content_settings->IsMicrophoneCameraStateChanged()) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
}
}
void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
selected_item_ = radio_index;
}
void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked(
content::MediaStreamType type,
const std::string& selected_device_id) {
DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
DCHECK_EQ(1U, bubble_content().media_menus.count(type));
MediaCaptureDevicesDispatcher* dispatcher =
MediaCaptureDevicesDispatcher::GetInstance();
const content::MediaStreamDevices& devices =
(type == content::MEDIA_DEVICE_AUDIO_CAPTURE) ?
dispatcher->GetAudioCaptureDevices() :
dispatcher->GetVideoCaptureDevices();
set_selected_device(GetMediaDeviceById(selected_device_id, devices));
}
// ContentSettingDomainListBubbleModel -----------------------------------------
class ContentSettingDomainListBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingDomainListBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
~ContentSettingDomainListBubbleModel() override {}
private:
void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
void SetDomainsAndCustomLink();
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingDomainListBubbleModel);
};
ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSimpleBubbleModel(
delegate, web_contents, profile, content_type) {
DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
"SetDomains currently only supports geolocation content type";
SetDomainsAndCustomLink();
}
void ContentSettingDomainListBubbleModel::MaybeAddDomainList(
const std::set<std::string>& hosts, int title_id) {
if (!hosts.empty()) {
DomainList domain_list;
domain_list.title = l10n_util::GetStringUTF16(title_id);
domain_list.hosts = hosts;
add_domain_list(domain_list);
}
}
void ContentSettingDomainListBubbleModel::SetDomainsAndCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState& usages =
content_settings->geolocation_usages_state();
ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state;
unsigned int tab_state_flags = 0;
usages.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
// Divide the tab's current geolocation users into sets according to their
// permission state.
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
set_custom_link_enabled(true);
} else if (tab_state_flags &
ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) {
set_custom_link(l10n_util::GetStringUTF16(
IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
}
}
void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
if (!web_contents())
return;
// Reset this embedder's entry to default for each of the requesting
// origins currently on the page.
const GURL& embedder_url = web_contents()->GetURL();
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState::StateMap& state_map =
content_settings->geolocation_usages_state().state_map();
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
PermissionUtil::ScopedRevocationReporter(
profile(), map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string(), CONTENT_SETTING_DEFAULT);
}
}
// ContentSettingMixedScriptBubbleModel ----------------------------------------
namespace {
void SetAllowRunningInsecureContent(content::RenderFrameHost* frame) {
chrome::mojom::InsecureContentRendererPtr renderer;
frame->GetRemoteInterfaces()->GetInterface(&renderer);
renderer->SetAllowRunningInsecureContent();
}
} // namespace
class ContentSettingMixedScriptBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingMixedScriptBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingMixedScriptBubbleModel() override {}
private:
void SetManageText();
// ContentSettingBubbleModel:
void OnLearnMoreClicked() override;
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingMixedScriptBubbleModel);
};
ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile)
: ContentSettingSimpleBubbleModel(
delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_BUBBLE);
set_custom_link_enabled(true);
set_show_learn_more(true);
SetManageText();
}
void ContentSettingMixedScriptBubbleModel::OnLearnMoreClicked() {
if (delegate())
delegate()->ShowLearnMorePage(content_type());
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_CLICKED_LEARN_MORE);
}
void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
DCHECK(rappor_service());
if (!web_contents())
return;
MixedContentSettingsTabHelper* mixed_content_settings =
MixedContentSettingsTabHelper::FromWebContents(web_contents());
if (mixed_content_settings) {
// Update browser side settings to allow active mixed content.
mixed_content_settings->AllowRunningOfInsecureContent();
}
// Update renderer side settings to allow active mixed content.
web_contents()->ForEachFrame(base::Bind(&::SetAllowRunningInsecureContent));
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_CLICKED_ALLOW);
rappor::SampleDomainAndRegistryFromGURL(
rappor_service(), "ContentSettings.MixedScript.UserClickedAllow",
web_contents()->GetLastCommittedURL());
}
// Don't set any manage text since none is displayed.
void ContentSettingMixedScriptBubbleModel::SetManageText() {
set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
}
// ContentSettingRPHBubbleModel ------------------------------------------------
ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ProtocolHandlerRegistry* registry)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS),
selected_item_(0),
interacted_(false),
registry_(registry),
pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
pending_handler_ = content_settings->pending_protocol_handler();
previous_handler_ = content_settings->previous_protocol_handler();
base::string16 protocol;
if (pending_handler_.protocol() == "mailto") {
protocol = l10n_util::GetStringUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
} else if (pending_handler_.protocol() == "webcal") {
protocol = l10n_util::GetStringUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
} else {
protocol = base::UTF8ToUTF16(pending_handler_.protocol());
}
// Note that we ignore the |title| parameter.
if (previous_handler_.IsEmpty()) {
set_title(l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
base::UTF8ToUTF16(pending_handler_.url().host()),
protocol));
} else {
set_title(l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
base::UTF8ToUTF16(pending_handler_.url().host()),
protocol,
base::UTF8ToUTF16(previous_handler_.url().host())));
}
base::string16 radio_allow_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT);
base::string16 radio_deny_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
base::string16 radio_ignore_label =
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
const GURL& url = web_contents->GetURL();
RadioGroup radio_group;
radio_group.url = url;
radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_deny_label);
radio_group.radio_items.push_back(radio_ignore_label);
ContentSetting setting =
content_settings->pending_protocol_handler_setting();
if (setting == CONTENT_SETTING_ALLOW)
radio_group.default_item = RPH_ALLOW;
else if (setting == CONTENT_SETTING_BLOCK)
radio_group.default_item = RPH_BLOCK;
else
radio_group.default_item = RPH_IGNORE;
selected_item_ = radio_group.default_item;
set_radio_group_enabled(true);
set_radio_group(radio_group);
}
ContentSettingRPHBubbleModel::~ContentSettingRPHBubbleModel() {
if (!web_contents() || !interacted_)
return;
// The user has one chance to deal with the RPH content setting UI,
// then we remove it.
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->ClearPendingProtocolHandler();
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::Source<WebContents>(web_contents()),
content::NotificationService::NoDetails());
set_radio_group(radio_group);
set_radio_group_enabled(true);
}
void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
if (selected_item_ == radio_index)
void ContentSettingMediaStreamBubbleModel::UpdateSettings(
ContentSetting setting) {
if (!profile())
return;
interacted_ = true;
selected_item_ = radio_index;
if (radio_index == RPH_ALLOW)
RegisterProtocolHandler();
else if (radio_index == RPH_BLOCK)
UnregisterProtocolHandler();
else if (radio_index == RPH_IGNORE)
IgnoreProtocolHandler();
else
NOTREACHED();
TabSpecificContentSettings* tab_content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
// The same urls must be used as in other places (e.g. the infobar) in
// order to override the existing rule. Otherwise a new rule is created.
// TODO(markusheintz): Extract to a helper so that there is only a single
// place to touch.
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
if (MicrophoneAccessed()) {
PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
profile(), tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(
tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
}
if (CameraAccessed()) {
PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
profile(), tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(
tab_content_settings->media_stream_access_origin(), GURL(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
}
}
void ContentSettingRPHBubbleModel::OnDoneClicked() {
interacted_ = true;
void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
content::MediaStreamType type,
const std::string& device) {
PrefService* prefs = profile()->GetPrefs();
if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
prefs->SetString(prefs::kDefaultAudioCaptureDevice, device);
} else {
DCHECK_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, type);
prefs->SetString(prefs::kDefaultVideoCaptureDevice, device);
}
}
void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
if (!web_contents())
return;
void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const std::string& requested_microphone =
content_settings->media_stream_requested_audio_device();
const std::string& requested_camera =
content_settings->media_stream_requested_video_device();
// A no-op if the handler hasn't been ignored, but needed in case the user
// selects sequences like register/ignore/register.
registry_->RemoveIgnoredHandler(pending_handler_);
// Add microphone menu.
PrefService* prefs = profile()->GetPrefs();
MediaCaptureDevicesDispatcher* dispatcher =
MediaCaptureDevicesDispatcher::GetInstance();
const content::MediaStreamDevices& microphones =
dispatcher->GetAudioCaptureDevices();
registry_->OnAcceptRegisterProtocolHandler(pending_handler_);
TabSpecificContentSettings::FromWebContents(web_contents())->
set_pending_protocol_handler_setting(CONTENT_SETTING_ALLOW);
}
if (MicrophoneAccessed()) {
MediaMenu mic_menu;
mic_menu.label = l10n_util::GetStringUTF16(IDS_MEDIA_SELECTED_MIC_LABEL);
if (!microphones.empty()) {
std::string preferred_mic;
if (requested_microphone.empty()) {
preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice);
mic_menu.disabled = false;
} else {
// Set the |disabled| to true in order to disable the device selection
// menu on the media settings bubble. This must be done if the website
// manages the microphone devices itself.
preferred_mic = requested_microphone;
mic_menu.disabled = true;
}
void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
if (!web_contents())
return;
mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
mic_menu.selected_device = mic_menu.default_device;
}
add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
}
registry_->OnDenyRegisterProtocolHandler(pending_handler_);
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_BLOCK);
ClearOrSetPreviousHandler();
}
if (CameraAccessed()) {
const content::MediaStreamDevices& cameras =
dispatcher->GetVideoCaptureDevices();
MediaMenu camera_menu;
camera_menu.label =
l10n_util::GetStringUTF16(IDS_MEDIA_SELECTED_CAMERA_LABEL);
if (!cameras.empty()) {
std::string preferred_camera;
if (requested_camera.empty()) {
preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
camera_menu.disabled = false;
} else {
// Disable the menu since the website is managing the camera devices
// itself.
preferred_camera = requested_camera;
camera_menu.disabled = true;
}
void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
if (!web_contents())
return;
camera_menu.default_device =
GetMediaDeviceById(preferred_camera, cameras);
camera_menu.selected_device = camera_menu.default_device;
}
add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
}
}
registry_->OnIgnoreRegisterProtocolHandler(pending_handler_);
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_DEFAULT);
ClearOrSetPreviousHandler();
void ContentSettingMediaStreamBubbleModel::SetManageText() {
DCHECK(CameraAccessed() || MicrophoneAccessed());
set_manage_text(l10n_util::GetStringUTF16(IDS_MANAGE));
}
void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
if (previous_handler_.IsEmpty()) {
registry_->ClearDefault(pending_handler_.protocol());
} else {
registry_->OnAcceptRegisterProtocolHandler(previous_handler_);
void ContentSettingMediaStreamBubbleModel::SetCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
if (content_settings->IsMicrophoneCameraStateChanged()) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
}
}
void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
selected_item_ = radio_index;
}
void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked(
content::MediaStreamType type,
const std::string& selected_device_id) {
DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
DCHECK_EQ(1U, bubble_content().media_menus.count(type));
MediaCaptureDevicesDispatcher* dispatcher =
MediaCaptureDevicesDispatcher::GetInstance();
const content::MediaStreamDevices& devices =
(type == content::MEDIA_DEVICE_AUDIO_CAPTURE)
? dispatcher->GetAudioCaptureDevices()
: dispatcher->GetVideoCaptureDevices();
set_selected_device(GetMediaDeviceById(selected_device_id, devices));
}
// ContentSettingSubresourceFilterBubbleModel ----------------------------------
ContentSettingSubresourceFilterBubbleModel::
......@@ -1387,94 +1481,6 @@ ContentSettingSubresourceFilterBubbleModel::AsSubresourceFilterBubbleModel() {
return this;
}
// ContentSettingMidiSysExBubbleModel ------------------------------------------
class ContentSettingMidiSysExBubbleModel
: public ContentSettingSimpleBubbleModel {
public:
ContentSettingMidiSysExBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile);
~ContentSettingMidiSysExBubbleModel() override {}
private:
void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
void SetDomainsAndCustomLink();
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingMidiSysExBubbleModel);
};
ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
SetDomainsAndCustomLink();
}
void ContentSettingMidiSysExBubbleModel::MaybeAddDomainList(
const std::set<std::string>& hosts, int title_id) {
if (!hosts.empty()) {
DomainList domain_list;
domain_list.title = l10n_util::GetStringUTF16(title_id);
domain_list.hosts = hosts;
add_domain_list(domain_list);
}
}
void ContentSettingMidiSysExBubbleModel::SetDomainsAndCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState& usages_state =
content_settings->midi_usages_state();
ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state;
unsigned int tab_state_flags = 0;
usages_state.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
// Divide the tab's current MIDI sysex users into sets according to their
// permission state.
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
IDS_MIDI_SYSEX_BUBBLE_ALLOWED);
MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
IDS_MIDI_SYSEX_BUBBLE_DENIED);
if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) {
set_custom_link(
l10n_util::GetStringUTF16(IDS_MIDI_SYSEX_BUBBLE_CLEAR_LINK));
set_custom_link_enabled(true);
} else if (tab_state_flags &
ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) {
set_custom_link(l10n_util::GetStringUTF16(
IDS_MIDI_SYSEX_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
}
}
void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() {
if (!web_contents())
return;
// Reset this embedder's entry to default for each of the requesting
// origins currently on the page.
const GURL& embedder_url = web_contents()->GetURL();
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState::StateMap& state_map =
content_settings->midi_usages_state().state_map();
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
PermissionUtil::ScopedRevocationReporter(
profile(), map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX, PermissionSourceUI::PAGE_ACTION);
map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
std::string(), CONTENT_SETTING_DEFAULT);
}
}
// ContentSettingDownloadsBubbleModel ------------------------------------------
ContentSettingDownloadsBubbleModel::ContentSettingDownloadsBubbleModel(
......@@ -1673,6 +1679,11 @@ ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) {
// ContentSettingBubbleModel ---------------------------------------------------
// This class must be placed last because it needs the definition of the other
// classes declared in this file.
const int ContentSettingBubbleModel::kAllowButtonIndex = 0;
// static
ContentSettingBubbleModel*
ContentSettingBubbleModel::CreateContentSettingBubbleModel(
......
......@@ -41,8 +41,7 @@ class RapporServiceImpl;
// The hierarchy of bubble models:
//
// ContentSettingsBubbleModel - base class
// ContentSettingMediaStreamBubbleModel - media (camera and mic)
// ContentSettingBubbleModel - base class
// ContentSettingSimpleBubbleModel - single content setting
// ContentSettingMixedScriptBubbleModel - mixed script
// ContentSettingRPHBubbleModel - protocol handlers
......@@ -52,13 +51,14 @@ class RapporServiceImpl;
// ContentSettingSingleRadioGroup - radio group
// ContentSettingCookiesBubbleModel - cookies
// ContentSettingPopupBubbleModel - popups
// ContentSettingMediaStreamBubbleModel - media (camera and mic)
// ContentSettingSubresourceFilterBubbleModel - filtered subresources
// ContentSettingDownloadsBubbleModel - automatic downloads
// ContentSettingFramebustBlockBubbleModel - blocked framebusts
// Forward declaration necessary for downcasts.
class ContentSettingMediaStreamBubbleModel;
class ContentSettingSimpleBubbleModel;
class ContentSettingMediaStreamBubbleModel;
class ContentSettingSubresourceFilterBubbleModel;
class ContentSettingDownloadsBubbleModel;
class ContentSettingFramebustBlockBubbleModel;
......@@ -155,6 +155,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(BubbleContent);
};
static const int kAllowButtonIndex;
// Creates a bubble model for a particular |content_type|. Note that not all
// bubbles fit this description.
// TODO(msramek): Move this to ContentSettingSimpleBubbleModel or remove
......@@ -217,8 +219,6 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
rappor_service_ = rappor_service;
}
static const int kAllowButtonIndex;
protected:
ContentSettingBubbleModel(
Delegate* delegate,
......@@ -340,33 +340,6 @@ class ContentSettingRPHBubbleModel : public ContentSettingSimpleBubbleModel {
DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHBubbleModel);
};
// The model for the deceptive content bubble.
class ContentSettingSubresourceFilterBubbleModel
: public ContentSettingBubbleModel {
public:
ContentSettingSubresourceFilterBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);
~ContentSettingSubresourceFilterBubbleModel() override;
private:
void SetMessage();
void SetTitle();
void SetManageText();
// ContentSettingBubbleModel:
void OnManageCheckboxChecked(bool is_checked) override;
ContentSettingSubresourceFilterBubbleModel* AsSubresourceFilterBubbleModel()
override;
void OnLearnMoreClicked() override;
void OnDoneClicked() override;
bool is_checked_ = false;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSubresourceFilterBubbleModel);
};
// The model of the content settings bubble for media settings.
class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel {
public:
......@@ -426,6 +399,33 @@ class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel {
DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaStreamBubbleModel);
};
// The model for the deceptive content bubble.
class ContentSettingSubresourceFilterBubbleModel
: public ContentSettingBubbleModel {
public:
ContentSettingSubresourceFilterBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);
~ContentSettingSubresourceFilterBubbleModel() override;
private:
void SetMessage();
void SetTitle();
void SetManageText();
// ContentSettingBubbleModel:
void OnManageCheckboxChecked(bool is_checked) override;
ContentSettingSubresourceFilterBubbleModel* AsSubresourceFilterBubbleModel()
override;
void OnLearnMoreClicked() override;
void OnDoneClicked() override;
bool is_checked_ = false;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSubresourceFilterBubbleModel);
};
// The model for automatic downloads setting.
class ContentSettingDownloadsBubbleModel : public ContentSettingBubbleModel {
public:
......
......@@ -4,6 +4,9 @@
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
......@@ -65,30 +68,14 @@ class ContentSettingGeolocationImageModel
DISALLOW_COPY_AND_ASSIGN(ContentSettingGeolocationImageModel);
};
// Image model for displaying media icons in the location bar.
class ContentSettingMediaImageModel : public ContentSettingImageModel {
public:
ContentSettingMediaImageModel();
void UpdateFromWebContents(WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents,
Profile* profile) override;
bool ShouldRunAnimation(WebContents* web_contents) override;
void SetAnimationHasRun(WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel);
};
class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel {
public:
ContentSettingRPHImageModel();
void UpdateFromWebContents(WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHImageModel);
};
class ContentSettingMIDISysExImageModel
......@@ -112,6 +99,25 @@ class ContentSettingDownloadsImageModel
DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel);
};
// Image model for displaying media icons in the location bar.
class ContentSettingMediaImageModel : public ContentSettingImageModel {
public:
ContentSettingMediaImageModel();
void UpdateFromWebContents(WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents,
Profile* profile) override;
bool ShouldRunAnimation(WebContents* web_contents) override;
void SetAnimationHasRun(WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel);
};
namespace {
struct ContentSettingsImageDetails {
......@@ -335,6 +341,101 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents(
: IDS_GEOLOCATION_BLOCKED_TOOLTIP));
}
// Protocol handlers -----------------------------------------------------------
ContentSettingRPHImageModel::ContentSettingRPHImageModel()
: ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
set_icon(vector_icons::kProtocolHandlerIcon, gfx::kNoneIcon);
set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP));
}
void ContentSettingRPHImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return;
if (content_settings->pending_protocol_handler().IsEmpty())
return;
set_visible(true);
}
// MIDI SysEx ------------------------------------------------------------------
ContentSettingMIDISysExImageModel::ContentSettingMIDISysExImageModel()
: ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {}
void ContentSettingMIDISysExImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return;
const ContentSettingsUsagesState& usages_state =
content_settings->midi_usages_state();
if (usages_state.state_map().empty())
return;
set_visible(true);
// If any embedded site has access the allowed icon takes priority over the
// blocked icon.
unsigned int state_flags = 0;
usages_state.GetDetailedInfo(nullptr, &state_flags);
bool allowed =
!!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED);
set_icon(vector_icons::kMidiIcon,
allowed ? gfx::kNoneIcon : kBlockedBadgeIcon);
set_tooltip(l10n_util::GetStringUTF16(allowed
? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP
: IDS_MIDI_SYSEX_BLOCKED_TOOLTIP));
}
// Automatic downloads ---------------------------------------------------------
ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel()
: ContentSettingSimpleImageModel(
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {}
void ContentSettingDownloadsImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
DownloadRequestLimiter* download_request_limiter =
g_browser_process->download_request_limiter();
// DownloadRequestLimiter can be absent in unit_tests.
if (!download_request_limiter)
return;
switch (download_request_limiter->GetDownloadUiStatus(web_contents)) {
case DownloadRequestLimiter::DOWNLOAD_UI_ALLOWED:
set_visible(true);
set_icon(kFileDownloadIcon, gfx::kNoneIcon);
set_explanatory_string_id(0);
set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE));
return;
case DownloadRequestLimiter::DOWNLOAD_UI_BLOCKED:
set_visible(true);
set_icon(kFileDownloadIcon, kBlockedBadgeIcon);
set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION);
set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE));
return;
case DownloadRequestLimiter::DOWNLOAD_UI_DEFAULT:
// No need to show icon otherwise.
return;
}
}
// Media -----------------------------------------------------------------------
ContentSettingMediaImageModel::ContentSettingMediaImageModel()
......@@ -474,7 +575,6 @@ void ContentSettingSubresourceFilterImageModel::SetAnimationHasRun(
}
// Blocked Framebust -----------------------------------------------------------
ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel()
: ContentSettingImageModel() {}
......@@ -518,102 +618,6 @@ void ContentSettingFramebustBlockImageModel::SetAnimationHasRun(
->set_animation_has_run();
}
// Protocol handlers -----------------------------------------------------------
ContentSettingRPHImageModel::ContentSettingRPHImageModel()
: ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
set_icon(vector_icons::kProtocolHandlerIcon, gfx::kNoneIcon);
set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP));
}
void ContentSettingRPHImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return;
if (content_settings->pending_protocol_handler().IsEmpty())
return;
set_visible(true);
}
// MIDI SysEx ------------------------------------------------------------------
ContentSettingMIDISysExImageModel::ContentSettingMIDISysExImageModel()
: ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
}
void ContentSettingMIDISysExImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return;
const ContentSettingsUsagesState& usages_state =
content_settings->midi_usages_state();
if (usages_state.state_map().empty())
return;
set_visible(true);
// If any embedded site has access the allowed icon takes priority over the
// blocked icon.
unsigned int state_flags = 0;
usages_state.GetDetailedInfo(nullptr, &state_flags);
bool allowed =
!!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED);
set_icon(vector_icons::kMidiIcon,
allowed ? gfx::kNoneIcon : kBlockedBadgeIcon);
set_tooltip(l10n_util::GetStringUTF16(allowed
? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP
: IDS_MIDI_SYSEX_BLOCKED_TOOLTIP));
}
// Automatic downloads ---------------------------------------------------------
ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel()
: ContentSettingSimpleImageModel(
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {}
void ContentSettingDownloadsImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
DownloadRequestLimiter* download_request_limiter =
g_browser_process->download_request_limiter();
// DownloadRequestLimiter can be absent in unit_tests.
if (!download_request_limiter)
return;
switch (download_request_limiter->GetDownloadUiStatus(web_contents)) {
case DownloadRequestLimiter::DOWNLOAD_UI_ALLOWED:
set_visible(true);
set_icon(kFileDownloadIcon, gfx::kNoneIcon);
set_explanatory_string_id(0);
set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE));
return;
case DownloadRequestLimiter::DOWNLOAD_UI_BLOCKED:
set_visible(true);
set_icon(kFileDownloadIcon, kBlockedBadgeIcon);
set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION);
set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE));
return;
case DownloadRequestLimiter::DOWNLOAD_UI_DEFAULT:
// No need to show icon otherwise.
return;
}
}
// Base class ------------------------------------------------------------------
gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const {
......
......@@ -5,6 +5,9 @@
#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#include <memory>
#include <vector>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
......
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