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

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

Powered by Google App Engine
This is Rietveld 408576698