Chromium Code Reviews| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // should always be allowed. | 101 // should always be allowed. |
| 102 | 102 |
| 103 // If the navigation is not to a chrome-extension:// URL, no need to perform | 103 // If the navigation is not to a chrome-extension:// URL, no need to perform |
| 104 // any more checks. | 104 // any more checks. |
| 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 content::RenderFrameHost* ancestor = navigation_handle()->GetParentFrame(); |
|
Charlie Reis
2017/05/04 16:29:58
ekaramad/lazyboy: I'm further simplifying your rec
EhsanK
2017/05/04 18:01:38
Thanks! This is quite useful in my current works s
| |
| 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 | |
| 114 // traverse up to the main frame. | |
| 115 content::RenderFrameHost* navigating_frame = | |
| 116 web_contents->FindFrameByFrameTreeNodeId( | |
| 117 navigation_handle()->GetFrameTreeNodeId()); | |
| 118 DCHECK(navigating_frame); | |
| 119 | |
| 120 // Traverse the chain of parent frames, checking if they are the same origin | |
| 121 // as the URL of this navigation. | |
| 122 content::RenderFrameHost* ancestor = navigating_frame->GetParent(); | |
| 123 bool external_ancestor = false; | 112 bool external_ancestor = false; |
| 124 while (ancestor) { | 113 while (ancestor) { |
| 125 if (ancestor->GetLastCommittedURL().GetOrigin() != url.GetOrigin()) { | 114 if (ancestor->GetLastCommittedURL().GetOrigin() != url.GetOrigin()) { |
| 126 // Ignore DevTools, as it is allowed to embed extension pages. | 115 // Ignore DevTools, as it is allowed to embed extension pages. |
| 127 if (!ancestor->GetLastCommittedURL().SchemeIs( | 116 if (!ancestor->GetLastCommittedURL().SchemeIs( |
| 128 content::kChromeDevToolsScheme)) { | 117 content::kChromeDevToolsScheme)) { |
| 129 external_ancestor = true; | 118 external_ancestor = true; |
| 130 break; | 119 break; |
| 131 } | 120 } |
| 132 } | 121 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 153 } | 142 } |
| 154 | 143 |
| 155 return content::NavigationThrottle::BLOCK_REQUEST; | 144 return content::NavigationThrottle::BLOCK_REQUEST; |
| 156 } | 145 } |
| 157 | 146 |
| 158 const char* ExtensionNavigationThrottle::GetNameForLogging() { | 147 const char* ExtensionNavigationThrottle::GetNameForLogging() { |
| 159 return "ExtensionNavigationThrottle"; | 148 return "ExtensionNavigationThrottle"; |
| 160 } | 149 } |
| 161 | 150 |
| 162 } // namespace extensions | 151 } // namespace extensions |
| OLD | NEW |