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