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 new TreeNode(new FrameNavigationEntry(-1, instance, url, referrer))), |
66 unique_id_(GetUniqueIDInConstructor()), | 68 unique_id_(GetUniqueIDInConstructor()), |
67 bindings_(kInvalidBindings), | 69 bindings_(kInvalidBindings), |
68 page_type_(PAGE_TYPE_NORMAL), | 70 page_type_(PAGE_TYPE_NORMAL), |
69 update_virtual_url_with_url_(false), | 71 update_virtual_url_with_url_(false), |
70 title_(title), | 72 title_(title), |
71 page_id_(page_id), | 73 page_id_(page_id), |
72 transition_type_(transition_type), | 74 transition_type_(transition_type), |
73 has_post_data_(false), | 75 has_post_data_(false), |
74 post_id_(-1), | 76 post_id_(-1), |
75 restore_type_(RESTORE_NONE), | 77 restore_type_(RESTORE_NONE), |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 set_should_clear_history_list(false); | 458 set_should_clear_history_list(false); |
457 set_frame_tree_node_id(-1); | 459 set_frame_tree_node_id(-1); |
458 | 460 |
459 #if defined(OS_ANDROID) | 461 #if defined(OS_ANDROID) |
460 // Reset the time stamp so that the metrics are not reported if this entry is | 462 // Reset the time stamp so that the metrics are not reported if this entry is |
461 // loaded again in the future. | 463 // loaded again in the future. |
462 set_intent_received_timestamp(base::TimeTicks()); | 464 set_intent_received_timestamp(base::TimeTicks()); |
463 #endif | 465 #endif |
464 } | 466 } |
465 | 467 |
466 void NavigationEntryImpl::AddOrUpdateFrameEntry(int frame_tree_node_id, | 468 void NavigationEntryImpl::AddOrUpdateFrameEntry(FrameTreeNode* frame_tree_node, |
467 SiteInstanceImpl* site_instance, | 469 SiteInstanceImpl* site_instance, |
468 const GURL& url, | 470 const GURL& url, |
469 const Referrer& referrer) { | 471 const Referrer& referrer) { |
470 // TODO(creis): Walk tree to find the node to update. | 472 // 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. | 473 // commits. Find it first. |
472 FrameNavigationEntry* frame_entry = | 474 DCHECK(frame_tree_node->parent()); |
473 new FrameNavigationEntry(site_instance, url, referrer); | 475 int parent_ftn_id = frame_tree_node->parent()->frame_tree_node_id(); |
474 root_node()->children.push_back( | 476 bool found = false; |
| 477 NavigationEntryImpl::TreeNode* parent_node = nullptr; |
| 478 std::queue<NavigationEntryImpl::TreeNode*> work_queue; |
| 479 work_queue.push(root_node()); |
| 480 while (!found && !work_queue.empty()) { |
| 481 parent_node = work_queue.front(); |
| 482 work_queue.pop(); |
| 483 // The root FNE will have an ID of -1, so check for that as well. |
| 484 if (parent_node->frame_entry->frame_tree_node_id() == parent_ftn_id || |
| 485 (parent_node->frame_entry->frame_tree_node_id() == -1 && |
| 486 parent_node == root_node() && |
| 487 frame_tree_node->parent()->IsMainFrame())) { |
| 488 found = true; |
| 489 break; |
| 490 } |
| 491 // Enqueue any children and keep looking. |
| 492 for (auto& child : parent_node->children) |
| 493 work_queue.push(child); |
| 494 } |
| 495 if (!found) { |
| 496 // The renderer should not send a commit for a subframe before its parent. |
| 497 // TODO(creis): This can currently happen because we don't yet clone the |
| 498 // FrameNavigationEntry tree on manual subframe navigations. Once that's |
| 499 // added, we should kill the renderer if we get here. |
| 500 return; |
| 501 } |
| 502 |
| 503 // Now check whether we have a TreeNode for the node itself. |
| 504 int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
| 505 for (TreeNode* child : parent_node->children) { |
| 506 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { |
| 507 // Update the existing FrameNavigationEntry. |
| 508 child->frame_entry->UpdateEntry(site_instance, url, referrer); |
| 509 return; |
| 510 } |
| 511 } |
| 512 |
| 513 // No entry exists yet, so create a new one. Unordered list, since we expect |
| 514 // to look up entries by frame sequence number or unique name. |
| 515 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( |
| 516 frame_tree_node_id, site_instance, url, referrer); |
| 517 parent_node->children.push_back( |
475 new NavigationEntryImpl::TreeNode(frame_entry)); | 518 new NavigationEntryImpl::TreeNode(frame_entry)); |
476 } | 519 } |
477 | 520 |
478 void NavigationEntryImpl::SetScreenshotPNGData( | 521 void NavigationEntryImpl::SetScreenshotPNGData( |
479 scoped_refptr<base::RefCountedBytes> png_data) { | 522 scoped_refptr<base::RefCountedBytes> png_data) { |
480 screenshot_ = png_data; | 523 screenshot_ = png_data; |
481 if (screenshot_.get()) | 524 if (screenshot_.get()) |
482 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 525 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
483 } | 526 } |
484 | 527 |
485 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 528 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
486 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 529 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
487 } | 530 } |
488 | 531 |
489 } // namespace content | 532 } // namespace content |
OLD | NEW |