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

Side by Side Diff: chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc

Issue 2703393007: Show meaningful name for cameras (Closed)
Patch Set: addressed comments 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings/settings_media_devices_selection_hand ler.h" 5 #include "chrome/browser/ui/webui/settings/settings_media_devices_selection_hand ler.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 "components/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
17 #include "extensions/strings/grit/extensions_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
17 19
18 namespace { 20 namespace {
19 21
20 const char kAudio[] = "mic"; 22 const char kAudio[] = "mic";
21 const char kVideo[] = "camera"; 23 const char kVideo[] = "camera";
22 24
23 } // namespace 25 } // namespace
24 26
25 namespace settings { 27 namespace settings {
26 28
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); 115 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
114 device_type = kVideo; 116 device_type = kVideo;
115 break; 117 break;
116 } 118 }
117 119
118 // Build the list of devices to send to JS. 120 // Build the list of devices to send to JS.
119 std::string default_id; 121 std::string default_id;
120 base::ListValue device_list; 122 base::ListValue device_list;
121 for (size_t i = 0; i < devices.size(); ++i) { 123 for (size_t i = 0; i < devices.size(); ++i) {
122 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); 124 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue());
123 entry->SetString("name", devices[i].name); 125 entry->SetString("name", GetDeviceDisplayName(devices[i]));
124 entry->SetString("id", devices[i].id); 126 entry->SetString("id", devices[i].id);
125 device_list.Append(std::move(entry)); 127 device_list.Append(std::move(entry));
126 if (devices[i].id == default_device) 128 if (devices[i].id == default_device)
127 default_id = default_device; 129 default_id = default_device;
128 } 130 }
129 131
130 // Use the first device as the default device if the preferred default device 132 // Use the first device as the default device if the preferred default device
131 // does not exist in the OS. 133 // does not exist in the OS.
132 if (!devices.empty() && default_id.empty()) 134 if (!devices.empty() && default_id.empty())
133 default_id = devices[0].id; 135 default_id = devices[0].id;
134 136
135 base::StringValue default_value(default_id); 137 base::StringValue default_value(default_id);
136 base::StringValue type_value(device_type); 138 base::StringValue type_value(device_type);
137 CallJavascriptFunction("cr.webUIListenerCallback", 139 CallJavascriptFunction("cr.webUIListenerCallback",
138 base::StringValue("updateDevicesMenu"), 140 base::StringValue("updateDevicesMenu"),
139 type_value, 141 type_value,
140 device_list, 142 device_list,
141 default_value); 143 default_value);
142 } 144 }
143 145
146 std::string MediaDevicesSelectionHandler::GetDeviceDisplayName(
147 const content::MediaStreamDevice& device) const {
148 std::string facing_info;
149 switch (device.video_facing) {
150 case media::VideoFacingMode::MEDIA_VIDEO_FACING_USER:
151 facing_info = l10n_util::GetStringUTF8(IDS_CAMERA_FACING_USER);
152 break;
153 case media::VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT:
154 facing_info = l10n_util::GetStringUTF8(IDS_CAMERA_FACING_ENVIRONMENT);
155 break;
156 case media::VideoFacingMode::MEDIA_VIDEO_FACING_NONE:
157 break;
158 case media::VideoFacingMode::NUM_MEDIA_VIDEO_FACING_MODES:
159 NOTREACHED();
160 break;
161 }
162
163 if (facing_info.empty())
164 return device.name;
165 return device.name + " " + facing_info;
166 }
167
144 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { 168 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) {
145 content::MediaStreamDevices devices; 169 content::MediaStreamDevices devices;
146 switch (type) { 170 switch (type) {
147 case AUDIO: 171 case AUDIO:
148 devices = MediaCaptureDevicesDispatcher::GetInstance()-> 172 devices = MediaCaptureDevicesDispatcher::GetInstance()->
149 GetAudioCaptureDevices(); 173 GetAudioCaptureDevices();
150 break; 174 break;
151 case VIDEO: 175 case VIDEO:
152 devices = MediaCaptureDevicesDispatcher::GetInstance()-> 176 devices = MediaCaptureDevicesDispatcher::GetInstance()->
153 GetVideoCaptureDevices(); 177 GetVideoCaptureDevices();
154 break; 178 break;
155 } 179 }
156 180
157 UpdateDevicesMenu(type, devices); 181 UpdateDevicesMenu(type, devices);
158 } 182 }
159 183
160 } // namespace settings 184 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698