| 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 "mojo/public/cpp/bindings/binding.h" | 13 #include "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 mojom::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 mojom::PermissionService { |
| 27 public: | 27 public: |
| 28 ~PermissionServiceImpl() override; | 28 ~PermissionServiceImpl() override; |
| 29 | 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( |
| 39 mojo::InterfaceRequest<PermissionService> request); | 39 PermissionServiceContext* context, |
| 40 mojo::InterfaceRequest<mojom::PermissionService> request); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; | 43 using PermissionStatusCallback = |
| 44 mojo::Callback<void(mojom::PermissionStatus)>; |
| 43 using PermissionsStatusCallback = | 45 using PermissionsStatusCallback = |
| 44 mojo::Callback<void(mojo::Array<PermissionStatus>)>; | 46 mojo::Callback<void(mojo::Array<mojom::PermissionStatus>)>; |
| 45 | 47 |
| 46 struct PendingRequest { | 48 struct PendingRequest { |
| 47 PendingRequest(const PermissionsStatusCallback& callback, | 49 PendingRequest(const PermissionsStatusCallback& callback, |
| 48 int request_count); | 50 int request_count); |
| 49 ~PendingRequest(); | 51 ~PendingRequest(); |
| 50 | 52 |
| 51 // Request ID received from the PermissionManager. | 53 // Request ID received from the PermissionManager. |
| 52 int id; | 54 int id; |
| 53 PermissionsStatusCallback callback; | 55 PermissionsStatusCallback callback; |
| 54 int request_count; | 56 int request_count; |
| 55 }; | 57 }; |
| 56 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 58 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
| 57 | 59 |
| 58 struct PendingSubscription { | 60 struct PendingSubscription { |
| 59 PendingSubscription(PermissionType permission, const GURL& origin, | 61 PendingSubscription(PermissionType permission, const GURL& origin, |
| 60 const PermissionStatusCallback& callback); | 62 const PermissionStatusCallback& callback); |
| 61 ~PendingSubscription(); | 63 ~PendingSubscription(); |
| 62 | 64 |
| 63 // Subscription ID received from the PermissionManager. | 65 // Subscription ID received from the PermissionManager. |
| 64 int id; | 66 int id; |
| 65 PermissionType permission; | 67 PermissionType permission; |
| 66 GURL origin; | 68 GURL origin; |
| 67 PermissionStatusCallback callback; | 69 PermissionStatusCallback callback; |
| 68 }; | 70 }; |
| 69 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; | 71 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; |
| 70 | 72 |
| 71 // PermissionService. | 73 // PermissionService. |
| 72 void HasPermission(PermissionName permission, | 74 void HasPermission(mojom::PermissionName permission, |
| 73 const mojo::String& origin, | 75 const mojo::String& origin, |
| 74 const PermissionStatusCallback& callback) override; | 76 const PermissionStatusCallback& callback) override; |
| 75 void RequestPermission(PermissionName permission, | 77 void RequestPermission(mojom::PermissionName permission, |
| 76 const mojo::String& origin, | 78 const mojo::String& origin, |
| 77 const PermissionStatusCallback& callback) override; | 79 const PermissionStatusCallback& callback) override; |
| 78 void RequestPermissions(mojo::Array<PermissionName> permissions, | 80 void RequestPermissions(mojo::Array<mojom::PermissionName> permissions, |
| 79 const mojo::String& origin, | 81 const mojo::String& origin, |
| 80 const PermissionsStatusCallback& callback) override; | 82 const PermissionsStatusCallback& callback) override; |
| 81 void RevokePermission(PermissionName permission, | 83 void RevokePermission(mojom::PermissionName permission, |
| 82 const mojo::String& origin, | 84 const mojo::String& origin, |
| 83 const PermissionStatusCallback& callback) override; | 85 const PermissionStatusCallback& callback) override; |
| 84 void GetNextPermissionChange( | 86 void GetNextPermissionChange( |
| 85 PermissionName permission, | 87 mojom::PermissionName permission, |
| 86 const mojo::String& origin, | 88 const mojo::String& origin, |
| 87 PermissionStatus last_known_status, | 89 mojom::PermissionStatus last_known_status, |
| 88 const PermissionStatusCallback& callback) override; | 90 const PermissionStatusCallback& callback) override; |
| 89 | 91 |
| 90 void OnConnectionError(); | 92 void OnConnectionError(); |
| 91 | 93 |
| 92 void OnRequestPermissionResponse( | 94 void OnRequestPermissionResponse(int pending_request_id, |
| 93 int pending_request_id, | 95 mojom::PermissionStatus status); |
| 94 PermissionStatus status); | |
| 95 void OnRequestPermissionsResponse( | 96 void OnRequestPermissionsResponse( |
| 96 int pending_request_id, | 97 int pending_request_id, |
| 97 const std::vector<PermissionStatus>& result); | 98 const std::vector<mojom::PermissionStatus>& result); |
| 98 | 99 |
| 99 PermissionStatus GetPermissionStatusFromName(PermissionName permission, | 100 mojom::PermissionStatus GetPermissionStatusFromName( |
| 100 const GURL& origin); | 101 mojom::PermissionName permission, |
| 101 PermissionStatus GetPermissionStatusFromType(PermissionType type, | 102 const GURL& origin); |
| 102 const GURL& origin); | 103 mojom::PermissionStatus GetPermissionStatusFromType(PermissionType type, |
| 104 const GURL& origin); |
| 103 void ResetPermissionStatus(PermissionType type, const GURL& origin); | 105 void ResetPermissionStatus(PermissionType type, const GURL& origin); |
| 104 | 106 |
| 105 void OnPermissionStatusChanged(int pending_subscription_id, | 107 void OnPermissionStatusChanged(int pending_subscription_id, |
| 106 PermissionStatus status); | 108 mojom::PermissionStatus status); |
| 107 | 109 |
| 108 RequestsMap pending_requests_; | 110 RequestsMap pending_requests_; |
| 109 SubscriptionsMap pending_subscriptions_; | 111 SubscriptionsMap pending_subscriptions_; |
| 110 // context_ owns |this|. | 112 // context_ owns |this|. |
| 111 PermissionServiceContext* context_; | 113 PermissionServiceContext* context_; |
| 112 mojo::Binding<PermissionService> binding_; | 114 mojo::Binding<mojom::PermissionService> binding_; |
| 113 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; | 115 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
| 114 | 116 |
| 115 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); | 117 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 } // namespace content | 120 } // namespace content |
| 119 | 121 |
| 120 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 122 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| OLD | NEW |