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/navigation_entry_impl.h" | 5 #include "content/browser/frame_host/navigation_entry_impl.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | |
11 #include "content/common/navigation_params.h" | 10 #include "content/common/navigation_params.h" |
12 #include "content/public/common/content_constants.h" | 11 #include "content/public/common/content_constants.h" |
13 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
14 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
15 #include "ui/gfx/text_elider.h" | 14 #include "ui/gfx/text_elider.h" |
16 | 15 |
17 // Use this to get a new unique ID for a NavigationEntry during construction. | 16 // Use this to get a new unique ID for a NavigationEntry during construction. |
18 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | 17 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
19 static int GetUniqueIDInConstructor() { | 18 static int GetUniqueIDInConstructor() { |
20 static int unique_id_counter = 0; | 19 static int unique_id_counter = 0; |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 copy->redirect_chain_ = redirect_chain_; | 379 copy->redirect_chain_ = redirect_chain_; |
381 // ResetForCommit: should_clear_history_list_ | 380 // ResetForCommit: should_clear_history_list_ |
382 copy->frame_to_navigate_ = frame_to_navigate_; | 381 copy->frame_to_navigate_ = frame_to_navigate_; |
383 // ResetForCommit: frame_tree_node_id_ | 382 // ResetForCommit: frame_tree_node_id_ |
384 // ResetForCommit: intent_received_timestamp_ | 383 // ResetForCommit: intent_received_timestamp_ |
385 copy->extra_data_ = extra_data_; | 384 copy->extra_data_ = extra_data_; |
386 | 385 |
387 return copy; | 386 return copy; |
388 } | 387 } |
389 | 388 |
390 void NavigationEntryImpl::ResetForCommit() { | |
clamy
2015/03/19 17:12:31
The git diff is a bit weird in this file. What I'm
| |
391 // Any state that only matters when a navigation entry is pending should be | |
392 // cleared here. | |
393 // TODO(creis): This state should be moved to NavigationRequest once | |
394 // PlzNavigate is enabled. | |
395 SetBrowserInitiatedPostData(nullptr); | |
396 set_source_site_instance(nullptr); | |
397 set_is_renderer_initiated(false); | |
398 set_transferred_global_request_id(GlobalRequestID()); | |
399 set_should_replace_entry(false); | |
400 | |
401 set_should_clear_history_list(false); | |
402 set_frame_tree_node_id(-1); | |
403 | |
404 #if defined(OS_ANDROID) | |
405 // Reset the time stamp so that the metrics are not reported if this entry is | |
406 // loaded again in the future. | |
407 set_intent_received_timestamp(base::TimeTicks()); | |
408 #endif | |
409 } | |
410 | |
411 void NavigationEntryImpl::SetScreenshotPNGData( | |
412 scoped_refptr<base::RefCountedBytes> png_data) { | |
413 screenshot_ = png_data; | |
414 if (screenshot_.get()) | |
415 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | |
416 } | |
417 | |
418 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | |
419 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | |
420 } | |
421 | |
422 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( | 389 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( |
clamy
2015/03/19 17:12:31
I've left the Construct methods here until we have
Charlie Reis
2015/03/19 20:45:51
Acknowledged.
| |
423 FrameMsg_Navigate_Type::Value navigation_type) const { | 390 FrameMsg_Navigate_Type::Value navigation_type) const { |
424 FrameMsg_UILoadMetricsReportType::Value report_type = | 391 FrameMsg_UILoadMetricsReportType::Value report_type = |
425 FrameMsg_UILoadMetricsReportType::NO_REPORT; | 392 FrameMsg_UILoadMetricsReportType::NO_REPORT; |
426 base::TimeTicks ui_timestamp = base::TimeTicks(); | 393 base::TimeTicks ui_timestamp = base::TimeTicks(); |
427 #if defined(OS_ANDROID) | 394 #if defined(OS_ANDROID) |
428 if (!intent_received_timestamp().is_null()) | 395 if (!intent_received_timestamp().is_null()) |
429 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | 396 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; |
430 ui_timestamp = intent_received_timestamp(); | 397 ui_timestamp = intent_received_timestamp(); |
431 #endif | 398 #endif |
432 | 399 |
433 return CommonNavigationParams( | 400 return CommonNavigationParams( |
434 GetURL(), GetReferrer(), GetTransitionType(), navigation_type, | 401 GetURL(), GetReferrer(), GetTransitionType(), navigation_type, |
435 !IsViewSourceMode(), ui_timestamp, report_type, GetBaseURLForDataURL(), | 402 !IsViewSourceMode(), ui_timestamp, report_type, GetBaseURLForDataURL(), |
436 GetHistoryURLForDataURL()); | 403 GetHistoryURLForDataURL()); |
437 } | 404 } |
438 | 405 |
406 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams() | |
407 const { | |
408 std::vector<unsigned char> browser_initiated_post_data; | |
409 if (GetBrowserInitiatedPostData()) { | |
410 browser_initiated_post_data.assign( | |
411 GetBrowserInitiatedPostData()->front(), | |
412 GetBrowserInitiatedPostData()->front() + | |
413 GetBrowserInitiatedPostData()->size()); | |
414 } | |
415 | |
416 return StartNavigationParams( | |
417 GetHasPostData(), extra_headers(), browser_initiated_post_data, | |
418 should_replace_entry(), transferred_global_request_id().child_id, | |
419 transferred_global_request_id().request_id); | |
420 } | |
421 | |
439 CommitNavigationParams NavigationEntryImpl::ConstructCommitNavigationParams( | 422 CommitNavigationParams NavigationEntryImpl::ConstructCommitNavigationParams( |
440 base::TimeTicks navigation_start) const { | 423 base::TimeTicks navigation_start, |
424 int pending_history_list_offset, | |
425 int current_history_list_offset, | |
426 int current_history_list_length) const { | |
441 // Set the redirect chain to the navigation's redirects, unless returning to a | 427 // Set the redirect chain to the navigation's redirects, unless returning to a |
442 // completed navigation (whose previous redirects don't apply). | 428 // completed navigation (whose previous redirects don't apply). |
443 std::vector<GURL> redirects; | 429 std::vector<GURL> redirects; |
444 if (ui::PageTransitionIsNewNavigation(GetTransitionType())) { | 430 if (ui::PageTransitionIsNewNavigation(GetTransitionType())) { |
445 redirects = GetRedirectChain(); | 431 redirects = GetRedirectChain(); |
446 } | 432 } |
447 | 433 |
448 return CommitNavigationParams(GetIsOverridingUserAgent(), navigation_start, | 434 int pending_offset_to_send = pending_history_list_offset; |
449 redirects, GetCanLoadLocalResources(), | 435 int current_offset_to_send = current_history_list_offset; |
450 GetFrameToNavigate(), base::Time::Now()); | 436 int current_length_to_send = current_history_list_length; |
451 } | |
452 | |
453 HistoryNavigationParams NavigationEntryImpl::ConstructHistoryNavigationParams( | |
454 NavigationControllerImpl* controller) const { | |
455 int pending_history_list_offset = controller->GetIndexOfEntry(this); | |
456 int current_history_list_offset = controller->GetLastCommittedEntryIndex(); | |
457 int current_history_list_length = controller->GetEntryCount(); | |
458 if (should_clear_history_list()) { | 437 if (should_clear_history_list()) { |
459 // Set the history list related parameters to the same values a | 438 // Set the history list related parameters to the same values a |
460 // NavigationController would return before its first navigation. This will | 439 // NavigationController would return before its first navigation. This will |
461 // fully clear the RenderView's view of the session history. | 440 // fully clear the RenderView's view of the session history. |
462 pending_history_list_offset = -1; | 441 pending_offset_to_send = -1; |
463 current_history_list_offset = -1; | 442 current_offset_to_send = -1; |
464 current_history_list_length = 0; | 443 current_length_to_send = 0; |
465 } | 444 } |
466 return HistoryNavigationParams( | 445 return CommitNavigationParams( |
467 GetPageState(), GetPageID(), pending_history_list_offset, | 446 GetIsOverridingUserAgent(), navigation_start, redirects, |
468 current_history_list_offset, current_history_list_length, | 447 GetCanLoadLocalResources(), GetFrameToNavigate(), base::Time::Now(), |
448 GetPageState(), GetPageID(), pending_offset_to_send, | |
449 current_offset_to_send, current_length_to_send, | |
469 should_clear_history_list()); | 450 should_clear_history_list()); |
470 } | 451 } |
471 | 452 |
472 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams() | 453 void NavigationEntryImpl::ResetForCommit() { |
473 const { | 454 // Any state that only matters when a navigation entry is pending should be |
474 std::vector<unsigned char> browser_initiated_post_data; | 455 // cleared here. |
475 if (GetBrowserInitiatedPostData()) { | 456 // TODO(creis): This state should be moved to NavigationRequest once |
476 browser_initiated_post_data.assign( | 457 // PlzNavigate is enabled. |
477 GetBrowserInitiatedPostData()->front(), | 458 SetBrowserInitiatedPostData(nullptr); |
478 GetBrowserInitiatedPostData()->front() + | 459 set_source_site_instance(nullptr); |
479 GetBrowserInitiatedPostData()->size()); | 460 set_is_renderer_initiated(false); |
480 } | 461 set_transferred_global_request_id(GlobalRequestID()); |
462 set_should_replace_entry(false); | |
481 | 463 |
482 return StartNavigationParams( | 464 set_should_clear_history_list(false); |
483 GetHasPostData(), extra_headers(), browser_initiated_post_data, | 465 set_frame_tree_node_id(-1); |
484 should_replace_entry(), transferred_global_request_id().child_id, | 466 |
485 transferred_global_request_id().request_id); | 467 #if defined(OS_ANDROID) |
468 // Reset the time stamp so that the metrics are not reported if this entry is | |
469 // loaded again in the future. | |
470 set_intent_received_timestamp(base::TimeTicks()); | |
471 #endif | |
472 } | |
473 | |
474 void NavigationEntryImpl::SetScreenshotPNGData( | |
475 scoped_refptr<base::RefCountedBytes> png_data) { | |
476 screenshot_ = png_data; | |
477 if (screenshot_.get()) | |
478 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | |
479 } | |
480 | |
481 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | |
482 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | |
486 } | 483 } |
487 | 484 |
488 } // namespace content | 485 } // namespace content |
OLD | NEW |