Chromium Code Reviews| 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 66% |
| 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..b5f58cd6fe33a6082b0dd5e87cfc034a404495dc 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 (c) 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,28 @@ const char kVideo[] = "camera"; |
| } // namespace |
| -namespace options { |
| +namespace settings { |
| -MediaDevicesSelectionHandler::MediaDevicesSelectionHandler() {} |
| +MediaDevicesSelectionHandler::MediaDevicesSelectionHandler( |
| + content::WebUI* webui) |
|
michaelpg
2016/06/07 16:03:30
just take a Profile* instead
Finnur
2016/06/07 16:48:24
Done.
|
| + : profile_(Profile::FromWebUI(webui)), initialized_(false) { |
| +} |
| MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() { |
| - MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
| + if (initialized_) |
|
michaelpg
2016/06/07 16:03:30
can this be a ScopedObserver instead of checking i
Finnur
2016/06/07 16:48:23
Actually, that's not a bad idea. Done.
|
| + 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,8 +57,31 @@ void MediaDevicesSelectionHandler::OnUpdateVideoDevices( |
| UpdateDevicesMenu(VIDEO, devices); |
| } |
| +void MediaDevicesSelectionHandler::GetDefaultCaptureDevices( |
| + const base::ListValue* args) { |
| + if (!initialized_) { |
|
michaelpg
2016/06/07 16:03:30
if (!scoped_observer_->IsObserving...
Finnur
2016/06/07 16:48:24
Acknowledged.
|
| + // Register to the device observer list to get up-to-date device lists. |
| + MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
| + initialized_ = true; |
| + } |
| + |
| + 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(initialized_); |
| DCHECK_EQ(2U, args->GetSize()); |
| std::string type, device; |
| if (!(args->GetString(0, &type) && args->GetString(1, &device))) { |
| @@ -89,9 +104,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 +140,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 +163,4 @@ void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) { |
| UpdateDevicesMenu(type, devices); |
| } |
| -} // namespace options |
| +} // namespace settings |