| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/webrtc/public_session_tab_capture_access_handler.
h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "chromeos/login/login_state.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/permissions/manifest_permission_set.h" |
| 16 #include "extensions/common/permissions/permission_set.h" |
| 17 #include "extensions/common/url_pattern_set.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 // Returns true if we're in a Public Session. |
| 22 bool IsPublicSession() { |
| 23 return chromeos::LoginState::IsInitialized() && |
| 24 chromeos::LoginState::Get()->IsPublicSessionUser(); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 PublicSessionTabCaptureAccessHandler::PublicSessionTabCaptureAccessHandler() {} |
| 30 |
| 31 PublicSessionTabCaptureAccessHandler::~PublicSessionTabCaptureAccessHandler() {} |
| 32 |
| 33 bool PublicSessionTabCaptureAccessHandler::SupportsStreamType( |
| 34 const content::MediaStreamType type, |
| 35 const extensions::Extension* extension) { |
| 36 return tab_capture_access_handler_.SupportsStreamType(type, extension); |
| 37 } |
| 38 |
| 39 bool PublicSessionTabCaptureAccessHandler::CheckMediaAccessPermission( |
| 40 content::WebContents* web_contents, |
| 41 const GURL& security_origin, |
| 42 content::MediaStreamType type, |
| 43 const extensions::Extension* extension) { |
| 44 return tab_capture_access_handler_.CheckMediaAccessPermission( |
| 45 web_contents, security_origin, type, extension); |
| 46 } |
| 47 |
| 48 void PublicSessionTabCaptureAccessHandler::HandleRequest( |
| 49 content::WebContents* web_contents, |
| 50 const content::MediaStreamRequest& request, |
| 51 const content::MediaResponseCallback& callback, |
| 52 const extensions::Extension* extension) { |
| 53 // This class handles requests for Public Sessions only, outside of them just |
| 54 // pass the request through to the original class. |
| 55 if (!IsPublicSession() || !extension) { |
| 56 return tab_capture_access_handler_.HandleRequest(web_contents, request, |
| 57 callback, extension); |
| 58 } |
| 59 |
| 60 UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| 61 |
| 62 if ((request.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && |
| 63 request.video_type != content::MEDIA_TAB_VIDEO_CAPTURE) || |
| 64 !user_choice.NeedsPrompting()) { |
| 65 return ChainHandleRequest(web_contents, request, callback, extension); |
| 66 } |
| 67 |
| 68 user_choice.SetPrompted(); |
| 69 |
| 70 extensions::APIPermissionSet new_apis; |
| 71 new_apis.insert(extensions::APIPermission::kTabCapture); |
| 72 auto permission_set = base::MakeUnique<extensions::PermissionSet>( |
| 73 new_apis, extensions::ManifestPermissionSet(), |
| 74 extensions::URLPatternSet(), extensions::URLPatternSet()); |
| 75 auto prompt = base::MakeUnique<ExtensionInstallPrompt>(web_contents); |
| 76 |
| 77 prompt->ShowDialog( |
| 78 base::Bind(&PublicSessionTabCaptureAccessHandler::ResolvePermissionPrompt, |
| 79 base::Unretained(this), web_contents, request, callback, |
| 80 extension), |
| 81 extension, |
| 82 nullptr, // Uses the extension icon. |
| 83 base::MakeUnique<ExtensionInstallPrompt::Prompt>( |
| 84 ExtensionInstallPrompt::PERMISSIONS_PROMPT), |
| 85 std::move(permission_set), |
| 86 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 87 |
| 88 extension_install_prompt_map_[extension->id()] = std::move(prompt); |
| 89 } |
| 90 |
| 91 void PublicSessionTabCaptureAccessHandler::ChainHandleRequest( |
| 92 content::WebContents* web_contents, |
| 93 const content::MediaStreamRequest& request, |
| 94 const content::MediaResponseCallback& callback, |
| 95 const extensions::Extension* extension) { |
| 96 DCHECK(IsPublicSession() && extension); |
| 97 const UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| 98 content::MediaStreamRequest request_copy(request); |
| 99 |
| 100 // If the user denied tab capture, here the request gets filtered out before |
| 101 // being passed on to the actual implementation. |
| 102 if (!user_choice.IsAllowed()) { |
| 103 request_copy.audio_type = content::MEDIA_NO_SERVICE; |
| 104 request_copy.video_type = content::MEDIA_NO_SERVICE; |
| 105 } |
| 106 |
| 107 // Pass the request through to the original class. |
| 108 tab_capture_access_handler_.HandleRequest(web_contents, request_copy, |
| 109 callback, extension); |
| 110 } |
| 111 |
| 112 void PublicSessionTabCaptureAccessHandler::ResolvePermissionPrompt( |
| 113 content::WebContents* web_contents, |
| 114 const content::MediaStreamRequest& request, |
| 115 const content::MediaResponseCallback& callback, |
| 116 const extensions::Extension* extension, |
| 117 ExtensionInstallPrompt::Result prompt_result) { |
| 118 // Dispose of the prompt as it's not needed anymore. |
| 119 extension_install_prompt_map_.erase(extension->id()); |
| 120 |
| 121 bool allowed = prompt_result == ExtensionInstallPrompt::Result::ACCEPTED; |
| 122 UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| 123 |
| 124 user_choice.Set(allowed); |
| 125 |
| 126 ChainHandleRequest(web_contents, request, callback, extension); |
| 127 } |
| 128 |
| 129 bool PublicSessionTabCaptureAccessHandler::UserChoice::IsAllowed() const { |
| 130 return tab_capture_allowed_; |
| 131 } |
| 132 |
| 133 bool PublicSessionTabCaptureAccessHandler::UserChoice::NeedsPrompting() const { |
| 134 return !tab_capture_prompted_; |
| 135 } |
| 136 |
| 137 void PublicSessionTabCaptureAccessHandler::UserChoice::Set(bool allowed) { |
| 138 tab_capture_allowed_ = allowed; |
| 139 } |
| 140 |
| 141 void PublicSessionTabCaptureAccessHandler::UserChoice::SetPrompted() { |
| 142 tab_capture_prompted_ = true; |
| 143 } |
| OLD | NEW |