| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 delegated_permissions_[child_rfh] = base::MakeUnique<DelegatedForChild>( | 73 delegated_permissions_[child_rfh] = base::MakeUnique<DelegatedForChild>( |
| 74 child_rfh, permissions, | 74 child_rfh, permissions, |
| 75 base::Bind(&DelegationTracker::RenderFrameHostChanged, | 75 base::Bind(&DelegationTracker::RenderFrameHostChanged, |
| 76 base::Unretained(this))); | 76 base::Unretained(this))); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool DelegationTracker::IsGranted(content::RenderFrameHost* requesting_rfh, | 79 bool DelegationTracker::IsGranted(content::RenderFrameHost* requesting_rfh, |
| 80 ContentSettingsType permission) { | 80 ContentSettingsType permission) { |
| 81 content::RenderFrameHost* child_rfh = requesting_rfh; | 81 content::RenderFrameHost* child_rfh = requesting_rfh; |
| 82 while (child_rfh->GetParent()) { | 82 while (child_rfh->GetParent()) { |
| 83 // Parents with unique origins can't delegate permission. | 83 // Parents with opaque origins can't delegate permission. |
| 84 url::Origin parent_origin = | 84 url::Origin parent_origin = |
| 85 child_rfh->GetParent()->GetLastCommittedOrigin(); | 85 child_rfh->GetParent()->GetLastCommittedOrigin(); |
| 86 if (parent_origin.unique()) | 86 if (parent_origin.opaque()) |
| 87 return false; | 87 return false; |
| 88 | 88 |
| 89 if (!child_rfh->GetLastCommittedOrigin().IsSameOriginWith(parent_origin)) { | 89 if (!child_rfh->GetLastCommittedOrigin().IsSameOriginWith(parent_origin)) { |
| 90 const auto& it = delegated_permissions_.find(child_rfh); | 90 const auto& it = delegated_permissions_.find(child_rfh); |
| 91 if (it == delegated_permissions_.end()) | 91 if (it == delegated_permissions_.end()) |
| 92 return false; | 92 return false; |
| 93 if (!it->second->HasPermission(permission)) | 93 if (!it->second->HasPermission(permission)) |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 child_rfh = child_rfh->GetParent(); | 96 child_rfh = child_rfh->GetParent(); |
| 97 } | 97 } |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void DelegationTracker::RenderFrameHostChanged(content::RenderFrameHost* rfh) { | 101 void DelegationTracker::RenderFrameHostChanged(content::RenderFrameHost* rfh) { |
| 102 delegated_permissions_.erase(rfh); | 102 delegated_permissions_.erase(rfh); |
| 103 } | 103 } |
| OLD | NEW |