| 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/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 // Force administrators to specify more-specific patterns by ignoring the |
| 60 // global wildcard pattern. |
| 61 if (pattern == ContentSettingsPattern::Wildcard()) { |
| 62 VLOG(0) << "Ignoring wildcard URL pattern: " << value; |
| 63 continue; |
| 64 } |
| 65 if (pattern.IsValid() && pattern.Matches(security_origin)) |
| 66 return true; |
| 67 } |
| 68 } |
| 69 return false; |
| 70 } |
| 71 |
| 72 void SamlMediaAccessHandler::HandleRequest( |
| 73 content::WebContents* web_contents, |
| 74 const content::MediaStreamRequest& request, |
| 75 const content::MediaResponseCallback& callback, |
| 76 const extensions::Extension* extension) { |
| 77 bool audio_allowed = false; |
| 78 bool video_allowed = |
| 79 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
| 80 CheckMediaAccessPermission(web_contents, request.security_origin, |
| 81 content::MEDIA_DEVICE_VIDEO_CAPTURE, |
| 82 extension); |
| 83 |
| 84 CheckDevicesAndRunCallback(web_contents, request, callback, audio_allowed, |
| 85 video_allowed); |
| 86 } |
| OLD | NEW |