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 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1383 |
1384 const WebHistoryItem& item = | 1384 const WebHistoryItem& item = |
1385 webview()->mainFrame()->previousHistoryItem(); | 1385 webview()->mainFrame()->previousHistoryItem(); |
1386 SendUpdateState(item); | 1386 SendUpdateState(item); |
1387 } | 1387 } |
1388 | 1388 |
1389 void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { | 1389 void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
1390 if (item.isNull()) | 1390 if (item.isNull()) |
1391 return; | 1391 return; |
1392 | 1392 |
1393 // Don't send state updates for chrome::kSwappedOutURL. | 1393 // Don't send state updates for content::kSwappedOutURL. |
1394 if (item.urlString() == WebString::fromUTF8(chrome::kSwappedOutURL)) | 1394 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL)) |
1395 return; | 1395 return; |
1396 | 1396 |
1397 Send(new ViewHostMsg_UpdateState( | 1397 Send(new ViewHostMsg_UpdateState( |
1398 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); | 1398 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
1399 } | 1399 } |
1400 | 1400 |
1401 void RenderViewImpl::OpenURL(WebFrame* frame, | 1401 void RenderViewImpl::OpenURL(WebFrame* frame, |
1402 const GURL& url, | 1402 const GURL& url, |
1403 const Referrer& referrer, | 1403 const Referrer& referrer, |
1404 WebNavigationPolicy policy) { | 1404 WebNavigationPolicy policy) { |
(...skipping 18 matching lines...) Expand all Loading... |
1423 | 1423 |
1424 if (!html.empty()) { | 1424 if (!html.empty()) { |
1425 error_html = &html; | 1425 error_html = &html; |
1426 } else { | 1426 } else { |
1427 content::GetContentClient()->renderer()->GetNavigationErrorStrings( | 1427 content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
1428 failed_request, error, &alt_html, NULL); | 1428 failed_request, error, &alt_html, NULL); |
1429 error_html = &alt_html; | 1429 error_html = &alt_html; |
1430 } | 1430 } |
1431 | 1431 |
1432 frame->loadHTMLString(*error_html, | 1432 frame->loadHTMLString(*error_html, |
1433 GURL(chrome::kUnreachableWebDataURL), | 1433 GURL(content::kUnreachableWebDataURL), |
1434 error.unreachableURL, | 1434 error.unreachableURL, |
1435 replace); | 1435 replace); |
1436 } | 1436 } |
1437 | 1437 |
1438 bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type, | 1438 bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type, |
1439 const string16& message, | 1439 const string16& message, |
1440 const string16& default_value, | 1440 const string16& default_value, |
1441 const GURL& frame_url, | 1441 const GURL& frame_url, |
1442 string16* result) { | 1442 string16* result) { |
1443 bool success = false; | 1443 bool success = false; |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 } | 2274 } |
2275 | 2275 |
2276 WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( | 2276 WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
2277 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, | 2277 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
2278 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { | 2278 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
2279 Referrer referrer( | 2279 Referrer referrer( |
2280 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), | 2280 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
2281 GetReferrerPolicyFromRequest(request)); | 2281 GetReferrerPolicyFromRequest(request)); |
2282 | 2282 |
2283 if (is_swapped_out_) { | 2283 if (is_swapped_out_) { |
2284 if (request.url() != GURL(chrome::kSwappedOutURL)) { | 2284 if (request.url() != GURL(content::kSwappedOutURL)) { |
2285 // Targeted links may try to navigate a swapped out frame. Allow the | 2285 // Targeted links may try to navigate a swapped out frame. Allow the |
2286 // browser process to navigate the tab instead. Note that it is also | 2286 // browser process to navigate the tab instead. Note that it is also |
2287 // possible for non-targeted navigations (from this view) to arrive | 2287 // possible for non-targeted navigations (from this view) to arrive |
2288 // here just after we are swapped out. It's ok to send them to the | 2288 // here just after we are swapped out. It's ok to send them to the |
2289 // browser, as long as they're for the top level frame. | 2289 // browser, as long as they're for the top level frame. |
2290 // TODO(creis): Ensure this supports targeted form submissions when | 2290 // TODO(creis): Ensure this supports targeted form submissions when |
2291 // fixing http://crbug.com/101395. | 2291 // fixing http://crbug.com/101395. |
2292 if (frame->parent() == NULL) { | 2292 if (frame->parent() == NULL) { |
2293 OpenURL(frame, request.url(), referrer, default_policy); | 2293 OpenURL(frame, request.url(), referrer, default_policy); |
2294 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. | 2294 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
2295 } | 2295 } |
2296 | 2296 |
2297 // We should otherwise ignore in-process iframe navigations, if they | 2297 // We should otherwise ignore in-process iframe navigations, if they |
2298 // arrive just after we are swapped out. | 2298 // arrive just after we are swapped out. |
2299 return WebKit::WebNavigationPolicyIgnore; | 2299 return WebKit::WebNavigationPolicyIgnore; |
2300 } | 2300 } |
2301 | 2301 |
2302 // Allow chrome::kSwappedOutURL to complete. | 2302 // Allow content::kSwappedOutURL to complete. |
2303 return default_policy; | 2303 return default_policy; |
2304 } | 2304 } |
2305 | 2305 |
2306 // Webkit is asking whether to navigate to a new URL. | 2306 // Webkit is asking whether to navigate to a new URL. |
2307 // This is fine normally, except if we're showing UI from one security | 2307 // This is fine normally, except if we're showing UI from one security |
2308 // context and they're trying to navigate to a different context. | 2308 // context and they're trying to navigate to a different context. |
2309 const GURL& url = request.url(); | 2309 const GURL& url = request.url(); |
2310 | 2310 |
2311 // A content initiated navigation may have originated from a link-click, | 2311 // A content initiated navigation may have originated from a link-click, |
2312 // script, drag-n-drop operation, etc. | 2312 // script, drag-n-drop operation, etc. |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2846 document_state->set_commit_load_time(Time::Now()); | 2846 document_state->set_commit_load_time(Time::Now()); |
2847 | 2847 |
2848 if (is_new_navigation) { | 2848 if (is_new_navigation) { |
2849 // When we perform a new navigation, we need to update the last committed | 2849 // When we perform a new navigation, we need to update the last committed |
2850 // session history entry with state for the page we are leaving. | 2850 // session history entry with state for the page we are leaving. |
2851 UpdateSessionHistory(frame); | 2851 UpdateSessionHistory(frame); |
2852 | 2852 |
2853 // We bump our Page ID to correspond with the new session history entry. | 2853 // We bump our Page ID to correspond with the new session history entry. |
2854 page_id_ = next_page_id_++; | 2854 page_id_ = next_page_id_++; |
2855 | 2855 |
2856 // Don't update history_page_ids_ (etc) for chrome::kSwappedOutURL, since | 2856 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since |
2857 // we don't want to forget the entry that was there, and since we will | 2857 // we don't want to forget the entry that was there, and since we will |
2858 // never come back to chrome::kSwappedOutURL. Note that we have to call | 2858 // never come back to content::kSwappedOutURL. Note that we have to call |
2859 // UpdateSessionHistory and update page_id_ even in this case, so that | 2859 // UpdateSessionHistory and update page_id_ even in this case, so that |
2860 // the current entry gets a state update and so that we don't send a | 2860 // the current entry gets a state update and so that we don't send a |
2861 // state update to the wrong entry when we swap back in. | 2861 // state update to the wrong entry when we swap back in. |
2862 if (GetLoadingUrl(frame) != GURL(chrome::kSwappedOutURL)) { | 2862 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) { |
2863 // Advance our offset in session history, applying the length limit. | 2863 // Advance our offset in session history, applying the length limit. |
2864 // There is now no forward history. | 2864 // There is now no forward history. |
2865 history_list_offset_++; | 2865 history_list_offset_++; |
2866 if (history_list_offset_ >= content::kMaxSessionHistoryEntries) | 2866 if (history_list_offset_ >= content::kMaxSessionHistoryEntries) |
2867 history_list_offset_ = content::kMaxSessionHistoryEntries - 1; | 2867 history_list_offset_ = content::kMaxSessionHistoryEntries - 1; |
2868 history_list_length_ = history_list_offset_ + 1; | 2868 history_list_length_ = history_list_offset_ + 1; |
2869 history_page_ids_.resize(history_list_length_, -1); | 2869 history_page_ids_.resize(history_list_length_, -1); |
2870 history_page_ids_[history_list_offset_] = page_id_; | 2870 history_page_ids_[history_list_offset_] = page_id_; |
2871 } | 2871 } |
2872 } else { | 2872 } else { |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4440 | 4440 |
4441 // Send an UpdateState message before we get swapped out. | 4441 // Send an UpdateState message before we get swapped out. |
4442 SyncNavigationState(); | 4442 SyncNavigationState(); |
4443 | 4443 |
4444 // Synchronously run the unload handler before sending the ACK. | 4444 // Synchronously run the unload handler before sending the ACK. |
4445 webview()->dispatchUnloadEvent(); | 4445 webview()->dispatchUnloadEvent(); |
4446 | 4446 |
4447 // Swap out and stop sending any IPC messages that are not ACKs. | 4447 // Swap out and stop sending any IPC messages that are not ACKs. |
4448 SetSwappedOut(true); | 4448 SetSwappedOut(true); |
4449 | 4449 |
4450 // Replace the page with a blank dummy URL. The unload handler will not be | 4450 // Replace the page with a blank dummy URL. The unload handler will not be |
4451 // run a second time, thanks to a check in FrameLoader::stopLoading. | 4451 // run a second time, thanks to a check in FrameLoader::stopLoading. |
4452 // We use loadRequest instead of loadHTMLString because the former commits | 4452 // We use loadRequest instead of loadHTMLString because the former commits |
4453 // synchronously. Otherwise a new navigation can interrupt the navigation | 4453 // synchronously. Otherwise a new navigation can interrupt the navigation |
4454 // to chrome::kSwappedOutURL. If that happens to be to the page we had been | 4454 // to content::kSwappedOutURL. If that happens to be to the page we had been |
4455 // showing, then WebKit will never send a commit and we'll be left spinning. | 4455 // showing, then WebKit will never send a commit and we'll be left spinning. |
4456 // TODO(creis): Need to add a better way to do this that avoids running the | 4456 // TODO(creis): Need to add a better way to do this that avoids running the |
4457 // beforeunload handler. For now, we just run it a second time silently. | 4457 // beforeunload handler. For now, we just run it a second time silently. |
4458 GURL swappedOutURL(chrome::kSwappedOutURL); | 4458 GURL swappedOutURL(content::kSwappedOutURL); |
4459 WebURLRequest request(swappedOutURL); | 4459 WebURLRequest request(swappedOutURL); |
4460 webview()->mainFrame()->loadRequest(request); | 4460 webview()->mainFrame()->loadRequest(request); |
4461 } | 4461 } |
4462 | 4462 |
4463 // Just echo back the params in the ACK. | 4463 // Just echo back the params in the ACK. |
4464 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); | 4464 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
4465 } | 4465 } |
4466 | 4466 |
4467 void RenderViewImpl::OnClosePage() { | 4467 void RenderViewImpl::OnClosePage() { |
4468 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); | 4468 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4521 } | 4521 } |
4522 | 4522 |
4523 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, | 4523 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
4524 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); | 4524 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
4525 if (!error_page_url.is_valid()) | 4525 if (!error_page_url.is_valid()) |
4526 return false; | 4526 return false; |
4527 | 4527 |
4528 // Load an empty page first so there is an immediate response to the error, | 4528 // Load an empty page first so there is an immediate response to the error, |
4529 // and then kick off a request for the alternate error page. | 4529 // and then kick off a request for the alternate error page. |
4530 frame->loadHTMLString(std::string(), | 4530 frame->loadHTMLString(std::string(), |
4531 GURL(chrome::kUnreachableWebDataURL), | 4531 GURL(content::kUnreachableWebDataURL), |
4532 error.unreachableURL, | 4532 error.unreachableURL, |
4533 replace); | 4533 replace); |
4534 | 4534 |
4535 // Now, create a fetcher for the error page and associate it with the data | 4535 // Now, create a fetcher for the error page and associate it with the data |
4536 // source we just created via the LoadHTMLString call. That way if another | 4536 // source we just created via the LoadHTMLString call. That way if another |
4537 // navigation occurs, the fetcher will get destroyed. | 4537 // navigation occurs, the fetcher will get destroyed. |
4538 DocumentState* document_state = | 4538 DocumentState* document_state = |
4539 DocumentState::FromDataSource(frame->provisionalDataSource()); | 4539 DocumentState::FromDataSource(frame->provisionalDataSource()); |
4540 document_state->set_alt_error_page_fetcher( | 4540 document_state->set_alt_error_page_fetcher( |
4541 new AltErrorPageResourceFetcher( | 4541 new AltErrorPageResourceFetcher( |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5250 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5250 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
5251 return !!RenderThreadImpl::current()->compositor_thread(); | 5251 return !!RenderThreadImpl::current()->compositor_thread(); |
5252 } | 5252 } |
5253 | 5253 |
5254 void RenderViewImpl::OnJavaBridgeInit() { | 5254 void RenderViewImpl::OnJavaBridgeInit() { |
5255 DCHECK(!java_bridge_dispatcher_.get()); | 5255 DCHECK(!java_bridge_dispatcher_.get()); |
5256 #if defined(ENABLE_JAVA_BRIDGE) | 5256 #if defined(ENABLE_JAVA_BRIDGE) |
5257 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 5257 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
5258 #endif | 5258 #endif |
5259 } | 5259 } |
OLD | NEW |