OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ |
7 | 7 |
8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
9 #include "content/public/common/permission_status.mojom.h" | 9 #include "content/public/common/permission_status.mojom.h" |
10 | 10 |
11 class GURL; | 11 class GURL; |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 enum class PermissionType; | 14 enum class PermissionType; |
15 class RenderFrameHost; | 15 class RenderFrameHost; |
16 | 16 |
17 // This class allows the content layer to manipulate permissions. It has to be | 17 // This class allows the content layer to manipulate permissions. It has to be |
18 // implemented by the embedder which ultimately handles the permission | 18 // implemented by the embedder which ultimately handles the permission |
19 // management for the content layer. | 19 // management for the content layer. |
20 class CONTENT_EXPORT PermissionManager { | 20 class CONTENT_EXPORT PermissionManager { |
21 public: | 21 public: |
22 virtual ~PermissionManager() = default; | 22 virtual ~PermissionManager() = default; |
23 | 23 |
24 // Requests a permission on behalf of a frame identified by render_frame_host. | 24 // Requests a permission on behalf of a frame identified by |
25 // The |request_id| is an identifier that can later be used if the request is | 25 // render_frame_host. |
26 // cancelled (see CancelPermissionRequest). | |
27 // When the permission request is handled, whether it failed, timed out or | 26 // When the permission request is handled, whether it failed, timed out or |
28 // succeeded, the |callback| will be run. | 27 // succeeded, the |callback| will be run. |
29 virtual void RequestPermission( | 28 // Returns a request id which can be used to cancel the permission (see |
| 29 // CancelPermissionRequest). This can be kNoPendingOperation if |
| 30 // there is no further need to cancel the permission in which case |callback| |
| 31 // was invoked. |
| 32 virtual int RequestPermission( |
30 PermissionType permission, | 33 PermissionType permission, |
31 RenderFrameHost* render_frame_host, | 34 RenderFrameHost* render_frame_host, |
32 int request_id, | |
33 const GURL& requesting_origin, | 35 const GURL& requesting_origin, |
34 bool user_gesture, | 36 bool user_gesture, |
35 const base::Callback<void(PermissionStatus)>& callback) = 0; | 37 const base::Callback<void(PermissionStatus)>& callback) = 0; |
36 | 38 |
37 // Cancels a previously requested permission. The given parameter must match | 39 // Cancels a previously requested permission. The given parameter must match |
38 // the ones passed to the RequestPermission call. | 40 // the ones passed to the RequestPermission call. |
39 virtual void CancelPermissionRequest(PermissionType permission, | 41 virtual void CancelPermissionRequest(PermissionType permission, |
40 RenderFrameHost* render_frame_host, | 42 RenderFrameHost* render_frame_host, |
41 int request_id, | 43 int request_id, |
42 const GURL& requesting_origin) = 0; | 44 const GURL& requesting_origin) = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
56 const GURL& embedding_origin) = 0; | 58 const GURL& embedding_origin) = 0; |
57 | 59 |
58 // Registers a permission usage. | 60 // Registers a permission usage. |
59 // TODO(mlamouri): see if we can remove this from the PermissionManager. | 61 // TODO(mlamouri): see if we can remove this from the PermissionManager. |
60 virtual void RegisterPermissionUsage(PermissionType permission, | 62 virtual void RegisterPermissionUsage(PermissionType permission, |
61 const GURL& requesting_origin, | 63 const GURL& requesting_origin, |
62 const GURL& embedding_origin) = 0; | 64 const GURL& embedding_origin) = 0; |
63 | 65 |
64 // Runs the given |callback| whenever the |permission| associated with the | 66 // Runs the given |callback| whenever the |permission| associated with the |
65 // pair { requesting_origin, embedding_origin } changes. | 67 // pair { requesting_origin, embedding_origin } changes. |
66 // Returns the subscription_id to be used to unsubscribe. | 68 // Returns the subscription_id to be used to unsubscribe. Can be |
| 69 // kNoPendingOperation if the subscribe was not successful. |
67 virtual int SubscribePermissionStatusChange( | 70 virtual int SubscribePermissionStatusChange( |
68 PermissionType permission, | 71 PermissionType permission, |
69 const GURL& requesting_origin, | 72 const GURL& requesting_origin, |
70 const GURL& embedding_origin, | 73 const GURL& embedding_origin, |
71 const base::Callback<void(PermissionStatus)>& callback) = 0; | 74 const base::Callback<void(PermissionStatus)>& callback) = 0; |
72 | 75 |
73 // Unregisters from permission status change notifications. | 76 // Unregisters from permission status change notifications. |
74 // The |subscription_id| must match the value returned by the | 77 // The |subscription_id| must match the value returned by the |
75 // SubscribePermissionStatusChange call. | 78 // SubscribePermissionStatusChange call. Unsubscribing |
| 79 // an already unsubscribed |subscription_id| or providing the |
| 80 // |subscription_id| kNoPendingOperation is a no-op. |
76 virtual void UnsubscribePermissionStatusChange(int subscription_id) = 0; | 81 virtual void UnsubscribePermissionStatusChange(int subscription_id) = 0; |
| 82 |
| 83 // Constant retured when registering and subscribing if |
| 84 // cancelling/unsubscribing at a later stage would have no effect. |
| 85 static const int kNoPendingOperation = -1; |
77 }; | 86 }; |
78 | 87 |
79 } // namespace content | 88 } // namespace content |
80 | 89 |
81 #endif // CONTENT_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ | 90 #endif // CONTENT_PUBLIC_BROWSER_PERMISSION_MANAGER_H_ |
OLD | NEW |