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

Side by Side Diff: chrome/browser/ui/webui/options/media_devices_selection_handler.cc

Issue 2703393007: Show meaningful name for cameras (Closed)
Patch Set: Moved to chrome/browser/ui/webui/ Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/media_devices_selection_handler.h" 5 #include "chrome/browser/ui/webui/options/media_devices_selection_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
18 #include "extensions/strings/grit/extensions_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
18 20
19 namespace { 21 namespace {
20 22
21 const char kAudio[] = "mic"; 23 const char kAudio[] = "mic";
22 const char kVideo[] = "camera"; 24 const char kVideo[] = "camera";
23 25
24 } // namespace 26 } // namespace
25 27
26 namespace options { 28 namespace options {
27 29
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); 108 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
107 device_type = kVideo; 109 device_type = kVideo;
108 break; 110 break;
109 } 111 }
110 112
111 // Build the list of devices to send to JS. 113 // Build the list of devices to send to JS.
112 std::string default_id; 114 std::string default_id;
113 base::ListValue device_list; 115 base::ListValue device_list;
114 for (size_t i = 0; i < devices.size(); ++i) { 116 for (size_t i = 0; i < devices.size(); ++i) {
115 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); 117 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue());
116 entry->SetString("name", devices[i].name); 118 entry->SetString("name", GetDeviceDisplayName(devices[i]));
117 entry->SetString("id", devices[i].id); 119 entry->SetString("id", devices[i].id);
118 device_list.Append(std::move(entry)); 120 device_list.Append(std::move(entry));
119 if (devices[i].id == default_device) 121 if (devices[i].id == default_device)
120 default_id = default_device; 122 default_id = default_device;
121 } 123 }
122 124
123 // Use the first device as the default device if the preferred default device 125 // Use the first device as the default device if the preferred default device
124 // does not exist in the OS. 126 // does not exist in the OS.
125 if (!devices.empty() && default_id.empty()) 127 if (!devices.empty() && default_id.empty())
126 default_id = devices[0].id; 128 default_id = devices[0].id;
127 129
128 base::StringValue default_value(default_id); 130 base::StringValue default_value(default_id);
129 base::StringValue type_value(device_type); 131 base::StringValue type_value(device_type);
130 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.updateDevicesMenu", 132 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.updateDevicesMenu",
131 type_value, device_list, 133 type_value, device_list,
132 default_value); 134 default_value);
133 } 135 }
134 136
137 std::string MediaDevicesSelectionHandler::GetDeviceDisplayName(
138 const content::MediaStreamDevice& device) {
139 std::string facing_info;
140 switch (device.video_facing) {
141 case media::VideoFacingMode::MEDIA_VIDEO_FACING_USER:
142 facing_info = l10n_util::GetStringUTF8(IDS_CAMERA_FACING_USER);
143 break;
144 case media::VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT:
145 facing_info = l10n_util::GetStringUTF8(IDS_CAMERA_FACING_ENVIRONMENT);
146 break;
147 case media::VideoFacingMode::MEDIA_VIDEO_FACING_NONE:
148 case media::VideoFacingMode::NUM_MEDIA_VIDEO_FACING_MODES:
mtomasz 2017/03/02 07:49:53 nit: Add NOTREACHED()?
shenghao 2017/03/02 12:43:41 MEDIA_VIDEO_FACING_NONE is possible. I added NOTRE
149 break;
150 }
151
152 if (facing_info.empty())
153 return device.name;
154 return device.name + " (" + facing_info + ")";
mtomasz 2017/03/02 07:49:53 This may provide broken strings in some languages,
shenghao 2017/03/02 12:43:41 I would just delete the brackets.
155 }
156
135 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { 157 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) {
136 content::MediaStreamDevices devices; 158 content::MediaStreamDevices devices;
137 switch (type) { 159 switch (type) {
138 case AUDIO: 160 case AUDIO:
139 devices = MediaCaptureDevicesDispatcher::GetInstance()-> 161 devices = MediaCaptureDevicesDispatcher::GetInstance()->
140 GetAudioCaptureDevices(); 162 GetAudioCaptureDevices();
141 break; 163 break;
142 case VIDEO: 164 case VIDEO:
143 devices = MediaCaptureDevicesDispatcher::GetInstance()-> 165 devices = MediaCaptureDevicesDispatcher::GetInstance()->
144 GetVideoCaptureDevices(); 166 GetVideoCaptureDevices();
145 break; 167 break;
146 } 168 }
147 169
148 UpdateDevicesMenu(type, devices); 170 UpdateDevicesMenu(type, devices);
149 } 171 }
150 172
151 } // namespace options 173 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698