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 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 enum class PermissionType; | 17 enum class PermissionType; |
18 | 18 |
19 // Implements the PermissionService Mojo interface. | 19 // Implements the PermissionService Mojo interface. |
20 // This service can be created from a RenderFrameHost or a RenderProcessHost. | 20 // This service can be created from a RenderFrameHost or a RenderProcessHost. |
21 // It is owned by a PermissionServiceContext. | 21 // It is owned by a PermissionServiceContext. |
22 // It receives at PermissionServiceContext instance when created which allows it | 22 // It receives at PermissionServiceContext instance when created which allows it |
23 // to have some information about the current context. That enables the service | 23 // to have some information about the current context. That enables the service |
24 // to know whether it can show UI and have knowledge of the associated | 24 // to know whether it can show UI and have knowledge of the associated |
25 // WebContents for example. | 25 // WebContents for example. |
26 class PermissionServiceImpl : public PermissionService { | 26 class PermissionServiceImpl : public PermissionService { |
27 public: | 27 public: |
28 ~PermissionServiceImpl() override; | 28 ~PermissionServiceImpl() override; |
29 | |
mlamouri (slow - plz ping)
2015/09/23 16:37:37
nit: do not remove this line.
Lalit Maganti
2015/09/24 09:24:11
Done.
| |
30 // Clear pending operations currently run by the service. This will be called | 29 // Clear pending operations currently run by the service. This will be called |
31 // by PermissionServiceContext when it will need the service to clear its | 30 // by PermissionServiceContext when it will need the service to clear its |
32 // state for example, if the frame changes. | 31 // state for example, if the frame changes. |
33 void CancelPendingOperations(); | 32 void CancelPendingOperations(); |
34 | 33 |
35 protected: | 34 protected: |
36 friend PermissionServiceContext; | 35 friend PermissionServiceContext; |
37 | 36 |
38 PermissionServiceImpl(PermissionServiceContext* context, | 37 PermissionServiceImpl(PermissionServiceContext* context, |
39 mojo::InterfaceRequest<PermissionService> request); | 38 mojo::InterfaceRequest<PermissionService> request); |
40 | 39 |
41 private: | 40 private: |
42 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; | 41 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; |
43 using PermissionsStatusCallback = | 42 using PermissionsStatusCallback = |
44 mojo::Callback<void(mojo::Array<PermissionStatus>)>; | 43 mojo::Callback<void(mojo::Array<PermissionStatus>)>; |
45 | 44 |
46 struct PendingRequest { | 45 struct PendingRequest { |
47 PendingRequest(PermissionType permission, const GURL& origin, | 46 PendingRequest(const PermissionsStatusCallback& callback, |
48 const PermissionStatusCallback& callback); | 47 int request_count); |
49 ~PendingRequest(); | 48 ~PendingRequest(); |
50 | 49 |
51 // Request ID received from the PermissionManager. | 50 // Request ID received from the PermissionManager. |
52 int id; | 51 int id; |
53 PermissionType permission; | 52 PermissionsStatusCallback callback; |
54 GURL origin; | 53 int request_count; |
55 PermissionStatusCallback callback; | |
56 }; | 54 }; |
57 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 55 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
58 | 56 |
59 struct PendingSubscription { | 57 struct PendingSubscription { |
60 PendingSubscription(PermissionType permission, const GURL& origin, | 58 PendingSubscription(PermissionType permission, const GURL& origin, |
61 const PermissionStatusCallback& callback); | 59 const PermissionStatusCallback& callback); |
62 ~PendingSubscription(); | 60 ~PendingSubscription(); |
63 | 61 |
64 // Subscription ID received from the PermissionManager. | 62 // Subscription ID received from the PermissionManager. |
65 int id; | 63 int id; |
(...skipping 19 matching lines...) Expand all Loading... | |
85 const mojo::String& origin, | 83 const mojo::String& origin, |
86 const PermissionStatusCallback& callback) override; | 84 const PermissionStatusCallback& callback) override; |
87 void GetNextPermissionChange( | 85 void GetNextPermissionChange( |
88 PermissionName permission, | 86 PermissionName permission, |
89 const mojo::String& origin, | 87 const mojo::String& origin, |
90 PermissionStatus last_known_status, | 88 PermissionStatus last_known_status, |
91 const PermissionStatusCallback& callback) override; | 89 const PermissionStatusCallback& callback) override; |
92 | 90 |
93 void OnConnectionError(); | 91 void OnConnectionError(); |
94 | 92 |
95 void OnRequestPermissionResponse(int request_id, PermissionStatus status); | 93 void OnRequestPermissionResponse( |
94 int pending_request_id, | |
95 PermissionStatus status); | |
96 void OnRequestPermissionsResponse( | |
97 int pending_request_id, | |
98 const std::vector<PermissionStatus>& result); | |
96 | 99 |
97 PermissionStatus GetPermissionStatusFromName(PermissionName permission, | 100 PermissionStatus GetPermissionStatusFromName(PermissionName permission, |
98 const GURL& origin); | 101 const GURL& origin); |
99 PermissionStatus GetPermissionStatusFromType(PermissionType type, | 102 PermissionStatus GetPermissionStatusFromType(PermissionType type, |
100 const GURL& origin); | 103 const GURL& origin); |
101 void ResetPermissionStatus(PermissionType type, const GURL& origin); | 104 void ResetPermissionStatus(PermissionType type, const GURL& origin); |
102 | 105 |
103 void OnPermissionStatusChanged(int pending_subscription_id, | 106 void OnPermissionStatusChanged(int pending_subscription_id, |
104 PermissionStatus status); | 107 PermissionStatus status); |
105 | 108 |
106 RequestsMap pending_requests_; | 109 RequestsMap pending_requests_; |
107 SubscriptionsMap pending_subscriptions_; | 110 SubscriptionsMap pending_subscriptions_; |
108 // context_ owns |this|. | 111 // context_ owns |this|. |
109 PermissionServiceContext* context_; | 112 PermissionServiceContext* context_; |
110 mojo::Binding<PermissionService> binding_; | 113 mojo::Binding<PermissionService> binding_; |
111 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; | 114 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
112 | 115 |
113 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); | 116 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
114 }; | 117 }; |
115 | 118 |
116 } // namespace content | 119 } // namespace content |
117 | 120 |
118 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 121 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
OLD | NEW |