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