| 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 "extensions/browser/extension_navigation_throttle.h" | 5 #include "extensions/browser/extension_navigation_throttle.h" |
| 6 | 6 |
| 7 #include "components/guest_view/browser/guest_view_base.h" | 7 #include "components/guest_view/browser/guest_view_base.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/navigation_handle.h" | 9 #include "content/public/browser/navigation_handle.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (!url.SchemeIs(extensions::kExtensionScheme)) | 105 if (!url.SchemeIs(extensions::kExtensionScheme)) |
| 106 return content::NavigationThrottle::PROCEED; | 106 return content::NavigationThrottle::PROCEED; |
| 107 | 107 |
| 108 // The subframe which is navigated needs to have all of its ancestors be | 108 // The subframe which is navigated needs to have all of its ancestors be |
| 109 // at the same origin, otherwise the resource needs to be explicitly listed | 109 // at the same origin, otherwise the resource needs to be explicitly listed |
| 110 // in web_accessible_resources. | 110 // in web_accessible_resources. |
| 111 // Since the RenderFrameHost is not known until navigation has committed, | 111 // Since the RenderFrameHost is not known until navigation has committed, |
| 112 // we can't get it from NavigationHandle. However, this code only cares about | 112 // we can't get it from NavigationHandle. However, this code only cares about |
| 113 // the ancestor chain, so find the current RenderFrameHost and use it to | 113 // the ancestor chain, so find the current RenderFrameHost and use it to |
| 114 // traverse up to the main frame. | 114 // traverse up to the main frame. |
| 115 content::RenderFrameHost* navigating_frame = nullptr; | 115 content::RenderFrameHost* navigating_frame = |
| 116 for (auto* frame : web_contents->GetAllFrames()) { | 116 web_contents->FindFrameByFrameTreeNodeId( |
| 117 if (frame->GetFrameTreeNodeId() == | 117 navigation_handle()->GetFrameTreeNodeId()); |
| 118 navigation_handle()->GetFrameTreeNodeId()) { | |
| 119 navigating_frame = frame; | |
| 120 break; | |
| 121 } | |
| 122 } | |
| 123 DCHECK(navigating_frame); | 118 DCHECK(navigating_frame); |
| 124 | 119 |
| 125 // Traverse the chain of parent frames, checking if they are the same origin | 120 // Traverse the chain of parent frames, checking if they are the same origin |
| 126 // as the URL of this navigation. | 121 // as the URL of this navigation. |
| 127 content::RenderFrameHost* ancestor = navigating_frame->GetParent(); | 122 content::RenderFrameHost* ancestor = navigating_frame->GetParent(); |
| 128 bool external_ancestor = false; | 123 bool external_ancestor = false; |
| 129 while (ancestor) { | 124 while (ancestor) { |
| 130 if (ancestor->GetLastCommittedURL().GetOrigin() != url.GetOrigin()) { | 125 if (ancestor->GetLastCommittedURL().GetOrigin() != url.GetOrigin()) { |
| 131 // Ignore DevTools, as it is allowed to embed extension pages. | 126 // Ignore DevTools, as it is allowed to embed extension pages. |
| 132 if (!ancestor->GetLastCommittedURL().SchemeIs( | 127 if (!ancestor->GetLastCommittedURL().SchemeIs( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 158 } | 153 } |
| 159 | 154 |
| 160 return content::NavigationThrottle::BLOCK_REQUEST; | 155 return content::NavigationThrottle::BLOCK_REQUEST; |
| 161 } | 156 } |
| 162 | 157 |
| 163 const char* ExtensionNavigationThrottle::GetNameForLogging() { | 158 const char* ExtensionNavigationThrottle::GetNameForLogging() { |
| 164 return "ExtensionNavigationThrottle"; | 159 return "ExtensionNavigationThrottle"; |
| 165 } | 160 } |
| 166 | 161 |
| 167 } // namespace extensions | 162 } // namespace extensions |
| OLD | NEW |