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