OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 process->FilterURL(true, &validated_params.searchable_form_url); | 1199 process->FilterURL(true, &validated_params.searchable_form_url); |
1200 | 1200 |
1201 // Without this check, the renderer can trick the browser into using | 1201 // Without this check, the renderer can trick the browser into using |
1202 // filenames it can't access in a future session restore. | 1202 // filenames it can't access in a future session restore. |
1203 if (!CanAccessFilesOfPageState(validated_params.page_state)) { | 1203 if (!CanAccessFilesOfPageState(validated_params.page_state)) { |
1204 bad_message::ReceivedBadMessage( | 1204 bad_message::ReceivedBadMessage( |
1205 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); | 1205 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); |
1206 return; | 1206 return; |
1207 } | 1207 } |
1208 | 1208 |
1209 // If the URL or |was_within_same_page| does not match what the | 1209 // PlzNavigate |
1210 // NavigationHandle expects, treat the commit as a new navigation. This can | 1210 if (!navigation_handle_ && IsBrowserSideNavigationEnabled()) { |
1211 // happen if an ongoing slow same-process navigation is interwoven with a | 1211 // PlzNavigate: the browser has not been notified about the start of the |
1212 // synchronous renderer-initiated navigation. | 1212 // load in this renderer yet (e.g., for same-page navigations that start in |
1213 // TODO(csharrison): Data navigations loaded with LoadDataWithBaseURL get | 1213 // the renderer). Do it now. |
1214 // reset here, because the NavigationHandle tracks the URL but the | 1214 DCHECK(validated_params.was_within_same_page); |
1215 // validated_params.url tracks the data. The trick of saving the old entry ids | 1215 if (!is_loading()) { |
1216 // for these navigations should go away when this is properly handled. See | 1216 bool was_loading = frame_tree_node()->frame_tree()->IsLoading(); |
1217 // crbug.com/588317. | 1217 is_loading_ = true; |
1218 int entry_id_for_data_nav = 0; | 1218 frame_tree_node()->DidStartLoading(true, was_loading); |
1219 bool is_renderer_initiated = true; | |
1220 if (navigation_handle_ && | |
1221 ((navigation_handle_->GetURL() != validated_params.url) || | |
1222 navigation_handle_->IsSamePage() != | |
1223 validated_params.was_within_same_page)) { | |
1224 // Make sure that the pending entry was really loaded via | |
1225 // LoadDataWithBaseURL and that it matches this handle. | |
1226 NavigationEntryImpl* pending_entry = | |
1227 NavigationEntryImpl::FromNavigationEntry( | |
1228 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); | |
1229 bool pending_entry_matches_handle = | |
1230 pending_entry && | |
1231 pending_entry->GetUniqueID() == | |
1232 navigation_handle_->pending_nav_entry_id(); | |
1233 // TODO(csharrison): The pending entry's base url should equal | |
1234 // |validated_params.base_url|. This is not the case for loads with invalid | |
1235 // base urls. | |
1236 if (navigation_handle_->GetURL() == validated_params.base_url && | |
1237 pending_entry_matches_handle && | |
1238 !pending_entry->GetBaseURLForDataURL().is_empty()) { | |
1239 entry_id_for_data_nav = navigation_handle_->pending_nav_entry_id(); | |
1240 is_renderer_initiated = pending_entry->is_renderer_initiated(); | |
1241 } | 1219 } |
1242 navigation_handle_.reset(); | 1220 pending_commit_ = false; |
1243 } | 1221 } |
1244 | 1222 |
1245 // Synchronous renderer-initiated navigations will send a | 1223 // Find the appropriate NavigationHandle for this navigation. |
1246 // DidCommitProvisionalLoad IPC without a prior DidStartProvisionalLoad | 1224 std::unique_ptr<NavigationHandleImpl> navigation_handle = |
1247 // message. Or in addition, the if block above can reset the NavigationHandle | 1225 TakeNavigationHandleForCommit(validated_params); |
1248 // in cases it doesn't match the expected commit. | 1226 DCHECK(navigation_handle); |
1249 if (!navigation_handle_) { | |
1250 // There is no pending NavigationEntry in these cases, so pass 0 as the | |
1251 // nav_id. If the previous handle was a prematurely aborted navigation | |
1252 // loaded via LoadDataWithBaseURL, propogate the entry id. | |
1253 navigation_handle_ = NavigationHandleImpl::Create( | |
1254 validated_params.url, frame_tree_node_, is_renderer_initiated, | |
1255 validated_params.was_within_same_page, validated_params.is_srcdoc, | |
1256 base::TimeTicks::Now(), entry_id_for_data_nav, | |
1257 false); // started_from_context_menu | |
1258 // PlzNavigate | |
1259 if (IsBrowserSideNavigationEnabled()) { | |
1260 // PlzNavigate: synchronous loads happen in the renderer, and the browser | |
1261 // has not been notified about the start of the load yet. Do it now. | |
1262 if (!is_loading()) { | |
1263 bool was_loading = frame_tree_node()->frame_tree()->IsLoading(); | |
1264 is_loading_ = true; | |
1265 frame_tree_node()->DidStartLoading(true, was_loading); | |
1266 } | |
1267 pending_commit_ = false; | |
1268 } | |
1269 } | |
1270 | 1227 |
1271 accessibility_reset_count_ = 0; | 1228 accessibility_reset_count_ = 0; |
1272 frame_tree_node()->navigator()->DidNavigate(this, validated_params); | 1229 frame_tree_node()->navigator()->DidNavigate(this, validated_params, |
| 1230 std::move(navigation_handle)); |
1273 | 1231 |
1274 // Since we didn't early return, it's safe to keep the commit state. | 1232 // Since we didn't early return, it's safe to keep the commit state. |
1275 commit_state_resetter.disable(); | 1233 commit_state_resetter.disable(); |
1276 | 1234 |
1277 // For a top-level frame, there are potential security concerns associated | 1235 // For a top-level frame, there are potential security concerns associated |
1278 // with displaying graphics from a previously loaded page after the URL in | 1236 // with displaying graphics from a previously loaded page after the URL in |
1279 // the omnibar has been changed. It is unappealing to clear the page | 1237 // the omnibar has been changed. It is unappealing to clear the page |
1280 // immediately, but if the renderer is taking a long time to issue any | 1238 // immediately, but if the renderer is taking a long time to issue any |
1281 // compositor output (possibly because of script deliberately creating this | 1239 // compositor output (possibly because of script deliberately creating this |
1282 // situation) then we clear it after a while anyway. | 1240 // situation) then we clear it after a while anyway. |
(...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3203 // handler after it's destroyed so it can't run after the RFHI is destroyed. | 3161 // handler after it's destroyed so it can't run after the RFHI is destroyed. |
3204 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( | 3162 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( |
3205 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); | 3163 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); |
3206 return web_bluetooth_service_.get(); | 3164 return web_bluetooth_service_.get(); |
3207 } | 3165 } |
3208 | 3166 |
3209 void RenderFrameHostImpl::DeleteWebBluetoothService() { | 3167 void RenderFrameHostImpl::DeleteWebBluetoothService() { |
3210 web_bluetooth_service_.reset(); | 3168 web_bluetooth_service_.reset(); |
3211 } | 3169 } |
3212 | 3170 |
| 3171 std::unique_ptr<NavigationHandleImpl> |
| 3172 RenderFrameHostImpl::TakeNavigationHandleForCommit( |
| 3173 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 3174 // If this is a same-page navigation, there isn't an existing NavigationHandle |
| 3175 // to use for the navigation. Create one, but don't reset any NavigationHandle |
| 3176 // tracking an ongoing navigation, since this may lead to the cancellation of |
| 3177 // the navigation. |
| 3178 if (params.was_within_same_page) { |
| 3179 // We don't ever expect navigation_handle_ to match, because handles are not |
| 3180 // created for same-page navigations. |
| 3181 DCHECK(!navigation_handle_ || !navigation_handle_->IsSamePage()); |
| 3182 |
| 3183 // First, determine if the navigation corresponds to the pending navigation |
| 3184 // entry. This is the case for a browser-initiated same-page navigation, |
| 3185 // which does not cause a NavigationHandle to be created because it does not |
| 3186 // go through DidStartProvisionalLoad. |
| 3187 bool is_renderer_initiated = true; |
| 3188 int pending_nav_entry_id = 0; |
| 3189 NavigationEntryImpl* pending_entry = |
| 3190 NavigationEntryImpl::FromNavigationEntry( |
| 3191 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); |
| 3192 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) { |
| 3193 pending_nav_entry_id = params.nav_entry_id; |
| 3194 is_renderer_initiated = pending_entry->is_renderer_initiated(); |
| 3195 } |
| 3196 |
| 3197 return NavigationHandleImpl::Create( |
| 3198 params.url, frame_tree_node_, is_renderer_initiated, |
| 3199 params.was_within_same_page, params.is_srcdoc, base::TimeTicks::Now(), |
| 3200 pending_nav_entry_id, false); // started_from_context_menu |
| 3201 } |
| 3202 |
| 3203 // Determine if the current NavigationHandle can be used. |
| 3204 if (navigation_handle_ && navigation_handle_->GetURL() == params.url) { |
| 3205 return std::move(navigation_handle_); |
| 3206 } |
| 3207 |
| 3208 // If the URL does not match what the NavigationHandle expects, treat the |
| 3209 // commit as a new navigation. This can happen when loading a Data |
| 3210 // navigation with LoadDataWithBaseURL. |
| 3211 // |
| 3212 // TODO(csharrison): Data navigations loaded with LoadDataWithBaseURL get |
| 3213 // reset here, because the NavigationHandle tracks the URL but the params.url |
| 3214 // tracks the data. The trick of saving the old entry ids for these |
| 3215 // navigations should go away when this is properly handled. |
| 3216 // See crbug.com/588317. |
| 3217 int entry_id_for_data_nav = 0; |
| 3218 bool is_renderer_initiated = true; |
| 3219 |
| 3220 // Make sure that the pending entry was really loaded via LoadDataWithBaseURL |
| 3221 // and that it matches this handle. TODO(csharrison): The pending entry's |
| 3222 // base url should equal |params.base_url|. This is not the case for loads |
| 3223 // with invalid base urls. |
| 3224 if (navigation_handle_) { |
| 3225 NavigationEntryImpl* pending_entry = |
| 3226 NavigationEntryImpl::FromNavigationEntry( |
| 3227 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); |
| 3228 bool pending_entry_matches_handle = |
| 3229 pending_entry && |
| 3230 pending_entry->GetUniqueID() == |
| 3231 navigation_handle_->pending_nav_entry_id(); |
| 3232 // TODO(csharrison): The pending entry's base url should equal |
| 3233 // |validated_params.base_url|. This is not the case for loads with invalid |
| 3234 // base urls. |
| 3235 if (navigation_handle_->GetURL() == params.base_url && |
| 3236 pending_entry_matches_handle && |
| 3237 !pending_entry->GetBaseURLForDataURL().is_empty()) { |
| 3238 entry_id_for_data_nav = navigation_handle_->pending_nav_entry_id(); |
| 3239 is_renderer_initiated = pending_entry->is_renderer_initiated(); |
| 3240 } |
| 3241 |
| 3242 // Reset any existing NavigationHandle. |
| 3243 navigation_handle_.reset(); |
| 3244 } |
| 3245 |
| 3246 // There is no pending NavigationEntry in these cases, so pass 0 as the |
| 3247 // pending_nav_entry_id. If the previous handle was a prematurely aborted |
| 3248 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. |
| 3249 return NavigationHandleImpl::Create( |
| 3250 params.url, frame_tree_node_, is_renderer_initiated, |
| 3251 params.was_within_same_page, params.is_srcdoc, base::TimeTicks::Now(), |
| 3252 entry_id_for_data_nav, false); // started_from_context_menu |
| 3253 } |
| 3254 |
3213 } // namespace content | 3255 } // namespace content |
OLD | NEW |