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

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

Issue 750633003: Implement HasPermission() method in PermissionService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 #include "content/browser/permissions/permission_service_impl.h" 5 #include "content/browser/permissions/permission_service_impl.h"
6 6
7 #include "content/browser/geolocation/geolocation_provider_impl.h" 7 #include "content/browser/geolocation/geolocation_provider_impl.h"
8 #include "content/public/browser/content_browser_client.h" 8 #include "content/public/browser/content_browser_client.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // This condition is valid if the call is coming from a ChildThread instead of 50 // This condition is valid if the call is coming from a ChildThread instead of
51 // a RenderFrame. Some consumers of the service run in Workers and some in 51 // a RenderFrame. Some consumers of the service run in Workers and some in
52 // Frames. In the context of a Worker, it is not possible to show a 52 // Frames. In the context of a Worker, it is not possible to show a
53 // permission prompt because there is no tab. In the context of a Frame, we 53 // permission prompt because there is no tab. In the context of a Frame, we
54 // can. Even if the call comes from a context where it is not possible to show 54 // can. Even if the call comes from a context where it is not possible to show
55 // any UI, we want to still return something relevant so the current 55 // any UI, we want to still return something relevant so the current
56 // permission status is returned. 56 // permission status is returned.
57 if (!context_->web_contents()) { 57 if (!context_->web_contents()) {
58 // There is no way to show a UI so the call will simply return the current 58 // There is no way to show a UI so the call will simply return the current
59 // permission. 59 // permission.
60 HasPermission(permission, origin, callback); 60 // Cannot use HasPermission() because it also needs context_->web_contents()
61 // to obtain the profile.
qsr 2014/11/24 11:51:11 The previous comment is wrong. Could you remove it
mlamouri (slow - plz ping) 2014/11/24 16:01:19 We must implement HasPermission() to work in a non
timvolodine 2014/11/24 18:54:22 Done.
timvolodine 2014/11/24 18:54:22 Done. permission_context has an additional constru
62 callback.Run(PERMISSION_STATUS_ASK);
61 return; 63 return;
62 } 64 }
63 65
64 PermissionType permission_type = PermissionNameToPermissionType(permission); 66 PermissionType permission_type = PermissionNameToPermissionType(permission);
65 int request_id = pending_requests_.Add( 67 int request_id = pending_requests_.Add(
66 new PendingRequest(permission_type, GURL(origin))); 68 new PendingRequest(permission_type, GURL(origin)));
67 69
68 GetContentClient()->browser()->RequestPermission( 70 GetContentClient()->browser()->RequestPermission(
69 permission_type, 71 permission_type,
70 context_->web_contents(), 72 context_->web_contents(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 it.GetCurrentValue()->origin); 109 it.GetCurrentValue()->origin);
108 } 110 }
109 111
110 pending_requests_.Clear(); 112 pending_requests_.Clear();
111 } 113 }
112 114
113 void PermissionServiceImpl::HasPermission( 115 void PermissionServiceImpl::HasPermission(
114 PermissionName permission, 116 PermissionName permission,
115 const mojo::String& origin, 117 const mojo::String& origin,
116 const mojo::Callback<void(PermissionStatus)>& callback) { 118 const mojo::Callback<void(PermissionStatus)>& callback) {
117 NOTIMPLEMENTED(); 119 DCHECK(context_->web_contents());
120
121 GetContentClient()->browser()->HasPermission(
122 PermissionNameToPermissionType(permission),
123 context_->web_contents(),
124 GURL(origin),
125 base::Bind(&PermissionServiceImpl::OnHasPermissionResponse,
126 weak_factory_.GetWeakPtr(),
127 callback));
128 }
129
130 void PermissionServiceImpl::OnHasPermissionResponse(
131 const mojo::Callback<void(PermissionStatus)>& callback,
132 bool allowed) {
133 callback.Run(allowed ? PERMISSION_STATUS_GRANTED : PERMISSION_STATUS_ASK);
118 } 134 }
119 135
120 } // namespace content 136 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698