Chromium Code Reviews| 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 | 901 |
| 902 renderer_preferences_.user_agent_override = override; | 902 renderer_preferences_.user_agent_override = override; |
| 903 | 903 |
| 904 // Send the new override string to the renderer. | 904 // Send the new override string to the renderer. |
| 905 RenderViewHost* host = GetRenderViewHost(); | 905 RenderViewHost* host = GetRenderViewHost(); |
| 906 if (host) | 906 if (host) |
| 907 host->SyncRendererPrefs(); | 907 host->SyncRendererPrefs(); |
| 908 | 908 |
| 909 // Reload the page if a load is currently in progress to avoid having | 909 // Reload the page if a load is currently in progress to avoid having |
| 910 // different parts of the page loaded using different user agents. | 910 // different parts of the page loaded using different user agents. |
| 911 NavigationEntry* entry = controller_.GetActiveEntry(); | 911 NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 912 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) | 912 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) |
| 913 controller_.ReloadIgnoringCache(true); | 913 controller_.ReloadIgnoringCache(true); |
| 914 | 914 |
| 915 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 915 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 916 UserAgentOverrideSet(override)); | 916 UserAgentOverrideSet(override)); |
| 917 } | 917 } |
| 918 | 918 |
| 919 const std::string& WebContentsImpl::GetUserAgentOverride() const { | 919 const std::string& WebContentsImpl::GetUserAgentOverride() const { |
| 920 return renderer_preferences_.user_agent_override; | 920 return renderer_preferences_.user_agent_override; |
| 921 } | 921 } |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1956 if (!GetURL().is_valid()) | 1956 if (!GetURL().is_valid()) |
| 1957 return; | 1957 return; |
| 1958 bool is_main_frame = (url == GetURL()); | 1958 bool is_main_frame = (url == GetURL()); |
| 1959 | 1959 |
| 1960 DownloadManager* dlm = | 1960 DownloadManager* dlm = |
| 1961 BrowserContext::GetDownloadManager(GetBrowserContext()); | 1961 BrowserContext::GetDownloadManager(GetBrowserContext()); |
| 1962 if (!dlm) | 1962 if (!dlm) |
| 1963 return; | 1963 return; |
| 1964 int64 post_id = -1; | 1964 int64 post_id = -1; |
| 1965 if (is_main_frame) { | 1965 if (is_main_frame) { |
| 1966 const NavigationEntry* entry = controller_.GetActiveEntry(); | 1966 const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1967 if (entry) | 1967 if (entry) |
| 1968 post_id = entry->GetPostID(); | 1968 post_id = entry->GetPostID(); |
| 1969 } | 1969 } |
| 1970 scoped_ptr<DownloadUrlParameters> params( | 1970 scoped_ptr<DownloadUrlParameters> params( |
| 1971 DownloadUrlParameters::FromWebContents(this, url)); | 1971 DownloadUrlParameters::FromWebContents(this, url)); |
| 1972 params->set_referrer(referrer); | 1972 params->set_referrer(referrer); |
| 1973 params->set_post_id(post_id); | 1973 params->set_post_id(post_id); |
| 1974 params->set_prefer_cache(true); | 1974 params->set_prefer_cache(true); |
| 1975 if (post_id >= 0) | 1975 if (post_id >= 0) |
| 1976 params->set_method("POST"); | 1976 params->set_method("POST"); |
| 1977 params->set_prompt(true); | 1977 params->set_prompt(true); |
| 1978 dlm->DownloadUrl(params.Pass()); | 1978 dlm->DownloadUrl(params.Pass()); |
| 1979 } | 1979 } |
| 1980 | 1980 |
| 1981 void WebContentsImpl::GenerateMHTML( | 1981 void WebContentsImpl::GenerateMHTML( |
| 1982 const base::FilePath& file, | 1982 const base::FilePath& file, |
| 1983 const base::Callback<void(int64)>& callback) { | 1983 const base::Callback<void(int64)>& callback) { |
| 1984 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); | 1984 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); |
| 1985 } | 1985 } |
| 1986 | 1986 |
| 1987 // TODO(nasko): Rename this method to IsVisibleEntry. | |
| 1987 bool WebContentsImpl::IsActiveEntry(int32 page_id) { | 1988 bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
| 1988 NavigationEntryImpl* active_entry = | 1989 NavigationEntryImpl* visible_entry = |
| 1989 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); | 1990 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry()); |
| 1990 return (active_entry != NULL && | 1991 return (visible_entry != NULL && |
| 1991 active_entry->site_instance() == GetSiteInstance() && | 1992 visible_entry->site_instance() == GetSiteInstance() && |
| 1992 active_entry->GetPageID() == page_id); | 1993 visible_entry->GetPageID() == page_id); |
| 1993 } | 1994 } |
| 1994 | 1995 |
| 1995 const std::string& WebContentsImpl::GetContentsMimeType() const { | 1996 const std::string& WebContentsImpl::GetContentsMimeType() const { |
| 1996 return contents_mime_type_; | 1997 return contents_mime_type_; |
| 1997 } | 1998 } |
| 1998 | 1999 |
| 1999 bool WebContentsImpl::WillNotifyDisconnection() const { | 2000 bool WebContentsImpl::WillNotifyDisconnection() const { |
| 2000 return notify_disconnection_; | 2001 return notify_disconnection_; |
| 2001 } | 2002 } |
| 2002 | 2003 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2064 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | 2065 HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
| 2065 if (!zoom_map) | 2066 if (!zoom_map) |
| 2066 return 0; | 2067 return 0; |
| 2067 | 2068 |
| 2068 double zoom_level; | 2069 double zoom_level; |
| 2069 if (temporary_zoom_settings_) { | 2070 if (temporary_zoom_settings_) { |
| 2070 zoom_level = zoom_map->GetTemporaryZoomLevel( | 2071 zoom_level = zoom_map->GetTemporaryZoomLevel( |
| 2071 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | 2072 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
| 2072 } else { | 2073 } else { |
| 2073 GURL url; | 2074 GURL url; |
| 2074 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2075 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 2075 // Since zoom map is updated using rewritten URL, use rewritten URL | 2076 // Since zoom map is updated using rewritten URL, use rewritten URL |
| 2076 // to get the zoom level. | 2077 // to get the zoom level. |
| 2077 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); | 2078 url = entry ? entry->GetURL() : GURL::EmptyGURL(); |
| 2078 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | 2079 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), |
| 2079 net::GetHostOrSpecFromURL(url)); | 2080 net::GetHostOrSpecFromURL(url)); |
| 2080 } | 2081 } |
| 2081 return zoom_level; | 2082 return zoom_level; |
| 2082 } | 2083 } |
| 2083 | 2084 |
| 2084 int WebContentsImpl::GetZoomPercent(bool* enable_increment, | 2085 int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
| 2085 bool* enable_decrement) const { | 2086 bool* enable_decrement) const { |
| 2086 *enable_decrement = *enable_increment = false; | 2087 *enable_decrement = *enable_increment = false; |
| 2087 // Calculate the zoom percent from the factor. Round up to the nearest whole | 2088 // Calculate the zoom percent from the factor. Round up to the nearest whole |
| 2088 // number. | 2089 // number. |
| 2089 int percent = static_cast<int>( | 2090 int percent = static_cast<int>( |
| 2090 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); | 2091 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
| 2091 *enable_decrement = percent > minimum_zoom_percent_; | 2092 *enable_decrement = percent > minimum_zoom_percent_; |
| 2092 *enable_increment = percent < maximum_zoom_percent_; | 2093 *enable_increment = percent < maximum_zoom_percent_; |
| 2093 return percent; | 2094 return percent; |
| 2094 } | 2095 } |
| 2095 | 2096 |
| 2096 void WebContentsImpl::ViewSource() { | 2097 void WebContentsImpl::ViewSource() { |
| 2097 if (!delegate_) | 2098 if (!delegate_) |
| 2098 return; | 2099 return; |
| 2099 | 2100 |
| 2100 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2101 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 2101 if (!active_entry) | 2102 if (!entry) |
| 2102 return; | 2103 return; |
| 2103 | 2104 |
| 2104 delegate_->ViewSourceForTab(this, active_entry->GetURL()); | 2105 delegate_->ViewSourceForTab(this, entry->GetURL()); |
| 2105 } | 2106 } |
| 2106 | 2107 |
| 2107 void WebContentsImpl::ViewFrameSource(const GURL& url, | 2108 void WebContentsImpl::ViewFrameSource(const GURL& url, |
| 2108 const PageState& page_state) { | 2109 const PageState& page_state) { |
| 2109 if (!delegate_) | 2110 if (!delegate_) |
| 2110 return; | 2111 return; |
| 2111 | 2112 |
| 2112 delegate_->ViewSourceForFrame(this, url, page_state); | 2113 delegate_->ViewSourceForFrame(this, url, page_state); |
| 2113 } | 2114 } |
| 2114 | 2115 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2149 bool is_favicon, | 2150 bool is_favicon, |
| 2150 uint32_t max_bitmap_size, | 2151 uint32_t max_bitmap_size, |
| 2151 const ImageDownloadCallback& callback) { | 2152 const ImageDownloadCallback& callback) { |
| 2152 RenderViewHost* host = GetRenderViewHost(); | 2153 RenderViewHost* host = GetRenderViewHost(); |
| 2153 int id = StartDownload(host, url, is_favicon, max_bitmap_size); | 2154 int id = StartDownload(host, url, is_favicon, max_bitmap_size); |
| 2154 image_download_map_[id] = callback; | 2155 image_download_map_[id] = callback; |
| 2155 return id; | 2156 return id; |
| 2156 } | 2157 } |
| 2157 | 2158 |
| 2158 bool WebContentsImpl::FocusLocationBarByDefault() { | 2159 bool WebContentsImpl::FocusLocationBarByDefault() { |
| 2159 NavigationEntry* entry = controller_.GetActiveEntry(); | 2160 NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 2160 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) | 2161 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) |
| 2161 return true; | 2162 return true; |
| 2162 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); | 2163 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
| 2163 } | 2164 } |
| 2164 | 2165 |
| 2165 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { | 2166 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
| 2166 if (delegate_) | 2167 if (delegate_) |
| 2167 delegate_->SetFocusToLocationBar(select_all); | 2168 delegate_->SetFocusToLocationBar(select_all); |
| 2168 } | 2169 } |
| 2169 | 2170 |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2909 NotificationService::current()->Notify( | 2910 NotificationService::current()->Notify( |
| 2910 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2911 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 2911 Source<WebContents>(this), | 2912 Source<WebContents>(this), |
| 2912 Details<RenderViewHost>(render_view_host)); | 2913 Details<RenderViewHost>(render_view_host)); |
| 2913 | 2914 |
| 2914 // When we're creating views, we're still doing initial setup, so we always | 2915 // When we're creating views, we're still doing initial setup, so we always |
| 2915 // use the pending Web UI rather than any possibly existing committed one. | 2916 // use the pending Web UI rather than any possibly existing committed one. |
| 2916 if (render_manager_.pending_web_ui()) | 2917 if (render_manager_.pending_web_ui()) |
| 2917 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 2918 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
| 2918 | 2919 |
| 2919 NavigationEntry* entry = controller_.GetActiveEntry(); | 2920 NavigationEntry* entry = controller_.GetPendingEntry(); |
| 2920 if (entry && entry->IsViewSourceMode()) { | 2921 if (entry && entry->IsViewSourceMode()) { |
| 2921 // Put the renderer in view source mode. | 2922 // Put the renderer in view source mode. |
| 2922 render_view_host->Send( | 2923 render_view_host->Send( |
| 2923 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 2924 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
| 2924 } | 2925 } |
| 2925 | 2926 |
| 2926 view_->RenderViewCreated(render_view_host); | 2927 view_->RenderViewCreated(render_view_host); |
| 2927 | 2928 |
| 2928 FOR_EACH_OBSERVER( | 2929 FOR_EACH_OBSERVER( |
| 2929 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 2930 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3066 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 3067 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 3067 // that is not recorded in the navigation history. For the purpose of | 3068 // that is not recorded in the navigation history. For the purpose of |
| 3068 // tracking navigation events, we treat this event as a sub frame navigation | 3069 // tracking navigation events, we treat this event as a sub frame navigation |
| 3069 // event. | 3070 // event. |
| 3070 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 3071 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
| 3071 PageTransition transition_type = params.transition; | 3072 PageTransition transition_type = params.transition; |
| 3072 // Whether or not a page transition was triggered by going backward or | 3073 // Whether or not a page transition was triggered by going backward or |
| 3073 // forward in the history is only stored in the navigation controller's | 3074 // forward in the history is only stored in the navigation controller's |
| 3074 // entry list. | 3075 // entry list. |
| 3075 if (did_navigate && | 3076 if (did_navigate && |
| 3076 (controller_.GetActiveEntry()->GetTransitionType() & | 3077 (controller_.GetLastCommittedEntry()->GetTransitionType() & |
| 3077 PAGE_TRANSITION_FORWARD_BACK)) { | 3078 PAGE_TRANSITION_FORWARD_BACK)) { |
| 3078 transition_type = PageTransitionFromInt( | 3079 transition_type = PageTransitionFromInt( |
| 3079 params.transition | PAGE_TRANSITION_FORWARD_BACK); | 3080 params.transition | PAGE_TRANSITION_FORWARD_BACK); |
| 3080 } | 3081 } |
| 3081 // Notify observers about the commit of the provisional load. | 3082 // Notify observers about the commit of the provisional load. |
| 3082 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3083 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3083 DidCommitProvisionalLoadForFrame(params.frame_id, | 3084 DidCommitProvisionalLoadForFrame(params.frame_id, |
| 3084 is_main_frame, params.url, transition_type, rvh)); | 3085 is_main_frame, params.url, transition_type, rvh)); |
| 3085 } | 3086 } |
| 3086 | 3087 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 real URL, rather than the |
| 3504 // display URL. | 3505 // display URL. |
|
Charlie Reis
2013/10/08 20:23:28
I think this comment is still worth updating becau
nasko
2013/10/08 21:45:54
Done.
| |
| 3505 GURL url = controller_.GetActiveEntry() | 3506 GURL url = controller_.GetActiveEntry() |
| 3506 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); | 3507 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); |
| 3507 return GetWebkitPrefs(GetRenderViewHost(), url); | 3508 return GetWebkitPrefs(GetRenderViewHost(), url); |
| 3508 } | 3509 } |
| 3509 | 3510 |
| 3510 int WebContentsImpl::CreateSwappedOutRenderView( | 3511 int WebContentsImpl::CreateSwappedOutRenderView( |
| 3511 SiteInstance* instance) { | 3512 SiteInstance* instance) { |
| 3512 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, | 3513 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, |
| 3513 true, true); | 3514 true, true); |
| 3514 } | 3515 } |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3817 } | 3818 } |
| 3818 | 3819 |
| 3819 void WebContentsImpl::OnFrameRemoved( | 3820 void WebContentsImpl::OnFrameRemoved( |
| 3820 RenderViewHostImpl* render_view_host, | 3821 RenderViewHostImpl* render_view_host, |
| 3821 int64 frame_id) { | 3822 int64 frame_id) { |
| 3822 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3823 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3823 FrameDetached(render_view_host, frame_id)); | 3824 FrameDetached(render_view_host, frame_id)); |
| 3824 } | 3825 } |
| 3825 | 3826 |
| 3826 } // namespace content | 3827 } // namespace content |
| OLD | NEW |