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

Side by Side Diff: android_webview/browser/aw_permission_manager.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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
« no previous file with comments | « no previous file | blimp/engine/browser/blimp_permission_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "android_webview/browser/aw_permission_manager.h" 5 #include "android_webview/browser/aw_permission_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" 9 #include "android_webview/browser/aw_browser_permission_request_delegate.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 10 matching lines...) Expand all
21 namespace android_webview { 21 namespace android_webview {
22 22
23 class LastRequestResultCache { 23 class LastRequestResultCache {
24 public: 24 public:
25 LastRequestResultCache() = default; 25 LastRequestResultCache() = default;
26 26
27 void SetResult(PermissionType permission, 27 void SetResult(PermissionType permission,
28 const GURL& requesting_origin, 28 const GURL& requesting_origin,
29 const GURL& embedding_origin, 29 const GURL& embedding_origin,
30 PermissionStatus status) { 30 PermissionStatus status) {
31 DCHECK(status == content::PERMISSION_STATUS_GRANTED || 31 DCHECK(status == content::PermissionStatus::GRANTED ||
32 status == content::PERMISSION_STATUS_DENIED); 32 status == content::PermissionStatus::DENIED);
33 33
34 // TODO(ddorwin): We should be denying empty origins at a higher level. 34 // TODO(ddorwin): We should be denying empty origins at a higher level.
35 if (requesting_origin.is_empty() || embedding_origin.is_empty()) { 35 if (requesting_origin.is_empty() || embedding_origin.is_empty()) {
36 DLOG(WARNING) << "Not caching result because of empty origin."; 36 DLOG(WARNING) << "Not caching result because of empty origin.";
37 return; 37 return;
38 } 38 }
39 39
40 if (!requesting_origin.is_valid()) { 40 if (!requesting_origin.is_valid()) {
41 NOTREACHED() << requesting_origin.possibly_invalid_spec(); 41 NOTREACHED() << requesting_origin.possibly_invalid_spec();
42 return; 42 return;
(...skipping 16 matching lines...) Expand all
59 return; 59 return;
60 } 60 }
61 pmi_result_cache_[key] = status; 61 pmi_result_cache_[key] = status;
62 } 62 }
63 63
64 PermissionStatus GetResult(PermissionType permission, 64 PermissionStatus GetResult(PermissionType permission,
65 const GURL& requesting_origin, 65 const GURL& requesting_origin,
66 const GURL& embedding_origin) const { 66 const GURL& embedding_origin) const {
67 // TODO(ddorwin): We should be denying empty origins at a higher level. 67 // TODO(ddorwin): We should be denying empty origins at a higher level.
68 if (requesting_origin.is_empty() || embedding_origin.is_empty()) { 68 if (requesting_origin.is_empty() || embedding_origin.is_empty()) {
69 return content::PERMISSION_STATUS_ASK; 69 return content::PermissionStatus::ASK;
70 } 70 }
71 71
72 DCHECK(requesting_origin.is_valid()) 72 DCHECK(requesting_origin.is_valid())
73 << requesting_origin.possibly_invalid_spec(); 73 << requesting_origin.possibly_invalid_spec();
74 DCHECK(embedding_origin.is_valid()) 74 DCHECK(embedding_origin.is_valid())
75 << embedding_origin.possibly_invalid_spec(); 75 << embedding_origin.possibly_invalid_spec();
76 76
77 if (permission != PermissionType::PROTECTED_MEDIA_IDENTIFIER) { 77 if (permission != PermissionType::PROTECTED_MEDIA_IDENTIFIER) {
78 NOTREACHED() << "Results are only cached for PROTECTED_MEDIA_IDENTIFIER"; 78 NOTREACHED() << "Results are only cached for PROTECTED_MEDIA_IDENTIFIER";
79 return content::PERMISSION_STATUS_ASK; 79 return content::PermissionStatus::ASK;
80 } 80 }
81 81
82 std::string key = GetCacheKey(requesting_origin, embedding_origin); 82 std::string key = GetCacheKey(requesting_origin, embedding_origin);
83 StatusMap::const_iterator it = pmi_result_cache_.find(key); 83 StatusMap::const_iterator it = pmi_result_cache_.find(key);
84 if (it == pmi_result_cache_.end()) { 84 if (it == pmi_result_cache_.end()) {
85 DLOG(WARNING) << "GetResult() called for uncached origins: " << key; 85 DLOG(WARNING) << "GetResult() called for uncached origins: " << key;
86 return content::PERMISSION_STATUS_ASK; 86 return content::PermissionStatus::ASK;
87 } 87 }
88 88
89 DCHECK(!key.empty()); 89 DCHECK(!key.empty());
90 return it->second; 90 return it->second;
91 } 91 }
92 92
93 void ClearResult(PermissionType permission, 93 void ClearResult(PermissionType permission,
94 const GURL& requesting_origin, 94 const GURL& requesting_origin,
95 const GURL& embedding_origin) { 95 const GURL& embedding_origin) {
96 // TODO(ddorwin): We should be denying empty origins at a higher level. 96 // TODO(ddorwin): We should be denying empty origins at a higher level.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 bool user_gesture, 172 bool user_gesture,
173 const base::Callback<void(PermissionStatus)>& callback) { 173 const base::Callback<void(PermissionStatus)>& callback) {
174 int render_process_id = render_frame_host->GetProcess()->GetID(); 174 int render_process_id = render_frame_host->GetProcess()->GetID();
175 int render_frame_id = render_frame_host->GetRoutingID(); 175 int render_frame_id = render_frame_host->GetRoutingID();
176 AwBrowserPermissionRequestDelegate* delegate = 176 AwBrowserPermissionRequestDelegate* delegate =
177 AwBrowserPermissionRequestDelegate::FromID(render_process_id, 177 AwBrowserPermissionRequestDelegate::FromID(render_process_id,
178 render_frame_id); 178 render_frame_id);
179 if (!delegate) { 179 if (!delegate) {
180 DVLOG(0) << "Dropping permission request for " 180 DVLOG(0) << "Dropping permission request for "
181 << static_cast<int>(permission); 181 << static_cast<int>(permission);
182 callback.Run(content::PERMISSION_STATUS_DENIED); 182 callback.Run(content::PermissionStatus::DENIED);
183 return kNoPendingOperation; 183 return kNoPendingOperation;
184 } 184 }
185 185
186 // Do not delegate any requests which are already pending. 186 // Do not delegate any requests which are already pending.
187 bool should_delegate_request = true; 187 bool should_delegate_request = true;
188 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); 188 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_);
189 !it.IsAtEnd(); it.Advance()) { 189 !it.IsAtEnd(); it.Advance()) {
190 if (permission == it.GetCurrentValue()->permission) { 190 if (permission == it.GetCurrentValue()->permission) {
191 should_delegate_request = false; 191 should_delegate_request = false;
192 break; 192 break;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 callback)); 238 callback));
239 } 239 }
240 break; 240 break;
241 case PermissionType::AUDIO_CAPTURE: 241 case PermissionType::AUDIO_CAPTURE:
242 case PermissionType::VIDEO_CAPTURE: 242 case PermissionType::VIDEO_CAPTURE:
243 case PermissionType::NOTIFICATIONS: 243 case PermissionType::NOTIFICATIONS:
244 case PermissionType::PUSH_MESSAGING: 244 case PermissionType::PUSH_MESSAGING:
245 case PermissionType::DURABLE_STORAGE: 245 case PermissionType::DURABLE_STORAGE:
246 NOTIMPLEMENTED() << "RequestPermission is not implemented for " 246 NOTIMPLEMENTED() << "RequestPermission is not implemented for "
247 << static_cast<int>(permission); 247 << static_cast<int>(permission);
248 callback.Run(content::PERMISSION_STATUS_DENIED); 248 callback.Run(content::PermissionStatus::DENIED);
249 break; 249 break;
250 case PermissionType::MIDI: 250 case PermissionType::MIDI:
251 callback.Run(content::PERMISSION_STATUS_GRANTED); 251 callback.Run(content::PermissionStatus::GRANTED);
252 break; 252 break;
253 case PermissionType::NUM: 253 case PermissionType::NUM:
254 NOTREACHED() << "PermissionType::NUM was not expected here."; 254 NOTREACHED() << "PermissionType::NUM was not expected here.";
255 callback.Run(content::PERMISSION_STATUS_DENIED); 255 callback.Run(content::PermissionStatus::DENIED);
256 break; 256 break;
257 } 257 }
258 return request_id; 258 return request_id;
259 } 259 }
260 260
261 int AwPermissionManager::RequestPermissions( 261 int AwPermissionManager::RequestPermissions(
262 const std::vector<PermissionType>& permissions, 262 const std::vector<PermissionType>& permissions,
263 content::RenderFrameHost* render_frame_host, 263 content::RenderFrameHost* render_frame_host,
264 const GURL& requesting_origin, 264 const GURL& requesting_origin,
265 bool user_gesture, 265 bool user_gesture,
(...skipping 14 matching lines...) Expand all
280 callback.Run(result); 280 callback.Run(result);
281 return kNoPendingOperation; 281 return kNoPendingOperation;
282 } 282 }
283 283
284 // static 284 // static
285 void AwPermissionManager::OnRequestResponse( 285 void AwPermissionManager::OnRequestResponse(
286 const base::WeakPtr<AwPermissionManager>& manager, 286 const base::WeakPtr<AwPermissionManager>& manager,
287 int request_id, 287 int request_id,
288 const base::Callback<void(PermissionStatus)>& callback, 288 const base::Callback<void(PermissionStatus)>& callback,
289 bool allowed) { 289 bool allowed) {
290 PermissionStatus status = allowed ? content::PERMISSION_STATUS_GRANTED 290 PermissionStatus status = allowed ? content::PermissionStatus::GRANTED
291 : content::PERMISSION_STATUS_DENIED; 291 : content::PermissionStatus::DENIED;
292 if (manager.get()) { 292 if (manager.get()) {
293 PendingRequest* pending_request = 293 PendingRequest* pending_request =
294 manager->pending_requests_.Lookup(request_id); 294 manager->pending_requests_.Lookup(request_id);
295 295
296 for (PendingRequestsMap::Iterator<PendingRequest> it( 296 for (PendingRequestsMap::Iterator<PendingRequest> it(
297 &manager->pending_requests_); 297 &manager->pending_requests_);
298 !it.IsAtEnd(); it.Advance()) { 298 !it.IsAtEnd(); it.Advance()) {
299 if (pending_request->permission == it.GetCurrentValue()->permission && 299 if (pending_request->permission == it.GetCurrentValue()->permission &&
300 it.GetCurrentKey() != request_id) { 300 it.GetCurrentKey() != request_id) {
301 it.GetCurrentValue()->callback.Run(status); 301 it.GetCurrentValue()->callback.Run(status);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 PermissionStatus AwPermissionManager::GetPermissionStatus( 385 PermissionStatus AwPermissionManager::GetPermissionStatus(
386 PermissionType permission, 386 PermissionType permission,
387 const GURL& requesting_origin, 387 const GURL& requesting_origin,
388 const GURL& embedding_origin) { 388 const GURL& embedding_origin) {
389 // Method is called outside the Permissions API only for this permission. 389 // Method is called outside the Permissions API only for this permission.
390 if (permission == PermissionType::PROTECTED_MEDIA_IDENTIFIER) { 390 if (permission == PermissionType::PROTECTED_MEDIA_IDENTIFIER) {
391 return result_cache_->GetResult(permission, requesting_origin, 391 return result_cache_->GetResult(permission, requesting_origin,
392 embedding_origin); 392 embedding_origin);
393 } else if (permission == PermissionType::MIDI) { 393 } else if (permission == PermissionType::MIDI) {
394 return content::PERMISSION_STATUS_GRANTED; 394 return content::PermissionStatus::GRANTED;
395 } 395 }
396 396
397 return content::PERMISSION_STATUS_DENIED; 397 return content::PermissionStatus::DENIED;
398 } 398 }
399 399
400 void AwPermissionManager::RegisterPermissionUsage( 400 void AwPermissionManager::RegisterPermissionUsage(
401 PermissionType permission, 401 PermissionType permission,
402 const GURL& requesting_origin, 402 const GURL& requesting_origin,
403 const GURL& embedding_origin) { 403 const GURL& embedding_origin) {
404 } 404 }
405 405
406 int AwPermissionManager::SubscribePermissionStatusChange( 406 int AwPermissionManager::SubscribePermissionStatusChange(
407 PermissionType permission, 407 PermissionType permission,
408 const GURL& requesting_origin, 408 const GURL& requesting_origin,
409 const GURL& embedding_origin, 409 const GURL& embedding_origin,
410 const base::Callback<void(PermissionStatus)>& callback) { 410 const base::Callback<void(PermissionStatus)>& callback) {
411 return kNoPendingOperation; 411 return kNoPendingOperation;
412 } 412 }
413 413
414 void AwPermissionManager::UnsubscribePermissionStatusChange( 414 void AwPermissionManager::UnsubscribePermissionStatusChange(
415 int subscription_id) { 415 int subscription_id) {
416 } 416 }
417 417
418 } // namespace android_webview 418 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | blimp/engine/browser/blimp_permission_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698