Index: chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc |
diff --git a/chrome/browser/ui/webui/options/media_devices_selection_handler.cc b/chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc |
similarity index 70% |
copy from chrome/browser/ui/webui/options/media_devices_selection_handler.cc |
copy to chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc |
index 2923325ecc27a7cf0712d2f25f671bd661a16c73..c9558e6172b55a6e11b65f9a243a164e1354424e 100644 |
--- a/chrome/browser/ui/webui/options/media_devices_selection_handler.cc |
+++ b/chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc |
@@ -1,8 +1,8 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/webui/options/media_devices_selection_handler.h" |
+#include "chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.h" |
#include <stddef.h> |
@@ -20,36 +20,27 @@ const char kVideo[] = "camera"; |
} // namespace |
-namespace options { |
+namespace settings { |
-MediaDevicesSelectionHandler::MediaDevicesSelectionHandler() {} |
+MediaDevicesSelectionHandler::MediaDevicesSelectionHandler(Profile* profile) |
+ : profile_(profile), observer_(this) { |
+ // Register to the device observer list to get up-to-date device lists. |
+ observer_.Add(MediaCaptureDevicesDispatcher::GetInstance()); |
michaelpg
2016/06/07 17:00:55
I think the idea is to do this in OnJavascriptAllo
Finnur
2016/06/08 12:40:41
Done.
|
+} |
MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() { |
- MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
} |
-void MediaDevicesSelectionHandler::GetLocalizedValues( |
- base::DictionaryValue* values) { |
- DCHECK(values); |
- |
- static OptionsStringResource resources[] = { |
- { "mediaSelectMicLabel", IDS_MEDIA_SELECTED_MIC_LABEL }, |
- { "mediaSelectCameraLabel", IDS_MEDIA_SELECTED_CAMERA_LABEL }, |
- }; |
- |
- RegisterStrings(values, resources, arraysize(resources)); |
+void MediaDevicesSelectionHandler::OnJavascriptAllowed() { |
} |
-void MediaDevicesSelectionHandler::InitializePage() { |
- // Register to the device observer list to get up-to-date device lists. |
- MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
- |
- // Update the device selection menus. |
- UpdateDevicesMenuForType(AUDIO); |
- UpdateDevicesMenuForType(VIDEO); |
+void MediaDevicesSelectionHandler::OnJavascriptDisallowed() { |
} |
void MediaDevicesSelectionHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("getDefaultCaptureDevices", |
+ base::Bind(&MediaDevicesSelectionHandler::GetDefaultCaptureDevices, |
+ base::Unretained(this))); |
web_ui()->RegisterMessageCallback("setDefaultCaptureDevice", |
base::Bind(&MediaDevicesSelectionHandler::SetDefaultCaptureDevice, |
base::Unretained(this))); |
@@ -65,6 +56,22 @@ void MediaDevicesSelectionHandler::OnUpdateVideoDevices( |
UpdateDevicesMenu(VIDEO, devices); |
} |
+void MediaDevicesSelectionHandler::GetDefaultCaptureDevices( |
+ const base::ListValue* args) { |
+ DCHECK_EQ(1U, args->GetSize()); |
+ std::string type; |
+ if (!args->GetString(0, &type)) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ DCHECK(!type.empty()); |
+ |
+ if (type == kAudio) |
+ UpdateDevicesMenuForType(AUDIO); |
+ else if (type == kVideo) |
+ UpdateDevicesMenuForType(VIDEO); |
+} |
+ |
void MediaDevicesSelectionHandler::SetDefaultCaptureDevice( |
const base::ListValue* args) { |
DCHECK_EQ(2U, args->GetSize()); |
@@ -77,8 +84,7 @@ void MediaDevicesSelectionHandler::SetDefaultCaptureDevice( |
DCHECK(!type.empty()); |
DCHECK(!device.empty()); |
- Profile* profile = Profile::FromWebUI(web_ui()); |
- PrefService* prefs = profile->GetPrefs(); |
+ PrefService* prefs = profile_->GetPrefs(); |
if (type == kAudio) |
prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); |
else if (type == kVideo) |
@@ -89,9 +95,10 @@ void MediaDevicesSelectionHandler::SetDefaultCaptureDevice( |
void MediaDevicesSelectionHandler::UpdateDevicesMenu( |
DeviceType type, const content::MediaStreamDevices& devices) { |
+ AllowJavascript(); |
+ |
// Get the default device unique id from prefs. |
- Profile* profile = Profile::FromWebUI(web_ui()); |
- PrefService* prefs = profile->GetPrefs(); |
+ PrefService* prefs = profile_->GetPrefs(); |
std::string default_device; |
std::string device_type; |
switch (type) { |
@@ -124,10 +131,11 @@ void MediaDevicesSelectionHandler::UpdateDevicesMenu( |
base::StringValue default_value(default_id); |
base::StringValue type_value(device_type); |
- web_ui()->CallJavascriptFunction("ContentSettings.updateDevicesMenu", |
- type_value, |
- device_list, |
- default_value); |
+ CallJavascriptFunction("cr.webUIListenerCallback", |
+ base::StringValue("updateDevicesMenu"), |
+ type_value, |
+ device_list, |
+ default_value); |
} |
void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { |
@@ -146,4 +154,4 @@ void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { |
UpdateDevicesMenu(type, devices); |
} |
-} // namespace options |
+} // namespace settings |