| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/delegation_tracker.h" | 5 #include "chrome/browser/permissions/delegation_tracker.h" |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/permissions/permission_util.h" | 10 #include "chrome/browser/permissions/permission_util.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 DelegationTracker::DelegationTracker() {} | 66 DelegationTracker::DelegationTracker() {} |
| 67 | 67 |
| 68 DelegationTracker::~DelegationTracker() {} | 68 DelegationTracker::~DelegationTracker() {} |
| 69 | 69 |
| 70 void DelegationTracker::SetDelegatedPermissions( | 70 void DelegationTracker::SetDelegatedPermissions( |
| 71 content::RenderFrameHost* child_rfh, | 71 content::RenderFrameHost* child_rfh, |
| 72 const std::vector<content::PermissionType>& permissions) { | 72 const std::vector<content::PermissionType>& permissions) { |
| 73 DCHECK(child_rfh && child_rfh->GetParent()); | 73 DCHECK(child_rfh && child_rfh->GetParent()); |
| 74 delegated_permissions_[child_rfh] = base::WrapUnique(new DelegatedForChild( | 74 delegated_permissions_[child_rfh] = base::MakeUnique<DelegatedForChild>( |
| 75 child_rfh, permissions, | 75 child_rfh, permissions, |
| 76 base::Bind(&DelegationTracker::RenderFrameHostChanged, | 76 base::Bind(&DelegationTracker::RenderFrameHostChanged, |
| 77 base::Unretained(this)))); | 77 base::Unretained(this))); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool DelegationTracker::IsGranted(content::RenderFrameHost* requesting_rfh, | 80 bool DelegationTracker::IsGranted(content::RenderFrameHost* requesting_rfh, |
| 81 const content::PermissionType& permission) { | 81 const content::PermissionType& permission) { |
| 82 content::RenderFrameHost* child_rfh = requesting_rfh; | 82 content::RenderFrameHost* child_rfh = requesting_rfh; |
| 83 while (child_rfh->GetParent()) { | 83 while (child_rfh->GetParent()) { |
| 84 // Parents with unique origins can't delegate permission. | 84 // Parents with unique origins can't delegate permission. |
| 85 url::Origin parent_origin = | 85 url::Origin parent_origin = |
| 86 child_rfh->GetParent()->GetLastCommittedOrigin(); | 86 child_rfh->GetParent()->GetLastCommittedOrigin(); |
| 87 if (parent_origin.unique()) | 87 if (parent_origin.unique()) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 if (!child_rfh->GetLastCommittedOrigin().IsSameOriginWith(parent_origin)) { | 90 if (!child_rfh->GetLastCommittedOrigin().IsSameOriginWith(parent_origin)) { |
| 91 const auto& it = delegated_permissions_.find(child_rfh); | 91 const auto& it = delegated_permissions_.find(child_rfh); |
| 92 if (it == delegated_permissions_.end()) | 92 if (it == delegated_permissions_.end()) |
| 93 return false; | 93 return false; |
| 94 if (!it->second->HasPermission(permission)) | 94 if (!it->second->HasPermission(permission)) |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 child_rfh = child_rfh->GetParent(); | 97 child_rfh = child_rfh->GetParent(); |
| 98 } | 98 } |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void DelegationTracker::RenderFrameHostChanged(content::RenderFrameHost* rfh) { | 102 void DelegationTracker::RenderFrameHostChanged(content::RenderFrameHost* rfh) { |
| 103 delegated_permissions_.erase(rfh); | 103 delegated_permissions_.erase(rfh); |
| 104 } | 104 } |
| OLD | NEW |