OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/browser/permissions/permission_service_context.h" | 11 #include "content/browser/permissions/permission_service_context.h" |
12 #include "content/common/permission_service.mojom.h" | 12 #include "content/common/permission_service.mojom.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 enum class PermissionType; | 16 enum class PermissionType; |
17 | 17 |
18 // Implements the PermissionService Mojo interface. | 18 // Implements the PermissionService Mojo interface. |
19 // This service can be created from a RenderFrameHost or a RenderProcessHost. | 19 // This service can be created from a RenderFrameHost or a RenderProcessHost. |
20 // It is owned by a PermissionServiceContext. | 20 // It is owned by a PermissionServiceContext. |
21 // It receives at PermissionServiceContext instance when created which allows it | 21 // It receives at PermissionServiceContext instance when created which allows it |
22 // to have some information about the current context. That enables the service | 22 // to have some information about the current context. That enables the service |
23 // to know whether it can show UI and have knowledge of the associated | 23 // to know whether it can show UI and have knowledge of the associated |
24 // WebContents for example. | 24 // WebContents for example. |
25 class PermissionServiceImpl : public mojo::InterfaceImpl<PermissionService> { | 25 class PermissionServiceImpl : public mojo::InterfaceImpl<PermissionService> { |
26 public: | 26 public: |
27 ~PermissionServiceImpl() override; | 27 ~PermissionServiceImpl() override; |
28 | 28 |
29 // Clear pending permissions associated with a given frame and request the | 29 // Clear pending operations currently run by the service. This will be called |
30 // browser to cancel the permission requests. | 30 // by PermissionServiceContext when it will need the service to clear its |
31 void CancelPendingRequests(); | 31 // state for example, if the frame changes. |
| 32 void CancelPendingOperations(); |
32 | 33 |
33 protected: | 34 protected: |
34 friend PermissionServiceContext; | 35 friend PermissionServiceContext; |
35 | 36 |
36 PermissionServiceImpl(PermissionServiceContext* context); | 37 PermissionServiceImpl(PermissionServiceContext* context); |
37 | 38 |
38 private: | 39 private: |
| 40 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; |
| 41 |
39 struct PendingRequest { | 42 struct PendingRequest { |
40 PendingRequest(PermissionType permission, const GURL& origin, | 43 PendingRequest(PermissionType permission, const GURL& origin, |
41 const mojo::Callback<void(PermissionStatus)>& callback); | 44 const PermissionStatusCallback& callback); |
42 ~PendingRequest(); | 45 ~PendingRequest(); |
43 | 46 |
44 PermissionType permission; | 47 PermissionType permission; |
45 GURL origin; | 48 GURL origin; |
46 mojo::Callback<void(PermissionStatus)> callback; | 49 PermissionStatusCallback callback; |
47 }; | 50 }; |
48 typedef IDMap<PendingRequest, IDMapOwnPointer> RequestsMap; | 51 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
| 52 |
| 53 struct PendingSubscription { |
| 54 PendingSubscription(PermissionType permission, const GURL& origin, |
| 55 const PermissionStatusCallback& callback); |
| 56 ~PendingSubscription(); |
| 57 |
| 58 PermissionType permission; |
| 59 GURL origin; |
| 60 PermissionStatusCallback callback; |
| 61 }; |
| 62 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; |
49 | 63 |
50 // PermissionService. | 64 // PermissionService. |
51 void HasPermission( | 65 void HasPermission(PermissionName permission, |
52 PermissionName permission, | 66 const mojo::String& origin, |
53 const mojo::String& origin, | 67 const PermissionStatusCallback& callback) override; |
54 const mojo::Callback<void(PermissionStatus)>& callback) override; | 68 void RequestPermission(PermissionName permission, |
55 void RequestPermission( | 69 const mojo::String& origin, |
56 PermissionName permission, | 70 bool user_gesture, |
57 const mojo::String& origin, | 71 const PermissionStatusCallback& callback) override; |
58 bool user_gesture, | 72 void RevokePermission(PermissionName permission, |
59 const mojo::Callback<void(PermissionStatus)>& callback) override; | 73 const mojo::String& origin, |
60 void RevokePermission( | 74 const PermissionStatusCallback& callback) override; |
61 PermissionName permission, | |
62 const mojo::String& origin, | |
63 const mojo::Callback<void(PermissionStatus)>& callback) override; | |
64 void GetNextPermissionChange( | 75 void GetNextPermissionChange( |
65 PermissionName permission, | 76 PermissionName permission, |
66 const mojo::String& origin, | 77 const mojo::String& origin, |
67 PermissionStatus last_known_status, | 78 PermissionStatus last_known_status, |
68 const mojo::Callback<void(PermissionStatus)>& callback) override; | 79 const PermissionStatusCallback& callback) override; |
69 | 80 |
70 // mojo::InterfaceImpl. | 81 // mojo::InterfaceImpl. |
71 void OnConnectionError() override; | 82 void OnConnectionError() override; |
72 | 83 |
73 void OnRequestPermissionResponse( | 84 void OnRequestPermissionResponse(int request_id, PermissionStatus status); |
74 int request_id, | |
75 PermissionStatus status); | |
76 | 85 |
77 PermissionStatus GetPermissionStatusFromName(PermissionName permission, | 86 PermissionStatus GetPermissionStatusFromName(PermissionName permission, |
78 const GURL& origin); | 87 const GURL& origin); |
79 PermissionStatus GetPermissionStatusFromType(PermissionType type, | 88 PermissionStatus GetPermissionStatusFromType(PermissionType type, |
80 const GURL& origin); | 89 const GURL& origin); |
81 void ResetPermissionStatus(PermissionType type, const GURL& origin); | 90 void ResetPermissionStatus(PermissionType type, const GURL& origin); |
82 | 91 |
83 void OnPermissionStatusChanged( | 92 void OnPermissionStatusChanged(const int* subscription_id, |
84 const mojo::Callback<void(PermissionStatus)>& callback, | 93 PermissionStatus status); |
85 const int* subscription_id, | |
86 PermissionStatus status); | |
87 | 94 |
88 RequestsMap pending_requests_; | 95 RequestsMap pending_requests_; |
| 96 SubscriptionsMap pending_subscriptions_; |
89 // context_ owns |this|. | 97 // context_ owns |this|. |
90 PermissionServiceContext* context_; | 98 PermissionServiceContext* context_; |
91 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; | 99 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
92 | 100 |
93 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); | 101 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
94 }; | 102 }; |
95 | 103 |
96 } // namespace content | 104 } // namespace content |
97 | 105 |
98 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 106 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
OLD | NEW |