| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/permissions/permission_service_context.h" | 12 #include "content/browser/permissions/permission_service_context.h" |
| 13 #include "content/common/content_export.h" |
| 13 #include "third_party/WebKit/public/platform/modules/permissions/permission.mojo
m.h" | 14 #include "third_party/WebKit/public/platform/modules/permissions/permission.mojo
m.h" |
| 14 #include "url/origin.h" | 15 #include "url/origin.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 enum class PermissionType; | 19 enum class PermissionType; |
| 19 | 20 |
| 20 // Implements the PermissionService Mojo interface. | 21 // Implements the PermissionService Mojo interface. |
| 21 // This service can be created from a RenderFrameHost or a RenderProcessHost. | 22 // This service can be created from a RenderFrameHost or a RenderProcessHost. |
| 22 // It is owned by a PermissionServiceContext. | 23 // It is owned by a PermissionServiceContext. |
| 23 // It receives at PermissionServiceContext instance when created which allows it | 24 // It receives at PermissionServiceContext instance when created which allows it |
| 24 // to have some information about the current context. That enables the service | 25 // to have some information about the current context. That enables the service |
| 25 // to know whether it can show UI and have knowledge of the associated | 26 // to know whether it can show UI and have knowledge of the associated |
| 26 // WebContents for example. | 27 // WebContents for example. |
| 27 class PermissionServiceImpl : public blink::mojom::PermissionService { | 28 class CONTENT_EXPORT PermissionServiceImpl |
| 29 : public blink::mojom::PermissionService { |
| 28 public: | 30 public: |
| 29 PermissionServiceImpl(PermissionServiceContext* context); | 31 PermissionServiceImpl(PermissionServiceContext* context); |
| 30 ~PermissionServiceImpl() override; | 32 ~PermissionServiceImpl() override; |
| 31 | 33 |
| 32 private: | 34 private: |
| 35 friend class PermissionServiceImplTest; |
| 36 |
| 33 using PermissionStatusCallback = | 37 using PermissionStatusCallback = |
| 34 base::Callback<void(blink::mojom::PermissionStatus)>; | 38 base::Callback<void(blink::mojom::PermissionStatus)>; |
| 35 | 39 |
| 36 struct PendingRequest { | 40 class PendingRequest; |
| 37 PendingRequest(const RequestPermissionsCallback& callback, | |
| 38 int request_count); | |
| 39 ~PendingRequest(); | |
| 40 | |
| 41 // Request ID received from the PermissionManager. | |
| 42 int id; | |
| 43 RequestPermissionsCallback callback; | |
| 44 int request_count; | |
| 45 }; | |
| 46 using RequestsMap = IDMap<std::unique_ptr<PendingRequest>>; | 41 using RequestsMap = IDMap<std::unique_ptr<PendingRequest>>; |
| 47 | 42 |
| 48 // blink::mojom::PermissionService. | 43 // blink::mojom::PermissionService. |
| 49 void HasPermission(blink::mojom::PermissionDescriptorPtr permission, | 44 void HasPermission(blink::mojom::PermissionDescriptorPtr permission, |
| 50 const url::Origin& origin, | 45 const url::Origin& origin, |
| 51 const PermissionStatusCallback& callback) override; | 46 const PermissionStatusCallback& callback) override; |
| 52 void RequestPermission(blink::mojom::PermissionDescriptorPtr permission, | 47 void RequestPermission(blink::mojom::PermissionDescriptorPtr permission, |
| 53 const url::Origin& origin, | 48 const url::Origin& origin, |
| 54 bool user_gesture, | 49 bool user_gesture, |
| 55 const PermissionStatusCallback& callback) override; | 50 const PermissionStatusCallback& callback) override; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 83 // context_ owns |this|. | 78 // context_ owns |this|. |
| 84 PermissionServiceContext* context_; | 79 PermissionServiceContext* context_; |
| 85 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; | 80 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
| 86 | 81 |
| 87 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); | 82 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 } // namespace content | 85 } // namespace content |
| 91 | 86 |
| 92 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 87 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| OLD | NEW |