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" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/common/navigation_params.h" | 11 #include "content/common/navigation_params.h" |
12 #include "content/public/common/content_constants.h" | 12 #include "content/public/common/content_constants.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "ui/gfx/text_elider.h" | 15 #include "ui/gfx/text_elider.h" |
16 | 16 |
17 // Use this to get a new unique ID for a NavigationEntry during construction. | 17 // 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). | 18 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
19 static int GetUniqueIDInConstructor() { | 19 static int GetUniqueIDInConstructor() { |
20 static int unique_id_counter = 0; | 20 static int unique_id_counter = 0; |
21 return ++unique_id_counter; | 21 return ++unique_id_counter; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 int NavigationEntryImpl::kInvalidBindings = -1; | 26 int NavigationEntryImpl::kInvalidBindings = -1; |
27 | 27 |
28 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) | 28 NavigationEntryImpl::TreeNode::TreeNode(NavigationEntryImpl* entry, |
29 : frame_entry(frame_entry) { | 29 FrameNavigationEntry* frame_entry) |
| 30 : entry(entry), |
| 31 frame_entry(nullptr) { |
| 32 if (frame_entry) |
| 33 SetFrameEntry(frame_entry); |
30 } | 34 } |
31 | 35 |
32 NavigationEntryImpl::TreeNode::~TreeNode() { | 36 NavigationEntryImpl::TreeNode::~TreeNode() { |
33 } | 37 } |
34 | 38 |
35 NavigationEntryImpl::TreeNode* NavigationEntryImpl::TreeNode::Clone() const { | 39 NavigationEntryImpl::TreeNode* NavigationEntryImpl::TreeNode::Clone() const { |
36 // Clone the tree using a copy of the FrameNavigationEntry, without sharing. | 40 // Clone the tree using a copy of the FrameNavigationEntry, without sharing. |
| 41 // TODO(creis): Should not have an |entry| in TreeNode. Currently sharing |
| 42 // it, which is very wrong. |
37 NavigationEntryImpl::TreeNode* copy = | 43 NavigationEntryImpl::TreeNode* copy = |
38 new NavigationEntryImpl::TreeNode(frame_entry->Clone()); | 44 new NavigationEntryImpl::TreeNode(entry, frame_entry->Clone()); |
39 | 45 |
40 // TODO(creis): Clone children once we add them. | 46 // TODO(creis): Clone children once we add them. |
41 return copy; | 47 return copy; |
42 } | 48 } |
43 | 49 |
| 50 void NavigationEntryImpl::TreeNode::SetFrameEntry( |
| 51 FrameNavigationEntry* new_frame_entry) { |
| 52 frame_entry = new_frame_entry; |
| 53 entry->frames_to_items_[new_frame_entry->frame_tree_node_id()] = this; |
| 54 |
| 55 // TODO(creis): Move NE::frame_to_target_ to FNE::target_. |
| 56 //entry->unique_names_to_items_[frame_entry->target()] = this; |
| 57 } |
| 58 |
44 NavigationEntry* NavigationEntry::Create() { | 59 NavigationEntry* NavigationEntry::Create() { |
45 return new NavigationEntryImpl(); | 60 return new NavigationEntryImpl(); |
46 } | 61 } |
47 | 62 |
48 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | 63 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( |
49 NavigationEntry* entry) { | 64 NavigationEntry* entry) { |
50 return static_cast<NavigationEntryImpl*>(entry); | 65 return static_cast<NavigationEntryImpl*>(entry); |
51 } | 66 } |
52 | 67 |
53 NavigationEntryImpl::NavigationEntryImpl() | 68 NavigationEntryImpl::NavigationEntryImpl() |
54 : NavigationEntryImpl(nullptr, -1, GURL(), Referrer(), base::string16(), | 69 : NavigationEntryImpl(nullptr, -1, GURL(), Referrer(), base::string16(), |
55 ui::PAGE_TRANSITION_LINK, false) { | 70 ui::PAGE_TRANSITION_LINK, false) { |
56 } | 71 } |
57 | 72 |
58 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, | 73 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, |
59 int page_id, | 74 int page_id, |
60 const GURL& url, | 75 const GURL& url, |
61 const Referrer& referrer, | 76 const Referrer& referrer, |
62 const base::string16& title, | 77 const base::string16& title, |
63 ui::PageTransition transition_type, | 78 ui::PageTransition transition_type, |
64 bool is_renderer_initiated) | 79 bool is_renderer_initiated) |
65 : frame_tree_( | 80 : frame_tree_(new TreeNode( |
66 new TreeNode(new FrameNavigationEntry(instance, url, referrer))), | 81 this, new FrameNavigationEntry(instance, url, referrer))), |
67 unique_id_(GetUniqueIDInConstructor()), | 82 unique_id_(GetUniqueIDInConstructor()), |
68 bindings_(kInvalidBindings), | 83 bindings_(kInvalidBindings), |
69 page_type_(PAGE_TYPE_NORMAL), | 84 page_type_(PAGE_TYPE_NORMAL), |
70 update_virtual_url_with_url_(false), | 85 update_virtual_url_with_url_(false), |
71 title_(title), | 86 title_(title), |
72 page_id_(page_id), | 87 page_id_(page_id), |
73 transition_type_(transition_type), | 88 transition_type_(transition_type), |
74 has_post_data_(false), | 89 has_post_data_(false), |
75 post_id_(-1), | 90 post_id_(-1), |
76 restore_type_(RESTORE_NONE), | 91 restore_type_(RESTORE_NONE), |
77 is_overriding_user_agent_(false), | 92 is_overriding_user_agent_(false), |
78 http_status_code_(0), | 93 http_status_code_(0), |
79 is_renderer_initiated_(is_renderer_initiated), | 94 is_renderer_initiated_(is_renderer_initiated), |
80 should_replace_entry_(false), | 95 should_replace_entry_(false), |
81 should_clear_history_list_(false), | 96 should_clear_history_list_(false), |
82 can_load_local_resources_(false), | 97 can_load_local_resources_(false) { |
83 frame_tree_node_id_(-1) { | |
84 } | 98 } |
85 | 99 |
86 NavigationEntryImpl::~NavigationEntryImpl() { | 100 NavigationEntryImpl::~NavigationEntryImpl() { |
87 } | 101 } |
88 | 102 |
89 int NavigationEntryImpl::GetUniqueID() const { | 103 int NavigationEntryImpl::GetUniqueID() const { |
90 return unique_id_; | 104 return unique_id_; |
91 } | 105 } |
92 | 106 |
93 PageType NavigationEntryImpl::GetPageType() const { | 107 PageType NavigationEntryImpl::GetPageType() const { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void NavigationEntryImpl::SetTitle(const base::string16& title) { | 145 void NavigationEntryImpl::SetTitle(const base::string16& title) { |
132 title_ = title; | 146 title_ = title; |
133 cached_display_title_.clear(); | 147 cached_display_title_.clear(); |
134 } | 148 } |
135 | 149 |
136 const base::string16& NavigationEntryImpl::GetTitle() const { | 150 const base::string16& NavigationEntryImpl::GetTitle() const { |
137 return title_; | 151 return title_; |
138 } | 152 } |
139 | 153 |
140 void NavigationEntryImpl::SetPageState(const PageState& state) { | 154 void NavigationEntryImpl::SetPageState(const PageState& state) { |
141 page_state_ = state; | 155 CHECK(state.ToEncodedData().empty() || state.IsValid()); |
| 156 frame_tree_->frame_entry->set_page_state(state); |
142 } | 157 } |
143 | 158 |
144 const PageState& NavigationEntryImpl::GetPageState() const { | 159 const PageState& NavigationEntryImpl::GetPageState() const { |
145 return page_state_; | 160 return frame_tree_->frame_entry->page_state(); |
146 } | 161 } |
147 | 162 |
148 void NavigationEntryImpl::SetPageID(int page_id) { | 163 void NavigationEntryImpl::SetPageID(int page_id) { |
149 page_id_ = page_id; | 164 page_id_ = page_id; |
150 } | 165 } |
151 | 166 |
152 int32 NavigationEntryImpl::GetPageID() const { | 167 int32 NavigationEntryImpl::GetPageID() const { |
153 return page_id_; | 168 return page_id_; |
154 } | 169 } |
155 | 170 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 if (iter == extra_data_.end()) | 349 if (iter == extra_data_.end()) |
335 return false; | 350 return false; |
336 *data = iter->second; | 351 *data = iter->second; |
337 return true; | 352 return true; |
338 } | 353 } |
339 | 354 |
340 void NavigationEntryImpl::ClearExtraData(const std::string& key) { | 355 void NavigationEntryImpl::ClearExtraData(const std::string& key) { |
341 extra_data_.erase(key); | 356 extra_data_.erase(key); |
342 } | 357 } |
343 | 358 |
| 359 void NavigationEntryImpl::ResetFrameTree() { |
| 360 frame_tree_.reset(new TreeNode(this, nullptr)); |
| 361 } |
| 362 |
| 363 NavigationEntryImpl::TreeNode* NavigationEntryImpl::GetTreeNodeForFrame( |
| 364 FrameTreeNode* frame_tree_node) { |
| 365 // Search based on FTN ID and unique name. |
| 366 // TODO(creis): We had been using a map of routing ID to frame sequence num. |
| 367 // Is that useful here? |
| 368 if (TreeNode* node = frames_to_items_[frame_tree_node->frame_tree_node_id()]) |
| 369 return node; |
| 370 // TODO(creis): Move NE::frame_to_target_ to FNE::target_. |
| 371 //if (TreeNode* node = unique_names_to_items_[frame_tree_node->name()]) |
| 372 // return node; |
| 373 return nullptr; |
| 374 } |
| 375 |
| 376 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntryForFrame( |
| 377 FrameTreeNode* frame_tree_node) { |
| 378 TreeNode* node = GetTreeNodeForFrame(frame_tree_node); |
| 379 if (node) |
| 380 return node->frame_entry.get(); |
| 381 return nullptr; |
| 382 } |
| 383 |
344 NavigationEntryImpl* NavigationEntryImpl::Clone() const { | 384 NavigationEntryImpl* NavigationEntryImpl::Clone() const { |
345 NavigationEntryImpl* copy = new NavigationEntryImpl(); | 385 NavigationEntryImpl* copy = new NavigationEntryImpl(); |
346 | 386 |
347 // TODO(creis): Only share the same FrameNavigationEntries if cloning within | 387 // TODO(creis): Only share the same FrameNavigationEntries if cloning within |
348 // the same tab. | 388 // the same tab. |
349 copy->frame_tree_.reset(frame_tree_->Clone()); | 389 copy->frame_tree_.reset(frame_tree_->Clone()); |
350 | 390 |
351 // Copy all state over, unless cleared in ResetForCommit. | 391 // Copy all state over, unless cleared in ResetForCommit. |
352 copy->unique_id_ = unique_id_; | 392 copy->unique_id_ = unique_id_; |
353 copy->bindings_ = bindings_; | 393 copy->bindings_ = bindings_; |
354 copy->page_type_ = page_type_; | 394 copy->page_type_ = page_type_; |
355 copy->virtual_url_ = virtual_url_; | 395 copy->virtual_url_ = virtual_url_; |
356 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; | 396 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; |
357 copy->title_ = title_; | 397 copy->title_ = title_; |
358 copy->favicon_ = favicon_; | 398 copy->favicon_ = favicon_; |
359 copy->page_state_ = page_state_; | |
360 copy->page_id_ = page_id_; | 399 copy->page_id_ = page_id_; |
361 copy->ssl_ = ssl_; | 400 copy->ssl_ = ssl_; |
362 copy->transition_type_ = transition_type_; | 401 copy->transition_type_ = transition_type_; |
363 copy->user_typed_url_ = user_typed_url_; | 402 copy->user_typed_url_ = user_typed_url_; |
364 copy->has_post_data_ = has_post_data_; | 403 copy->has_post_data_ = has_post_data_; |
365 copy->post_id_ = post_id_; | 404 copy->post_id_ = post_id_; |
366 copy->restore_type_ = restore_type_; | 405 copy->restore_type_ = restore_type_; |
367 copy->original_request_url_ = original_request_url_; | 406 copy->original_request_url_ = original_request_url_; |
368 copy->is_overriding_user_agent_ = is_overriding_user_agent_; | 407 copy->is_overriding_user_agent_ = is_overriding_user_agent_; |
369 copy->timestamp_ = timestamp_; | 408 copy->timestamp_ = timestamp_; |
(...skipping 22 matching lines...) Expand all Loading... |
392 // cleared here. | 431 // cleared here. |
393 // TODO(creis): This state should be moved to NavigationRequest once | 432 // TODO(creis): This state should be moved to NavigationRequest once |
394 // PlzNavigate is enabled. | 433 // PlzNavigate is enabled. |
395 SetBrowserInitiatedPostData(nullptr); | 434 SetBrowserInitiatedPostData(nullptr); |
396 set_source_site_instance(nullptr); | 435 set_source_site_instance(nullptr); |
397 set_is_renderer_initiated(false); | 436 set_is_renderer_initiated(false); |
398 set_transferred_global_request_id(GlobalRequestID()); | 437 set_transferred_global_request_id(GlobalRequestID()); |
399 set_should_replace_entry(false); | 438 set_should_replace_entry(false); |
400 | 439 |
401 set_should_clear_history_list(false); | 440 set_should_clear_history_list(false); |
402 set_frame_tree_node_id(-1); | |
403 | 441 |
404 #if defined(OS_ANDROID) | 442 #if defined(OS_ANDROID) |
405 // Reset the time stamp so that the metrics are not reported if this entry is | 443 // Reset the time stamp so that the metrics are not reported if this entry is |
406 // loaded again in the future. | 444 // loaded again in the future. |
407 set_intent_received_timestamp(base::TimeTicks()); | 445 set_intent_received_timestamp(base::TimeTicks()); |
408 #endif | 446 #endif |
409 } | 447 } |
410 | 448 |
411 void NavigationEntryImpl::SetScreenshotPNGData( | 449 void NavigationEntryImpl::SetScreenshotPNGData( |
412 scoped_refptr<base::RefCountedBytes> png_data) { | 450 scoped_refptr<base::RefCountedBytes> png_data) { |
413 screenshot_ = png_data; | 451 screenshot_ = png_data; |
414 if (screenshot_.get()) | 452 if (screenshot_.get()) |
415 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 453 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
416 } | 454 } |
417 | 455 |
418 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 456 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
419 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 457 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
420 } | 458 } |
421 | 459 |
422 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( | 460 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( |
| 461 const FrameNavigationEntry& frame_entry, |
423 FrameMsg_Navigate_Type::Value navigation_type) const { | 462 FrameMsg_Navigate_Type::Value navigation_type) const { |
424 FrameMsg_UILoadMetricsReportType::Value report_type = | 463 FrameMsg_UILoadMetricsReportType::Value report_type = |
425 FrameMsg_UILoadMetricsReportType::NO_REPORT; | 464 FrameMsg_UILoadMetricsReportType::NO_REPORT; |
426 base::TimeTicks ui_timestamp = base::TimeTicks(); | 465 base::TimeTicks ui_timestamp = base::TimeTicks(); |
427 #if defined(OS_ANDROID) | 466 #if defined(OS_ANDROID) |
428 if (!intent_received_timestamp().is_null()) | 467 if (!intent_received_timestamp().is_null()) |
429 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | 468 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; |
430 ui_timestamp = intent_received_timestamp(); | 469 ui_timestamp = intent_received_timestamp(); |
431 #endif | 470 #endif |
432 | 471 |
433 return CommonNavigationParams( | 472 return CommonNavigationParams( |
434 GetURL(), GetReferrer(), GetTransitionType(), navigation_type, | 473 frame_entry.url(), frame_entry.referrer(), GetTransitionType(), |
435 !IsViewSourceMode(), ui_timestamp, report_type, GetBaseURLForDataURL(), | 474 navigation_type, !IsViewSourceMode(), ui_timestamp, report_type, |
436 GetHistoryURLForDataURL()); | 475 GetBaseURLForDataURL(), GetHistoryURLForDataURL()); |
437 } | 476 } |
438 | 477 |
439 CommitNavigationParams NavigationEntryImpl::ConstructCommitNavigationParams( | 478 CommitNavigationParams NavigationEntryImpl::ConstructCommitNavigationParams( |
440 base::TimeTicks navigation_start) const { | 479 base::TimeTicks navigation_start) const { |
441 // Set the redirect chain to the navigation's redirects, unless returning to a | 480 // Set the redirect chain to the navigation's redirects, unless returning to a |
442 // completed navigation (whose previous redirects don't apply). | 481 // completed navigation (whose previous redirects don't apply). |
443 std::vector<GURL> redirects; | 482 std::vector<GURL> redirects; |
444 if (ui::PageTransitionIsNewNavigation(GetTransitionType())) { | 483 if (ui::PageTransitionIsNewNavigation(GetTransitionType())) { |
445 redirects = GetRedirectChain(); | 484 redirects = GetRedirectChain(); |
446 } | 485 } |
447 | 486 |
448 return CommitNavigationParams(GetIsOverridingUserAgent(), navigation_start, | 487 return CommitNavigationParams(GetIsOverridingUserAgent(), navigation_start, |
449 redirects, GetCanLoadLocalResources(), | 488 redirects, GetCanLoadLocalResources(), |
450 GetFrameToNavigate(), base::Time::Now()); | 489 GetFrameToNavigate(), base::Time::Now()); |
451 } | 490 } |
452 | 491 |
453 HistoryNavigationParams NavigationEntryImpl::ConstructHistoryNavigationParams( | 492 HistoryNavigationParams NavigationEntryImpl::ConstructHistoryNavigationParams( |
| 493 const FrameNavigationEntry& frame_entry, |
454 NavigationControllerImpl* controller) const { | 494 NavigationControllerImpl* controller) const { |
455 int pending_history_list_offset = controller->GetIndexOfEntry(this); | 495 int pending_history_list_offset = controller->GetIndexOfEntry(this); |
456 int current_history_list_offset = controller->GetLastCommittedEntryIndex(); | 496 int current_history_list_offset = controller->GetLastCommittedEntryIndex(); |
457 int current_history_list_length = controller->GetEntryCount(); | 497 int current_history_list_length = controller->GetEntryCount(); |
458 if (should_clear_history_list()) { | 498 if (should_clear_history_list()) { |
459 // Set the history list related parameters to the same values a | 499 // Set the history list related parameters to the same values a |
460 // NavigationController would return before its first navigation. This will | 500 // NavigationController would return before its first navigation. This will |
461 // fully clear the RenderView's view of the session history. | 501 // fully clear the RenderView's view of the session history. |
462 pending_history_list_offset = -1; | 502 pending_history_list_offset = -1; |
463 current_history_list_offset = -1; | 503 current_history_list_offset = -1; |
464 current_history_list_length = 0; | 504 current_history_list_length = 0; |
465 } | 505 } |
466 return HistoryNavigationParams( | 506 return HistoryNavigationParams( |
467 GetPageState(), GetPageID(), pending_history_list_offset, | 507 frame_entry.page_state(), GetPageID(), pending_history_list_offset, |
468 current_history_list_offset, current_history_list_length, | 508 current_history_list_offset, current_history_list_length, |
469 should_clear_history_list()); | 509 should_clear_history_list()); |
470 } | 510 } |
471 | 511 |
472 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams() | 512 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams() |
473 const { | 513 const { |
474 std::vector<unsigned char> browser_initiated_post_data; | 514 std::vector<unsigned char> browser_initiated_post_data; |
475 if (GetBrowserInitiatedPostData()) { | 515 if (GetBrowserInitiatedPostData()) { |
476 browser_initiated_post_data.assign( | 516 browser_initiated_post_data.assign( |
477 GetBrowserInitiatedPostData()->front(), | 517 GetBrowserInitiatedPostData()->front(), |
478 GetBrowserInitiatedPostData()->front() + | 518 GetBrowserInitiatedPostData()->front() + |
479 GetBrowserInitiatedPostData()->size()); | 519 GetBrowserInitiatedPostData()->size()); |
480 } | 520 } |
481 | 521 |
482 return StartNavigationParams( | 522 return StartNavigationParams( |
483 GetHasPostData(), extra_headers(), browser_initiated_post_data, | 523 GetHasPostData(), extra_headers(), browser_initiated_post_data, |
484 should_replace_entry(), transferred_global_request_id().child_id, | 524 should_replace_entry(), transferred_global_request_id().child_id, |
485 transferred_global_request_id().request_id); | 525 transferred_global_request_id().request_id); |
486 } | 526 } |
487 | 527 |
488 } // namespace content | 528 } // namespace content |
OLD | NEW |