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

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

Issue 2746873004: Move ChromeOS login media access logic into a MediaAccessHandler (Closed)
Patch Set: Move SAML access logic into MediaAccessHandler 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/saml_media_access_handler.cc
diff --git a/chrome/browser/media/saml_media_access_handler.cc b/chrome/browser/media/saml_media_access_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3156162fb51b078b53171a07496e203c94d510ea
--- /dev/null
+++ b/chrome/browser/media/saml_media_access_handler.cc
@@ -0,0 +1,84 @@
+// 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/saml_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 "chromeos/settings/cros_settings_names.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+
+SamlMediaAccessHandler::SamlMediaAccessHandler() {}
+
+SamlMediaAccessHandler::~SamlMediaAccessHandler() {}
+
+bool SamlMediaAccessHandler::SupportsStreamType(
+ content::WebContents* web_contents,
+ const content::MediaStreamType type,
+ const extensions::Extension* extension) {
+ if (type != content::MEDIA_DEVICE_VIDEO_CAPTURE)
+ return false;
+
+ chromeos::LoginDisplayHost* login_display_host =
+ 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 SamlMediaAccessHandler::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;
+
+ const chromeos::CrosSettings* const settings = chromeos::CrosSettings::Get();
+ if (!settings)
+ return false;
+
+ 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;
+ if (base_value->GetAsString(&value)) {
+ const ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(value);
+ if (pattern == ContentSettingsPattern::Wildcard()) {
Sergey Ulanov 2017/03/15 22:48:31 Maybe add a comment to explain why this is necessa
raymes 2017/03/16 02:30:37 Done.
+ LOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
Sergey Ulanov 2017/03/15 22:48:31 Does this need to be a WARNING? Can it be a VLOG(0
raymes 2017/03/16 02:30:37 I would say so. Done.
+ continue;
+ }
+ if (pattern.IsValid() && pattern.Matches(security_origin))
+ return true;
+ }
+ }
+ return false;
+}
+
+void SamlMediaAccessHandler::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