blob: babbf971f26fb8ea21aa941d4dc433b54d336af6 [file] [log] [blame]
guidoudf036b32016-10-31 14:51:141// 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"
guidou098908e52016-11-09 23:06:2211#include "base/macros.h"
guidoudf036b32016-10-31 14:51:1412#include "content/browser/renderer_host/media/media_devices_manager.h"
13#include "content/common/content_export.h"
14
guidoudf036b32016-10-31 14:51:1415namespace content {
16
17// This class provides various utility functions to check if a render frame
18// has permission to access media devices. Note that none of the methods
19// prompts the user to request permission.
20class CONTENT_EXPORT MediaDevicesPermissionChecker {
21 public:
22 MediaDevicesPermissionChecker();
guidou098908e52016-11-09 23:06:2223 // This constructor creates a MediaDevicesPermissionChecker that replies
24 // |override_value| to all permission requests. Use only for testing.
25 explicit MediaDevicesPermissionChecker(bool override_value);
guidoudf036b32016-10-31 14:51:1426
guidoua72075a2017-05-15 08:36:1727 // Checks if the origin associated to a render frame identified by
28 // |render_process_id| and |render_frame_id| is allowed to access the media
29 // device type |device_type|.
guidoudf036b32016-10-31 14:51:1430 // This method must be called on the UI thread.
31 bool CheckPermissionOnUIThread(MediaDeviceType device_type,
32 int render_process_id,
guidoua72075a2017-05-15 08:36:1733 int render_frame_id) const;
guidoudf036b32016-10-31 14:51:1434
guidoua72075a2017-05-15 08:36:1735 // Checks if the origin associated to a render frame identified by
36 // |render_process_id| and |render_frame_id| is allowed to access the media
37 // device type |device_type|. The result is passed to |callback|.
guidoudf036b32016-10-31 14:51:1438 // This method can be called on any thread. |callback| is fired on the same
39 // thread this method is called on.
40 void CheckPermission(MediaDeviceType device_type,
41 int render_process_id,
42 int render_frame_id,
maxmorinfd2012282017-05-16 10:30:5543 base::OnceCallback<void(bool)> callback) const;
guidoudf036b32016-10-31 14:51:1444
guidoua72075a2017-05-15 08:36:1745 // Checks if the origin associated to a render frame identified by
46 // |render_process_id| and |render_frame_id| is allowed to access the media
47 // device types marked with a value of true in |requested_device_types|. The
48 // result is passed to |callback|. The result is indexed by MediaDeviceType.
49 // Entries in the result with a value of true for requested device types
50 // indicate that the frame has permission to access devices of the
51 // corresponding types.
guidoudf036b32016-10-31 14:51:1452 // This method can be called on any thread. |callback| is fired on the same
53 // thread this method is called on.
54 void CheckPermissions(
55 MediaDevicesManager::BoolDeviceTypes requested_device_types,
56 int render_process_id,
57 int render_frame_id,
maxmorinfd2012282017-05-16 10:30:5558 base::OnceCallback<void(const MediaDevicesManager::BoolDeviceTypes&)>
guidou098908e52016-11-09 23:06:2259 callback) const;
guidoudf036b32016-10-31 14:51:1460
61 private:
guidou098908e52016-11-09 23:06:2262 const bool use_override_;
63 const bool override_value_;
64
65 DISALLOW_COPY_AND_ASSIGN(MediaDevicesPermissionChecker);
guidoudf036b32016-10-31 14:51:1466};
67
68} // namespace content
69
70#endif // CONTENT_BROWSER_MEDIA_MEDIA_DEVICES_PERMISSION_CHECKER_H_