| 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> | 7 #include <queue> | 
| 8 | 8 | 
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" | 
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37     FrameTreeNode* frame_tree_node) const { | 37     FrameTreeNode* frame_tree_node) const { | 
| 38   if (frame_tree_node->frame_tree_node_id() == | 38   if (frame_tree_node->frame_tree_node_id() == | 
| 39       frame_entry->frame_tree_node_id()) | 39       frame_entry->frame_tree_node_id()) | 
| 40     return true; | 40     return true; | 
| 41 | 41 | 
| 42   // For now, we set the root FNE's FrameTreeNode ID to -1. | 42   // For now, we set the root FNE's FrameTreeNode ID to -1. | 
| 43   return frame_tree_node->IsMainFrame() && | 43   return frame_tree_node->IsMainFrame() && | 
| 44          frame_entry->frame_tree_node_id() == -1; | 44          frame_entry->frame_tree_node_id() == -1; | 
| 45 } | 45 } | 
| 46 | 46 | 
| 47 NavigationEntryImpl::TreeNode* NavigationEntryImpl::TreeNode::Clone() const { | 47 scoped_ptr<NavigationEntryImpl::TreeNode> | 
|  | 48 NavigationEntryImpl::TreeNode::CloneAndReplace( | 
|  | 49     FrameTreeNode* frame_tree_node, | 
|  | 50     FrameNavigationEntry* frame_navigation_entry) const { | 
|  | 51   if (frame_tree_node && MatchesFrame(frame_tree_node)) { | 
|  | 52     // Replace this node in the cloned tree and prune its children. | 
|  | 53     return make_scoped_ptr( | 
|  | 54         new NavigationEntryImpl::TreeNode(frame_navigation_entry)); | 
|  | 55   } | 
|  | 56 | 
| 48   // Clone the tree using a copy of the FrameNavigationEntry, without sharing. | 57   // Clone the tree using a copy of the FrameNavigationEntry, without sharing. | 
| 49   NavigationEntryImpl::TreeNode* copy = | 58   // TODO(creis): Share FNEs unless it's for another tab. | 
| 50       new NavigationEntryImpl::TreeNode(frame_entry->Clone()); | 59   scoped_ptr<NavigationEntryImpl::TreeNode> copy( | 
|  | 60       new NavigationEntryImpl::TreeNode(frame_entry->Clone())); | 
| 51 | 61 | 
| 52   // TODO(creis): Clone children once we add them. | 62   // Recursively clone the children. | 
| 53   return copy; | 63   for (auto& child : children) { | 
|  | 64     copy->children.push_back( | 
|  | 65         child->CloneAndReplace(frame_tree_node, frame_navigation_entry)); | 
|  | 66   } | 
|  | 67 | 
|  | 68   return copy.Pass(); | 
| 54 } | 69 } | 
| 55 | 70 | 
| 56 NavigationEntry* NavigationEntry::Create() { | 71 NavigationEntry* NavigationEntry::Create() { | 
| 57   return new NavigationEntryImpl(); | 72   return new NavigationEntryImpl(); | 
| 58 } | 73 } | 
| 59 | 74 | 
| 60 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | 75 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | 
| 61     NavigationEntry* entry) { | 76     NavigationEntry* entry) { | 
| 62   return static_cast<NavigationEntryImpl*>(entry); | 77   return static_cast<NavigationEntryImpl*>(entry); | 
| 63 } | 78 } | 
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 344     return false; | 359     return false; | 
| 345   *data = iter->second; | 360   *data = iter->second; | 
| 346   return true; | 361   return true; | 
| 347 } | 362 } | 
| 348 | 363 | 
| 349 void NavigationEntryImpl::ClearExtraData(const std::string& key) { | 364 void NavigationEntryImpl::ClearExtraData(const std::string& key) { | 
| 350   extra_data_.erase(key); | 365   extra_data_.erase(key); | 
| 351 } | 366 } | 
| 352 | 367 | 
| 353 NavigationEntryImpl* NavigationEntryImpl::Clone() const { | 368 NavigationEntryImpl* NavigationEntryImpl::Clone() const { | 
|  | 369   return NavigationEntryImpl::CloneAndReplace(nullptr, nullptr); | 
|  | 370 } | 
|  | 371 | 
|  | 372 NavigationEntryImpl* NavigationEntryImpl::CloneAndReplace( | 
|  | 373     FrameTreeNode* frame_tree_node, | 
|  | 374     FrameNavigationEntry* frame_navigation_entry) const { | 
| 354   NavigationEntryImpl* copy = new NavigationEntryImpl(); | 375   NavigationEntryImpl* copy = new NavigationEntryImpl(); | 
| 355 | 376 | 
| 356   // TODO(creis): Only share the same FrameNavigationEntries if cloning within | 377   // TODO(creis): Only share the same FrameNavigationEntries if cloning within | 
| 357   // the same tab. | 378   // the same tab. | 
| 358   copy->frame_tree_.reset(frame_tree_->Clone()); | 379   copy->frame_tree_ = | 
|  | 380       frame_tree_->CloneAndReplace(frame_tree_node, frame_navigation_entry); | 
| 359 | 381 | 
| 360   // Copy most state over, unless cleared in ResetForCommit. | 382   // Copy most state over, unless cleared in ResetForCommit. | 
| 361   // Don't copy unique_id_, otherwise it won't be unique. | 383   // Don't copy unique_id_, otherwise it won't be unique. | 
| 362   copy->bindings_ = bindings_; | 384   copy->bindings_ = bindings_; | 
| 363   copy->page_type_ = page_type_; | 385   copy->page_type_ = page_type_; | 
| 364   copy->virtual_url_ = virtual_url_; | 386   copy->virtual_url_ = virtual_url_; | 
| 365   copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; | 387   copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; | 
| 366   copy->title_ = title_; | 388   copy->title_ = title_; | 
| 367   copy->favicon_ = favicon_; | 389   copy->favicon_ = favicon_; | 
| 368   copy->page_id_ = page_id_; | 390   copy->page_id_ = page_id_; | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 486                                                 const GURL& url, | 508                                                 const GURL& url, | 
| 487                                                 const Referrer& referrer, | 509                                                 const Referrer& referrer, | 
| 488                                                 const PageState& page_state) { | 510                                                 const PageState& page_state) { | 
| 489   // We should already have a TreeNode for the parent node by the time this node | 511   // We should already have a TreeNode for the parent node by the time this node | 
| 490   // commits.  Find it first. | 512   // commits.  Find it first. | 
| 491   DCHECK(frame_tree_node->parent()); | 513   DCHECK(frame_tree_node->parent()); | 
| 492   NavigationEntryImpl::TreeNode* parent_node = | 514   NavigationEntryImpl::TreeNode* parent_node = | 
| 493       FindFrameEntry(frame_tree_node->parent()); | 515       FindFrameEntry(frame_tree_node->parent()); | 
| 494   if (!parent_node) { | 516   if (!parent_node) { | 
| 495     // The renderer should not send a commit for a subframe before its parent. | 517     // The renderer should not send a commit for a subframe before its parent. | 
| 496     // TODO(creis): This can currently happen because we don't yet clone the | 518     // TODO(creis): Kill the renderer if we get here. | 
| 497     // FrameNavigationEntry tree on manual subframe navigations.  Once that's | 519     NOTREACHED() << "Shouldn't see a commit for a subframe before parent."; | 
| 498     // added, we should kill the renderer if we get here. |  | 
| 499     return; | 520     return; | 
| 500   } | 521   } | 
| 501 | 522 | 
| 502   // Now check whether we have a TreeNode for the node itself. | 523   // Now check whether we have a TreeNode for the node itself. | 
| 503   int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 524   int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 
| 504   for (TreeNode* child : parent_node->children) { | 525   for (TreeNode* child : parent_node->children) { | 
| 505     if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { | 526     if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { | 
| 506       // Update the existing FrameNavigationEntry. | 527       // Update the existing FrameNavigationEntry (e.g., for replaceState). | 
| 507       child->frame_entry->UpdateEntry(site_instance, url, referrer, page_state); | 528       child->frame_entry->UpdateEntry(site_instance, url, referrer, page_state); | 
| 508       return; | 529       return; | 
| 509     } | 530     } | 
| 510   } | 531   } | 
| 511 | 532 | 
| 512   // No entry exists yet, so create a new one unless it's for about:blank. | 533   // No entry exists yet, so create a new one unless it's for about:blank. | 
| 513   // Unordered list, since we expect to look up entries by frame sequence number | 534   // Unordered list, since we expect to look up entries by frame sequence number | 
| 514   // or unique name. | 535   // or unique name. | 
| 515   if (url == GURL(url::kAboutBlankURL)) | 536   if (url == GURL(url::kAboutBlankURL)) | 
| 516     return; | 537     return; | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 551       return node; | 572       return node; | 
| 552     } | 573     } | 
| 553     // Enqueue any children and keep looking. | 574     // Enqueue any children and keep looking. | 
| 554     for (auto& child : node->children) | 575     for (auto& child : node->children) | 
| 555       work_queue.push(child); | 576       work_queue.push(child); | 
| 556   } | 577   } | 
| 557   return nullptr; | 578   return nullptr; | 
| 558 } | 579 } | 
| 559 | 580 | 
| 560 }  // namespace content | 581 }  // namespace content | 
| OLD | NEW | 
|---|