OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 } | 1353 } |
1354 | 1354 |
1355 void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { | 1355 void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
1356 MaybeHandleDebugURL(params.url); | 1356 MaybeHandleDebugURL(params.url); |
1357 if (!webview()) | 1357 if (!webview()) |
1358 return; | 1358 return; |
1359 | 1359 |
1360 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); | 1360 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
1361 | 1361 |
1362 bool is_reload = IsReload(params); | 1362 bool is_reload = IsReload(params); |
1363 WebURLRequest::CachePolicy cache_policy = | |
1364 WebURLRequest::UseProtocolCachePolicy; | |
1363 | 1365 |
1364 // If this is a stale back/forward (due to a recent navigation the browser | 1366 // If this is a stale back/forward (due to a recent navigation the browser |
1365 // didn't know about), ignore it. | 1367 // didn't know about), ignore it. |
1366 if (IsBackForwardToStaleEntry(params, is_reload)) | 1368 if (IsBackForwardToStaleEntry(params, is_reload)) |
1367 return; | 1369 return; |
1368 | 1370 |
1369 // Swap this renderer back in if necessary. | 1371 // Swap this renderer back in if necessary. |
1370 if (is_swapped_out_) { | 1372 if (is_swapped_out_) { |
1371 // We marked the view as hidden when swapping the view out, so be sure to | 1373 // We marked the view as hidden when swapping the view out, so be sure to |
1372 // reset the visibility state before navigating to the new URL. | 1374 // reset the visibility state before navigating to the new URL. |
1373 webview()->setVisibilityState(visibilityState(), false); | 1375 webview()->setVisibilityState(visibilityState(), false); |
1374 | 1376 |
1375 // If this is an attempt to reload while we are swapped out, we should not | 1377 // If this is an attempt to reload while we are swapped out, we should not |
1376 // reload swappedout://, but the previous page, which is stored in | 1378 // reload swappedout://, but the previous page, which is stored in |
1377 // params.state. Setting is_reload to false will treat this like a back | 1379 // params.state. Setting is_reload to false will treat this like a back |
1378 // navigation to accomplish that. | 1380 // navigation to accomplish that. |
1379 is_reload = false; | 1381 is_reload = false; |
1382 cache_policy = WebURLRequest::ReloadIgnoringCacheData; | |
1380 | 1383 |
1381 // We refresh timezone when a view is swapped in since timezone | 1384 // We refresh timezone when a view is swapped in since timezone |
1382 // can get out of sync when the system timezone is updated while | 1385 // can get out of sync when the system timezone is updated while |
1383 // the view is swapped out. | 1386 // the view is swapped out. |
1384 NotifyTimezoneChange(webview()->mainFrame()); | 1387 NotifyTimezoneChange(webview()->mainFrame()); |
1385 | 1388 |
1386 SetSwappedOut(false); | 1389 SetSwappedOut(false); |
1387 } | 1390 } |
1388 | 1391 |
1389 if (params.should_clear_history_list) { | 1392 if (params.should_clear_history_list) { |
(...skipping 13 matching lines...) Expand all Loading... | |
1403 | 1406 |
1404 WebFrame* frame = webview()->mainFrame(); | 1407 WebFrame* frame = webview()->mainFrame(); |
1405 if (!params.frame_to_navigate.empty()) { | 1408 if (!params.frame_to_navigate.empty()) { |
1406 frame = webview()->findFrameByName( | 1409 frame = webview()->findFrameByName( |
1407 WebString::fromUTF8(params.frame_to_navigate)); | 1410 WebString::fromUTF8(params.frame_to_navigate)); |
1408 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; | 1411 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; |
1409 } | 1412 } |
1410 | 1413 |
1411 if (is_reload && frame->currentHistoryItem().isNull()) { | 1414 if (is_reload && frame->currentHistoryItem().isNull()) { |
1412 // We cannot reload if we do not have any history state. This happens, for | 1415 // We cannot reload if we do not have any history state. This happens, for |
1413 // example, when recovering from a crash. Our workaround here is a bit of | 1416 // example, when recovering from a crash. |
1414 // a hack since it means that reload after a crashed tab does not cause an | |
1415 // end-to-end cache validation. | |
1416 is_reload = false; | 1417 is_reload = false; |
1418 cache_policy = WebURLRequest::ReloadIgnoringCacheData; | |
darin (slow to review)
2014/01/07 07:39:59
good fix for that old bug.
| |
1417 } | 1419 } |
1418 | 1420 |
1419 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); | 1421 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); |
1420 | 1422 |
1421 // If we are reloading, then WebKit will use the history state of the current | 1423 // If we are reloading, then WebKit will use the history state of the current |
1422 // page, so we should just ignore any given history state. Otherwise, if we | 1424 // page, so we should just ignore any given history state. Otherwise, if we |
1423 // have history state, then we need to navigate to it, which corresponds to a | 1425 // have history state, then we need to navigate to it, which corresponds to a |
1424 // back/forward navigation event. | 1426 // back/forward navigation event. |
1425 if (is_reload) { | 1427 if (is_reload) { |
1426 bool reload_original_url = | 1428 bool reload_original_url = |
1427 (params.navigation_type == | 1429 (params.navigation_type == |
1428 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); | 1430 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
1429 bool ignore_cache = (params.navigation_type == | 1431 bool ignore_cache = (params.navigation_type == |
1430 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); | 1432 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
1431 | 1433 |
1432 if (reload_original_url) | 1434 if (reload_original_url) |
1433 frame->reloadWithOverrideURL(params.url, true); | 1435 frame->reloadWithOverrideURL(params.url, true); |
1434 else | 1436 else |
1435 frame->reload(ignore_cache); | 1437 frame->reload(ignore_cache); |
1436 } else if (params.page_state.IsValid()) { | 1438 } else if (params.page_state.IsValid()) { |
1437 // We must know the page ID of the page we are navigating back to. | 1439 // We must know the page ID of the page we are navigating back to. |
1438 DCHECK_NE(params.page_id, -1); | 1440 DCHECK_NE(params.page_id, -1); |
1439 WebHistoryItem item = PageStateToHistoryItem(params.page_state); | 1441 WebHistoryItem item = PageStateToHistoryItem(params.page_state); |
1440 if (!item.isNull()) { | 1442 if (!item.isNull()) { |
1441 // Ensure we didn't save the swapped out URL in UpdateState, since the | 1443 // Ensure we didn't save the swapped out URL in UpdateState, since the |
1442 // browser should never be telling us to navigate to swappedout://. | 1444 // browser should never be telling us to navigate to swappedout://. |
1443 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); | 1445 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
1444 frame->loadHistoryItem(item); | 1446 frame->loadHistoryItem(item, cache_policy); |
1445 } | 1447 } |
1446 } else if (!params.base_url_for_data_url.is_empty()) { | 1448 } else if (!params.base_url_for_data_url.is_empty()) { |
1447 // A loadData request with a specified base URL. | 1449 // A loadData request with a specified base URL. |
1448 std::string mime_type, charset, data; | 1450 std::string mime_type, charset, data; |
1449 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { | 1451 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
1450 frame->loadData( | 1452 frame->loadData( |
1451 WebData(data.c_str(), data.length()), | 1453 WebData(data.c_str(), data.length()), |
1452 WebString::fromUTF8(mime_type), | 1454 WebString::fromUTF8(mime_type), |
1453 WebString::fromUTF8(charset), | 1455 WebString::fromUTF8(charset), |
1454 params.base_url_for_data_url, | 1456 params.base_url_for_data_url, |
(...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3445 InternalDocumentStateData* internal_data = | 3447 InternalDocumentStateData* internal_data = |
3446 InternalDocumentStateData::FromDocumentState(document_state); | 3448 InternalDocumentStateData::FromDocumentState(document_state); |
3447 | 3449 |
3448 if (!params.url.SchemeIs(kJavaScriptScheme) && | 3450 if (!params.url.SchemeIs(kJavaScriptScheme) && |
3449 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { | 3451 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
3450 // We're doing a load of a page that was restored from the last session. By | 3452 // We're doing a load of a page that was restored from the last session. By |
3451 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which | 3453 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
3452 // can result in stale data for pages that are set to expire. We explicitly | 3454 // can result in stale data for pages that are set to expire. We explicitly |
3453 // override that by setting the policy here so that as necessary we load | 3455 // override that by setting the policy here so that as necessary we load |
3454 // from the network. | 3456 // from the network. |
3457 // | |
3458 // TODO(davidben): Remove this in favor of passing a cache policy to the | |
3459 // loadHistoryItem call in OnNavigate. That requires not overloading | |
3460 // UseProtocolCachePolicy to mean both "normal load" and "determine cache | |
3461 // policy based on load type, etc". | |
3455 internal_data->set_cache_policy_override( | 3462 internal_data->set_cache_policy_override( |
3456 WebURLRequest::UseProtocolCachePolicy); | 3463 WebURLRequest::UseProtocolCachePolicy); |
3457 } | 3464 } |
3458 | 3465 |
3459 if (IsReload(params)) | 3466 if (IsReload(params)) |
3460 document_state->set_load_type(DocumentState::RELOAD); | 3467 document_state->set_load_type(DocumentState::RELOAD); |
3461 else if (params.page_state.IsValid()) | 3468 else if (params.page_state.IsValid()) |
3462 document_state->set_load_type(DocumentState::HISTORY_LOAD); | 3469 document_state->set_load_type(DocumentState::HISTORY_LOAD); |
3463 else | 3470 else |
3464 document_state->set_load_type(DocumentState::NORMAL_LOAD); | 3471 document_state->set_load_type(DocumentState::NORMAL_LOAD); |
(...skipping 2983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6448 for (size_t i = 0; i < icon_urls.size(); i++) { | 6455 for (size_t i = 0; i < icon_urls.size(); i++) { |
6449 WebURL url = icon_urls[i].iconURL(); | 6456 WebURL url = icon_urls[i].iconURL(); |
6450 if (!url.isEmpty()) | 6457 if (!url.isEmpty()) |
6451 urls.push_back(FaviconURL(url, | 6458 urls.push_back(FaviconURL(url, |
6452 ToFaviconType(icon_urls[i].iconType()))); | 6459 ToFaviconType(icon_urls[i].iconType()))); |
6453 } | 6460 } |
6454 SendUpdateFaviconURL(urls); | 6461 SendUpdateFaviconURL(urls); |
6455 } | 6462 } |
6456 | 6463 |
6457 } // namespace content | 6464 } // namespace content |
OLD | NEW |