Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc |
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
| index 92112a7ef3239998949b2b27a6b573dc8a7a43af..a528f4327a75192dc645d872832950398d4ac870 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -274,6 +274,13 @@ void NotifyCacheOnIO( |
| GetCache()->OnExternalCacheHit(url, http_method); |
| } |
| +// Helper function for retrieving all the sites in a frame tree. |
|
Charlie Reis
2013/09/24 18:25:58
Thanks for leaving this part in, but the UMA stats
awong
2013/09/26 21:25:24
Sounds good, but not quite sure how you want me to
|
| +bool CollectSites(BrowserContext* context, std::set<GURL>* sites, |
|
Charlie Reis
2013/09/24 18:25:58
Style nit: each parameter should be on its own lin
awong
2013/09/26 21:25:24
Done.
|
| + FrameTreeNode* node) { |
| + sites->insert(SiteInstance::GetSiteForURL(context, node->current_url())); |
| + return true; |
| +} |
| + |
| } // namespace |
| WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
| @@ -372,6 +379,10 @@ WebContentsImpl::WebContentsImpl( |
| fullscreen_widget_routing_id_(MSG_ROUTING_NONE) { |
| for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| g_created_callbacks.Get().at(i).Run(this); |
| + frame_tree_.SetFrameRemoveListener( |
| + base::Bind(&WebContentsImpl::OnFrameRemoved, |
| + base::Unretained(this))); |
| + |
| } |
| WebContentsImpl::~WebContentsImpl() { |
| @@ -718,8 +729,6 @@ bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
| IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, |
| OnOpenDateTimeDialog) |
| #endif |
| - IPC_MESSAGE_HANDLER(ViewHostMsg_FrameAttached, OnFrameAttached) |
| - IPC_MESSAGE_HANDLER(ViewHostMsg_FrameDetached, OnFrameDetached) |
| IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP_EX() |
| @@ -1021,27 +1030,10 @@ uint64 WebContentsImpl::GetUploadPosition() const { |
| } |
| std::set<GURL> WebContentsImpl::GetSitesInTab() const { |
| - BrowserContext* browser_context = GetBrowserContext(); |
| std::set<GURL> sites; |
| - if (!frame_tree_root_.get()) |
| - return sites; |
| - |
| - // Iterates over the FrameTreeNodes to find each unique site URL that is |
| - // currently committed. |
| - FrameTreeNode* node = NULL; |
| - std::queue<FrameTreeNode*> queue; |
| - queue.push(frame_tree_root_.get()); |
| - |
| - while (!queue.empty()) { |
| - node = queue.front(); |
| - queue.pop(); |
| - sites.insert(SiteInstance::GetSiteForURL(browser_context, |
| - node->current_url())); |
| - |
| - for (size_t i = 0; i < node->child_count(); ++i) |
| - queue.push(node->child_at(i)); |
| - } |
| - |
| + frame_tree_.ForEach(Bind(&CollectSites, |
| + base::Unretained(GetBrowserContext()), |
| + base::Unretained(&sites))); |
| return sites; |
| } |
| @@ -1735,6 +1727,10 @@ SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| return controller_.GetSessionStorageNamespace(instance); |
| } |
| +FrameTree* WebContentsImpl::GetFrameTree() { |
| + return &frame_tree_; |
| +} |
| + |
| void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { |
| if (browser_plugin_embedder_) |
| browser_plugin_embedder_->DidSendScreenRects(); |
| @@ -2629,52 +2625,6 @@ void WebContentsImpl::OnUpdateFaviconURL( |
| DidUpdateFaviconURL(page_id, candidates)); |
| } |
| -FrameTreeNode* WebContentsImpl::FindFrameTreeNodeByID(int64 frame_id) { |
| - // TODO(nasko): Remove this check once we move to creating the root node |
| - // through RenderFrameHost creation. |
| - if (!frame_tree_root_.get()) |
| - return NULL; |
| - |
| - FrameTreeNode* node = NULL; |
| - std::queue<FrameTreeNode*> queue; |
| - queue.push(frame_tree_root_.get()); |
| - |
| - while (!queue.empty()) { |
| - node = queue.front(); |
| - queue.pop(); |
| - if (node->frame_id() == frame_id) |
| - return node; |
| - |
| - for (size_t i = 0; i < node->child_count(); ++i) |
| - queue.push(node->child_at(i)); |
| - } |
| - |
| - return NULL; |
| -} |
| - |
| -void WebContentsImpl::OnFrameAttached( |
| - int64 parent_frame_id, |
| - int64 frame_id, |
| - const std::string& frame_name) { |
| - FrameTreeNode* parent = FindFrameTreeNodeByID(parent_frame_id); |
| - if (!parent) |
| - return; |
| - |
| - FrameTreeNode* node = new FrameTreeNode(frame_id, frame_name); |
| - parent->AddChild(node); |
| -} |
| - |
| -void WebContentsImpl::OnFrameDetached(int64 parent_frame_id, int64 frame_id) { |
| - FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| - FrameDetached(message_source_, frame_id)); |
| - |
| - FrameTreeNode* parent = FindFrameTreeNodeByID(parent_frame_id); |
| - if (!parent) |
| - return; |
| - |
| - parent->RemoveChild(frame_id); |
| -} |
| - |
| void WebContentsImpl::OnMediaNotification(int64 player_cookie, |
| bool has_video, |
| bool has_audio, |
| @@ -3044,12 +2994,10 @@ void WebContentsImpl::DidGetRedirectForResourceRequest( |
| void WebContentsImpl::DidNavigate( |
| RenderViewHost* rvh, |
| const ViewHostMsg_FrameNavigate_Params& params) { |
| - // If we don't have a frame tree root yet, this is the first navigation in |
| - // using the current RenderViewHost, so we need to create it with the proper |
| - // frame id. |
| - if (!frame_tree_root_.get()) { |
| + if (frame_tree_.IsFirstNavigationAfterSwap()) { |
| + // First navigation should be a main frame navigation. |
| DCHECK(PageTransitionIsMainFrame(params.transition)); |
| - frame_tree_root_.reset(new FrameTreeNode(params.frame_id, std::string())); |
| + frame_tree_.OnFirstNavigationAfterSwap(params.frame_id); |
| } |
| if (PageTransitionIsMainFrame(params.transition)) { |
| @@ -3065,10 +3013,6 @@ void WebContentsImpl::DidNavigate( |
| render_manager_.DidNavigateMainFrame(rvh); |
| } |
| - // We expect to have a valid frame tree root node at all times when |
| - // navigating. |
| - DCHECK(frame_tree_root_.get()); |
| - |
| // Update the site of the SiteInstance if it doesn't have one yet, unless |
| // assigning a site is not necessary for this URL. In that case, the |
| // SiteInstance can still be considered unused until a navigation to a real |
| @@ -3095,9 +3039,7 @@ void WebContentsImpl::DidNavigate( |
| // For now, keep track of each frame's URL in its FrameTreeNode. This lets |
| // us estimate our process count for implementing OOP iframes. |
| // TODO(creis): Remove this when we track which pages commit in each frame. |
| - FrameTreeNode* node = FindFrameTreeNodeByID(params.frame_id); |
| - if (node) |
| - node->set_current_url(params.url); |
| + frame_tree_.SetFrameUrl(params.frame_id, params.url); |
| // Send notification about committed provisional loads. This notification is |
| // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| @@ -3675,24 +3617,6 @@ void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) { |
| view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); |
| view_->RenderViewSwappedIn(render_manager_.current_host()); |
| - |
| - FrameTreeNode* root = NULL; |
| - RenderViewHostImpl* new_rvh = static_cast<RenderViewHostImpl*>( |
| - render_manager_.current_host()); |
| - |
| - // We are doing a cross-site navigation and swapping processes. Since frame |
| - // ids are unique to a process, we need to recreate the frame tree with the |
| - // proper main frame id. |
| - // Note that it is possible for this method to be called before the new RVH |
| - // has committed a navigation (if RenderViewHostManager short-circuits the |
| - // CommitPending call because the current RVH is dead). In that case, we |
| - // haven't heard a valid frame id to use to initialize the root node, so clear |
| - // out the root node and the first subsequent navigation message will set it |
| - // correctly. |
| - if (new_rvh->main_frame_id() != -1) |
| - root = new FrameTreeNode(new_rvh->main_frame_id(), std::string()); |
| - |
| - frame_tree_root_.reset(root); |
| } |
| int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( |
| @@ -3866,4 +3790,9 @@ gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { |
| return size; |
| } |
| +void WebContentsImpl::OnFrameRemoved(int64 frame_id) { |
| + FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| + FrameDetached(message_source_, frame_id)); |
| +} |
| + |
| } // namespace content |