| 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 extensions are installed by admin policy hence they can |
| 21 // freely use the camera and microphone without the user knowing. This is not |
| 22 // acceptable from a security/privacy standpoint so we show the user a dialog |
| 23 // where they can choose whether to allow the extension access to camera and/or |
| 24 // microphone. Note: camera and microphone are used through audioCapture and |
| 25 // videoCapture manifest permissions which are limited to platform apps only. |
| 26 class PublicSessionMediaAccessHandler : public MediaAccessHandler { |
| 27 public: |
| 28 PublicSessionMediaAccessHandler(); |
| 29 ~PublicSessionMediaAccessHandler() override; |
| 30 |
| 31 // MediaAccessHandler implementation. |
| 32 bool SupportsStreamType(const content::MediaStreamType type, |
| 33 const extensions::Extension* extension) override; |
| 34 bool CheckMediaAccessPermission( |
| 35 content::WebContents* web_contents, |
| 36 const GURL& security_origin, |
| 37 content::MediaStreamType type, |
| 38 const extensions::Extension* extension) override; |
| 39 void HandleRequest(content::WebContents* web_contents, |
| 40 const content::MediaStreamRequest& request, |
| 41 const content::MediaResponseCallback& callback, |
| 42 const extensions::Extension* extension) override; |
| 43 |
| 44 private: |
| 45 // Helper function used to chain the HandleRequest call into the original |
| 46 // inside of ExtensionMediaAccessHandler. |
| 47 void ChainHandleRequest(content::WebContents* web_contents, |
| 48 const content::MediaStreamRequest& request, |
| 49 const content::MediaResponseCallback& callback, |
| 50 const extensions::Extension* extension); |
| 51 |
| 52 // Function used to resolve user decision regarding allowing audio/video. |
| 53 void ResolvePermissionPrompt( |
| 54 content::WebContents* web_contents, |
| 55 const content::MediaStreamRequest& request, |
| 56 const content::MediaResponseCallback& callback, |
| 57 const extensions::Extension* extension, |
| 58 const std::unique_ptr<ExtensionInstallPrompt>& prompt, |
| 59 ExtensionInstallPrompt::Result prompt_result); |
| 60 |
| 61 // Class used to cache user choice regarding allowing audio/video capture. |
| 62 class UserChoice { |
| 63 public: |
| 64 // Helper function for checking if audio/video is allowed by user choice. |
| 65 bool IsAllowed(content::MediaStreamType type) const; |
| 66 // Helper function which returns true if audio/video wasn't prompted yet. |
| 67 bool NeedsPrompting(content::MediaStreamType type) const; |
| 68 void Set(content::MediaStreamType type, bool allowed); |
| 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 ExtensionMediaAccessHandler extension_media_access_handler_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(PublicSessionMediaAccessHandler); |
| 81 }; |
| 82 |
| 83 #endif // CHROME_BROWSER_MEDIA_PUBLIC_SESSION_MEDIA_ACCESS_HANDLER_H_ |
| OLD | NEW |