Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/browser/permissions/permission_service_impl.h

Issue 1260193009: renderer: implement multiple permission requesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions-request-multiple
Patch Set: Merge patches Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
18 class PermissionPendingSingleRequest;
19 class PermissionPendingMultipleRequest;
17 enum class PermissionType; 20 enum class PermissionType;
18 21
19 // Implements the PermissionService Mojo interface. 22 // Implements the PermissionService Mojo interface.
20 // This service can be created from a RenderFrameHost or a RenderProcessHost. 23 // This service can be created from a RenderFrameHost or a RenderProcessHost.
21 // It is owned by a PermissionServiceContext. 24 // It is owned by a PermissionServiceContext.
22 // It receives at PermissionServiceContext instance when created which allows it 25 // It receives at PermissionServiceContext instance when created which allows it
23 // to have some information about the current context. That enables the service 26 // 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 27 // to know whether it can show UI and have knowledge of the associated
25 // WebContents for example. 28 // WebContents for example.
26 class PermissionServiceImpl : public PermissionService { 29 class PermissionServiceImpl : public PermissionService {
27 public: 30 public:
28 ~PermissionServiceImpl() override; 31 ~PermissionServiceImpl() override;
29 32
30 // Clear pending operations currently run by the service. This will be called 33 // Clear pending operations currently run by the service. This will be called
31 // by PermissionServiceContext when it will need the service to clear its 34 // by PermissionServiceContext when it will need the service to clear its
32 // state for example, if the frame changes. 35 // state for example, if the frame changes.
33 void CancelPendingOperations(); 36 void CancelPendingOperations();
34 37
35 protected: 38 protected:
36 friend PermissionServiceContext; 39 friend PermissionServiceContext;
37 40
38 PermissionServiceImpl(PermissionServiceContext* context, 41 PermissionServiceImpl(PermissionServiceContext* context,
39 mojo::InterfaceRequest<PermissionService> request); 42 mojo::InterfaceRequest<PermissionService> request);
40 43
41 private: 44 private:
42 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; 45 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>;
46 using PermissionsStatusCallback =
47 mojo::Callback<void(mojo::Array<PermissionStatus>)>;
43 48
44 struct PendingRequest { 49 using RequestsMap = IDMap<PermissionPendingRequest, IDMapOwnPointer>;
45 PendingRequest(PermissionType permission, const GURL& origin,
46 const PermissionStatusCallback& callback);
47 ~PendingRequest();
48
49 PermissionType permission;
50 GURL origin;
51 PermissionStatusCallback callback;
52 };
53 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>;
54 50
55 struct PendingSubscription { 51 struct PendingSubscription {
56 PendingSubscription(PermissionType permission, const GURL& origin, 52 PendingSubscription(PermissionType permission, const GURL& origin,
57 const PermissionStatusCallback& callback); 53 const PermissionStatusCallback& callback);
58 ~PendingSubscription(); 54 ~PendingSubscription();
59 55
60 // Subscription ID received from the PermissionManager. 56 // Subscription ID received from the PermissionManager.
61 int id; 57 int id;
62 PermissionType permission; 58 PermissionType permission;
63 GURL origin; 59 GURL origin;
64 PermissionStatusCallback callback; 60 PermissionStatusCallback callback;
65 }; 61 };
66 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; 62 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>;
67 63
68 // PermissionService. 64 // PermissionService.
69 void HasPermission(PermissionName permission, 65 void HasPermission(PermissionName permission,
70 const mojo::String& origin, 66 const mojo::String& origin,
71 const PermissionStatusCallback& callback) override; 67 const PermissionStatusCallback& callback) override;
72 void RequestPermission(PermissionName permission, 68 void RequestPermission(PermissionName permission,
73 const mojo::String& origin, 69 const mojo::String& origin,
74 bool user_gesture, 70 bool user_gesture,
75 const PermissionStatusCallback& callback) override; 71 const PermissionStatusCallback& callback) override;
72 void RequestPermissions(mojo::Array<PermissionName> permissions,
73 const mojo::String& origin,
74 bool user_gesture,
75 const PermissionsStatusCallback& callback) override;
76 void RevokePermission(PermissionName permission, 76 void RevokePermission(PermissionName permission,
77 const mojo::String& origin, 77 const mojo::String& origin,
78 const PermissionStatusCallback& callback) override; 78 const PermissionStatusCallback& callback) override;
79 void GetNextPermissionChange( 79 void GetNextPermissionChange(
80 PermissionName permission, 80 PermissionName permission,
81 const mojo::String& origin, 81 const mojo::String& origin,
82 PermissionStatus last_known_status, 82 PermissionStatus last_known_status,
83 const PermissionStatusCallback& callback) override; 83 const PermissionStatusCallback& callback) override;
84 84
85 void OnConnectionError(); 85 void OnConnectionError();
86 86
87 void OnRequestPermissionResponse(int request_id, PermissionStatus status); 87 void OnRequestPermissionResponse(int request_id,
88 PermissionPendingSingleRequest* request,
89 PermissionStatus status);
90
91 void OnRequestPermissionsResponse(
92 int request_id,
93 PermissionPendingMultipleRequest* request,
94 const std::vector<PermissionStatus>& status);
88 95
89 PermissionStatus GetPermissionStatusFromName(PermissionName permission, 96 PermissionStatus GetPermissionStatusFromName(PermissionName permission,
90 const GURL& origin); 97 const GURL& origin);
91 PermissionStatus GetPermissionStatusFromType(PermissionType type, 98 PermissionStatus GetPermissionStatusFromType(PermissionType type,
92 const GURL& origin); 99 const GURL& origin);
93 void ResetPermissionStatus(PermissionType type, const GURL& origin); 100 void ResetPermissionStatus(PermissionType type, const GURL& origin);
94 101
95 void OnPermissionStatusChanged(int pending_subscription_id, 102 void OnPermissionStatusChanged(int pending_subscription_id,
96 PermissionStatus status); 103 PermissionStatus status);
97 104
98 RequestsMap pending_requests_; 105 RequestsMap pending_requests_;
99 SubscriptionsMap pending_subscriptions_; 106 SubscriptionsMap pending_subscriptions_;
100 // context_ owns |this|. 107 // context_ owns |this|.
101 PermissionServiceContext* context_; 108 PermissionServiceContext* context_;
102 mojo::Binding<PermissionService> binding_; 109 mojo::Binding<PermissionService> binding_;
103 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; 110 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_;
104 111
105 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); 112 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl);
106 }; 113 };
107 114
108 } // namespace content 115 } // namespace content
109 116
110 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ 117 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698