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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/saml_media_access_handler.h"
6
7 #include "base/values.h"
8 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
9 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
10 #include "chrome/browser/chromeos/settings/cros_settings.h"
11 #include "chromeos/settings/cros_settings_names.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h"
13
14 SamlMediaAccessHandler::SamlMediaAccessHandler() {}
15
16 SamlMediaAccessHandler::~SamlMediaAccessHandler() {}
17
18 bool SamlMediaAccessHandler::SupportsStreamType(
19 content::WebContents* web_contents,
20 const content::MediaStreamType type,
21 const extensions::Extension* extension) {
22 if (type != content::MEDIA_DEVICE_VIDEO_CAPTURE)
23 return false;
24
25 chromeos::LoginDisplayHost* login_display_host =
26 chromeos::LoginDisplayHost::default_host();
27 chromeos::WebUILoginView* webui_login_view =
28 login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
29 content::WebContents* login_web_contents =
30 webui_login_view ? webui_login_view->GetWebContents() : nullptr;
31 return web_contents == login_web_contents;
32 }
33
34 bool SamlMediaAccessHandler::CheckMediaAccessPermission(
35 content::WebContents* web_contents,
36 const GURL& security_origin,
37 content::MediaStreamType type,
38 const extensions::Extension* extension) {
39 if (type != content::MEDIA_DEVICE_VIDEO_CAPTURE)
40 return false;
41
42 const chromeos::CrosSettings* const settings = chromeos::CrosSettings::Get();
43 if (!settings)
44 return false;
45
46 const base::Value* const raw_list_value =
47 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
48 if (!raw_list_value)
49 return false;
50
51 const base::ListValue* list_value;
52 const bool is_list = raw_list_value->GetAsList(&list_value);
53 DCHECK(is_list);
54 for (const auto& base_value : *list_value) {
55 std::string value;
56 if (base_value->GetAsString(&value)) {
57 const ContentSettingsPattern pattern =
58 ContentSettingsPattern::FromString(value);
59 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.
60 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.
61 continue;
62 }
63 if (pattern.IsValid() && pattern.Matches(security_origin))
64 return true;
65 }
66 }
67 return false;
68 }
69
70 void SamlMediaAccessHandler::HandleRequest(
71 content::WebContents* web_contents,
72 const content::MediaStreamRequest& request,
73 const content::MediaResponseCallback& callback,
74 const extensions::Extension* extension) {
75 bool audio_allowed = false;
76 bool video_allowed =
77 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
78 CheckMediaAccessPermission(web_contents, request.security_origin,
79 content::MEDIA_DEVICE_VIDEO_CAPTURE,
80 extension);
81
82 CheckDevicesAndRunCallback(web_contents, request, callback, audio_allowed,
83 video_allowed);
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698