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