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" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "content/public/common/browser_side_navigation_policy.h" | 12 #include "content/public/common/browser_side_navigation_policy.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 15 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
16 #include "extensions/browser/url_request_util.h" | 16 #include "extensions/browser/url_request_util.h" |
| 17 #include "extensions/browser/view_type_utils.h" |
17 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
19 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
20 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" | 21 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
21 #include "extensions/common/manifest_handlers/webview_info.h" | 22 #include "extensions/common/manifest_handlers/webview_info.h" |
22 #include "extensions/common/permissions/api_permission.h" | 23 #include "extensions/common/permissions/api_permission.h" |
23 #include "extensions/common/permissions/permissions_data.h" | 24 #include "extensions/common/permissions/permissions_data.h" |
24 #include "ui/base/page_transition_types.h" | 25 #include "ui/base/page_transition_types.h" |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 &partition_domain, &partition_id, &in_memory); | 102 &partition_domain, &partition_id, &in_memory); |
102 | 103 |
103 bool allowed = true; | 104 bool allowed = true; |
104 url_request_util::AllowCrossRendererResourceLoadHelper( | 105 url_request_util::AllowCrossRendererResourceLoadHelper( |
105 is_guest, target_extension, owner_extension, partition_id, url.path(), | 106 is_guest, target_extension, owner_extension, partition_id, url.path(), |
106 navigation_handle()->GetPageTransition(), &allowed); | 107 navigation_handle()->GetPageTransition(), &allowed); |
107 if (!allowed) | 108 if (!allowed) |
108 return content::NavigationThrottle::BLOCK_REQUEST; | 109 return content::NavigationThrottle::BLOCK_REQUEST; |
109 } | 110 } |
110 | 111 |
| 112 // Platform apps should only load in app windows, or guest views; never in |
| 113 // regular tabs. TODO(nick): Further restrict the !guest case below. |
| 114 if (target_extension->is_platform_app() && !guest) { |
| 115 switch (GetViewType(web_contents)) { |
| 116 case VIEW_TYPE_APP_WINDOW: |
| 117 case VIEW_TYPE_BACKGROUND_CONTENTS: |
| 118 case VIEW_TYPE_EXTENSION_BACKGROUND_PAGE: |
| 119 case VIEW_TYPE_PANEL: |
| 120 break; |
| 121 default: |
| 122 return content::NavigationThrottle::CANCEL; |
| 123 } |
| 124 } |
| 125 |
111 return content::NavigationThrottle::PROCEED; | 126 return content::NavigationThrottle::PROCEED; |
112 } | 127 } |
113 | 128 |
114 // This is a subframe navigation to a |target_extension| resource. | 129 // This is a subframe navigation to a |target_extension| resource. |
115 // Enforce the web_accessible_resources restriction, and same-origin | 130 // Enforce the web_accessible_resources restriction, and same-origin |
116 // restrictions for platform apps. | 131 // restrictions for platform apps. |
117 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); | 132 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); |
118 | 133 |
119 // Look to see if all ancestors belong to |target_extension|. If not, | 134 // Look to see if all ancestors belong to |target_extension|. If not, |
120 // then the web_accessible_resource restriction applies. | 135 // then the web_accessible_resource restriction applies. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return CANCEL; | 199 return CANCEL; |
185 } | 200 } |
186 return result; | 201 return result; |
187 } | 202 } |
188 | 203 |
189 const char* ExtensionNavigationThrottle::GetNameForLogging() { | 204 const char* ExtensionNavigationThrottle::GetNameForLogging() { |
190 return "ExtensionNavigationThrottle"; | 205 return "ExtensionNavigationThrottle"; |
191 } | 206 } |
192 | 207 |
193 } // namespace extensions | 208 } // namespace extensions |
OLD | NEW |