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 @@ ...@@ -6,6 +6,9 @@
#include <stddef.h> #include <stddef.h>
#include <memory>
#include <utility>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -76,14 +79,6 @@ using content_settings::SETTING_SOURCE_NONE; ...@@ -76,14 +79,6 @@ using content_settings::SETTING_SOURCE_NONE;
namespace { 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 { struct ContentSettingsTypeIdEntry {
ContentSettingsType type; ContentSettingsType type;
int id; int id;
...@@ -99,25 +94,14 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, ...@@ -99,25 +94,14 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
return 0; return 0;
} }
const content::MediaStreamDevice& GetMediaDeviceById( void SetAllowRunningInsecureContent(content::RenderFrameHost* frame) {
const std::string& device_id, chrome::mojom::InsecureContentRendererPtr renderer;
const content::MediaStreamDevices& devices) { frame->GetRemoteInterfaces()->GetInterface(&renderer);
DCHECK(!devices.empty()); renderer->SetAllowRunningInsecureContent();
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 } // namespace
const int ContentSettingBubbleModel::kAllowButtonIndex = 0;
// ContentSettingSimpleBubbleModel --------------------------------------------- // ContentSettingSimpleBubbleModel ---------------------------------------------
ContentSettingSimpleBubbleModel::ContentSettingSimpleBubbleModel( ContentSettingSimpleBubbleModel::ContentSettingSimpleBubbleModel(
...@@ -240,222 +224,418 @@ void ContentSettingSimpleBubbleModel::SetCustomLink() { ...@@ -240,222 +224,418 @@ void ContentSettingSimpleBubbleModel::SetCustomLink() {
void ContentSettingSimpleBubbleModel::OnCustomLinkClicked() { void ContentSettingSimpleBubbleModel::OnCustomLinkClicked() {
} }
// ContentSettingSingleRadioGroup ---------------------------------------------- // ContentSettingMixedScriptBubbleModel ----------------------------------------
class ContentSettingSingleRadioGroup : public ContentSettingSimpleBubbleModel { class ContentSettingMixedScriptBubbleModel
: public ContentSettingSimpleBubbleModel {
public: public:
ContentSettingSingleRadioGroup(Delegate* delegate, ContentSettingMixedScriptBubbleModel(Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile, Profile* profile);
ContentSettingsType content_type);
~ContentSettingSingleRadioGroup() override;
protected: ~ContentSettingMixedScriptBubbleModel() override {}
bool settings_changed() const;
int selected_item() const { return selected_item_; }
private: private:
void SetRadioGroup(); void SetManageText();
void SetNarrowestContentSetting(ContentSetting setting);
void OnRadioClicked(int radio_index) override;
ContentSetting block_setting_; // ContentSettingBubbleModel:
int selected_item_; void OnLearnMoreClicked() override;
void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSingleRadioGroup); DISALLOW_COPY_AND_ASSIGN(ContentSettingMixedScriptBubbleModel);
}; };
ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup( ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel(
Delegate* delegate, Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile, Profile* profile)
ContentSettingsType content_type)
: ContentSettingSimpleBubbleModel(delegate, : ContentSettingSimpleBubbleModel(delegate,
web_contents, web_contents,
profile, profile,
content_type), CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
block_setting_(CONTENT_SETTING_BLOCK), content_settings::RecordMixedScriptAction(
selected_item_(0) { content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_BUBBLE);
SetRadioGroup(); set_custom_link_enabled(true);
set_show_learn_more(true);
SetManageText();
} }
ContentSettingSingleRadioGroup::~ContentSettingSingleRadioGroup() { void ContentSettingMixedScriptBubbleModel::OnLearnMoreClicked() {
if (settings_changed()) { if (delegate())
ContentSetting setting = delegate()->ShowLearnMorePage(content_type());
selected_item_ == kAllowButtonIndex ?
CONTENT_SETTING_ALLOW :
block_setting_;
SetNarrowestContentSetting(setting);
}
}
bool ContentSettingSingleRadioGroup::settings_changed() const { content_settings::RecordMixedScriptAction(
return selected_item_ != bubble_content().radio_group.default_item; content_settings::MIXED_SCRIPT_ACTION_CLICKED_LEARN_MORE);
} }
// Initialize the radio group by setting the appropriate labels for the void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
// content type and setting the default value based on the content setting. DCHECK(rappor_service());
void ContentSettingSingleRadioGroup::SetRadioGroup() { if (!web_contents())
GURL url = web_contents()->GetURL(); return;
base::string16 display_host =
url_formatter::FormatUrlForSecurityDisplay(url);
if (display_host.empty())
display_host = base::ASCIIToUTF16(url.spec());
TabSpecificContentSettings* content_settings = MixedContentSettingsTabHelper* mixed_content_settings =
TabSpecificContentSettings::FromWebContents(web_contents()); MixedContentSettingsTabHelper::FromWebContents(web_contents());
bool allowed = !content_settings->IsContentBlocked(content_type()); if (mixed_content_settings) {
DCHECK(!allowed || content_settings->IsContentAllowed(content_type())); // Update browser side settings to allow active mixed content.
mixed_content_settings->AllowRunningOfInsecureContent();
}
RadioGroup radio_group; // Update renderer side settings to allow active mixed content.
radio_group.url = url; web_contents()->ForEachFrame(
base::BindRepeating(&::SetAllowRunningInsecureContent));
static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { content_settings::RecordMixedScriptAction(
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, content_settings::MIXED_SCRIPT_ACTION_CLICKED_ALLOW);
{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; rappor::SampleDomainAndRegistryFromGURL(
if (allowed) { rappor_service(), "ContentSettings.MixedScript.UserClickedAllow",
int resource_id = GetIdForContentType(kAllowedAllowIDs, web_contents()->GetLastCommittedURL());
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[] = { // Don't set any manage text since none is displayed.
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, void ContentSettingMixedScriptBubbleModel::SetManageText() {
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
{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; // ContentSettingRPHBubbleModel ------------------------------------------------
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); namespace {
radio_group.radio_items.push_back(radio_block_label);
ContentSetting setting;
SettingSource setting_source = SETTING_SOURCE_NONE;
if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { // These states must match the order of appearance of the radio buttons
content_settings::CookieSettings* cookie_settings = // in the XIB file for the Mac port.
CookieSettingsFactory::GetForProfile(profile()).get(); enum RPHState {
cookie_settings->GetCookieSetting(url, url, &setting_source, &setting); 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 { } else {
SettingInfo info; protocol = base::UTF8ToUTF16(pending_handler_.protocol());
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) { // Note that we ignore the |title| parameter.
radio_group.default_item = kAllowButtonIndex; if (previous_handler_.IsEmpty()) {
// |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. set_title(l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
base::UTF8ToUTF16(pending_handler_.url().host()), protocol));
} else { } else {
radio_group.default_item = 1; set_title(l10n_util::GetStringFUTF16(
block_setting_ = setting; 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()); base::string16 radio_allow_label =
// Prevent creation of content settings for illegal urls like about:blank l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT);
bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type()); 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; selected_item_ = radio_group.default_item;
set_radio_group_enabled(true);
set_radio_group(radio_group); set_radio_group(radio_group);
} }
void ContentSettingSingleRadioGroup::SetNarrowestContentSetting( ContentSettingRPHBubbleModel::~ContentSettingRPHBubbleModel() {
ContentSetting setting) { if (!web_contents() || !interacted_)
if (!profile())
return; return;
auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); // The user has one chance to deal with the RPH content setting UI,
map->SetNarrowestContentSetting(bubble_content().radio_group.url, // then we remove it.
bubble_content().radio_group.url, auto* settings = TabSpecificContentSettings::FromWebContents(web_contents());
content_type(), setting); settings->ClearPendingProtocolHandler();
} content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) { content::Source<WebContents>(web_contents()),
selected_item_ = radio_index; content::NotificationService::NoDetails());
} }
// ContentSettingCookiesBubbleModel --------------------------------------------
class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
if (selected_item_ == radio_index)
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();
}
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: public:
ContentSettingCookiesBubbleModel(Delegate* delegate, ContentSettingMidiSysExBubbleModel(Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile); Profile* profile);
~ContentSettingCookiesBubbleModel() override; ~ContentSettingMidiSysExBubbleModel() override {}
private: private:
void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
void SetDomainsAndCustomLink();
void OnCustomLinkClicked() override; void OnCustomLinkClicked() override;
DISALLOW_COPY_AND_ASSIGN(ContentSettingCookiesBubbleModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingMidiSysExBubbleModel);
}; };
ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel( ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel(
Delegate* delegate, Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile) Profile* profile)
: ContentSettingSingleRadioGroup(delegate, : ContentSettingSimpleBubbleModel(delegate,
web_contents, web_contents,
profile, profile,
CONTENT_SETTINGS_TYPE_COOKIES) { CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
set_custom_link_enabled(true); SetDomainsAndCustomLink();
} }
ContentSettingCookiesBubbleModel::~ContentSettingCookiesBubbleModel() { void ContentSettingMidiSysExBubbleModel::MaybeAddDomainList(
// On some plattforms e.g. MacOS X it is possible to close a tab while the const std::set<std::string>& hosts,
// cookies settings bubble is open. This resets the web contents to NULL. int title_id) {
if (settings_changed() && web_contents()) { if (!hosts.empty()) {
CollectedCookiesInfoBarDelegate::Create( DomainList domain_list;
InfoBarService::FromWebContents(web_contents())); domain_list.title = l10n_util::GetStringUTF16(title_id);
domain_list.hosts = hosts;
add_domain_list(domain_list);
} }
} }
void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() { 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()) if (!web_contents())
return; return;
content::NotificationService::current()->Notify( // Reset this embedder's entry to default for each of the requesting
chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, // origins currently on the page.
content::Source<TabSpecificContentSettings>( const GURL& embedder_url = web_contents()->GetURL();
TabSpecificContentSettings::FromWebContents(web_contents())), TabSpecificContentSettings* content_settings =
content::NotificationService::NoDetails()); TabSpecificContentSettings::FromWebContents(web_contents());
delegate()->ShowCollectedCookiesDialog(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);
}
}
// 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);
}
} }
// ContentSettingPluginBubbleModel --------------------------------------------- // ContentSettingPluginBubbleModel ---------------------------------------------
...@@ -550,10 +730,225 @@ void ContentSettingPluginBubbleModel::RunPluginsOnPage() { ...@@ -550,10 +730,225 @@ void ContentSettingPluginBubbleModel::RunPluginsOnPage() {
->set_load_plugins_link_enabled(false); ->set_load_plugins_link_enabled(false);
} }
// ContentSettingPopupBubbleModel ---------------------------------------------- // ContentSettingSingleRadioGroup ----------------------------------------------
class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup, class ContentSettingSingleRadioGroup : public ContentSettingSimpleBubbleModel {
public PopupBlockerTabHelper::Observer { public:
ContentSettingSingleRadioGroup(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
~ContentSettingSingleRadioGroup() override;
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: public:
ContentSettingPopupBubbleModel(Delegate* delegate, ContentSettingPopupBubbleModel(Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
...@@ -655,7 +1050,7 @@ void ContentSettingPopupBubbleModel::OnListItemClicked(int index, ...@@ -655,7 +1050,7 @@ void ContentSettingPopupBubbleModel::OnListItemClicked(int index,
} }
} }
ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel(){ ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel() {
// User selected to always allow pop-ups from. // User selected to always allow pop-ups from.
if (settings_changed() && selected_item() == kAllowButtonIndex) { if (settings_changed() && selected_item() == kAllowButtonIndex) {
// Increases the counter. // Increases the counter.
...@@ -671,6 +1066,25 @@ ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel(){ ...@@ -671,6 +1066,25 @@ ContentSettingPopupBubbleModel::~ContentSettingPopupBubbleModel(){
// ContentSettingMediaStreamBubbleModel ---------------------------------------- // 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( ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
Delegate* delegate, Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
...@@ -720,7 +1134,7 @@ ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { ...@@ -720,7 +1134,7 @@ ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
} }
ContentSettingMediaStreamBubbleModel* ContentSettingMediaStreamBubbleModel*
ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() { ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() {
return this; return this;
} }
...@@ -731,9 +1145,9 @@ void ContentSettingMediaStreamBubbleModel::OnManageButtonClicked() { ...@@ -731,9 +1145,9 @@ void ContentSettingMediaStreamBubbleModel::OnManageButtonClicked() {
if (MicrophoneAccessed() && CameraAccessed()) { if (MicrophoneAccessed() && CameraAccessed()) {
delegate()->ShowMediaSettingsPage(); delegate()->ShowMediaSettingsPage();
} else { } else {
delegate()->ShowContentSettingsPage(CameraAccessed() delegate()->ShowContentSettingsPage(
? CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA CameraAccessed() ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
: CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); : CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
} }
} }
...@@ -813,21 +1227,21 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { ...@@ -813,21 +1227,21 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
radio_item_setting_[0] = CONTENT_SETTING_ALLOW; radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW;
if (MicrophoneAccessed()) if (MicrophoneAccessed())
radio_allow_label_id = CameraAccessed() ? radio_allow_label_id =
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW : CameraAccessed() ? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW
IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW; : IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW;
} else { } else {
radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK; radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK;
if (MicrophoneAccessed()) if (MicrophoneAccessed())
radio_allow_label_id = CameraAccessed() ? radio_allow_label_id = CameraAccessed()
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK : ? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK
IDS_BLOCKED_MEDIASTREAM_MIC_ASK; : IDS_BLOCKED_MEDIASTREAM_MIC_ASK;
} }
radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION; radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION;
if (MicrophoneAccessed()) if (MicrophoneAccessed())
radio_block_label_id = CameraAccessed() ? radio_block_label_id =
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION : CameraAccessed() ? IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION
IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION; : IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION;
} else { } else {
if (MicrophoneAccessed() && CameraAccessed()) { if (MicrophoneAccessed() && CameraAccessed()) {
radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
...@@ -842,9 +1256,12 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { ...@@ -842,9 +1256,12 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
} }
selected_item_ = selected_item_ =
(MicrophoneAccessed() && content_settings->IsContentBlocked( (MicrophoneAccessed() && content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) || CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) ||
(CameraAccessed() && content_settings->IsContentBlocked( (CameraAccessed() &&
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) ? 1 : 0; content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA))
? 1
: 0;
base::string16 radio_allow_label = base::string16 radio_allow_label =
l10n_util::GetStringFUTF16(radio_allow_label_id, display_host); l10n_util::GetStringFUTF16(radio_allow_label_id, display_host);
...@@ -853,475 +1270,152 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { ...@@ -853,475 +1270,152 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
radio_group.default_item = selected_item_; radio_group.default_item = selected_item_;
radio_group.radio_items.push_back(radio_allow_label); radio_group.radio_items.push_back(radio_allow_label);
radio_group.radio_items.push_back(radio_block_label); radio_group.radio_items.push_back(radio_block_label);
set_radio_group(radio_group); set_radio_group(radio_group);
set_radio_group_enabled(true); 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());
} }
void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) { void ContentSettingMediaStreamBubbleModel::UpdateSettings(
if (selected_item_ == radio_index) ContentSetting setting) {
if (!profile())
return; return;
interacted_ = true; TabSpecificContentSettings* tab_content_settings =
selected_item_ = radio_index; TabSpecificContentSettings::FromWebContents(web_contents());
// The same urls must be used as in other places (e.g. the infobar) in
if (radio_index == RPH_ALLOW) // order to override the existing rule. Otherwise a new rule is created.
RegisterProtocolHandler(); // TODO(markusheintz): Extract to a helper so that there is only a single
else if (radio_index == RPH_BLOCK) // place to touch.
UnregisterProtocolHandler(); HostContentSettingsMap* map =
else if (radio_index == RPH_IGNORE) HostContentSettingsMapFactory::GetForProfile(profile());
IgnoreProtocolHandler(); if (MicrophoneAccessed()) {
else PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
NOTREACHED(); 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() { void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
interacted_ = true; 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() { void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
if (!web_contents()) TabSpecificContentSettings* content_settings =
return; 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 // Add microphone menu.
// selects sequences like register/ignore/register. PrefService* prefs = profile()->GetPrefs();
registry_->RemoveIgnoredHandler(pending_handler_); MediaCaptureDevicesDispatcher* dispatcher =
MediaCaptureDevicesDispatcher::GetInstance();
const content::MediaStreamDevices& microphones =
dispatcher->GetAudioCaptureDevices();
registry_->OnAcceptRegisterProtocolHandler(pending_handler_); if (MicrophoneAccessed()) {
TabSpecificContentSettings::FromWebContents(web_contents())-> MediaMenu mic_menu;
set_pending_protocol_handler_setting(CONTENT_SETTING_ALLOW); 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() { mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
if (!web_contents()) mic_menu.selected_device = mic_menu.default_device;
return; }
add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
}
registry_->OnDenyRegisterProtocolHandler(pending_handler_); if (CameraAccessed()) {
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents()); const content::MediaStreamDevices& cameras =
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_BLOCK); dispatcher->GetVideoCaptureDevices();
ClearOrSetPreviousHandler(); 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() { camera_menu.default_device =
if (!web_contents()) GetMediaDeviceById(preferred_camera, cameras);
return; camera_menu.selected_device = camera_menu.default_device;
}
add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
}
}
registry_->OnIgnoreRegisterProtocolHandler(pending_handler_); void ContentSettingMediaStreamBubbleModel::SetManageText() {
auto* settings = TabSpecificContentSettings::FromWebContents(web_contents()); DCHECK(CameraAccessed() || MicrophoneAccessed());
settings->set_pending_protocol_handler_setting(CONTENT_SETTING_DEFAULT); set_manage_text(l10n_util::GetStringUTF16(IDS_MANAGE));
ClearOrSetPreviousHandler();
} }
void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { void ContentSettingMediaStreamBubbleModel::SetCustomLink() {
if (previous_handler_.IsEmpty()) { TabSpecificContentSettings* content_settings =
registry_->ClearDefault(pending_handler_.protocol()); TabSpecificContentSettings::FromWebContents(web_contents());
} else { if (content_settings->IsMicrophoneCameraStateChanged()) {
registry_->OnAcceptRegisterProtocolHandler(previous_handler_); 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 ----------------------------------
ContentSettingSubresourceFilterBubbleModel:: ContentSettingSubresourceFilterBubbleModel::
...@@ -1387,94 +1481,6 @@ ContentSettingSubresourceFilterBubbleModel::AsSubresourceFilterBubbleModel() { ...@@ -1387,94 +1481,6 @@ ContentSettingSubresourceFilterBubbleModel::AsSubresourceFilterBubbleModel() {
return this; 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::ContentSettingDownloadsBubbleModel( ContentSettingDownloadsBubbleModel::ContentSettingDownloadsBubbleModel(
...@@ -1673,6 +1679,11 @@ ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) { ...@@ -1673,6 +1679,11 @@ ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) {
// ContentSettingBubbleModel --------------------------------------------------- // 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 // static
ContentSettingBubbleModel* ContentSettingBubbleModel*
ContentSettingBubbleModel::CreateContentSettingBubbleModel( ContentSettingBubbleModel::CreateContentSettingBubbleModel(
......
...@@ -41,8 +41,7 @@ class RapporServiceImpl; ...@@ -41,8 +41,7 @@ class RapporServiceImpl;
// The hierarchy of bubble models: // The hierarchy of bubble models:
// //
// ContentSettingsBubbleModel - base class // ContentSettingBubbleModel - base class
// ContentSettingMediaStreamBubbleModel - media (camera and mic)
// ContentSettingSimpleBubbleModel - single content setting // ContentSettingSimpleBubbleModel - single content setting
// ContentSettingMixedScriptBubbleModel - mixed script // ContentSettingMixedScriptBubbleModel - mixed script
// ContentSettingRPHBubbleModel - protocol handlers // ContentSettingRPHBubbleModel - protocol handlers
...@@ -52,13 +51,14 @@ class RapporServiceImpl; ...@@ -52,13 +51,14 @@ class RapporServiceImpl;
// ContentSettingSingleRadioGroup - radio group // ContentSettingSingleRadioGroup - radio group
// ContentSettingCookiesBubbleModel - cookies // ContentSettingCookiesBubbleModel - cookies
// ContentSettingPopupBubbleModel - popups // ContentSettingPopupBubbleModel - popups
// ContentSettingMediaStreamBubbleModel - media (camera and mic)
// ContentSettingSubresourceFilterBubbleModel - filtered subresources // ContentSettingSubresourceFilterBubbleModel - filtered subresources
// ContentSettingDownloadsBubbleModel - automatic downloads // ContentSettingDownloadsBubbleModel - automatic downloads
// ContentSettingFramebustBlockBubbleModel - blocked framebusts // ContentSettingFramebustBlockBubbleModel - blocked framebusts
// Forward declaration necessary for downcasts. // Forward declaration necessary for downcasts.
class ContentSettingMediaStreamBubbleModel;
class ContentSettingSimpleBubbleModel; class ContentSettingSimpleBubbleModel;
class ContentSettingMediaStreamBubbleModel;
class ContentSettingSubresourceFilterBubbleModel; class ContentSettingSubresourceFilterBubbleModel;
class ContentSettingDownloadsBubbleModel; class ContentSettingDownloadsBubbleModel;
class ContentSettingFramebustBlockBubbleModel; class ContentSettingFramebustBlockBubbleModel;
...@@ -155,6 +155,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver { ...@@ -155,6 +155,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(BubbleContent); DISALLOW_COPY_AND_ASSIGN(BubbleContent);
}; };
static const int kAllowButtonIndex;
// Creates a bubble model for a particular |content_type|. Note that not all // Creates a bubble model for a particular |content_type|. Note that not all
// bubbles fit this description. // bubbles fit this description.
// TODO(msramek): Move this to ContentSettingSimpleBubbleModel or remove // TODO(msramek): Move this to ContentSettingSimpleBubbleModel or remove
...@@ -217,8 +219,6 @@ class ContentSettingBubbleModel : public content::NotificationObserver { ...@@ -217,8 +219,6 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
rappor_service_ = rappor_service; rappor_service_ = rappor_service;
} }
static const int kAllowButtonIndex;
protected: protected:
ContentSettingBubbleModel( ContentSettingBubbleModel(
Delegate* delegate, Delegate* delegate,
...@@ -340,33 +340,6 @@ class ContentSettingRPHBubbleModel : public ContentSettingSimpleBubbleModel { ...@@ -340,33 +340,6 @@ class ContentSettingRPHBubbleModel : public ContentSettingSimpleBubbleModel {
DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHBubbleModel); 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. // The model of the content settings bubble for media settings.
class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel { class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel {
public: public:
...@@ -426,6 +399,33 @@ class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel { ...@@ -426,6 +399,33 @@ class ContentSettingMediaStreamBubbleModel : public ContentSettingBubbleModel {
DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaStreamBubbleModel); 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. // The model for automatic downloads setting.
class ContentSettingDownloadsBubbleModel : public ContentSettingBubbleModel { class ContentSettingDownloadsBubbleModel : public ContentSettingBubbleModel {
public: public:
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/ui/content_settings/content_setting_image_model.h" #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include <string>
#include <utility>
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -65,30 +68,14 @@ class ContentSettingGeolocationImageModel ...@@ -65,30 +68,14 @@ class ContentSettingGeolocationImageModel
DISALLOW_COPY_AND_ASSIGN(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 { class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel {
public: public:
ContentSettingRPHImageModel(); ContentSettingRPHImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; void UpdateFromWebContents(WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHImageModel);
}; };
class ContentSettingMIDISysExImageModel class ContentSettingMIDISysExImageModel
...@@ -112,6 +99,25 @@ class ContentSettingDownloadsImageModel ...@@ -112,6 +99,25 @@ class ContentSettingDownloadsImageModel
DISALLOW_COPY_AND_ASSIGN(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 { namespace {
struct ContentSettingsImageDetails { struct ContentSettingsImageDetails {
...@@ -335,6 +341,101 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents( ...@@ -335,6 +341,101 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents(
: IDS_GEOLOCATION_BLOCKED_TOOLTIP)); : 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 ----------------------------------------------------------------------- // Media -----------------------------------------------------------------------
ContentSettingMediaImageModel::ContentSettingMediaImageModel() ContentSettingMediaImageModel::ContentSettingMediaImageModel()
...@@ -474,7 +575,6 @@ void ContentSettingSubresourceFilterImageModel::SetAnimationHasRun( ...@@ -474,7 +575,6 @@ void ContentSettingSubresourceFilterImageModel::SetAnimationHasRun(
} }
// Blocked Framebust ----------------------------------------------------------- // Blocked Framebust -----------------------------------------------------------
ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel() ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel()
: ContentSettingImageModel() {} : ContentSettingImageModel() {}
...@@ -518,102 +618,6 @@ void ContentSettingFramebustBlockImageModel::SetAnimationHasRun( ...@@ -518,102 +618,6 @@ void ContentSettingFramebustBlockImageModel::SetAnimationHasRun(
->set_animation_has_run(); ->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 ------------------------------------------------------------------ // Base class ------------------------------------------------------------------
gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const { gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const {
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ #ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#define 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/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.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