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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 | 867 |
868 renderer_preferences_.user_agent_override = override; | 868 renderer_preferences_.user_agent_override = override; |
869 | 869 |
870 // Send the new override string to the renderer. | 870 // Send the new override string to the renderer. |
871 RenderViewHost* host = GetRenderViewHost(); | 871 RenderViewHost* host = GetRenderViewHost(); |
872 if (host) | 872 if (host) |
873 host->SyncRendererPrefs(); | 873 host->SyncRendererPrefs(); |
874 | 874 |
875 // Reload the page if a load is currently in progress to avoid having | 875 // Reload the page if a load is currently in progress to avoid having |
876 // different parts of the page loaded using different user agents. | 876 // different parts of the page loaded using different user agents. |
877 NavigationEntry* entry = controller_.GetActiveEntry(); | 877 NavigationEntry* entry = controller_.GetVisibleEntry(); |
878 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) | 878 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) |
879 controller_.ReloadIgnoringCache(true); | 879 controller_.ReloadIgnoringCache(true); |
880 | 880 |
881 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 881 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
882 UserAgentOverrideSet(override)); | 882 UserAgentOverrideSet(override)); |
883 } | 883 } |
884 | 884 |
885 const std::string& WebContentsImpl::GetUserAgentOverride() const { | 885 const std::string& WebContentsImpl::GetUserAgentOverride() const { |
886 return renderer_preferences_.user_agent_override; | 886 return renderer_preferences_.user_agent_override; |
887 } | 887 } |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1905 if (!GetURL().is_valid()) | 1905 if (!GetURL().is_valid()) |
1906 return; | 1906 return; |
1907 bool is_main_frame = (url == GetURL()); | 1907 bool is_main_frame = (url == GetURL()); |
1908 | 1908 |
1909 DownloadManager* dlm = | 1909 DownloadManager* dlm = |
1910 BrowserContext::GetDownloadManager(GetBrowserContext()); | 1910 BrowserContext::GetDownloadManager(GetBrowserContext()); |
1911 if (!dlm) | 1911 if (!dlm) |
1912 return; | 1912 return; |
1913 int64 post_id = -1; | 1913 int64 post_id = -1; |
1914 if (is_main_frame) { | 1914 if (is_main_frame) { |
1915 const NavigationEntry* entry = controller_.GetActiveEntry(); | 1915 const NavigationEntry* entry = controller_.GetVisibleEntry(); |
Charlie Reis
2013/08/16 22:10:14
I have similar concerns here as with the SavePacka
nasko
2013/09/12 17:56:31
Done.
| |
1916 if (entry) | 1916 if (entry) |
1917 post_id = entry->GetPostID(); | 1917 post_id = entry->GetPostID(); |
1918 } | 1918 } |
1919 scoped_ptr<DownloadUrlParameters> params( | 1919 scoped_ptr<DownloadUrlParameters> params( |
1920 DownloadUrlParameters::FromWebContents(this, url)); | 1920 DownloadUrlParameters::FromWebContents(this, url)); |
1921 params->set_referrer(referrer); | 1921 params->set_referrer(referrer); |
1922 params->set_post_id(post_id); | 1922 params->set_post_id(post_id); |
1923 params->set_prefer_cache(true); | 1923 params->set_prefer_cache(true); |
1924 if (post_id >= 0) | 1924 if (post_id >= 0) |
1925 params->set_method("POST"); | 1925 params->set_method("POST"); |
1926 params->set_prompt(true); | 1926 params->set_prompt(true); |
1927 dlm->DownloadUrl(params.Pass()); | 1927 dlm->DownloadUrl(params.Pass()); |
1928 } | 1928 } |
1929 | 1929 |
1930 void WebContentsImpl::GenerateMHTML( | 1930 void WebContentsImpl::GenerateMHTML( |
1931 const base::FilePath& file, | 1931 const base::FilePath& file, |
1932 const base::Callback<void(const base::FilePath&, int64)>& callback) { | 1932 const base::Callback<void(const base::FilePath&, int64)>& callback) { |
1933 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback); | 1933 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback); |
1934 } | 1934 } |
1935 | 1935 |
1936 bool WebContentsImpl::IsActiveEntry(int32 page_id) { | 1936 bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
Charlie Reis
2013/08/16 22:10:14
We should at least have a TODO to change this to I
nasko
2013/09/12 17:56:31
Done.
| |
1937 NavigationEntryImpl* active_entry = | 1937 NavigationEntryImpl* active_entry = |
1938 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); | 1938 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry()); |
1939 return (active_entry != NULL && | 1939 return (active_entry != NULL && |
1940 active_entry->site_instance() == GetSiteInstance() && | 1940 active_entry->site_instance() == GetSiteInstance() && |
1941 active_entry->GetPageID() == page_id); | 1941 active_entry->GetPageID() == page_id); |
1942 } | 1942 } |
1943 | 1943 |
1944 const std::string& WebContentsImpl::GetContentsMimeType() const { | 1944 const std::string& WebContentsImpl::GetContentsMimeType() const { |
1945 return contents_mime_type_; | 1945 return contents_mime_type_; |
1946 } | 1946 } |
1947 | 1947 |
1948 bool WebContentsImpl::WillNotifyDisconnection() const { | 1948 bool WebContentsImpl::WillNotifyDisconnection() const { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2013 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | 2013 HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
2014 if (!zoom_map) | 2014 if (!zoom_map) |
2015 return 0; | 2015 return 0; |
2016 | 2016 |
2017 double zoom_level; | 2017 double zoom_level; |
2018 if (temporary_zoom_settings_) { | 2018 if (temporary_zoom_settings_) { |
2019 zoom_level = zoom_map->GetTemporaryZoomLevel( | 2019 zoom_level = zoom_map->GetTemporaryZoomLevel( |
2020 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | 2020 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
2021 } else { | 2021 } else { |
2022 GURL url; | 2022 GURL url; |
2023 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2023 NavigationEntry* active_entry = GetController().GetVisibleEntry(); |
Charlie Reis
2013/08/16 22:10:14
nit: visible_entry
Actually, this is broken. It'
nasko
2013/09/12 17:56:31
Done.
| |
2024 // Since zoom map is updated using rewritten URL, use rewritten URL | 2024 // Since zoom map is updated using rewritten URL, use rewritten URL |
2025 // to get the zoom level. | 2025 // to get the zoom level. |
2026 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); | 2026 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); |
2027 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | 2027 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), |
2028 net::GetHostOrSpecFromURL(url)); | 2028 net::GetHostOrSpecFromURL(url)); |
2029 } | 2029 } |
2030 return zoom_level; | 2030 return zoom_level; |
2031 } | 2031 } |
2032 | 2032 |
2033 int WebContentsImpl::GetZoomPercent(bool* enable_increment, | 2033 int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
2034 bool* enable_decrement) const { | 2034 bool* enable_decrement) const { |
2035 *enable_decrement = *enable_increment = false; | 2035 *enable_decrement = *enable_increment = false; |
2036 // Calculate the zoom percent from the factor. Round up to the nearest whole | 2036 // Calculate the zoom percent from the factor. Round up to the nearest whole |
2037 // number. | 2037 // number. |
2038 int percent = static_cast<int>( | 2038 int percent = static_cast<int>( |
2039 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); | 2039 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
2040 *enable_decrement = percent > minimum_zoom_percent_; | 2040 *enable_decrement = percent > minimum_zoom_percent_; |
2041 *enable_increment = percent < maximum_zoom_percent_; | 2041 *enable_increment = percent < maximum_zoom_percent_; |
2042 return percent; | 2042 return percent; |
2043 } | 2043 } |
2044 | 2044 |
2045 void WebContentsImpl::ViewSource() { | 2045 void WebContentsImpl::ViewSource() { |
2046 if (!delegate_) | 2046 if (!delegate_) |
2047 return; | 2047 return; |
2048 | 2048 |
2049 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2049 NavigationEntry* active_entry = GetController().GetVisibleEntry(); |
Charlie Reis
2013/08/16 22:10:14
nit: visible_entry
Is this correct? I'm seeing a
nasko
2013/09/12 17:56:31
The URL passed in isn't used. Eventually down the
| |
2050 if (!active_entry) | 2050 if (!active_entry) |
2051 return; | 2051 return; |
2052 | 2052 |
2053 delegate_->ViewSourceForTab(this, active_entry->GetURL()); | 2053 delegate_->ViewSourceForTab(this, active_entry->GetURL()); |
2054 } | 2054 } |
2055 | 2055 |
2056 void WebContentsImpl::ViewFrameSource(const GURL& url, | 2056 void WebContentsImpl::ViewFrameSource(const GURL& url, |
2057 const PageState& page_state) { | 2057 const PageState& page_state) { |
2058 if (!delegate_) | 2058 if (!delegate_) |
2059 return; | 2059 return; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2100 uint32_t max_image_size, | 2100 uint32_t max_image_size, |
2101 const ImageDownloadCallback& callback) { | 2101 const ImageDownloadCallback& callback) { |
2102 RenderViewHost* host = GetRenderViewHost(); | 2102 RenderViewHost* host = GetRenderViewHost(); |
2103 int id = StartDownload( | 2103 int id = StartDownload( |
2104 host, url, is_favicon, preferred_image_size, max_image_size); | 2104 host, url, is_favicon, preferred_image_size, max_image_size); |
2105 image_download_map_[id] = callback; | 2105 image_download_map_[id] = callback; |
2106 return id; | 2106 return id; |
2107 } | 2107 } |
2108 | 2108 |
2109 bool WebContentsImpl::FocusLocationBarByDefault() { | 2109 bool WebContentsImpl::FocusLocationBarByDefault() { |
2110 NavigationEntry* entry = controller_.GetActiveEntry(); | 2110 NavigationEntry* entry = controller_.GetVisibleEntry(); |
2111 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) | 2111 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) |
2112 return true; | 2112 return true; |
2113 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); | 2113 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
2114 } | 2114 } |
2115 | 2115 |
2116 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { | 2116 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
2117 if (delegate_) | 2117 if (delegate_) |
2118 delegate_->SetFocusToLocationBar(select_all); | 2118 delegate_->SetFocusToLocationBar(select_all); |
2119 } | 2119 } |
2120 | 2120 |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2856 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2856 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2857 return; | 2857 return; |
2858 | 2858 |
2859 if (delegate_) | 2859 if (delegate_) |
2860 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); | 2860 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); |
2861 | 2861 |
2862 NotificationService::current()->Notify( | 2862 NotificationService::current()->Notify( |
2863 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2863 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2864 Source<WebContents>(this), | 2864 Source<WebContents>(this), |
2865 Details<RenderViewHost>(render_view_host)); | 2865 Details<RenderViewHost>(render_view_host)); |
2866 NavigationEntry* entry = controller_.GetActiveEntry(); | 2866 NavigationEntry* entry = controller_.GetVisibleEntry(); |
Charlie Reis
2013/08/16 22:10:14
Is this buggy? Depends on whether render_view_hos
nasko
2013/09/12 17:56:31
I'm not sure I follow your comment, but the code h
| |
2867 if (!entry) | 2867 if (!entry) |
2868 return; | 2868 return; |
2869 | 2869 |
2870 // When we're creating views, we're still doing initial setup, so we always | 2870 // When we're creating views, we're still doing initial setup, so we always |
2871 // use the pending Web UI rather than any possibly existing committed one. | 2871 // use the pending Web UI rather than any possibly existing committed one. |
2872 if (render_manager_.pending_web_ui()) | 2872 if (render_manager_.pending_web_ui()) |
2873 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 2873 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
2874 | 2874 |
2875 if (entry->IsViewSourceMode()) { | 2875 if (entry->IsViewSourceMode()) { |
2876 // Put the renderer in view source mode. | 2876 // Put the renderer in view source mode. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2995 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 2995 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
2996 // that is not recorded in the navigation history. For the purpose of | 2996 // that is not recorded in the navigation history. For the purpose of |
2997 // tracking navigation events, we treat this event as a sub frame navigation | 2997 // tracking navigation events, we treat this event as a sub frame navigation |
2998 // event. | 2998 // event. |
2999 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 2999 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
3000 PageTransition transition_type = params.transition; | 3000 PageTransition transition_type = params.transition; |
3001 // Whether or not a page transition was triggered by going backward or | 3001 // Whether or not a page transition was triggered by going backward or |
3002 // forward in the history is only stored in the navigation controller's | 3002 // forward in the history is only stored in the navigation controller's |
3003 // entry list. | 3003 // entry list. |
3004 if (did_navigate && | 3004 if (did_navigate && |
3005 (controller_.GetActiveEntry()->GetTransitionType() & | 3005 (controller_.GetVisibleEntry()->GetTransitionType() & |
Charlie Reis
2013/08/16 22:10:14
Can this ever be different from GetLastCommittedEn
nasko
2013/09/12 17:56:31
I think you are right and it can't be different if
| |
3006 PAGE_TRANSITION_FORWARD_BACK)) { | 3006 PAGE_TRANSITION_FORWARD_BACK)) { |
3007 transition_type = PageTransitionFromInt( | 3007 transition_type = PageTransitionFromInt( |
3008 params.transition | PAGE_TRANSITION_FORWARD_BACK); | 3008 params.transition | PAGE_TRANSITION_FORWARD_BACK); |
3009 } | 3009 } |
3010 // Notify observers about the commit of the provisional load. | 3010 // Notify observers about the commit of the provisional load. |
3011 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3011 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3012 DidCommitProvisionalLoadForFrame(params.frame_id, | 3012 DidCommitProvisionalLoadForFrame(params.frame_id, |
3013 is_main_frame, params.url, transition_type, rvh)); | 3013 is_main_frame, params.url, transition_type, rvh)); |
3014 } | 3014 } |
3015 | 3015 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3418 const string16& source_id) { | 3418 const string16& source_id) { |
3419 if (!delegate_) | 3419 if (!delegate_) |
3420 return false; | 3420 return false; |
3421 return delegate_->AddMessageToConsole(this, level, message, line_no, | 3421 return delegate_->AddMessageToConsole(this, level, message, line_no, |
3422 source_id); | 3422 source_id); |
3423 } | 3423 } |
3424 | 3424 |
3425 WebPreferences WebContentsImpl::GetWebkitPrefs() { | 3425 WebPreferences WebContentsImpl::GetWebkitPrefs() { |
3426 // We want to base the page config off of the real URL, rather than the | 3426 // We want to base the page config off of the real URL, rather than the |
3427 // display URL. | 3427 // display URL. |
3428 GURL url = controller_.GetActiveEntry() | 3428 GURL url = controller_.GetVisibleEntry() |
Charlie Reis
2013/08/16 22:10:14
This looks buggy, since GetVisibleEntry does not m
nasko
2013/09/12 17:56:31
Done.
| |
3429 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); | 3429 ? controller_.GetVisibleEntry()->GetURL() : GURL::EmptyGURL(); |
3430 return GetWebkitPrefs(GetRenderViewHost(), url); | 3430 return GetWebkitPrefs(GetRenderViewHost(), url); |
3431 } | 3431 } |
3432 | 3432 |
3433 int WebContentsImpl::CreateSwappedOutRenderView( | 3433 int WebContentsImpl::CreateSwappedOutRenderView( |
3434 SiteInstance* instance) { | 3434 SiteInstance* instance) { |
3435 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true); | 3435 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true); |
3436 } | 3436 } |
3437 | 3437 |
3438 void WebContentsImpl::OnUserGesture() { | 3438 void WebContentsImpl::OnUserGesture() { |
3439 // Notify observers. | 3439 // Notify observers. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3721 } | 3721 } |
3722 | 3722 |
3723 void WebContentsImpl::ClearAllPowerSaveBlockers() { | 3723 void WebContentsImpl::ClearAllPowerSaveBlockers() { |
3724 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin()); | 3724 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin()); |
3725 i != power_save_blockers_.end(); ++i) | 3725 i != power_save_blockers_.end(); ++i) |
3726 STLDeleteValues(&power_save_blockers_[i->first]); | 3726 STLDeleteValues(&power_save_blockers_[i->first]); |
3727 power_save_blockers_.clear(); | 3727 power_save_blockers_.clear(); |
3728 } | 3728 } |
3729 | 3729 |
3730 } // namespace content | 3730 } // namespace content |
OLD | NEW |