Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: content/browser/media/media_devices_permission_checker.h

Issue 2436113002: Introduce MediaDevicesPermissionChecker. (Closed)
Patch Set: address xhwang's comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/media/media_devices_permission_checker.h
diff --git a/content/browser/media/media_devices_permission_checker.h b/content/browser/media/media_devices_permission_checker.h
new file mode 100644
index 0000000000000000000000000000000000000000..a8c4ca0bc8b1ea68ea4f9bb2e34c27eaca0ab07c
--- /dev/null
+++ b/content/browser/media/media_devices_permission_checker.h
@@ -0,0 +1,90 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_
+#define CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_
+
+#include <memory>
+
+#include "base/callback.h"
+#include "content/browser/renderer_host/media/media_devices_manager.h"
+#include "content/common/content_export.h"
+
+namespace url {
+class Origin;
+}
+
+namespace content {
+
+// This class provides various utility functions to check if a render frame
+// has permission to access media devices. Note that none of the methods
+// prompts the user to request permission.
+class CONTENT_EXPORT MediaDevicesPermissionChecker {
+ public:
+ MediaDevicesPermissionChecker();
+
+ // Checks if the origin |security_origin| associated to a render frame
+ // identified by |render_process_id| and |render_frame_id| is allowed to
+ // access the media device type |device_type|.
+ // This method must be called on the UI thread.
+ bool CheckPermissionOnUIThread(MediaDeviceType device_type,
+ int render_process_id,
+ int render_frame_id,
+ const url::Origin& security_origin);
+
+ // Checks if the origin |security_origin| associated to a render frame
+ // identified by |render_process_id| and |render_frame_id| is allowed to
+ // access the media device type |device_type|. The result is passed to
+ // |callback|.
+ // This method can be called on any thread. |callback| is fired on the same
+ // thread this method is called on.
+ void CheckPermission(MediaDeviceType device_type,
+ int render_process_id,
+ int render_frame_id,
+ const url::Origin& security_origin,
+ const base::Callback<void(bool)>& callback);
+
+ // Checks if the origin |security_origin| associated to a render frame
+ // identified by |render_process_id| and |render_frame_id| is allowed to
+ // access the media device types marked with a value of true in
+ // |requested_device_types|. The result is indexed by MediaDeviceType.
+ // Entries in the result with a value of true for requested device types
+ // indicate that the frame has permission to access devices of the
+ // corresponding types.
+ // This method must be called on the UI thread.
+ MediaDevicesManager::BoolDeviceTypes CheckPermissionsOnUIThread(
+ MediaDevicesManager::BoolDeviceTypes requested_device_types,
+ int render_process_id,
+ int render_frame_id,
+ const url::Origin& security_origin);
+
+ // Checks if the origin |security_origin| associated to a render frame
+ // identified by |render_process_id| and |render_frame_id| is allowed to
+ // access the media device types marked with a value of true in
+ // |requested_device_types|. The result is passed to |callback|. The result is
+ // indexed by MediaDeviceType. Entries in the result with a value of true for
+ // requested device types indicate that the frame has permission to access
+ // devices of the corresponding types.
+ // This method can be called on any thread. |callback| is fired on the same
+ // thread this method is called on.
+ void CheckPermissions(
+ MediaDevicesManager::BoolDeviceTypes requested_device_types,
+ int render_process_id,
+ int render_frame_id,
+ const url::Origin& security_origin,
+ const base::Callback<void(const MediaDevicesManager::BoolDeviceTypes&)>&
+ callback);
+
+ // Forces a specific value to be returned by the permission-checking functions
+ // for all device types. Use only for testing.
+ void OverridePermissionsForTesting(bool override_value);
+
+ private:
+ bool use_override_;
+ bool override_value_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/media/media_devices_permission_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698