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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/media/media_internals.h" | |
9 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
12 | 11 |
13 namespace { | 12 namespace { |
14 | 13 |
15 const char kAudio[] = "mic"; | 14 const char kAudio[] = "mic"; |
16 const char kVideo[] = "camera"; | 15 const char kVideo[] = "camera"; |
17 | 16 |
18 } // namespace | 17 } // namespace |
19 | 18 |
20 namespace options { | 19 namespace options { |
21 | 20 |
22 MediaDevicesSelectionHandler::MediaDevicesSelectionHandler() {} | 21 MediaDevicesSelectionHandler::MediaDevicesSelectionHandler() {} |
23 | 22 |
24 MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() { | 23 MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() { |
25 // Register to the device observer list to get up-to-date device lists. | 24 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
26 MediaCaptureDevicesDispatcher* dispatcher = | |
27 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); | |
28 dispatcher->RemoveObserver(this); | |
29 } | 25 } |
30 | 26 |
31 void MediaDevicesSelectionHandler::GetLocalizedValues(DictionaryValue* values) { | 27 void MediaDevicesSelectionHandler::GetLocalizedValues(DictionaryValue* values) { |
32 DCHECK(values); | 28 DCHECK(values); |
33 | 29 |
34 static OptionsStringResource resources[] = { | 30 static OptionsStringResource resources[] = { |
35 { "mediaSelectMicLabel", IDS_MEDIA_SELECTED_MIC_LABEL }, | 31 { "mediaSelectMicLabel", IDS_MEDIA_SELECTED_MIC_LABEL }, |
36 { "mediaSelectCameraLabel", IDS_MEDIA_SELECTED_CAMERA_LABEL }, | 32 { "mediaSelectCameraLabel", IDS_MEDIA_SELECTED_CAMERA_LABEL }, |
37 }; | 33 }; |
38 | 34 |
39 RegisterStrings(values, resources, arraysize(resources)); | 35 RegisterStrings(values, resources, arraysize(resources)); |
40 } | 36 } |
41 | 37 |
42 void MediaDevicesSelectionHandler::InitializePage() { | 38 void MediaDevicesSelectionHandler::InitializePage() { |
43 // Register to the device observer list to get up-to-date device lists. | 39 // Register to the device observer list to get up-to-date device lists. |
44 MediaCaptureDevicesDispatcher* dispatcher = | 40 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
45 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); | |
46 dispatcher->AddObserver(this); | |
47 | 41 |
48 // Update the device selection menus. | 42 // Update the device selection menus. |
49 UpdateDevicesMenuForType(AUDIO); | 43 UpdateDevicesMenuForType(AUDIO); |
50 UpdateDevicesMenuForType(VIDEO); | 44 UpdateDevicesMenuForType(VIDEO); |
51 } | 45 } |
52 | 46 |
53 void MediaDevicesSelectionHandler::RegisterMessages() { | 47 void MediaDevicesSelectionHandler::RegisterMessages() { |
54 web_ui()->RegisterMessageCallback("setDefaultCaptureDevice", | 48 web_ui()->RegisterMessageCallback("setDefaultCaptureDevice", |
55 base::Bind(&MediaDevicesSelectionHandler::SetDefaultCaptureDevice, | 49 base::Bind(&MediaDevicesSelectionHandler::SetDefaultCaptureDevice, |
56 base::Unretained(this))); | 50 base::Unretained(this))); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 119 |
126 StringValue default_value(default_id); | 120 StringValue default_value(default_id); |
127 StringValue type_value(device_type); | 121 StringValue type_value(device_type); |
128 web_ui()->CallJavascriptFunction("ContentSettings.updateDevicesMenu", | 122 web_ui()->CallJavascriptFunction("ContentSettings.updateDevicesMenu", |
129 type_value, | 123 type_value, |
130 device_list, | 124 device_list, |
131 default_value); | 125 default_value); |
132 } | 126 } |
133 | 127 |
134 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { | 128 void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { |
135 scoped_refptr<MediaCaptureDevicesDispatcher> dispatcher = | |
136 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); | |
137 content::MediaStreamDevices devices; | 129 content::MediaStreamDevices devices; |
138 switch (type) { | 130 switch (type) { |
139 case AUDIO: | 131 case AUDIO: |
140 devices = dispatcher->GetAudioCaptureDevices(); | 132 devices = MediaCaptureDevicesDispatcher::GetInstance()-> |
| 133 GetAudioCaptureDevices(); |
141 break; | 134 break; |
142 case VIDEO: | 135 case VIDEO: |
143 devices = dispatcher->GetVideoCaptureDevices(); | 136 devices = MediaCaptureDevicesDispatcher::GetInstance()-> |
| 137 GetVideoCaptureDevices(); |
144 break; | 138 break; |
145 } | 139 } |
146 | 140 |
147 UpdateDevicesMenu(type, devices); | 141 UpdateDevicesMenu(type, devices); |
148 } | 142 } |
149 | 143 |
150 } // namespace options | 144 } // namespace options |
OLD | NEW |