OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry"); | 1731 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry"); |
1732 | 1732 |
1733 // The renderer will reject IPC messages with URLs longer than | 1733 // The renderer will reject IPC messages with URLs longer than |
1734 // this limit, so don't attempt to navigate with a longer URL. | 1734 // this limit, so don't attempt to navigate with a longer URL. |
1735 if (entry.GetURL().spec().size() > GetMaxURLChars()) { | 1735 if (entry.GetURL().spec().size() > GetMaxURLChars()) { |
1736 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() | 1736 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() |
1737 << " characters."; | 1737 << " characters."; |
1738 return false; | 1738 return false; |
1739 } | 1739 } |
1740 | 1740 |
1741 // TODO(creis): Use entry->frame_tree_node_id() to pick which | 1741 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to |
1742 // RenderFrameHostManager to use. | 1742 // use. |
| 1743 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id(); |
| 1744 if (entry.frame_tree_node_id() != -1) |
| 1745 frame_tree_node_id = entry.frame_tree_node_id(); |
| 1746 |
| 1747 RenderFrameHostManager* manager = |
| 1748 frame_tree_.FindByID(frame_tree_node_id)->render_manager(); |
1743 RenderViewHostImpl* dest_render_view_host = | 1749 RenderViewHostImpl* dest_render_view_host = |
1744 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry)); | 1750 static_cast<RenderViewHostImpl*>(manager->Navigate(entry)); |
1745 if (!dest_render_view_host) | 1751 if (!dest_render_view_host) |
1746 return false; // Unable to create the desired render view host. | 1752 return false; // Unable to create the desired render view host. |
1747 | 1753 |
1748 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 1754 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
1749 // Double check that here. | 1755 // Double check that here. |
1750 int enabled_bindings = dest_render_view_host->GetEnabledBindings(); | 1756 int enabled_bindings = dest_render_view_host->GetEnabledBindings(); |
1751 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); | 1757 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); |
1752 bool is_allowed_in_web_ui_renderer = | 1758 bool is_allowed_in_web_ui_renderer = |
1753 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 1759 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
1754 GetBrowserContext(), entry.GetURL(), data_urls_allowed); | 1760 GetBrowserContext(), entry.GetURL(), data_urls_allowed); |
1755 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 1761 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
1756 !is_allowed_in_web_ui_renderer) { | 1762 !is_allowed_in_web_ui_renderer) { |
1757 // Log the URL to help us diagnose any future failures of this CHECK. | 1763 // Log the URL to help us diagnose any future failures of this CHECK. |
1758 GetContentClient()->SetActiveURL(entry.GetURL()); | 1764 GetContentClient()->SetActiveURL(entry.GetURL()); |
1759 CHECK(0); | 1765 CHECK(0); |
1760 } | 1766 } |
1761 | 1767 |
1762 // Notify observers that we will navigate in this RV. | 1768 // Notify observers that we will navigate in this RV. |
1763 FOR_EACH_OBSERVER(WebContentsObserver, | 1769 FOR_EACH_OBSERVER(WebContentsObserver, |
1764 observers_, | 1770 observers_, |
1765 AboutToNavigateRenderView(dest_render_view_host)); | 1771 AboutToNavigateRenderView(dest_render_view_host)); |
1766 | 1772 |
1767 // Used for page load time metrics. | 1773 // Used for page load time metrics. |
1768 current_load_start_ = base::TimeTicks::Now(); | 1774 current_load_start_ = base::TimeTicks::Now(); |
1769 | 1775 |
1770 // Navigate in the desired RenderViewHost. | 1776 // Navigate in the desired RenderViewHost. |
| 1777 // TODO(creis): As a temporary hack, we currently do cross-process subframe |
| 1778 // navigations in a top-level frame of the new process. Thus, we don't yet |
| 1779 // need to store the correct frame ID in ViewMsg_Navigate_Params. |
1771 ViewMsg_Navigate_Params navigate_params; | 1780 ViewMsg_Navigate_Params navigate_params; |
1772 MakeNavigateParams(entry, controller_, delegate_, reload_type, | 1781 MakeNavigateParams(entry, controller_, delegate_, reload_type, |
1773 &navigate_params); | 1782 &navigate_params); |
1774 dest_render_view_host->Navigate(navigate_params); | 1783 dest_render_view_host->Navigate(navigate_params); |
1775 | 1784 |
1776 if (entry.GetPageID() == -1) { | 1785 if (entry.GetPageID() == -1) { |
1777 // HACK!! This code suppresses javascript: URLs from being added to | 1786 // HACK!! This code suppresses javascript: URLs from being added to |
1778 // session history, which is what we want to do for javascript: URLs that | 1787 // session history, which is what we want to do for javascript: URLs that |
1779 // do not generate content. What we really need is a message from the | 1788 // do not generate content. What we really need is a message from the |
1780 // renderer telling us that a new page was not created. The same message | 1789 // renderer telling us that a new page was not created. The same message |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2961 | 2970 |
2962 // TODO(avi): Remove. http://crbug.com/170921 | 2971 // TODO(avi): Remove. http://crbug.com/170921 |
2963 NotificationService::current()->Notify( | 2972 NotificationService::current()->Notify( |
2964 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 2973 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
2965 Source<WebContents>(this), | 2974 Source<WebContents>(this), |
2966 Details<const ResourceRedirectDetails>(&details)); | 2975 Details<const ResourceRedirectDetails>(&details)); |
2967 } | 2976 } |
2968 | 2977 |
2969 void WebContentsImpl::DidNavigate( | 2978 void WebContentsImpl::DidNavigate( |
2970 RenderViewHost* rvh, | 2979 RenderViewHost* rvh, |
2971 const ViewHostMsg_FrameNavigate_Params& params) { | 2980 const ViewHostMsg_FrameNavigate_Params& orig_params) { |
2972 if (frame_tree_.IsFirstNavigationAfterSwap()) { | 2981 ViewHostMsg_FrameNavigate_Params params(orig_params); |
| 2982 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
| 2983 if (!rvhi->HasFrameID(params.frame_id)) { |
2973 // First navigation should be a main frame navigation. | 2984 // First navigation should be a main frame navigation. |
2974 DCHECK(PageTransitionIsMainFrame(params.transition)); | 2985 // TODO(creis): This DCHECK is disabled for now because cross-process |
2975 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id); | 2986 // subframe navigations currently have a main frame PageTransition. |
| 2987 //DCHECK(PageTransitionIsMainFrame(params.transition)); |
| 2988 rvhi->RegisterFrameID(params.frame_id, |
| 2989 frame_tree_.root()->frame_tree_node_id()); |
| 2990 } |
| 2991 |
| 2992 // Look up the FrameTreeNode ID that the renderer-specific frame ID |
| 2993 // corresponds to. |
| 2994 int frame_tree_node_id = rvhi->GetFrameTreeNodeID(params.frame_id); |
| 2995 |
| 2996 // TODO(creis): In the short term, cross-process subframe navigations are |
| 2997 // happening in the pending RenderViewHost's top-level frame. (We need to |
| 2998 // both mirror the frame tree and get the navigation to occur in the correct |
| 2999 // subframe to fix this.) Until then, we should check whether we have a |
| 3000 // pending NavigationEntry with a frame ID and if so, treat the cross-process |
| 3001 // "main frame" navigation as a subframe navigation. This limits us to a |
| 3002 // single cross-process subframe per RVH, and it affects NavigateToEntry and |
| 3003 // DidStartProvisionalLoad. |
| 3004 NavigationEntryImpl* pending_entry = NavigationEntryImpl::FromNavigationEntry( |
| 3005 controller_.GetPendingEntry()); |
| 3006 int root_ftn_id = frame_tree_.root()->frame_tree_node_id(); |
| 3007 if (pending_entry && |
| 3008 pending_entry->frame_tree_node_id() != -1 && |
| 3009 pending_entry->frame_tree_node_id() != root_ftn_id) { |
| 3010 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
| 3011 frame_tree_node_id = pending_entry->frame_tree_node_id(); |
2976 } | 3012 } |
2977 | 3013 |
2978 if (PageTransitionIsMainFrame(params.transition)) { | 3014 if (PageTransitionIsMainFrame(params.transition)) { |
2979 // When overscroll navigation gesture is enabled, a screenshot of the page | 3015 // When overscroll navigation gesture is enabled, a screenshot of the page |
2980 // in its current state is taken so that it can be used during the | 3016 // in its current state is taken so that it can be used during the |
2981 // nav-gesture. It is necessary to take the screenshot here, before calling | 3017 // nav-gesture. It is necessary to take the screenshot here, before calling |
2982 // RenderFrameHostManager::DidNavigateMainFrame, because that can change | 3018 // RenderFrameHostManager::DidNavigateMainFrame, because that can change |
2983 // WebContents::GetRenderViewHost to return the new host, instead of the one | 3019 // WebContents::GetRenderViewHost to return the new host, instead of the one |
2984 // that may have just been swapped out. | 3020 // that may have just been swapped out. |
2985 if (delegate_ && delegate_->CanOverscrollContent()) | 3021 if (delegate_ && delegate_->CanOverscrollContent()) |
2986 controller_.TakeScreenshot(); | 3022 controller_.TakeScreenshot(); |
| 3023 } |
2987 | 3024 |
2988 GetRenderManager()->DidNavigateMainFrame(rvh); | 3025 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 3026 if (!frame) { |
| 3027 // Just for debugging. We can't trust the renderer to lie about the ID. |
| 3028 NOTREACHED(); |
| 3029 return; |
2989 } | 3030 } |
| 3031 // TODO(creis): Rename to DidNavigateFrame. |
| 3032 frame->render_manager()->DidNavigateMainFrame(rvh); |
2990 | 3033 |
2991 // Update the site of the SiteInstance if it doesn't have one yet, unless | 3034 // Update the site of the SiteInstance if it doesn't have one yet, unless |
2992 // assigning a site is not necessary for this URL. In that case, the | 3035 // assigning a site is not necessary for this URL. In that case, the |
2993 // SiteInstance can still be considered unused until a navigation to a real | 3036 // SiteInstance can still be considered unused until a navigation to a real |
2994 // page. | 3037 // page. |
2995 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() && | 3038 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() && |
2996 ShouldAssignSiteForURL(params.url)) { | 3039 ShouldAssignSiteForURL(params.url)) { |
2997 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); | 3040 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); |
2998 } | 3041 } |
2999 | 3042 |
3000 // Need to update MIME type here because it's referred to in | 3043 // Need to update MIME type here because it's referred to in |
3001 // UpdateNavigationCommands() called by RendererDidNavigate() to | 3044 // UpdateNavigationCommands() called by RendererDidNavigate() to |
3002 // determine whether or not to enable the encoding menu. | 3045 // determine whether or not to enable the encoding menu. |
3003 // It's updated only for the main frame. For a subframe, | 3046 // It's updated only for the main frame. For a subframe, |
3004 // RenderView::UpdateURL does not set params.contents_mime_type. | 3047 // RenderView::UpdateURL does not set params.contents_mime_type. |
3005 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) | 3048 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
3006 // TODO(jungshik): Add a test for the encoding menu to avoid | 3049 // TODO(jungshik): Add a test for the encoding menu to avoid |
3007 // regressing it again. | 3050 // regressing it again. |
3008 if (PageTransitionIsMainFrame(params.transition)) | 3051 if (PageTransitionIsMainFrame(params.transition)) |
3009 contents_mime_type_ = params.contents_mime_type; | 3052 contents_mime_type_ = params.contents_mime_type; |
3010 | 3053 |
3011 LoadCommittedDetails details; | 3054 LoadCommittedDetails details; |
3012 bool did_navigate = controller_.RendererDidNavigate(params, &details); | 3055 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details); |
3013 | 3056 |
3014 // For now, keep track of each frame's URL in its FrameTreeNode. This lets | 3057 // For now, keep track of each frame's URL in its FrameTreeNode. This lets |
3015 // us estimate our process count for implementing OOP iframes. | 3058 // us estimate our process count for implementing OOP iframes. |
3016 // TODO(creis): Remove this when we track which pages commit in each frame. | 3059 // TODO(creis): Remove this when we track which pages commit in each frame. |
3017 frame_tree_.SetFrameUrl(params.frame_id, params.url); | 3060 frame_tree_.SetFrameUrl(frame_tree_node_id, params.url); |
3018 | 3061 |
3019 // Send notification about committed provisional loads. This notification is | 3062 // Send notification about committed provisional loads. This notification is |
3020 // different from the NAV_ENTRY_COMMITTED notification which doesn't include | 3063 // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
3021 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. | 3064 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
3022 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) { | 3065 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) { |
3023 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 3066 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
3024 // that is not recorded in the navigation history. For the purpose of | 3067 // that is not recorded in the navigation history. For the purpose of |
3025 // tracking navigation events, we treat this event as a sub frame navigation | 3068 // tracking navigation events, we treat this event as a sub frame navigation |
3026 // event. | 3069 // event. |
3027 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 3070 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3277 int64 source_frame_id, | 3320 int64 source_frame_id, |
3278 const GlobalRequestID& old_request_id, | 3321 const GlobalRequestID& old_request_id, |
3279 bool should_replace_current_entry, | 3322 bool should_replace_current_entry, |
3280 bool user_gesture) { | 3323 bool user_gesture) { |
3281 WebContents* new_contents = NULL; | 3324 WebContents* new_contents = NULL; |
3282 GURL dest_url(url); | 3325 GURL dest_url(url); |
3283 if (!GetContentClient()->browser()->ShouldAllowOpenURL( | 3326 if (!GetContentClient()->browser()->ShouldAllowOpenURL( |
3284 GetSiteInstance(), url)) | 3327 GetSiteInstance(), url)) |
3285 dest_url = GURL(kAboutBlankURL); | 3328 dest_url = GURL(kAboutBlankURL); |
3286 | 3329 |
3287 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id. | 3330 int64 frame_tree_node_id = -1; |
3288 int frame_tree_node_id = -1; | 3331 if (source_frame_id != -1) { |
| 3332 frame_tree_node_id = static_cast<RenderViewHostImpl*>( |
| 3333 GetRenderViewHost())->GetFrameTreeNodeID(source_frame_id); |
| 3334 } |
3289 OpenURLParams params(dest_url, referrer, source_frame_id, | 3335 OpenURLParams params(dest_url, referrer, source_frame_id, |
3290 frame_tree_node_id, disposition, | 3336 frame_tree_node_id, disposition, |
3291 page_transition, true /* is_renderer_initiated */); | 3337 page_transition, true /* is_renderer_initiated */); |
3292 if (redirect_chain.size() > 0) | 3338 if (redirect_chain.size() > 0) |
3293 params.redirect_chain = redirect_chain; | 3339 params.redirect_chain = redirect_chain; |
3294 params.transferred_global_request_id = old_request_id; | 3340 params.transferred_global_request_id = old_request_id; |
3295 params.should_replace_current_entry = should_replace_current_entry; | 3341 params.should_replace_current_entry = should_replace_current_entry; |
3296 params.user_gesture = user_gesture; | 3342 params.user_gesture = user_gesture; |
3297 | 3343 |
3298 if (GetRenderManager()->web_ui()) { | 3344 if (GetRenderManager()->web_ui()) { |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3824 } | 3870 } |
3825 | 3871 |
3826 void WebContentsImpl::OnFrameRemoved( | 3872 void WebContentsImpl::OnFrameRemoved( |
3827 RenderViewHostImpl* render_view_host, | 3873 RenderViewHostImpl* render_view_host, |
3828 int64 frame_id) { | 3874 int64 frame_id) { |
3829 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3875 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3830 FrameDetached(render_view_host, frame_id)); | 3876 FrameDetached(render_view_host, frame_id)); |
3831 } | 3877 } |
3832 | 3878 |
3833 } // namespace content | 3879 } // namespace content |
OLD | NEW |