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