Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 25654005: Remove GetActiveEntry usage from content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comment, added TODO, rebased on ToT. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 903
904 renderer_preferences_.user_agent_override = override; 904 renderer_preferences_.user_agent_override = override;
905 905
906 // Send the new override string to the renderer. 906 // Send the new override string to the renderer.
907 RenderViewHost* host = GetRenderViewHost(); 907 RenderViewHost* host = GetRenderViewHost();
908 if (host) 908 if (host)
909 host->SyncRendererPrefs(); 909 host->SyncRendererPrefs();
910 910
911 // Reload the page if a load is currently in progress to avoid having 911 // Reload the page if a load is currently in progress to avoid having
912 // different parts of the page loaded using different user agents. 912 // different parts of the page loaded using different user agents.
913 NavigationEntry* entry = controller_.GetActiveEntry(); 913 NavigationEntry* entry = controller_.GetVisibleEntry();
914 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) 914 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
915 controller_.ReloadIgnoringCache(true); 915 controller_.ReloadIgnoringCache(true);
916 916
917 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 917 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
918 UserAgentOverrideSet(override)); 918 UserAgentOverrideSet(override));
919 } 919 }
920 920
921 const std::string& WebContentsImpl::GetUserAgentOverride() const { 921 const std::string& WebContentsImpl::GetUserAgentOverride() const {
922 return renderer_preferences_.user_agent_override; 922 return renderer_preferences_.user_agent_override;
923 } 923 }
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 if (!GetURL().is_valid()) 1958 if (!GetURL().is_valid())
1959 return; 1959 return;
1960 bool is_main_frame = (url == GetURL()); 1960 bool is_main_frame = (url == GetURL());
1961 1961
1962 DownloadManager* dlm = 1962 DownloadManager* dlm =
1963 BrowserContext::GetDownloadManager(GetBrowserContext()); 1963 BrowserContext::GetDownloadManager(GetBrowserContext());
1964 if (!dlm) 1964 if (!dlm)
1965 return; 1965 return;
1966 int64 post_id = -1; 1966 int64 post_id = -1;
1967 if (is_main_frame) { 1967 if (is_main_frame) {
1968 const NavigationEntry* entry = controller_.GetActiveEntry(); 1968 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
1969 if (entry) 1969 if (entry)
1970 post_id = entry->GetPostID(); 1970 post_id = entry->GetPostID();
1971 } 1971 }
1972 scoped_ptr<DownloadUrlParameters> params( 1972 scoped_ptr<DownloadUrlParameters> params(
1973 DownloadUrlParameters::FromWebContents(this, url)); 1973 DownloadUrlParameters::FromWebContents(this, url));
1974 params->set_referrer(referrer); 1974 params->set_referrer(referrer);
1975 params->set_post_id(post_id); 1975 params->set_post_id(post_id);
1976 params->set_prefer_cache(true); 1976 params->set_prefer_cache(true);
1977 if (post_id >= 0) 1977 if (post_id >= 0)
1978 params->set_method("POST"); 1978 params->set_method("POST");
1979 params->set_prompt(true); 1979 params->set_prompt(true);
1980 dlm->DownloadUrl(params.Pass()); 1980 dlm->DownloadUrl(params.Pass());
1981 } 1981 }
1982 1982
1983 void WebContentsImpl::GenerateMHTML( 1983 void WebContentsImpl::GenerateMHTML(
1984 const base::FilePath& file, 1984 const base::FilePath& file,
1985 const base::Callback<void(int64)>& callback) { 1985 const base::Callback<void(int64)>& callback) {
1986 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); 1986 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
1987 } 1987 }
1988 1988
1989 // TODO(nasko): Rename this method to IsVisibleEntry.
1989 bool WebContentsImpl::IsActiveEntry(int32 page_id) { 1990 bool WebContentsImpl::IsActiveEntry(int32 page_id) {
1990 NavigationEntryImpl* active_entry = 1991 NavigationEntryImpl* visible_entry =
1991 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); 1992 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1992 return (active_entry != NULL && 1993 return (visible_entry != NULL &&
1993 active_entry->site_instance() == GetSiteInstance() && 1994 visible_entry->site_instance() == GetSiteInstance() &&
1994 active_entry->GetPageID() == page_id); 1995 visible_entry->GetPageID() == page_id);
1995 } 1996 }
1996 1997
1997 const std::string& WebContentsImpl::GetContentsMimeType() const { 1998 const std::string& WebContentsImpl::GetContentsMimeType() const {
1998 return contents_mime_type_; 1999 return contents_mime_type_;
1999 } 2000 }
2000 2001
2001 bool WebContentsImpl::WillNotifyDisconnection() const { 2002 bool WebContentsImpl::WillNotifyDisconnection() const {
2002 return notify_disconnection_; 2003 return notify_disconnection_;
2003 } 2004 }
2004 2005
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 HostZoomMap::GetForBrowserContext(GetBrowserContext())); 2067 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
2067 if (!zoom_map) 2068 if (!zoom_map)
2068 return 0; 2069 return 0;
2069 2070
2070 double zoom_level; 2071 double zoom_level;
2071 if (temporary_zoom_settings_) { 2072 if (temporary_zoom_settings_) {
2072 zoom_level = zoom_map->GetTemporaryZoomLevel( 2073 zoom_level = zoom_map->GetTemporaryZoomLevel(
2073 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); 2074 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
2074 } else { 2075 } else {
2075 GURL url; 2076 GURL url;
2076 NavigationEntry* active_entry = GetController().GetActiveEntry(); 2077 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2077 // Since zoom map is updated using rewritten URL, use rewritten URL 2078 // Since zoom map is updated using rewritten URL, use rewritten URL
2078 // to get the zoom level. 2079 // to get the zoom level.
2079 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); 2080 url = entry ? entry->GetURL() : GURL::EmptyGURL();
2080 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), 2081 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2081 net::GetHostOrSpecFromURL(url)); 2082 net::GetHostOrSpecFromURL(url));
2082 } 2083 }
2083 return zoom_level; 2084 return zoom_level;
2084 } 2085 }
2085 2086
2086 int WebContentsImpl::GetZoomPercent(bool* enable_increment, 2087 int WebContentsImpl::GetZoomPercent(bool* enable_increment,
2087 bool* enable_decrement) const { 2088 bool* enable_decrement) const {
2088 *enable_decrement = *enable_increment = false; 2089 *enable_decrement = *enable_increment = false;
2089 // Calculate the zoom percent from the factor. Round up to the nearest whole 2090 // Calculate the zoom percent from the factor. Round up to the nearest whole
2090 // number. 2091 // number.
2091 int percent = static_cast<int>( 2092 int percent = static_cast<int>(
2092 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); 2093 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
2093 *enable_decrement = percent > minimum_zoom_percent_; 2094 *enable_decrement = percent > minimum_zoom_percent_;
2094 *enable_increment = percent < maximum_zoom_percent_; 2095 *enable_increment = percent < maximum_zoom_percent_;
2095 return percent; 2096 return percent;
2096 } 2097 }
2097 2098
2098 void WebContentsImpl::ViewSource() { 2099 void WebContentsImpl::ViewSource() {
2099 if (!delegate_) 2100 if (!delegate_)
2100 return; 2101 return;
2101 2102
2102 NavigationEntry* active_entry = GetController().GetActiveEntry(); 2103 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2103 if (!active_entry) 2104 if (!entry)
2104 return; 2105 return;
2105 2106
2106 delegate_->ViewSourceForTab(this, active_entry->GetURL()); 2107 delegate_->ViewSourceForTab(this, entry->GetURL());
2107 } 2108 }
2108 2109
2109 void WebContentsImpl::ViewFrameSource(const GURL& url, 2110 void WebContentsImpl::ViewFrameSource(const GURL& url,
2110 const PageState& page_state) { 2111 const PageState& page_state) {
2111 if (!delegate_) 2112 if (!delegate_)
2112 return; 2113 return;
2113 2114
2114 delegate_->ViewSourceForFrame(this, url, page_state); 2115 delegate_->ViewSourceForFrame(this, url, page_state);
2115 } 2116 }
2116 2117
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 bool is_favicon, 2152 bool is_favicon,
2152 uint32_t max_bitmap_size, 2153 uint32_t max_bitmap_size,
2153 const ImageDownloadCallback& callback) { 2154 const ImageDownloadCallback& callback) {
2154 RenderViewHost* host = GetRenderViewHost(); 2155 RenderViewHost* host = GetRenderViewHost();
2155 int id = StartDownload(host, url, is_favicon, max_bitmap_size); 2156 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
2156 image_download_map_[id] = callback; 2157 image_download_map_[id] = callback;
2157 return id; 2158 return id;
2158 } 2159 }
2159 2160
2160 bool WebContentsImpl::FocusLocationBarByDefault() { 2161 bool WebContentsImpl::FocusLocationBarByDefault() {
2161 NavigationEntry* entry = controller_.GetActiveEntry(); 2162 NavigationEntry* entry = controller_.GetVisibleEntry();
2162 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) 2163 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
2163 return true; 2164 return true;
2164 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); 2165 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
2165 } 2166 }
2166 2167
2167 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { 2168 void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
2168 if (delegate_) 2169 if (delegate_)
2169 delegate_->SetFocusToLocationBar(select_all); 2170 delegate_->SetFocusToLocationBar(select_all);
2170 } 2171 }
2171 2172
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 NotificationService::current()->Notify( 2918 NotificationService::current()->Notify(
2918 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, 2919 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2919 Source<WebContents>(this), 2920 Source<WebContents>(this),
2920 Details<RenderViewHost>(render_view_host)); 2921 Details<RenderViewHost>(render_view_host));
2921 2922
2922 // When we're creating views, we're still doing initial setup, so we always 2923 // When we're creating views, we're still doing initial setup, so we always
2923 // use the pending Web UI rather than any possibly existing committed one. 2924 // use the pending Web UI rather than any possibly existing committed one.
2924 if (render_manager_.pending_web_ui()) 2925 if (render_manager_.pending_web_ui())
2925 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); 2926 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
2926 2927
2927 NavigationEntry* entry = controller_.GetActiveEntry(); 2928 NavigationEntry* entry = controller_.GetPendingEntry();
2928 if (entry && entry->IsViewSourceMode()) { 2929 if (entry && entry->IsViewSourceMode()) {
2929 // Put the renderer in view source mode. 2930 // Put the renderer in view source mode.
2930 render_view_host->Send( 2931 render_view_host->Send(
2931 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); 2932 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
2932 } 2933 }
2933 2934
2934 view_->RenderViewCreated(render_view_host); 2935 view_->RenderViewCreated(render_view_host);
2935 2936
2936 FOR_EACH_OBSERVER( 2937 FOR_EACH_OBSERVER(
2937 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); 2938 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 // For AUTO_SUBFRAME navigations, an event for the main frame is generated 3075 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
3075 // that is not recorded in the navigation history. For the purpose of 3076 // that is not recorded in the navigation history. For the purpose of
3076 // tracking navigation events, we treat this event as a sub frame navigation 3077 // tracking navigation events, we treat this event as a sub frame navigation
3077 // event. 3078 // event.
3078 bool is_main_frame = did_navigate ? details.is_main_frame : false; 3079 bool is_main_frame = did_navigate ? details.is_main_frame : false;
3079 PageTransition transition_type = params.transition; 3080 PageTransition transition_type = params.transition;
3080 // Whether or not a page transition was triggered by going backward or 3081 // Whether or not a page transition was triggered by going backward or
3081 // forward in the history is only stored in the navigation controller's 3082 // forward in the history is only stored in the navigation controller's
3082 // entry list. 3083 // entry list.
3083 if (did_navigate && 3084 if (did_navigate &&
3084 (controller_.GetActiveEntry()->GetTransitionType() & 3085 (controller_.GetLastCommittedEntry()->GetTransitionType() &
3085 PAGE_TRANSITION_FORWARD_BACK)) { 3086 PAGE_TRANSITION_FORWARD_BACK)) {
3086 transition_type = PageTransitionFromInt( 3087 transition_type = PageTransitionFromInt(
3087 params.transition | PAGE_TRANSITION_FORWARD_BACK); 3088 params.transition | PAGE_TRANSITION_FORWARD_BACK);
3088 } 3089 }
3089 // Notify observers about the commit of the provisional load. 3090 // Notify observers about the commit of the provisional load.
3090 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3091 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3091 DidCommitProvisionalLoadForFrame(params.frame_id, 3092 DidCommitProvisionalLoadForFrame(params.frame_id,
3092 is_main_frame, params.url, transition_type, rvh)); 3093 is_main_frame, params.url, transition_type, rvh));
3093 } 3094 }
3094 3095
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 const string16& message, 3494 const string16& message,
3494 int32 line_no, 3495 int32 line_no,
3495 const string16& source_id) { 3496 const string16& source_id) {
3496 if (!delegate_) 3497 if (!delegate_)
3497 return false; 3498 return false;
3498 return delegate_->AddMessageToConsole(this, level, message, line_no, 3499 return delegate_->AddMessageToConsole(this, level, message, line_no,
3499 source_id); 3500 source_id);
3500 } 3501 }
3501 3502
3502 WebPreferences WebContentsImpl::GetWebkitPrefs() { 3503 WebPreferences WebContentsImpl::GetWebkitPrefs() {
3503 // We want to base the page config off of the real URL, rather than the 3504 // We want to base the page config off of the actual URL, rather than the
3504 // display URL. 3505 // virtual URL.
3506 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3507 // as it is deprecated and can be out of sync with GetRenderViewHost().
3505 GURL url = controller_.GetActiveEntry() 3508 GURL url = controller_.GetActiveEntry()
3506 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); 3509 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3507 return GetWebkitPrefs(GetRenderViewHost(), url); 3510 return GetWebkitPrefs(GetRenderViewHost(), url);
3508 } 3511 }
3509 3512
3510 int WebContentsImpl::CreateSwappedOutRenderView( 3513 int WebContentsImpl::CreateSwappedOutRenderView(
3511 SiteInstance* instance) { 3514 SiteInstance* instance) {
3512 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, 3515 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE,
3513 true, true); 3516 true, true);
3514 } 3517 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 } 3820 }
3818 3821
3819 void WebContentsImpl::OnFrameRemoved( 3822 void WebContentsImpl::OnFrameRemoved(
3820 RenderViewHostImpl* render_view_host, 3823 RenderViewHostImpl* render_view_host,
3821 int64 frame_id) { 3824 int64 frame_id) {
3822 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3825 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3823 FrameDetached(render_view_host, frame_id)); 3826 FrameDetached(render_view_host, frame_id));
3824 } 3827 }
3825 3828
3826 } // namespace content 3829 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698