Chromium Code Reviews| 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 <queue> | |
| 8 | |
| 7 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/common/navigation_params.h" | 12 #include "content/common/navigation_params.h" |
| 11 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
| 12 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 13 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 14 #include "ui/gfx/text_elider.h" | 16 #include "ui/gfx/text_elider.h" |
| 15 | 17 |
| 16 // Use this to get a new unique ID for a NavigationEntry during construction. | 18 // Use this to get a new unique ID for a NavigationEntry during construction. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 } | 57 } |
| 56 | 58 |
| 57 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, | 59 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, |
| 58 int page_id, | 60 int page_id, |
| 59 const GURL& url, | 61 const GURL& url, |
| 60 const Referrer& referrer, | 62 const Referrer& referrer, |
| 61 const base::string16& title, | 63 const base::string16& title, |
| 62 ui::PageTransition transition_type, | 64 ui::PageTransition transition_type, |
| 63 bool is_renderer_initiated) | 65 bool is_renderer_initiated) |
| 64 : frame_tree_( | 66 : frame_tree_( |
| 65 new TreeNode(new FrameNavigationEntry(instance, url, referrer))), | 67 // TODO(creis): Pass in FTN ID? How? |
|
Charlie Reis
2015/05/14 16:52:08
Oops, I'll remove this TODO, since it's covered el
| |
| 68 new TreeNode(new FrameNavigationEntry(-1, instance, url, referrer))), | |
| 66 unique_id_(GetUniqueIDInConstructor()), | 69 unique_id_(GetUniqueIDInConstructor()), |
| 67 bindings_(kInvalidBindings), | 70 bindings_(kInvalidBindings), |
| 68 page_type_(PAGE_TYPE_NORMAL), | 71 page_type_(PAGE_TYPE_NORMAL), |
| 69 update_virtual_url_with_url_(false), | 72 update_virtual_url_with_url_(false), |
| 70 title_(title), | 73 title_(title), |
| 71 page_id_(page_id), | 74 page_id_(page_id), |
| 72 transition_type_(transition_type), | 75 transition_type_(transition_type), |
| 73 has_post_data_(false), | 76 has_post_data_(false), |
| 74 post_id_(-1), | 77 post_id_(-1), |
| 75 restore_type_(RESTORE_NONE), | 78 restore_type_(RESTORE_NONE), |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 set_should_clear_history_list(false); | 459 set_should_clear_history_list(false); |
| 457 set_frame_tree_node_id(-1); | 460 set_frame_tree_node_id(-1); |
| 458 | 461 |
| 459 #if defined(OS_ANDROID) | 462 #if defined(OS_ANDROID) |
| 460 // Reset the time stamp so that the metrics are not reported if this entry is | 463 // Reset the time stamp so that the metrics are not reported if this entry is |
| 461 // loaded again in the future. | 464 // loaded again in the future. |
| 462 set_intent_received_timestamp(base::TimeTicks()); | 465 set_intent_received_timestamp(base::TimeTicks()); |
| 463 #endif | 466 #endif |
| 464 } | 467 } |
| 465 | 468 |
| 466 void NavigationEntryImpl::AddOrUpdateFrameEntry(int frame_tree_node_id, | 469 void NavigationEntryImpl::AddOrUpdateFrameEntry(FrameTreeNode* frame_tree_node, |
| 467 SiteInstanceImpl* site_instance, | 470 SiteInstanceImpl* site_instance, |
| 468 const GURL& url, | 471 const GURL& url, |
| 469 const Referrer& referrer) { | 472 const Referrer& referrer) { |
| 470 // TODO(creis): Walk tree to find the node to update. | 473 // We should already have a TreeNode for the parent node by the time this node |
| 471 // TODO(creis): Only create a new entry if one doesn't exist yet. | 474 // commits. Find it first. |
| 472 FrameNavigationEntry* frame_entry = | 475 DCHECK(frame_tree_node->parent()); |
| 473 new FrameNavigationEntry(site_instance, url, referrer); | 476 int parent_ftn_id = frame_tree_node->parent()->frame_tree_node_id(); |
| 474 root_node()->children.push_back( | 477 bool found = false; |
| 478 NavigationEntryImpl::TreeNode* parent_node = nullptr; | |
| 479 std::queue<NavigationEntryImpl::TreeNode*> work_queue; | |
| 480 work_queue.push(root_node()); | |
| 481 while (!found && !work_queue.empty()) { | |
| 482 parent_node = work_queue.front(); | |
| 483 work_queue.pop(); | |
| 484 // The root FNE will have an ID of -1, so check for that as well. | |
| 485 if (parent_node->frame_entry->frame_tree_node_id() == parent_ftn_id || | |
| 486 (parent_node->frame_entry->frame_tree_node_id() == -1 && | |
| 487 parent_node == root_node() && | |
| 488 frame_tree_node->parent()->IsMainFrame())) { | |
| 489 found = true; | |
| 490 break; | |
| 491 } | |
| 492 // Enqueue any children and keep looking. | |
| 493 for (size_t i = 0; i < parent_node->children.size(); i++) | |
|
Avi (use Gerrit)
2015/05/14 18:01:11
for (auto& child : parent_node->children) ?
Charlie Reis
2015/05/14 19:00:37
Done.
| |
| 494 work_queue.push(parent_node->children[i]); | |
| 495 } | |
| 496 if (!found) { | |
| 497 // The renderer should not send a commit for a subframe before its parent. | |
| 498 // TODO(creis): This can currently happen because we don't yet clone the | |
| 499 // FrameNavigationEntry tree on manual subframe navigations. Once that's | |
| 500 // added, we should kill the renderer if we get here. | |
| 501 return; | |
| 502 } | |
| 503 | |
| 504 // Now check whether we have a TreeNode for the node itself. | |
| 505 int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | |
| 506 for (TreeNode* child : parent_node->children) { | |
| 507 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { | |
| 508 // Update the existing FrameNavigationEntry. | |
| 509 child->frame_entry->UpdateEntry(site_instance, url, referrer); | |
| 510 return; | |
| 511 } | |
| 512 } | |
| 513 | |
| 514 // No entry exists yet, so create a new one. Unordered list, since we expect | |
| 515 // to look up entries by frame sequence number or unique name. | |
| 516 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( | |
| 517 frame_tree_node_id, site_instance, url, referrer); | |
| 518 parent_node->children.push_back( | |
| 475 new NavigationEntryImpl::TreeNode(frame_entry)); | 519 new NavigationEntryImpl::TreeNode(frame_entry)); |
| 476 } | 520 } |
| 477 | 521 |
| 478 void NavigationEntryImpl::SetScreenshotPNGData( | 522 void NavigationEntryImpl::SetScreenshotPNGData( |
| 479 scoped_refptr<base::RefCountedBytes> png_data) { | 523 scoped_refptr<base::RefCountedBytes> png_data) { |
| 480 screenshot_ = png_data; | 524 screenshot_ = png_data; |
| 481 if (screenshot_.get()) | 525 if (screenshot_.get()) |
| 482 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 526 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
| 483 } | 527 } |
| 484 | 528 |
| 485 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 529 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
| 486 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 530 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
| 487 } | 531 } |
| 488 | 532 |
| 489 } // namespace content | 533 } // namespace content |
| OLD | NEW |