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