Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4289)

Unified Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 1266583003: Fix the links in the media bubble pointing to the media UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The definitions too. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/chrome_pages.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/content_settings/content_setting_bubble_model.cc
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
index b16b6682d80e5e8a0ad110f8fda478973c7602ce..339c59664f20f9e0c525f99c15e266e45f0bfd38 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
@@ -578,12 +578,21 @@ class ContentSettingMediaStreamBubbleModel
~ContentSettingMediaStreamBubbleModel() override;
+ void OnManageLinkClicked() override;
+
private:
+ // Helper functions to check if this bubble was invoked for microphone,
+ // camera, or both devices.
+ bool MicrophoneAccessed() const;
+ bool CameraAccessed() const;
+
void SetTitle();
// Sets the data for the radio buttons of the bubble.
void SetRadioGroup();
// Sets the data for the media menus of the bubble.
void SetMediaMenus();
+ // Set the settings management link.
+ void SetManageLink();
void SetCustomLink();
// Updates the camera and microphone setting with the passed |setting|.
void UpdateSettings(ContentSetting setting);
@@ -614,6 +623,16 @@ ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM),
selected_item_(0),
state_(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) {
+ // TODO(msramek): Every bubble is tied to a particular content setting.
+ // The media bubble has three states - mic only, camera only, and both.
+ // However, it is always tied to the deprecated MEDIASTREAM setting. Refactor
+ // this so that it refers to the MIC setting for microphone and CAMERA
+ // setting for camera to reduce the duplication of code in practically every
+ // method. Furthermore, it should be possible not to tie the bubble to any
+ // particular content setting type, as we still need the bubble for both
+ // camera and microphone, but should not use the deprecated MEDIASTREAM
+ // setting.
+
DCHECK(profile);
// Initialize the content settings associated with the individual radio
// buttons.
@@ -623,12 +642,12 @@ ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
state_ = content_settings->GetMicrophoneCameraState();
- DCHECK(state_ & (TabSpecificContentSettings::MICROPHONE_ACCESSED |
- TabSpecificContentSettings::CAMERA_ACCESSED));
+ DCHECK(CameraAccessed() || MicrophoneAccessed());
SetTitle();
SetRadioGroup();
SetMediaMenus();
+ SetManageLink();
SetCustomLink();
}
@@ -653,18 +672,40 @@ ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
}
}
+bool ContentSettingMediaStreamBubbleModel::MicrophoneAccessed() const {
+ return (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0;
+}
+
+bool ContentSettingMediaStreamBubbleModel::CameraAccessed() const {
+ return (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0;
+}
+
+void ContentSettingMediaStreamBubbleModel::OnManageLinkClicked() {
+ if (!delegate())
+ return;
+
+ if (MicrophoneAccessed()) {
+ delegate()->ShowContentSettingsPage(CameraAccessed()
+ ? CONTENT_SETTINGS_TYPE_MEDIASTREAM
+ : CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
+ } else {
+ delegate()->ShowContentSettingsPage(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
+ }
+}
+
void ContentSettingMediaStreamBubbleModel::SetTitle() {
- DCHECK_NE(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED, state_);
+ DCHECK(CameraAccessed() || MicrophoneAccessed());
int title_id = 0;
if (state_ & TabSpecificContentSettings::MICROPHONE_BLOCKED) {
title_id = (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) ?
IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED;
} else if (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) {
title_id = IDS_CAMERA_BLOCKED;
- } else if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
- title_id = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) ?
- IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED;
- } else if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
+ } else if (MicrophoneAccessed()) {
+ title_id = CameraAccessed() ? IDS_MICROPHONE_CAMERA_ALLOWED
+ : IDS_MICROPHONE_ACCESSED;
+ } else if (CameraAccessed()) {
title_id = IDS_CAMERA_ACCESSED;
}
set_title(l10n_util::GetStringUTF8(title_id));
@@ -684,9 +725,7 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
if (display_host.empty())
display_host = url.spec();
- bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0;
- bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0;
- DCHECK(is_mic || is_cam);
+ DCHECK(CameraAccessed() || MicrophoneAccessed());
int radio_allow_label_id = 0;
int radio_block_label_id = 0;
if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED |
@@ -694,27 +733,27 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
if (content::IsOriginSecure(url)) {
radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW;
- if (is_mic)
- radio_allow_label_id = is_cam ?
+ if (MicrophoneAccessed())
+ 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 (is_mic)
- radio_allow_label_id = is_cam ?
+ if (MicrophoneAccessed())
+ 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 (is_mic)
- radio_block_label_id = is_cam ?
+ if (MicrophoneAccessed())
+ radio_block_label_id = CameraAccessed() ?
IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION :
IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION;
} else {
- if (is_mic && is_cam) {
+ if (MicrophoneAccessed() && CameraAccessed()) {
radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK;
- } else if (is_mic) {
+ } else if (MicrophoneAccessed()) {
radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION;
radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK;
} else {
@@ -723,9 +762,9 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
}
}
selected_item_ =
- (is_mic && content_settings->IsContentBlocked(
+ (MicrophoneAccessed() && content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) ||
- (is_cam && content_settings->IsContentBlocked(
+ (CameraAccessed() && content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) ? 1 : 0;
std::string radio_allow_label = l10n_util::GetStringFUTF8(
@@ -757,12 +796,12 @@ void ContentSettingMediaStreamBubbleModel::UpdateSettings(
tab_content_settings->media_stream_access_origin());
ContentSettingsPattern secondary_pattern =
ContentSettingsPattern::Wildcard();
- if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
+ if (MicrophoneAccessed()) {
content_settings->SetContentSetting(
primary_pattern, secondary_pattern,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
}
- if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
+ if (CameraAccessed()) {
content_settings->SetContentSetting(
primary_pattern, secondary_pattern,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
@@ -797,7 +836,7 @@ void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
const content::MediaStreamDevices& microphones =
dispatcher->GetAudioCaptureDevices();
- if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
+ if (MicrophoneAccessed()) {
MediaMenu mic_menu;
mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL);
if (!microphones.empty()) {
@@ -819,7 +858,7 @@ void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
}
- if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
+ if (CameraAccessed()) {
const content::MediaStreamDevices& cameras =
dispatcher->GetVideoCaptureDevices();
MediaMenu camera_menu;
@@ -845,6 +884,17 @@ void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
}
}
+void ContentSettingMediaStreamBubbleModel::SetManageLink() {
+ // By default, the manage link refers to both media types. We only need
+ // to change the link text if only one media type was accessed.
+ if (CameraAccessed() && MicrophoneAccessed())
+ return;
+
+ set_manage_link(l10n_util::GetStringUTF8(MicrophoneAccessed()
+ ? IDS_MEDIASTREAM_MICROPHONE_BUBBLE_MANAGE_LINK
+ : IDS_MEDIASTREAM_CAMERA_BUBBLE_MANAGE_LINK));
+}
+
void ContentSettingMediaStreamBubbleModel::SetCustomLink() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
« no previous file with comments | « chrome/browser/ui/chrome_pages.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698