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

Unified Diff: chrome/browser/media/media_stream_devices_menu_model.cc

Issue 10537099: add "always allow" option to the mediastream infobar and allow user to allow/not allow acces to devi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed sky's comment and replaced "Do not allow any site to" with "Do not allow sites to" Created 8 years, 6 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
Index: chrome/browser/media/media_stream_devices_menu_model.cc
diff --git a/chrome/browser/media/media_stream_devices_menu_model.cc b/chrome/browser/media/media_stream_devices_menu_model.cc
index 0355767cede5c682a331c38f6e5fff68efac8dc5..f32f5aa7ef18857a207a62e356308418b76310db 100644
--- a/chrome/browser/media/media_stream_devices_menu_model.cc
+++ b/chrome/browser/media/media_stream_devices_menu_model.cc
@@ -7,6 +7,7 @@
#include <utility>
#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/media_stream_infobar_delegate.h"
#include "content/public/common/media_stream_request.h"
#include "grit/generated_resources.h"
@@ -16,21 +17,24 @@ MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel(
const MediaStreamInfoBarDelegate* delegate)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
selected_command_id_audio_(-1),
- selected_command_id_video_(-1) {
- const bool nonempty_audio_section =
- delegate->has_audio() && !delegate->GetAudioDevices().empty();
- if (delegate->has_video() && !delegate->GetVideoDevices().empty()) {
+ selected_command_id_video_(-1),
+ always_allow_(false) {
+ bool audio = delegate->HasAudio() && !delegate->GetAudioDevices().empty();
+ bool video = delegate->HasVideo() && !delegate->GetVideoDevices().empty();
+ if (video) {
// The default command ID is the first element that will be inserted.
selected_command_id_video_ = commands_.size();
AddDevices(delegate->GetVideoDevices());
- if (nonempty_audio_section)
+ if (audio)
AddSeparator();
}
- if (nonempty_audio_section) {
+ if (audio) {
// The default command ID is the first element that will be inserted.
selected_command_id_audio_ = commands_.size();
AddDevices(delegate->GetAudioDevices());
}
+
+ AddAlwaysAllowOption(audio, video);
}
MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() {
@@ -48,8 +52,13 @@ bool MediaStreamDevicesMenuModel::GetSelectedDeviceId(
}
bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const {
- return (selected_command_id_audio_ == command_id ||
- selected_command_id_video_ == command_id);
+ switch (command_id) {
+ case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
+ return always_allow_;
+ default:
+ return (selected_command_id_audio_ == command_id ||
+ selected_command_id_video_ == command_id);
+ }
}
bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const {
@@ -63,13 +72,20 @@ bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId(
}
void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) {
- CommandMap::iterator it = commands_.find(command_id);
- DCHECK(it != commands_.end());
+ switch (command_id) {
+ case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
+ always_allow_ = !always_allow_;
+ break;
+ default:
+ CommandMap::iterator it = commands_.find(command_id);
+ DCHECK(it != commands_.end());
- if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
- selected_command_id_audio_ = command_id;
- else
- selected_command_id_video_ = command_id;
+ if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
+ selected_command_id_audio_ = command_id;
+ else
+ selected_command_id_video_ = command_id;
+ break;
+ }
}
void MediaStreamDevicesMenuModel::AddDevices(
@@ -79,9 +95,21 @@ void MediaStreamDevicesMenuModel::AddDevices(
commands_.insert(std::make_pair(command_id, devices[i]));
int message_id = (devices[i].type ==
content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ?
- IDS_MEDIA_CAPTURE_MIC : IDS_MEDIA_CAPTURE_VIDEO;
+ IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO;
AddCheckItem(command_id,
l10n_util::GetStringFUTF16(message_id,
UTF8ToUTF16(devices[i].name)));
}
}
+
+void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) {
+ int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW;
+ int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO;
+ if (audio && !video)
+ message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY;
+ else if (!audio && video)
+ message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY;
+
+ AddSeparator();
+ AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id));
+}
« no previous file with comments | « chrome/browser/media/media_stream_devices_menu_model.h ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698