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