Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 8404018: chrome.loadTimes() shouldn't be affected by in-document navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix style Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 completed_client_redirect_src_ = from; 2257 completed_client_redirect_src_ = from;
2258 FOR_EACH_OBSERVER( 2258 FOR_EACH_OBSERVER(
2259 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from)); 2259 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
2260 } 2260 }
2261 2261
2262 void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { 2262 void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2263 // The rest of RenderView assumes that a WebDataSource will always have a 2263 // The rest of RenderView assumes that a WebDataSource will always have a
2264 // non-null NavigationState. 2264 // non-null NavigationState.
2265 bool content_initiated = !pending_navigation_state_.get(); 2265 bool content_initiated = !pending_navigation_state_.get();
2266 NavigationState* state = content_initiated ? 2266 NavigationState* state = content_initiated ?
2267 NavigationState::CreateContentInitiated() : 2267 NavigationState::CreateContentInitiated(ds) :
2268 pending_navigation_state_.release(); 2268 pending_navigation_state_.release();
2269 2269
2270 // NavigationState::referred_by_prefetcher_ is true if we are 2270 // NavigationState::referred_by_prefetcher_ is true if we are
2271 // navigating from a page that used prefetching using a link on that 2271 // navigating from a page that used prefetching using a link on that
2272 // page. We are early enough in the request process here that we 2272 // page. We are early enough in the request process here that we
2273 // can still see the NavigationState of the previous page and set 2273 // can still see the NavigationState of the previous page and set
2274 // this value appropriately. 2274 // this value appropriately.
2275 // TODO(gavinp): catch the important case of navigation in a new 2275 // TODO(gavinp): catch the important case of navigation in a new
2276 // renderer process. 2276 // renderer process.
2277 if (webview()) { 2277 if (webview()) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 2313
2314 ds->setExtraData(state); 2314 ds->setExtraData(state);
2315 2315
2316 FOR_EACH_OBSERVER( 2316 FOR_EACH_OBSERVER(
2317 RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); 2317 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
2318 } 2318 }
2319 2319
2320 void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { 2320 void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
2321 WebDataSource* ds = frame->provisionalDataSource(); 2321 WebDataSource* ds = frame->provisionalDataSource();
2322 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 2322 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2323 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2323 2324
2324 // Update the request time if WebKit has better knowledge of it. 2325 // Update the request time if WebKit has better knowledge of it.
2325 if (navigation_state->request_time().is_null()) { 2326 if (load_times->request_time().is_null()) {
2326 double event_time = ds->triggeringEventTime(); 2327 double event_time = ds->triggeringEventTime();
2327 if (event_time != 0.0) 2328 if (event_time != 0.0)
2328 navigation_state->set_request_time(Time::FromDoubleT(event_time)); 2329 load_times->set_request_time(Time::FromDoubleT(event_time));
2329 } 2330 }
2330 2331
2331 // Start time is only set after request time. 2332 // Start time is only set after request time.
2332 navigation_state->set_start_load_time(Time::Now()); 2333 load_times->set_start_load_time(Time::Now());
2333 2334
2334 bool is_top_most = !frame->parent(); 2335 bool is_top_most = !frame->parent();
2335 if (is_top_most) { 2336 if (is_top_most) {
2336 navigation_gesture_ = frame->isProcessingUserGesture() ? 2337 navigation_gesture_ = frame->isProcessingUserGesture() ?
2337 NavigationGestureUser : NavigationGestureAuto; 2338 NavigationGestureUser : NavigationGestureAuto;
2338 2339
2339 // Make sure redirect tracking state is clear for the new load. 2340 // Make sure redirect tracking state is clear for the new load.
2340 completed_client_redirect_src_ = GURL(); 2341 completed_client_redirect_src_ = GURL();
2341 } else if (frame->parent()->isLoading()) { 2342 } else if (frame->parent()->isLoading()) {
2342 // Take note of AUTO_SUBFRAME loads here, so that we can know how to 2343 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 navigation_state->transition_type() == 2430 navigation_state->transition_type() ==
2430 content::PAGE_TRANSITION_AUTO_SUBFRAME; 2431 content::PAGE_TRANSITION_AUTO_SUBFRAME;
2431 2432
2432 // If we failed on a browser initiated request, then make sure that our error 2433 // If we failed on a browser initiated request, then make sure that our error
2433 // page load is regarded as the same browser initiated request. 2434 // page load is regarded as the same browser initiated request.
2434 if (!navigation_state->is_content_initiated()) { 2435 if (!navigation_state->is_content_initiated()) {
2435 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( 2436 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2436 navigation_state->pending_page_id(), 2437 navigation_state->pending_page_id(),
2437 navigation_state->pending_history_list_offset(), 2438 navigation_state->pending_history_list_offset(),
2438 navigation_state->transition_type(), 2439 navigation_state->transition_type(),
2439 navigation_state->request_time())); 2440 navigation_state->load_times()->request_time()));
2440 } 2441 }
2441 2442
2442 // Provide the user with a more helpful error page? 2443 // Provide the user with a more helpful error page?
2443 if (MaybeLoadAlternateErrorPage(frame, error, replace)) 2444 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2444 return; 2445 return;
2445 2446
2446 // Fallback to a local error page. 2447 // Fallback to a local error page.
2447 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); 2448 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
2448 } 2449 }
2449 2450
2450 void RenderViewImpl::didReceiveDocumentData( 2451 void RenderViewImpl::didReceiveDocumentData(
2451 WebFrame* frame, const char* data, size_t data_len, 2452 WebFrame* frame, const char* data, size_t data_len,
2452 bool& prevent_default) { 2453 bool& prevent_default) {
2453 NavigationState* navigation_state = 2454 NavigationState* navigation_state =
2454 NavigationState::FromDataSource(frame->dataSource()); 2455 NavigationState::FromDataSource(frame->dataSource());
2455 navigation_state->set_use_error_page(false); 2456 navigation_state->set_use_error_page(false);
2456 } 2457 }
2457 2458
2458 void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, 2459 void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2459 bool is_new_navigation) { 2460 bool is_new_navigation) {
2460 NavigationState* navigation_state = 2461 NavigationState* navigation_state =
2461 NavigationState::FromDataSource(frame->dataSource()); 2462 NavigationState::FromDataSource(frame->dataSource());
2463 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2462 2464
2463 navigation_state->set_commit_load_time(Time::Now()); 2465 if (load_times->commit_load_time().is_null())
2466 load_times->set_commit_load_time(Time::Now());
2467
2464 if (is_new_navigation) { 2468 if (is_new_navigation) {
2465 // When we perform a new navigation, we need to update the last committed 2469 // When we perform a new navigation, we need to update the last committed
2466 // session history entry with state for the page we are leaving. 2470 // session history entry with state for the page we are leaving.
2467 UpdateSessionHistory(frame); 2471 UpdateSessionHistory(frame);
2468 2472
2469 // We bump our Page ID to correspond with the new session history entry. 2473 // We bump our Page ID to correspond with the new session history entry.
2470 page_id_ = next_page_id_++; 2474 page_id_ = next_page_id_++;
2471 2475
2472 // Advance our offset in session history, applying the length limit. There 2476 // Advance our offset in session history, applying the length limit. There
2473 // is now no forward history. 2477 // is now no forward history.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2559 2563
2560 void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { 2564 void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2561 FOR_EACH_OBSERVER(RenderViewObserver, observers_, 2565 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2562 DidChangeIcon(frame, type)); 2566 DidChangeIcon(frame, type));
2563 } 2567 }
2564 2568
2565 void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { 2569 void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
2566 WebDataSource* ds = frame->dataSource(); 2570 WebDataSource* ds = frame->dataSource();
2567 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 2571 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2568 DCHECK(navigation_state); 2572 DCHECK(navigation_state);
2569 navigation_state->set_finish_document_load_time(Time::Now()); 2573 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2574 load_times->set_finish_document_load_time(Time::Now());
2570 2575
2571 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); 2576 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
2572 2577
2573 FOR_EACH_OBSERVER(RenderViewObserver, observers_, 2578 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2574 DidFinishDocumentLoad(frame)); 2579 DidFinishDocumentLoad(frame));
2575 2580
2576 // Check whether we have new encoding name. 2581 // Check whether we have new encoding name.
2577 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); 2582 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
2578 } 2583 }
2579 2584
2580 void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { 2585 void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
2581 if (webview()->mainFrame() == frame) { 2586 if (webview()->mainFrame() == frame) {
2582 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, 2587 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2583 page_id_)); 2588 page_id_));
2584 } 2589 }
2585 } 2590 }
2586 2591
2587 void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { 2592 void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
2588 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); 2593 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
2589 } 2594 }
2590 2595
2591 void RenderViewImpl::didFinishLoad(WebFrame* frame) { 2596 void RenderViewImpl::didFinishLoad(WebFrame* frame) {
2592 WebDataSource* ds = frame->dataSource(); 2597 WebDataSource* ds = frame->dataSource();
2593 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 2598 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2594 DCHECK(navigation_state); 2599 DCHECK(navigation_state);
2595 navigation_state->set_finish_load_time(Time::Now()); 2600 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2601 load_times->set_finish_load_time(Time::Now());
2596 2602
2597 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); 2603 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
2598 2604
2599 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier())); 2605 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
2600 } 2606 }
2601 2607
2602 void RenderViewImpl::didNavigateWithinPage( 2608 void RenderViewImpl::didNavigateWithinPage(
2603 WebFrame* frame, bool is_new_navigation) { 2609 WebFrame* frame, bool is_new_navigation) {
2604 // If this was a reference fragment navigation that we initiated, then we 2610 // If this was a reference fragment navigation that we initiated, then we
2605 // could end up having a non-null pending navigation state. We just need to 2611 // could end up having a non-null pending navigation state. We just need to
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2686 return; 2692 return;
2687 2693
2688 // If we are in view source mode, then just let the user see the source of 2694 // If we are in view source mode, then just let the user see the source of
2689 // the server's error page. 2695 // the server's error page.
2690 if (frame->isViewSourceModeEnabled()) 2696 if (frame->isViewSourceModeEnabled())
2691 return; 2697 return;
2692 2698
2693 NavigationState* navigation_state = 2699 NavigationState* navigation_state =
2694 NavigationState::FromDataSource(frame->provisionalDataSource()); 2700 NavigationState::FromDataSource(frame->provisionalDataSource());
2695 CHECK(navigation_state); 2701 CHECK(navigation_state);
2702 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2696 int http_status_code = response.httpStatusCode(); 2703 int http_status_code = response.httpStatusCode();
2697 2704
2698 // Record page load flags. 2705 // Record page load flags.
2699 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); 2706 load_times->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2700 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); 2707 load_times->set_was_npn_negotiated(response.wasNpnNegotiated());
2701 navigation_state->set_was_alternate_protocol_available( 2708 load_times->set_was_alternate_protocol_available(
2702 response.wasAlternateProtocolAvailable()); 2709 response.wasAlternateProtocolAvailable());
2703 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); 2710 load_times->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2704 navigation_state->set_http_status_code(http_status_code); 2711 load_times->set_http_status_code(http_status_code);
2705 // Whether or not the http status code actually corresponds to an error is 2712 // Whether or not the http status code actually corresponds to an error is
2706 // only checked when the page is done loading, if |use_error_page| is 2713 // only checked when the page is done loading, if |use_error_page| is
2707 // still true. 2714 // still true.
2708 navigation_state->set_use_error_page(true); 2715 navigation_state->set_use_error_page(true);
2709 } 2716 }
2710 2717
2711 void RenderViewImpl::didFinishResourceLoad( 2718 void RenderViewImpl::didFinishResourceLoad(
2712 WebFrame* frame, unsigned identifier) { 2719 WebFrame* frame, unsigned identifier) {
2713 NavigationState* navigation_state = 2720 NavigationState* navigation_state =
2714 NavigationState::FromDataSource(frame->dataSource()); 2721 NavigationState::FromDataSource(frame->dataSource());
2722 NavigationState::LoadTimes* load_times = navigation_state->load_times();
2715 if (!navigation_state->use_error_page()) 2723 if (!navigation_state->use_error_page())
2716 return; 2724 return;
2717 2725
2718 // Do not show error page when DevTools is attached. 2726 // Do not show error page when DevTools is attached.
2719 if (devtools_agent_->IsAttached()) 2727 if (devtools_agent_->IsAttached())
2720 return; 2728 return;
2721 2729
2722 // Display error page, if appropriate. 2730 // Display error page, if appropriate.
2723 int http_status_code = navigation_state->http_status_code(); 2731 int http_status_code = load_times->http_status_code();
2724 if (http_status_code == 404) { 2732 if (http_status_code == 404) {
2725 // On 404s, try a remote search page as a fallback. 2733 // On 404s, try a remote search page as a fallback.
2726 const GURL& document_url = frame->document().url(); 2734 const GURL& document_url = frame->document().url();
2727 2735
2728 const GURL& error_page_url = 2736 const GURL& error_page_url =
2729 GetAlternateErrorPageURL(document_url, HTTP_404); 2737 GetAlternateErrorPageURL(document_url, HTTP_404);
2730 if (error_page_url.is_valid()) { 2738 if (error_page_url.is_valid()) {
2731 WebURLError original_error; 2739 WebURLError original_error;
2732 original_error.domain = "http"; 2740 original_error.domain = "http";
2733 original_error.reason = 404; 2741 original_error.reason = 404;
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
4009 pepper_delegate_.ViewFlushedPaint(); 4017 pepper_delegate_.ViewFlushedPaint();
4010 4018
4011 WebFrame* main_frame = webview()->mainFrame(); 4019 WebFrame* main_frame = webview()->mainFrame();
4012 4020
4013 // If we have a provisional frame we are between the start and commit stages 4021 // If we have a provisional frame we are between the start and commit stages
4014 // of loading and we don't want to save stats. 4022 // of loading and we don't want to save stats.
4015 if (!main_frame->provisionalDataSource()) { 4023 if (!main_frame->provisionalDataSource()) {
4016 WebDataSource* ds = main_frame->dataSource(); 4024 WebDataSource* ds = main_frame->dataSource();
4017 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 4025 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4018 DCHECK(navigation_state); 4026 DCHECK(navigation_state);
4027 NavigationState::LoadTimes* load_times = navigation_state->load_times();
4019 4028
4020 // TODO(jar): The following code should all be inside a method, probably in 4029 // TODO(jar): The following code should all be inside a method, probably in
4021 // NavigatorState. 4030 // NavigatorState.
4022 Time now = Time::Now(); 4031 Time now = Time::Now();
4023 if (navigation_state->first_paint_time().is_null()) { 4032 if (load_times->first_paint_time().is_null()) {
4024 navigation_state->set_first_paint_time(now); 4033 load_times->set_first_paint_time(now);
4025 } 4034 }
4026 if (navigation_state->first_paint_after_load_time().is_null() && 4035 if (load_times->first_paint_after_load_time().is_null() &&
4027 !navigation_state->finish_load_time().is_null()) { 4036 !load_times->finish_load_time().is_null()) {
4028 navigation_state->set_first_paint_after_load_time(now); 4037 load_times->set_first_paint_after_load_time(now);
4029 } 4038 }
4030 } 4039 }
4031 } 4040 }
4032 4041
4033 void RenderViewImpl::OnViewContextSwapBuffersPosted() { 4042 void RenderViewImpl::OnViewContextSwapBuffersPosted() {
4034 RenderWidget::OnSwapBuffersPosted(); 4043 RenderWidget::OnSwapBuffersPosted();
4035 } 4044 }
4036 4045
4037 void RenderViewImpl::OnViewContextSwapBuffersComplete() { 4046 void RenderViewImpl::OnViewContextSwapBuffersComplete() {
4038 RenderWidget::OnSwapBuffersComplete(); 4047 RenderWidget::OnSwapBuffersComplete();
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
4667 return webview()->settings()->useThreadedCompositor(); 4676 return webview()->settings()->useThreadedCompositor();
4668 } 4677 }
4669 4678
4670 void RenderViewImpl::OnJavaBridgeInit( 4679 void RenderViewImpl::OnJavaBridgeInit(
4671 const IPC::ChannelHandle& channel_handle) { 4680 const IPC::ChannelHandle& channel_handle) {
4672 DCHECK(!java_bridge_dispatcher_.get()); 4681 DCHECK(!java_bridge_dispatcher_.get());
4673 #if defined(ENABLE_JAVA_BRIDGE) 4682 #if defined(ENABLE_JAVA_BRIDGE)
4674 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle)); 4683 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle));
4675 #endif 4684 #endif
4676 } 4685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698