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

Side by Side 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, 8 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/chromeos_login_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 "chrome/common/url_constants.h"
12 #include "chromeos/settings/cros_settings_names.h"
13 #include "components/content_settings/core/common/content_settings_pattern.h"
14
15 ChromeOSLoginMediaAccessHandler::ChromeOSLoginMediaAccessHandler() {}
16
17 ChromeOSLoginMediaAccessHandler::~ChromeOSLoginMediaAccessHandler() {}
18
19 bool ChromeOSLoginMediaAccessHandler::SupportsStreamType(
20 content::WebContents* web_contents,
21 const content::MediaStreamType type,
22 const extensions::Extension* extension) {
23 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
24 chromeos::LoginDisplayHost::default_host();
25 chromeos::WebUILoginView* webui_login_view =
26 login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
27 content::WebContents* login_web_contents =
28 webui_login_view ? webui_login_view->GetWebContents() : nullptr;
29 return web_contents == login_web_contents;
30 }
31
32 bool ChromeOSLoginMediaAccessHandler::CheckMediaAccessPermission(
33 content::WebContents* web_contents,
34 const GURL& security_origin,
35 content::MediaStreamType type,
36 const extensions::Extension* extension) {
37 if (type != content::MEDIA_DEVICE_VIDEO_CAPTURE)
38 return false;
39
40 // When creating new user (including supervised user), we must be able to use
41 // the camera to capture a user image.
42 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.
43 return true;
44
45 const chromeos::CrosSettings* const settings = chromeos::CrosSettings::Get();
46 if (!settings)
47 return false;
48
49 // The following checks are for SAML logins.
50 const base::Value* const raw_list_value =
51 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
52 if (!raw_list_value)
53 return false;
54
55 const base::ListValue* list_value;
56 const bool is_list = raw_list_value->GetAsList(&list_value);
57 DCHECK(is_list);
58 for (const auto& base_value : *list_value) {
59 std::string value;
emaxx 2017/04/06 02:41:47 nit #include <string>
raymes 2017/04/10 00:16:49 Done.
60 if (base_value->GetAsString(&value)) {
61 const ContentSettingsPattern pattern =
62 ContentSettingsPattern::FromString(value);
63 // Force administrators to specify more-specific patterns by ignoring the
64 // global wildcard pattern.
65 if (pattern == ContentSettingsPattern::Wildcard()) {
66 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.
67 continue;
68 }
69 if (pattern.IsValid() && pattern.Matches(security_origin))
70 return true;
71 }
72 }
73 return false;
74 }
75
76 void ChromeOSLoginMediaAccessHandler::HandleRequest(
77 content::WebContents* web_contents,
78 const content::MediaStreamRequest& request,
79 const content::MediaResponseCallback& callback,
80 const extensions::Extension* extension) {
81 bool audio_allowed = false;
82 bool video_allowed =
83 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
84 CheckMediaAccessPermission(web_contents, request.security_origin,
85 content::MEDIA_DEVICE_VIDEO_CAPTURE,
86 extension);
87
88 CheckDevicesAndRunCallback(web_contents, request, callback, audio_allowed,
89 video_allowed);
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698