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

Unified Diff: chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.cc

Issue 2039833004: Site Settings Desktop: Implement media picker for camera/mic categories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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 69%
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 77618f38866431cd4d0dfd7499f86b56e3e19de1..9e8be216f64f3760805318fbfd8ef0333bfc48c4 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,28 @@ const char kVideo[] = "camera";
} // namespace
-namespace options {
+namespace settings {
-MediaDevicesSelectionHandler::MediaDevicesSelectionHandler() {}
-
-MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() {
- MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
+MediaDevicesSelectionHandler::MediaDevicesSelectionHandler(Profile* profile)
+ : profile_(profile), observer_(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));
+MediaDevicesSelectionHandler::~MediaDevicesSelectionHandler() {
}
-void MediaDevicesSelectionHandler::InitializePage() {
+void MediaDevicesSelectionHandler::OnJavascriptAllowed() {
// Register to the device observer list to get up-to-date device lists.
- MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
+ observer_.Add(MediaCaptureDevicesDispatcher::GetInstance());
+}
- // Update the device selection menus.
- UpdateDevicesMenuForType(AUDIO);
- UpdateDevicesMenuForType(VIDEO);
+void MediaDevicesSelectionHandler::OnJavascriptDisallowed() {
+ observer_.RemoveAll();
}
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 +57,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 +85,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 +96,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,9 +132,11 @@ void MediaDevicesSelectionHandler::UpdateDevicesMenu(
base::StringValue default_value(default_id);
base::StringValue type_value(device_type);
- web_ui()->CallJavascriptFunctionUnsafe("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) {
@@ -145,4 +155,4 @@ void MediaDevicesSelectionHandler::UpdateDevicesMenuForType(DeviceType type) {
UpdateDevicesMenu(type, devices);
}
-} // namespace options
+} // namespace settings
« no previous file with comments | « chrome/browser/ui/webui/settings/settings_media_devices_selection_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698