| 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 #ifndef CHROME_BROWSER_MEDIA_PUBLIC_SESSION_MEDIA_ACCESS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_PUBLIC_SESSION_MEDIA_ACCESS_HANDLER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/media/extension_media_access_handler.h" |
| 11 #include "chrome/browser/media/media_access_handler.h" |
| 12 #include "content/public/common/media_stream_request.h" |
| 13 #include "extensions/common/extension_id.h" |
| 14 |
| 15 // MediaAccessHandler for extension capturing requests in Public Sessions. This |
| 16 // class is implemented as a wrapper around ExtensionMediaAccessHandler. It |
| 17 // allows for finer access control to audioCapture/videoCapture manifest |
| 18 // permission features inside of Public Sessions. |
| 19 // |
| 20 // In Public Sessions, apps and extensions are force-installed by admin policy |
| 21 // so the user does not get a chance to review the permissions for these apps. |
| 22 // This is not acceptable from a security/privacy standpoint, so when an app |
| 23 // uses the capture APIs for the first time, we show the user a dialog where |
| 24 // they can choose whether to allow the extension access to camera and/or |
| 25 // microphone. Note: camera and microphone are used through audioCapture and |
| 26 // videoCapture manifest permissions which are limited to platform apps only. |
| 27 class PublicSessionMediaAccessHandler : public MediaAccessHandler { |
| 28 public: |
| 29 PublicSessionMediaAccessHandler(); |
| 30 ~PublicSessionMediaAccessHandler() override; |
| 31 |
| 32 // MediaAccessHandler implementation. |
| 33 bool SupportsStreamType(const content::MediaStreamType type, |
| 34 const extensions::Extension* extension) override; |
| 35 bool CheckMediaAccessPermission( |
| 36 content::WebContents* web_contents, |
| 37 const GURL& security_origin, |
| 38 content::MediaStreamType type, |
| 39 const extensions::Extension* extension) override; |
| 40 void HandleRequest(content::WebContents* web_contents, |
| 41 const content::MediaStreamRequest& request, |
| 42 const content::MediaResponseCallback& callback, |
| 43 const extensions::Extension* extension) override; |
| 44 |
| 45 private: |
| 46 // Helper function used to chain the HandleRequest call into the original |
| 47 // inside of ExtensionMediaAccessHandler. |
| 48 void ChainHandleRequest(content::WebContents* web_contents, |
| 49 const content::MediaStreamRequest& request, |
| 50 const content::MediaResponseCallback& callback, |
| 51 const extensions::Extension* extension); |
| 52 |
| 53 // Function used to resolve user decision regarding allowing audio/video. |
| 54 void ResolvePermissionPrompt(content::WebContents* web_contents, |
| 55 const content::MediaStreamRequest& request, |
| 56 const content::MediaResponseCallback& callback, |
| 57 const extensions::Extension* extension, |
| 58 ExtensionInstallPrompt::Result prompt_result); |
| 59 |
| 60 // Class used to cache user choice regarding allowing audio/video capture. |
| 61 class UserChoice { |
| 62 public: |
| 63 // Helper function for checking if audio/video is allowed by user choice. |
| 64 bool IsAllowed(content::MediaStreamType type) const; |
| 65 // Helper function which returns true if audio/video wasn't prompted yet. |
| 66 bool NeedsPrompting(content::MediaStreamType type) const; |
| 67 void Set(content::MediaStreamType type, bool allowed); |
| 68 void SetPrompted(content::MediaStreamType type); |
| 69 |
| 70 private: |
| 71 bool audio_prompted_ = false; |
| 72 bool audio_allowed_ = false; |
| 73 bool video_prompted_ = false; |
| 74 bool video_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 ExtensionMediaAccessHandler extension_media_access_handler_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(PublicSessionMediaAccessHandler); |
| 83 }; |
| 84 |
| 85 #endif // CHROME_BROWSER_MEDIA_PUBLIC_SESSION_MEDIA_ACCESS_HANDLER_H_ |
| OLD | NEW |