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

Unified Diff: chrome/browser/media/chromeos_login_media_access_handler.cc

Issue 2746873004: Move ChromeOS login media access logic into a MediaAccessHandler (Closed)
Patch Set: ChromeOSLoginMediaAccessHandler Created 3 years, 9 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/media/chromeos_login_media_access_handler.cc
diff --git a/chrome/browser/media/chromeos_login_media_access_handler.cc b/chrome/browser/media/chromeos_login_media_access_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ab48effb8ba0e4f780013c09cacd08c0c5dcb10
--- /dev/null
+++ b/chrome/browser/media/chromeos_login_media_access_handler.cc
@@ -0,0 +1,90 @@
+// Copyright 2017 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/media/chromeos_login_media_access_handler.h"
+
+#include "base/values.h"
+#include "chrome/browser/chromeos/login/ui/login_display_host.h"
+#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/common/url_constants.h"
+#include "chromeos/settings/cros_settings_names.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+
+ChromeOSLoginMediaAccessHandler::ChromeOSLoginMediaAccessHandler() {}
+
+ChromeOSLoginMediaAccessHandler::~ChromeOSLoginMediaAccessHandler() {}
+
+bool ChromeOSLoginMediaAccessHandler::SupportsStreamType(
+ content::WebContents* web_contents,
+ const content::MediaStreamType type,
+ const extensions::Extension* extension) {
+ chromeos::LoginDisplayHost* login_display_host =
achuithb 2017/04/05 00:55:36 Can we add a DCHECK(web_contents);
raymes 2017/04/10 00:16:49 Done.
raymes 2017/04/10 02:42:28 It turns out this can be nullptr, so I've added a
+ chromeos::LoginDisplayHost::default_host();
+ chromeos::WebUILoginView* webui_login_view =
+ login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
+ content::WebContents* login_web_contents =
+ webui_login_view ? webui_login_view->GetWebContents() : nullptr;
+ return web_contents == login_web_contents;
+}
+
+bool ChromeOSLoginMediaAccessHandler::CheckMediaAccessPermission(
+ content::WebContents* web_contents,
+ const GURL& security_origin,
+ content::MediaStreamType type,
+ const extensions::Extension* extension) {
+ if (type != content::MEDIA_DEVICE_VIDEO_CAPTURE)
+ return false;
+
+ // When creating new user (including supervised user), we must be able to use
+ // the camera to capture a user image.
+ if (security_origin.spec() == chrome::kChromeUIOobeURL)
emaxx 2017/04/06 02:41:47 nit: #include "url/gurl.h"
raymes 2017/04/10 00:16:49 Done.
+ return true;
+
+ const chromeos::CrosSettings* const settings = chromeos::CrosSettings::Get();
+ if (!settings)
+ return false;
+
+ // The following checks are for SAML logins.
+ const base::Value* const raw_list_value =
+ settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
+ if (!raw_list_value)
+ return false;
+
+ const base::ListValue* list_value;
+ const bool is_list = raw_list_value->GetAsList(&list_value);
+ DCHECK(is_list);
+ for (const auto& base_value : *list_value) {
+ std::string value;
emaxx 2017/04/06 02:41:47 nit #include <string>
raymes 2017/04/10 00:16:49 Done.
+ if (base_value->GetAsString(&value)) {
+ const ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(value);
+ // Force administrators to specify more-specific patterns by ignoring the
+ // global wildcard pattern.
+ if (pattern == ContentSettingsPattern::Wildcard()) {
+ VLOG(0) << "Ignoring wildcard URL pattern: " << value;
achuithb 2017/04/05 00:55:36 Should this be VLOG(1)?
emaxx 2017/04/06 02:41:47 nit: #include "base/logging.h"
raymes 2017/04/10 00:16:49 Done.
raymes 2017/04/10 00:16:49 Done.
+ continue;
+ }
+ if (pattern.IsValid() && pattern.Matches(security_origin))
+ return true;
+ }
+ }
+ return false;
+}
+
+void ChromeOSLoginMediaAccessHandler::HandleRequest(
+ content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback,
+ const extensions::Extension* extension) {
+ bool audio_allowed = false;
+ bool video_allowed =
+ request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
+ CheckMediaAccessPermission(web_contents, request.security_origin,
+ content::MEDIA_DEVICE_VIDEO_CAPTURE,
+ extension);
+
+ CheckDevicesAndRunCallback(web_contents, request, callback, audio_allowed,
+ video_allowed);
+}

Powered by Google App Engine
This is Rietveld 408576698