Chromium Code Reviews| Index: chrome/browser/media/webrtc/public_session_tab_capture_access_handler.cc |
| diff --git a/chrome/browser/media/webrtc/public_session_tab_capture_access_handler.cc b/chrome/browser/media/webrtc/public_session_tab_capture_access_handler.cc |
| index 65e2d33159f6fae40a6111a5502a2bd4e5671386..75274c668224c89023ee624d87b767da08d6f731 100644 |
| --- a/chrome/browser/media/webrtc/public_session_tab_capture_access_handler.cc |
| +++ b/chrome/browser/media/webrtc/public_session_tab_capture_access_handler.cc |
| @@ -9,6 +9,8 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/memory/ptr_util.h" |
| +#include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" |
| +#include "chrome/browser/profiles/profiles_state.h" |
| #include "chromeos/login/login_state.h" |
| #include "content/public/browser/web_contents.h" |
| #include "extensions/common/extension.h" |
| @@ -16,16 +18,6 @@ |
| #include "extensions/common/permissions/permission_set.h" |
| #include "extensions/common/url_pattern_set.h" |
| -namespace { |
| - |
| -// Returns true if we're in a Public Session. |
| -bool IsPublicSession() { |
| - return chromeos::LoginState::IsInitialized() && |
| - chromeos::LoginState::Get()->IsPublicSessionUser(); |
| -} |
| - |
| -} // namespace |
| - |
| PublicSessionTabCaptureAccessHandler::PublicSessionTabCaptureAccessHandler() {} |
| PublicSessionTabCaptureAccessHandler::~PublicSessionTabCaptureAccessHandler() {} |
| @@ -52,54 +44,36 @@ void PublicSessionTabCaptureAccessHandler::HandleRequest( |
| const extensions::Extension* extension) { |
| // This class handles requests for Public Sessions only, outside of them just |
| // pass the request through to the original class. |
| - if (!IsPublicSession() || !extension) { |
| + if (!profiles::IsPublicSession() || !extension || |
| + (request.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && |
| + request.video_type != content::MEDIA_TAB_VIDEO_CAPTURE)) { |
| return tab_capture_access_handler_.HandleRequest(web_contents, request, |
| callback, extension); |
| } |
| - UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| - |
| - if ((request.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && |
| - request.video_type != content::MEDIA_TAB_VIDEO_CAPTURE) || |
| - !user_choice.NeedsPrompting()) { |
| - return ChainHandleRequest(web_contents, request, callback, extension); |
| - } |
| - |
| - user_choice.SetPrompted(); |
| + // This Unretained is safe because the lifetime of this object is until |
| + // process exit (living inside a base::Singleton object). |
| + auto prompt_resolved_callback = base::Bind( |
| + &PublicSessionTabCaptureAccessHandler::ChainHandleRequest, |
| + base::Unretained(this), web_contents, request, callback, extension); |
| - extensions::APIPermissionSet new_apis; |
| - new_apis.insert(extensions::APIPermission::kTabCapture); |
| - auto permission_set = base::MakeUnique<extensions::PermissionSet>( |
| - new_apis, extensions::ManifestPermissionSet(), |
| - extensions::URLPatternSet(), extensions::URLPatternSet()); |
| - auto prompt = base::MakeUnique<ExtensionInstallPrompt>(web_contents); |
| - |
| - prompt->ShowDialog( |
| - base::Bind(&PublicSessionTabCaptureAccessHandler::ResolvePermissionPrompt, |
| - base::Unretained(this), web_contents, request, callback, |
| - extension), |
| - extension, |
| - nullptr, // Uses the extension icon. |
| - base::MakeUnique<ExtensionInstallPrompt::Prompt>( |
| - ExtensionInstallPrompt::PERMISSIONS_PROMPT), |
| - std::move(permission_set), |
| - ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| - |
| - extension_install_prompt_map_[extension->id()] = std::move(prompt); |
| + extensions::permission_helper::HandlePermissionRequest( |
| + *extension, {extensions::APIPermission::kTabCapture}, web_contents, |
| + prompt_resolved_callback); |
| } |
| void PublicSessionTabCaptureAccessHandler::ChainHandleRequest( |
| content::WebContents* web_contents, |
| const content::MediaStreamRequest& request, |
| const content::MediaResponseCallback& callback, |
| - const extensions::Extension* extension) { |
| - DCHECK(IsPublicSession() && extension); |
| - const UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| + const extensions::Extension* extension, |
| + extensions::PermissionIDSet allowed_permissions) { |
| + DCHECK(profiles::IsPublicSession() && extension); |
|
Andrew T Wilson (Slow)
2017/02/07 14:26:51
BTW, if this DCHECK is hit, it won't be clear whic
Ivan Šandrk
2017/02/07 20:41:32
Good point. Though I've decided to completely remo
|
| content::MediaStreamRequest request_copy(request); |
| // If the user denied tab capture, here the request gets filtered out before |
| // being passed on to the actual implementation. |
| - if (!user_choice.IsAllowed()) { |
| + if (!allowed_permissions.ContainsID(extensions::APIPermission::kTabCapture)) { |
| request_copy.audio_type = content::MEDIA_NO_SERVICE; |
| request_copy.video_type = content::MEDIA_NO_SERVICE; |
| } |
| @@ -108,36 +82,3 @@ void PublicSessionTabCaptureAccessHandler::ChainHandleRequest( |
| tab_capture_access_handler_.HandleRequest(web_contents, request_copy, |
| callback, extension); |
| } |
| - |
| -void PublicSessionTabCaptureAccessHandler::ResolvePermissionPrompt( |
| - content::WebContents* web_contents, |
| - const content::MediaStreamRequest& request, |
| - const content::MediaResponseCallback& callback, |
| - const extensions::Extension* extension, |
| - ExtensionInstallPrompt::Result prompt_result) { |
| - // Dispose of the prompt as it's not needed anymore. |
| - extension_install_prompt_map_.erase(extension->id()); |
| - |
| - bool allowed = prompt_result == ExtensionInstallPrompt::Result::ACCEPTED; |
| - UserChoice& user_choice = user_choice_cache_[extension->id()]; |
| - |
| - user_choice.Set(allowed); |
| - |
| - ChainHandleRequest(web_contents, request, callback, extension); |
| -} |
| - |
| -bool PublicSessionTabCaptureAccessHandler::UserChoice::IsAllowed() const { |
| - return tab_capture_allowed_; |
| -} |
| - |
| -bool PublicSessionTabCaptureAccessHandler::UserChoice::NeedsPrompting() const { |
| - return !tab_capture_prompted_; |
| -} |
| - |
| -void PublicSessionTabCaptureAccessHandler::UserChoice::Set(bool allowed) { |
| - tab_capture_allowed_ = allowed; |
| -} |
| - |
| -void PublicSessionTabCaptureAccessHandler::UserChoice::SetPrompted() { |
| - tab_capture_prompted_ = true; |
| -} |