| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_WEBRTC_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER_H_ | 6 #define CHROME_BROWSER_MEDIA_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/media/capture_access_handler_base.h" | 10 #include "chrome/browser/media/capture_access_handler_base.h" |
| 11 #include "chrome/browser/media/webrtc/tab_capture_access_handler.h" | 11 #include "chrome/browser/media/webrtc/tab_capture_access_handler.h" |
| 12 #include "content/public/common/media_stream_request.h" | 12 #include "content/public/common/media_stream_request.h" |
| 13 #include "extensions/common/extension_id.h" | 13 #include "extensions/common/extension_id.h" |
| 14 #include "extensions/common/permissions/api_permission_set.h" |
| 14 | 15 |
| 15 // MediaAccessHandler for TabCapture API in Public Sessions. This class is | 16 // MediaAccessHandler for TabCapture API in Public Sessions. This class is |
| 16 // implemented as a wrapper around TabCaptureAccessHandler. It allows for finer | 17 // implemented as a wrapper around TabCaptureAccessHandler. It allows for finer |
| 17 // access control to the TabCapture manifest permission feature inside of Public | 18 // access control to the TabCapture manifest permission feature inside of Public |
| 18 // Sessions. | 19 // Sessions. |
| 19 // | 20 // |
| 20 // In Public Sessions, extensions (and apps) are force-installed by admin policy | 21 // In Public Sessions, extensions (and apps) are force-installed by admin policy |
| 21 // so the user does not get a chance to review the permissions for these | 22 // so the user does not get a chance to review the permissions for these |
| 22 // extensions. This is not acceptable from a security/privacy standpoint, so | 23 // extensions. This is not acceptable from a security/privacy standpoint, so |
| 23 // when an extension uses the TabCapture API for the first time, we show the | 24 // when an extension uses the TabCapture API for the first time, we show the |
| 24 // user a dialog where they can choose whether to allow the extension access to | 25 // user a dialog where they can choose whether to allow the extension access to |
| 25 // the API. | 26 // the API. |
| 26 // | |
| 27 // TODO(isandrk): Refactor common code out of this class and | |
| 28 // PublicSessionMediaAccessHandler (crbug.com/672620). | |
| 29 class PublicSessionTabCaptureAccessHandler : public CaptureAccessHandlerBase { | 27 class PublicSessionTabCaptureAccessHandler : public CaptureAccessHandlerBase { |
| 30 public: | 28 public: |
| 31 PublicSessionTabCaptureAccessHandler(); | 29 PublicSessionTabCaptureAccessHandler(); |
| 32 ~PublicSessionTabCaptureAccessHandler() override; | 30 ~PublicSessionTabCaptureAccessHandler() override; |
| 33 | 31 |
| 34 // MediaAccessHandler implementation. | 32 // MediaAccessHandler implementation. |
| 35 bool SupportsStreamType(const content::MediaStreamType type, | 33 bool SupportsStreamType(const content::MediaStreamType type, |
| 36 const extensions::Extension* extension) override; | 34 const extensions::Extension* extension) override; |
| 37 bool CheckMediaAccessPermission( | 35 bool CheckMediaAccessPermission( |
| 38 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
| 39 const GURL& security_origin, | 37 const GURL& security_origin, |
| 40 content::MediaStreamType type, | 38 content::MediaStreamType type, |
| 41 const extensions::Extension* extension) override; | 39 const extensions::Extension* extension) override; |
| 42 void HandleRequest(content::WebContents* web_contents, | 40 void HandleRequest(content::WebContents* web_contents, |
| 43 const content::MediaStreamRequest& request, | 41 const content::MediaStreamRequest& request, |
| 44 const content::MediaResponseCallback& callback, | 42 const content::MediaResponseCallback& callback, |
| 45 const extensions::Extension* extension) override; | 43 const extensions::Extension* extension) override; |
| 46 | 44 |
| 47 private: | 45 private: |
| 48 // Helper function used to chain the HandleRequest call into the original | 46 // Helper function used to chain the HandleRequest call into the original |
| 49 // inside of TabCaptureAccessHandler. | 47 // inside of TabCaptureAccessHandler. |
| 50 void ChainHandleRequest(content::WebContents* web_contents, | 48 void ChainHandleRequest( |
| 51 const content::MediaStreamRequest& request, | 49 content::WebContents* web_contents, |
| 52 const content::MediaResponseCallback& callback, | 50 const content::MediaStreamRequest& request, |
| 53 const extensions::Extension* extension); | 51 const content::MediaResponseCallback& callback, |
| 52 const extensions::Extension* extension, |
| 53 const extensions::PermissionIDSet& allowed_permissions); |
| 54 | 54 |
| 55 // Function used to resolve user decision regarding allowing tab capture. | |
| 56 void ResolvePermissionPrompt(content::WebContents* web_contents, | |
| 57 const content::MediaStreamRequest& request, | |
| 58 const content::MediaResponseCallback& callback, | |
| 59 const extensions::Extension* extension, | |
| 60 ExtensionInstallPrompt::Result prompt_result); | |
| 61 | |
| 62 // Class used to cache user choice regarding allowing tab capture. | |
| 63 class UserChoice { | |
| 64 public: | |
| 65 // Helper function for checking if tab capture is allowed by user choice. | |
| 66 bool IsAllowed() const; | |
| 67 // Helper function which returns true if user choice wasn't prompted yet. | |
| 68 bool NeedsPrompting() const; | |
| 69 void Set(bool allowed); | |
| 70 void SetPrompted(); | |
| 71 | |
| 72 private: | |
| 73 bool tab_capture_prompted_ = false; | |
| 74 bool tab_capture_allowed_ = false; | |
| 75 }; | |
| 76 | |
| 77 std::map<extensions::ExtensionId, UserChoice> user_choice_cache_; | |
| 78 std::map<extensions::ExtensionId, std::unique_ptr<ExtensionInstallPrompt>> | |
| 79 extension_install_prompt_map_; | |
| 80 TabCaptureAccessHandler tab_capture_access_handler_; | 55 TabCaptureAccessHandler tab_capture_access_handler_; |
| 81 | 56 |
| 82 DISALLOW_COPY_AND_ASSIGN(PublicSessionTabCaptureAccessHandler); | 57 DISALLOW_COPY_AND_ASSIGN(PublicSessionTabCaptureAccessHandler); |
| 83 }; | 58 }; |
| 84 | 59 |
| 85 #endif // CHROME_BROWSER_MEDIA_WEBRTC_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER
_H_ | 60 #endif // CHROME_BROWSER_MEDIA_PUBLIC_SESSION_TAB_CAPTURE_ACCESS_HANDLER_H_ |
| OLD | NEW |