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

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

Issue 990303002: Implement PermissionService::GetNextPermissionChange. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_impl
Patch Set: fix chromecast/ Created 5 years, 8 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 #include "content/browser/permissions/permission_service_impl.h" 5 #include "content/browser/permissions/permission_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/public/browser/browser_context.h" 8 #include "content/public/browser/browser_context.h"
9 #include "content/public/browser/permission_manager.h" 9 #include "content/public/browser/permission_manager.h"
10 #include "content/public/browser/permission_type.h" 10 #include "content/public/browser/permission_type.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 pending_requests_.Clear(); 133 pending_requests_.Clear();
134 } 134 }
135 135
136 void PermissionServiceImpl::HasPermission( 136 void PermissionServiceImpl::HasPermission(
137 PermissionName permission, 137 PermissionName permission,
138 const mojo::String& origin, 138 const mojo::String& origin,
139 const mojo::Callback<void(PermissionStatus)>& callback) { 139 const mojo::Callback<void(PermissionStatus)>& callback) {
140 DCHECK(context_->GetBrowserContext()); 140 DCHECK(context_->GetBrowserContext());
141 141
142 callback.Run(GetPermissionStatus(PermissionNameToPermissionType(permission), 142 callback.Run(GetPermissionStatusFromName(permission, GURL(origin)));
143 GURL(origin)));
144 } 143 }
145 144
146 void PermissionServiceImpl::RevokePermission( 145 void PermissionServiceImpl::RevokePermission(
147 PermissionName permission, 146 PermissionName permission,
148 const mojo::String& origin, 147 const mojo::String& origin,
149 const mojo::Callback<void(PermissionStatus)>& callback) { 148 const mojo::Callback<void(PermissionStatus)>& callback) {
150 GURL origin_url(origin); 149 GURL origin_url(origin);
151 PermissionType permission_type = PermissionNameToPermissionType(permission); 150 PermissionType permission_type = PermissionNameToPermissionType(permission);
152 PermissionStatus status = GetPermissionStatus(permission_type, origin_url); 151 PermissionStatus status = GetPermissionStatusFromType(permission_type,
152 origin_url);
153 153
154 // Resetting the permission should only be possible if the permission is 154 // Resetting the permission should only be possible if the permission is
155 // already granted. 155 // already granted.
156 if (status != PERMISSION_STATUS_GRANTED) { 156 if (status != PERMISSION_STATUS_GRANTED) {
157 callback.Run(status); 157 callback.Run(status);
158 return; 158 return;
159 } 159 }
160 160
161 ResetPermissionStatus(permission_type, origin_url); 161 ResetPermissionStatus(permission_type, origin_url);
162 162
163 callback.Run(GetPermissionStatus(permission_type, origin_url)); 163 callback.Run(GetPermissionStatusFromType(permission_type, origin_url));
164 } 164 }
165 165
166 PermissionStatus PermissionServiceImpl::GetPermissionStatus(PermissionType type, 166 void PermissionServiceImpl::GetNextPermissionChange(
167 GURL origin) { 167 PermissionName permission,
168 const mojo::String& origin,
169 PermissionStatus last_known_status,
170 const mojo::Callback<void(PermissionStatus)>& callback) {
171 PermissionStatus current_status =
172 GetPermissionStatusFromName(permission, GURL(origin));
173 if (current_status != last_known_status) {
174 callback.Run(current_status);
175 return;
176 }
177
178 BrowserContext* browser_context = context_->GetBrowserContext();
179 DCHECK(browser_context);
180 if (!browser_context->GetPermissionManager()) {
181 callback.Run(current_status);
182 return;
183 }
184
185 int* subscription_id = new int();
186
187 GURL embedding_origin = context_->GetEmbeddingOrigin();
188 *subscription_id =
189 browser_context->GetPermissionManager()->SubscribePermissionStatusChange(
190 PermissionNameToPermissionType(permission),
191 GURL(origin),
192 // If the embedding_origin is empty, we,ll use the |origin| instead.
193 embedding_origin.is_empty() ? GURL(origin) : embedding_origin,
194 base::Bind(&PermissionServiceImpl::OnPermissionStatusChanged,
195 weak_factory_.GetWeakPtr(),
196 callback,
197 base::Owned(subscription_id)));
198 }
199
200 PermissionStatus PermissionServiceImpl::GetPermissionStatusFromName(
201 PermissionName permission, const GURL& origin) {
202 return GetPermissionStatusFromType(PermissionNameToPermissionType(permission),
203 origin);
204 }
205
206 PermissionStatus PermissionServiceImpl::GetPermissionStatusFromType(
207 PermissionType type, const GURL& origin) {
168 BrowserContext* browser_context = context_->GetBrowserContext(); 208 BrowserContext* browser_context = context_->GetBrowserContext();
169 DCHECK(browser_context); 209 DCHECK(browser_context);
170 if (!browser_context->GetPermissionManager()) 210 if (!browser_context->GetPermissionManager())
171 return content::PERMISSION_STATUS_DENIED; 211 return PERMISSION_STATUS_DENIED;
172 212
173 // If the embedding_origin is empty we'll use |origin| instead. 213 // If the embedding_origin is empty we'll use |origin| instead.
174 GURL embedding_origin = context_->GetEmbeddingOrigin(); 214 GURL embedding_origin = context_->GetEmbeddingOrigin();
175 return browser_context->GetPermissionManager()->GetPermissionStatus( 215 return browser_context->GetPermissionManager()->GetPermissionStatus(
176 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); 216 type, origin, embedding_origin.is_empty() ? origin : embedding_origin);
177 } 217 }
178 218
179 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type, 219 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type,
180 GURL origin) { 220 const GURL& origin) {
181 BrowserContext* browser_context = context_->GetBrowserContext(); 221 BrowserContext* browser_context = context_->GetBrowserContext();
182 DCHECK(browser_context); 222 DCHECK(browser_context);
183 if (!browser_context->GetPermissionManager()) 223 if (!browser_context->GetPermissionManager())
184 return; 224 return;
185 225
186 // If the embedding_origin is empty we'll use |origin| instead. 226 // If the embedding_origin is empty we'll use |origin| instead.
187 GURL embedding_origin = context_->GetEmbeddingOrigin(); 227 GURL embedding_origin = context_->GetEmbeddingOrigin();
188 browser_context->GetPermissionManager()->ResetPermission( 228 browser_context->GetPermissionManager()->ResetPermission(
189 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); 229 type, origin, embedding_origin.is_empty() ? origin : embedding_origin);
190 } 230 }
191 231
232 void PermissionServiceImpl::OnPermissionStatusChanged(
233 const mojo::Callback<void(PermissionStatus)>& callback,
234 const int* subscription_id,
235 PermissionStatus status) {
236 callback.Run(status);
237
238 BrowserContext* browser_context = context_->GetBrowserContext();
239 DCHECK(browser_context);
240 if (!browser_context->GetPermissionManager())
241 return;
242 browser_context->GetPermissionManager()->UnsubscribePermissionStatusChange(
243 *subscription_id);
244 }
245
192 } // namespace content 246 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/permissions/permission_service_impl.h ('k') | content/common/permission_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698