| 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 CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 12 #include "content/common/content_export.h" |
| 13 |
| 14 namespace url { |
| 15 class Origin; |
| 16 } |
| 17 |
| 18 namespace content { |
| 19 |
| 20 // This class provides various utility functions to check if a render frame |
| 21 // has permission to access media devices. Note that none of the methods |
| 22 // prompts the user to request permission. |
| 23 class CONTENT_EXPORT MediaDevicesPermissionChecker { |
| 24 public: |
| 25 MediaDevicesPermissionChecker(); |
| 26 |
| 27 // Checks if the origin |security_origin| associated to a render frame |
| 28 // identified by |render_process_id| and |render_frame_id| is allowed to |
| 29 // access the media device type |device_type|. |
| 30 // This method must be called on the UI thread. |
| 31 bool CheckPermissionOnUIThread(MediaDeviceType device_type, |
| 32 int render_process_id, |
| 33 int render_frame_id, |
| 34 const url::Origin& security_origin); |
| 35 |
| 36 // Checks if the origin |security_origin| associated to a render frame |
| 37 // identified by |render_process_id| and |render_frame_id| is allowed to |
| 38 // access the media device type |device_type|. The result is passed to |
| 39 // |callback|. |
| 40 // This method can be called on any thread. |callback| is fired on the same |
| 41 // thread this method is called on. |
| 42 void CheckPermission(MediaDeviceType device_type, |
| 43 int render_process_id, |
| 44 int render_frame_id, |
| 45 const url::Origin& security_origin, |
| 46 const base::Callback<void(bool)>& callback); |
| 47 |
| 48 // Checks if the origin |security_origin| associated to a render frame |
| 49 // identified by |render_process_id| and |render_frame_id| is allowed to |
| 50 // access the media device types marked with a value of true in |
| 51 // |requested_device_types|. The result is indexed by MediaDeviceType. |
| 52 // Entries in the result with a value of true for requested device types |
| 53 // indicate that the frame has permission to access devices of the |
| 54 // corresponding types. |
| 55 // This method must be called on the UI thread. |
| 56 MediaDevicesManager::BoolDeviceTypes CheckPermissionsOnUIThread( |
| 57 MediaDevicesManager::BoolDeviceTypes requested_device_types, |
| 58 int render_process_id, |
| 59 int render_frame_id, |
| 60 const url::Origin& security_origin); |
| 61 |
| 62 // Checks if the origin |security_origin| associated to a render frame |
| 63 // identified by |render_process_id| and |render_frame_id| is allowed to |
| 64 // access the media device types marked with a value of true in |
| 65 // |requested_device_types|. The result is passed to |callback|. The result is |
| 66 // indexed by MediaDeviceType. Entries in the result with a value of true for |
| 67 // requested device types indicate that the frame has permission to access |
| 68 // devices of the corresponding types. |
| 69 // This method can be called on any thread. |callback| is fired on the same |
| 70 // thread this method is called on. |
| 71 void CheckPermissions( |
| 72 MediaDevicesManager::BoolDeviceTypes requested_device_types, |
| 73 int render_process_id, |
| 74 int render_frame_id, |
| 75 const url::Origin& security_origin, |
| 76 const base::Callback<void(const MediaDevicesManager::BoolDeviceTypes&)>& |
| 77 callback); |
| 78 |
| 79 // Forces a specific value to be returned by the permission-checking functions |
| 80 // for all device types. Use only for testing. |
| 81 void OverridePermissionsForTesting(bool override_value); |
| 82 |
| 83 private: |
| 84 bool use_override_; |
| 85 bool override_value_; |
| 86 }; |
| 87 |
| 88 } // namespace content |
| 89 |
| 90 #endif // CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_ |
| OLD | NEW |