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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 is_guest, target_extension, owner_extension, partition_id, url.path(), | 109 is_guest, target_extension, owner_extension, partition_id, url.path(), |
110 navigation_handle()->GetPageTransition(), &allowed); | 110 navigation_handle()->GetPageTransition(), &allowed); |
111 if (!allowed) | 111 if (!allowed) |
112 return content::NavigationThrottle::BLOCK_REQUEST; | 112 return content::NavigationThrottle::BLOCK_REQUEST; |
113 } | 113 } |
114 | 114 |
115 return content::NavigationThrottle::PROCEED; | 115 return content::NavigationThrottle::PROCEED; |
116 } | 116 } |
117 | 117 |
118 // This is a subframe navigation to a |target_extension| resource. | 118 // This is a subframe navigation to a |target_extension| resource. |
119 // Enforce the web_accessible_resources restriction. | 119 // Enforce the web_accessible_resources restriction, and same-origin |
120 // restrictions for platform apps. | |
120 content::RenderFrameHost* parent = web_contents->FindFrameByFrameTreeNodeId( | 121 content::RenderFrameHost* parent = web_contents->FindFrameByFrameTreeNodeId( |
121 navigation_handle()->GetParentFrameTreeNodeId()); | 122 navigation_handle()->GetParentFrameTreeNodeId()); |
122 | 123 |
123 // Look to see if all ancestors belong to |target_extension|. If not, | 124 // Look to see if all ancestors belong to |target_extension|. If not, |
124 // then the web_accessible_resource restriction applies. | 125 // then the web_accessible_resource restriction applies. |
125 bool external_ancestor = false; | 126 bool external_ancestor = false; |
126 for (auto* ancestor = parent; ancestor; ancestor = ancestor->GetParent()) { | 127 for (auto* ancestor = parent; ancestor; ancestor = ancestor->GetParent()) { |
127 // Look for a match on the last committed origin. This handles the | 128 // Look for a match on the last committed origin. This handles the |
128 // common case, and the about:blank case. | 129 // common case, and the about:blank case. |
129 if (ancestor->GetLastCommittedOrigin() == target_origin) | 130 if (ancestor->GetLastCommittedOrigin() == target_origin) |
(...skipping 16 matching lines...) Expand all Loading... | |
146 | 147 |
147 if (external_ancestor) { | 148 if (external_ancestor) { |
148 // Cancel navigations to nested URLs, to match the main frame behavior. | 149 // Cancel navigations to nested URLs, to match the main frame behavior. |
149 if (!url_has_extension_scheme) | 150 if (!url_has_extension_scheme) |
150 return content::NavigationThrottle::CANCEL; | 151 return content::NavigationThrottle::CANCEL; |
151 | 152 |
152 // |url| must be in the manifest's "web_accessible_resources" section. | 153 // |url| must be in the manifest's "web_accessible_resources" section. |
153 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(target_extension, | 154 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(target_extension, |
154 url.path())) | 155 url.path())) |
155 return content::NavigationThrottle::BLOCK_REQUEST; | 156 return content::NavigationThrottle::BLOCK_REQUEST; |
157 | |
158 // A platform app may not be loaded in an <iframe> by another origin. | |
159 // | |
160 // In fact, platform apps may not have any cross-origin iframes at all; for | |
161 // non-extension origins of |url| this is enforced by means of a Content | |
162 // Security Policy. But CSP is incapable of blocking the chrome-extension | |
163 // scheme. Thus, this case must be handled specially here. | |
164 if (target_extension->is_platform_app()) | |
165 return content::NavigationThrottle::CANCEL; | |
166 | |
167 // A platform app may not load another extension in an <iframe>. | |
168 const Extension* parent_extension = | |
169 registry->enabled_extensions().GetExtensionOrAppByURL( | |
170 parent->GetSiteInstance()->GetSiteURL()); | |
171 if (parent_extension && parent_extension->is_platform_app()) | |
172 return content::NavigationThrottle::BLOCK_REQUEST; | |
Devlin
2017/05/01 22:10:36
Document why the BLOCK vs CANCEL?
| |
156 } | 173 } |
157 | 174 |
158 return content::NavigationThrottle::PROCEED; | 175 return content::NavigationThrottle::PROCEED; |
159 } | 176 } |
160 | 177 |
161 } // namespace extensions | 178 } // namespace extensions |
OLD | NEW |