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

Side by Side Diff: chrome/browser/permissions/permission_manager.cc

Issue 2723983004: Add PermissionManager::GetPermissionStatusForFrame function (Closed)
Patch Set: Add PermissionManager::GetPermissionStatusForFrame function Created 3 years, 9 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 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 "chrome/browser/permissions/permission_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (!pending_requests_.Lookup(request_id)) 327 if (!pending_requests_.Lookup(request_id))
328 return kNoPendingOperation; 328 return kNoPendingOperation;
329 329
330 return request_id; 330 return request_id;
331 } 331 }
332 332
333 PermissionResult PermissionManager::GetPermissionStatus( 333 PermissionResult PermissionManager::GetPermissionStatus(
334 ContentSettingsType permission, 334 ContentSettingsType permission,
335 const GURL& requesting_origin, 335 const GURL& requesting_origin,
336 const GURL& embedding_origin) { 336 const GURL& embedding_origin) {
337 if (IsConstantPermission(permission)) { 337 return GetPermissionStatusHelper(permission, nullptr /* render_frame_host */,
338 return PermissionResult(GetContentSettingForConstantPermission(permission), 338 requesting_origin, embedding_origin);
339 PermissionStatusSource::UNSPECIFIED); 339 }
340 } 340
341 PermissionContextBase* context = GetPermissionContext(permission); 341 PermissionResult PermissionManager::GetPermissionStatusForFrame(
342 PermissionResult result = context->GetPermissionStatus( 342 ContentSettingsType permission,
343 requesting_origin.GetOrigin(), embedding_origin.GetOrigin()); 343 content::RenderFrameHost* render_frame_host) {
344 DCHECK(result.content_setting == CONTENT_SETTING_ALLOW || 344 content::WebContents* web_contents =
345 result.content_setting == CONTENT_SETTING_ASK || 345 content::WebContents::FromRenderFrameHost(render_frame_host);
346 result.content_setting == CONTENT_SETTING_BLOCK); 346 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin();
347 return result; 347 return GetPermissionStatusHelper(
348 permission, render_frame_host,
349 render_frame_host->GetLastCommittedURL().GetOrigin(), embedding_origin);
348 } 350 }
349 351
350 int PermissionManager::RequestPermission( 352 int PermissionManager::RequestPermission(
351 PermissionType permission, 353 PermissionType permission,
352 content::RenderFrameHost* render_frame_host, 354 content::RenderFrameHost* render_frame_host,
353 const GURL& requesting_origin, 355 const GURL& requesting_origin,
354 bool user_gesture, 356 bool user_gesture,
355 const base::Callback<void(PermissionStatus)>& callback) { 357 const base::Callback<void(PermissionStatus)>& callback) {
356 ContentSettingsType content_settings_type = 358 ContentSettingsType content_settings_type =
357 PermissionTypeToContentSetting(permission); 359 PermissionTypeToContentSetting(permission);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 subscription->current_value = new_value; 519 subscription->current_value = new_value;
518 520
519 // Add the callback to |callbacks| which will be run after the loop to 521 // Add the callback to |callbacks| which will be run after the loop to
520 // prevent re-entrance issues. 522 // prevent re-entrance issues.
521 callbacks.push_back(base::Bind(subscription->callback, new_value)); 523 callbacks.push_back(base::Bind(subscription->callback, new_value));
522 } 524 }
523 525
524 for (const auto& callback : callbacks) 526 for (const auto& callback : callbacks)
525 callback.Run(); 527 callback.Run();
526 } 528 }
529
530 PermissionResult PermissionManager::GetPermissionStatusHelper(
531 ContentSettingsType permission,
532 content::RenderFrameHost* render_frame_host,
533 const GURL& requesting_origin,
534 const GURL& embedding_origin) {
535 if (IsConstantPermission(permission)) {
536 return PermissionResult(GetContentSettingForConstantPermission(permission),
537 PermissionStatusSource::UNSPECIFIED);
538 }
539 PermissionContextBase* context = GetPermissionContext(permission);
540 PermissionResult result = context->GetPermissionStatus(
541 nullptr /* render_frame_host */, requesting_origin.GetOrigin(),
542 embedding_origin.GetOrigin());
543 DCHECK(result.content_setting == CONTENT_SETTING_ALLOW ||
544 result.content_setting == CONTENT_SETTING_ASK ||
545 result.content_setting == CONTENT_SETTING_BLOCK);
546 return result;
547 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_manager.h ('k') | chrome/browser/plugins/flash_permission_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698