| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/frame_host/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/debug/dump_without_crashing.h" | 9 #include "base/debug/dump_without_crashing.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 if (!callback.is_null()) | 1093 if (!callback.is_null()) |
| 1094 callback.Run(result); | 1094 callback.Run(result); |
| 1095 | 1095 |
| 1096 // No code after running the callback, as it might have resulted in our | 1096 // No code after running the callback, as it might have resulted in our |
| 1097 // destruction. | 1097 // destruction. |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 void NavigationHandleImpl::RegisterNavigationThrottles() { | 1100 void NavigationHandleImpl::RegisterNavigationThrottles() { |
| 1101 // Register the navigation throttles. The vector returned by | 1101 // Note: |throttle_| might not be empty. Some NavigationThrottles might have |
| 1102 // CreateThrottlesForNavigation is not assigned to throttles_ directly because | 1102 // been registered with RegisterThrottleForTesting. These must reside at the |
| 1103 // it would overwrite any throttles previously added with | 1103 // end of |throttles_|. TestNavigationManagerThrottle expects that the |
| 1104 // RegisterThrottleForTesting. | 1104 // NavigationThrottles added for test are the last NavigationThrottles to |
| 1105 // TODO(carlosk, arthursonzogni): should simplify this to either use | 1105 // execute. Take them out while appending the rest of the |
| 1106 // |throttles_| directly (except for the case described above) or | 1106 // NavigationThrottles. |
| 1107 // |throttles_to_register| for registering all throttles. | 1107 std::vector<std::unique_ptr<NavigationThrottle>> testing_throttles = |
| 1108 std::vector<std::unique_ptr<NavigationThrottle>> throttles_to_register = | 1108 std::move(throttles_); |
| 1109 GetDelegate()->CreateThrottlesForNavigation(this); | 1109 |
| 1110 throttles_ = GetDelegate()->CreateThrottlesForNavigation(this); |
| 1110 | 1111 |
| 1111 // Check for renderer-inititated main frame navigations to data URLs. This is | 1112 // Check for renderer-inititated main frame navigations to data URLs. This is |
| 1112 // done first as it may block the main frame navigation altogether. | 1113 // done first as it may block the main frame navigation altogether. |
| 1113 std::unique_ptr<NavigationThrottle> data_url_navigation_throttle = | 1114 AddThrottle(DataUrlNavigationThrottle::CreateThrottleForNavigation(this)); |
| 1114 DataUrlNavigationThrottle::CreateThrottleForNavigation(this); | |
| 1115 if (data_url_navigation_throttle) | |
| 1116 throttles_to_register.push_back(std::move(data_url_navigation_throttle)); | |
| 1117 | 1115 |
| 1118 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = | 1116 AddThrottle(AncestorThrottle::MaybeCreateThrottleFor(this)); |
| 1119 content::AncestorThrottle::MaybeCreateThrottleFor(this); | 1117 AddThrottle(FormSubmissionThrottle::MaybeCreateThrottleFor(this)); |
| 1120 if (ancestor_throttle) | |
| 1121 throttles_.push_back(std::move(ancestor_throttle)); | |
| 1122 | |
| 1123 std::unique_ptr<content::NavigationThrottle> form_submission_throttle = | |
| 1124 content::FormSubmissionThrottle::MaybeCreateThrottleFor(this); | |
| 1125 if (form_submission_throttle) | |
| 1126 throttles_.push_back(std::move(form_submission_throttle)); | |
| 1127 | 1118 |
| 1128 // Check for mixed content. This is done after the AncestorThrottle and the | 1119 // Check for mixed content. This is done after the AncestorThrottle and the |
| 1129 // FormSubmissionThrottle so that when folks block mixed content with a CSP | 1120 // FormSubmissionThrottle so that when folks block mixed content with a CSP |
| 1130 // policy, they don't get a warning. They'll still get a warning in the | 1121 // policy, they don't get a warning. They'll still get a warning in the |
| 1131 // console about CSP blocking the load. | 1122 // console about CSP blocking the load. |
| 1132 std::unique_ptr<NavigationThrottle> mixed_content_throttle = | 1123 AddThrottle( |
| 1133 MixedContentNavigationThrottle::CreateThrottleForNavigation(this); | 1124 MixedContentNavigationThrottle::CreateThrottleForNavigation(this)); |
| 1134 if (mixed_content_throttle) | |
| 1135 throttles_to_register.push_back(std::move(mixed_content_throttle)); | |
| 1136 | 1125 |
| 1137 std::unique_ptr<NavigationThrottle> devtools_throttle = | 1126 AddThrottle(RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this)); |
| 1138 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); | |
| 1139 if (devtools_throttle) | |
| 1140 throttles_to_register.push_back(std::move(devtools_throttle)); | |
| 1141 | 1127 |
| 1142 throttles_.insert(throttles_.begin(), | 1128 // Insert all testing NavigationThrottles last. |
| 1143 std::make_move_iterator(throttles_to_register.begin()), | 1129 throttles_.insert(throttles_.end(), |
| 1144 std::make_move_iterator(throttles_to_register.end())); | 1130 std::make_move_iterator(testing_throttles.begin()), |
| 1131 std::make_move_iterator(testing_throttles.end())); |
| 1132 } |
| 1133 |
| 1134 void NavigationHandleImpl::AddThrottle( |
| 1135 std::unique_ptr<NavigationThrottle> throttle) { |
| 1136 if (throttle) |
| 1137 throttles_.push_back(std::move(throttle)); |
| 1145 } | 1138 } |
| 1146 | 1139 |
| 1147 bool NavigationHandleImpl::IsSelfReferentialURL() { | 1140 bool NavigationHandleImpl::IsSelfReferentialURL() { |
| 1148 // about: URLs should be exempted since they are reserved for other purposes | 1141 // about: URLs should be exempted since they are reserved for other purposes |
| 1149 // and cannot be the source of infinite recursion. See | 1142 // and cannot be the source of infinite recursion. See |
| 1150 // https://crbug.com/341858 . | 1143 // https://crbug.com/341858 . |
| 1151 if (url_.SchemeIs("about")) | 1144 if (url_.SchemeIs("about")) |
| 1152 return false; | 1145 return false; |
| 1153 | 1146 |
| 1154 // Browser-triggered navigations should be exempted. | 1147 // Browser-triggered navigations should be exempted. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 // Stop expecting a navigation to the current site URL in the current expected | 1184 // Stop expecting a navigation to the current site URL in the current expected |
| 1192 // process. | 1185 // process. |
| 1193 SetExpectedProcess(nullptr); | 1186 SetExpectedProcess(nullptr); |
| 1194 | 1187 |
| 1195 // Update the site URL and the expected process. | 1188 // Update the site URL and the expected process. |
| 1196 site_url_ = new_site_url; | 1189 site_url_ = new_site_url; |
| 1197 SetExpectedProcess(post_redirect_process); | 1190 SetExpectedProcess(post_redirect_process); |
| 1198 } | 1191 } |
| 1199 | 1192 |
| 1200 } // namespace content | 1193 } // namespace content |
| OLD | NEW |