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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 | 879 |
880 renderer_preferences_.user_agent_override = override; | 880 renderer_preferences_.user_agent_override = override; |
881 | 881 |
882 // Send the new override string to the renderer. | 882 // Send the new override string to the renderer. |
883 RenderViewHost* host = GetRenderViewHost(); | 883 RenderViewHost* host = GetRenderViewHost(); |
884 if (host) | 884 if (host) |
885 host->SyncRendererPrefs(); | 885 host->SyncRendererPrefs(); |
886 | 886 |
887 // Reload the page if a load is currently in progress to avoid having | 887 // Reload the page if a load is currently in progress to avoid having |
888 // different parts of the page loaded using different user agents. | 888 // different parts of the page loaded using different user agents. |
889 NavigationEntry* entry = controller_.GetActiveEntry(); | 889 NavigationEntry* entry = controller_.GetVisibleEntry(); |
890 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) | 890 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) |
891 controller_.ReloadIgnoringCache(true); | 891 controller_.ReloadIgnoringCache(true); |
892 | 892 |
893 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 893 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
894 UserAgentOverrideSet(override)); | 894 UserAgentOverrideSet(override)); |
895 } | 895 } |
896 | 896 |
897 const std::string& WebContentsImpl::GetUserAgentOverride() const { | 897 const std::string& WebContentsImpl::GetUserAgentOverride() const { |
898 return renderer_preferences_.user_agent_override; | 898 return renderer_preferences_.user_agent_override; |
899 } | 899 } |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1920 if (!GetURL().is_valid()) | 1920 if (!GetURL().is_valid()) |
1921 return; | 1921 return; |
1922 bool is_main_frame = (url == GetURL()); | 1922 bool is_main_frame = (url == GetURL()); |
1923 | 1923 |
1924 DownloadManager* dlm = | 1924 DownloadManager* dlm = |
1925 BrowserContext::GetDownloadManager(GetBrowserContext()); | 1925 BrowserContext::GetDownloadManager(GetBrowserContext()); |
1926 if (!dlm) | 1926 if (!dlm) |
1927 return; | 1927 return; |
1928 int64 post_id = -1; | 1928 int64 post_id = -1; |
1929 if (is_main_frame) { | 1929 if (is_main_frame) { |
1930 const NavigationEntry* entry = controller_.GetActiveEntry(); | 1930 const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
1931 if (entry) | 1931 if (entry) |
1932 post_id = entry->GetPostID(); | 1932 post_id = entry->GetPostID(); |
1933 } | 1933 } |
1934 scoped_ptr<DownloadUrlParameters> params( | 1934 scoped_ptr<DownloadUrlParameters> params( |
1935 DownloadUrlParameters::FromWebContents(this, url)); | 1935 DownloadUrlParameters::FromWebContents(this, url)); |
1936 params->set_referrer(referrer); | 1936 params->set_referrer(referrer); |
1937 params->set_post_id(post_id); | 1937 params->set_post_id(post_id); |
1938 params->set_prefer_cache(true); | 1938 params->set_prefer_cache(true); |
1939 if (post_id >= 0) | 1939 if (post_id >= 0) |
1940 params->set_method("POST"); | 1940 params->set_method("POST"); |
1941 params->set_prompt(true); | 1941 params->set_prompt(true); |
1942 dlm->DownloadUrl(params.Pass()); | 1942 dlm->DownloadUrl(params.Pass()); |
1943 } | 1943 } |
1944 | 1944 |
1945 void WebContentsImpl::GenerateMHTML( | 1945 void WebContentsImpl::GenerateMHTML( |
1946 const base::FilePath& file, | 1946 const base::FilePath& file, |
1947 const base::Callback<void(int64)>& callback) { | 1947 const base::Callback<void(int64)>& callback) { |
1948 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); | 1948 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); |
1949 } | 1949 } |
1950 | 1950 |
1951 // TODO(nasko): Rename this method to IsVisibleEntry. | |
1951 bool WebContentsImpl::IsActiveEntry(int32 page_id) { | 1952 bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
1952 NavigationEntryImpl* active_entry = | 1953 NavigationEntryImpl* visible_entry = |
1953 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); | 1954 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry()); |
1954 return (active_entry != NULL && | 1955 return (visible_entry != NULL && |
1955 active_entry->site_instance() == GetSiteInstance() && | 1956 visible_entry->site_instance() == GetSiteInstance() && |
1956 active_entry->GetPageID() == page_id); | 1957 visible_entry->GetPageID() == page_id); |
1957 } | 1958 } |
1958 | 1959 |
1959 const std::string& WebContentsImpl::GetContentsMimeType() const { | 1960 const std::string& WebContentsImpl::GetContentsMimeType() const { |
1960 return contents_mime_type_; | 1961 return contents_mime_type_; |
1961 } | 1962 } |
1962 | 1963 |
1963 bool WebContentsImpl::WillNotifyDisconnection() const { | 1964 bool WebContentsImpl::WillNotifyDisconnection() const { |
1964 return notify_disconnection_; | 1965 return notify_disconnection_; |
1965 } | 1966 } |
1966 | 1967 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2028 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | 2029 HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
2029 if (!zoom_map) | 2030 if (!zoom_map) |
2030 return 0; | 2031 return 0; |
2031 | 2032 |
2032 double zoom_level; | 2033 double zoom_level; |
2033 if (temporary_zoom_settings_) { | 2034 if (temporary_zoom_settings_) { |
2034 zoom_level = zoom_map->GetTemporaryZoomLevel( | 2035 zoom_level = zoom_map->GetTemporaryZoomLevel( |
2035 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | 2036 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
2036 } else { | 2037 } else { |
2037 GURL url; | 2038 GURL url; |
2038 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2039 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
2039 // Since zoom map is updated using rewritten URL, use rewritten URL | 2040 // Since zoom map is updated using rewritten URL, use rewritten URL |
2040 // to get the zoom level. | 2041 // to get the zoom level. |
2041 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); | 2042 url = entry ? entry->GetURL() : GURL::EmptyGURL(); |
2042 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | 2043 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), |
2043 net::GetHostOrSpecFromURL(url)); | 2044 net::GetHostOrSpecFromURL(url)); |
2044 } | 2045 } |
2045 return zoom_level; | 2046 return zoom_level; |
2046 } | 2047 } |
2047 | 2048 |
2048 int WebContentsImpl::GetZoomPercent(bool* enable_increment, | 2049 int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
2049 bool* enable_decrement) const { | 2050 bool* enable_decrement) const { |
2050 *enable_decrement = *enable_increment = false; | 2051 *enable_decrement = *enable_increment = false; |
2051 // Calculate the zoom percent from the factor. Round up to the nearest whole | 2052 // Calculate the zoom percent from the factor. Round up to the nearest whole |
2052 // number. | 2053 // number. |
2053 int percent = static_cast<int>( | 2054 int percent = static_cast<int>( |
2054 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); | 2055 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
2055 *enable_decrement = percent > minimum_zoom_percent_; | 2056 *enable_decrement = percent > minimum_zoom_percent_; |
2056 *enable_increment = percent < maximum_zoom_percent_; | 2057 *enable_increment = percent < maximum_zoom_percent_; |
2057 return percent; | 2058 return percent; |
2058 } | 2059 } |
2059 | 2060 |
2060 void WebContentsImpl::ViewSource() { | 2061 void WebContentsImpl::ViewSource() { |
2061 if (!delegate_) | 2062 if (!delegate_) |
2062 return; | 2063 return; |
2063 | 2064 |
2064 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2065 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
2065 if (!active_entry) | 2066 if (!entry) |
2066 return; | 2067 return; |
2067 | 2068 |
2068 delegate_->ViewSourceForTab(this, active_entry->GetURL()); | 2069 delegate_->ViewSourceForTab(this, entry->GetURL()); |
2069 } | 2070 } |
2070 | 2071 |
2071 void WebContentsImpl::ViewFrameSource(const GURL& url, | 2072 void WebContentsImpl::ViewFrameSource(const GURL& url, |
2072 const PageState& page_state) { | 2073 const PageState& page_state) { |
2073 if (!delegate_) | 2074 if (!delegate_) |
2074 return; | 2075 return; |
2075 | 2076 |
2076 delegate_->ViewSourceForFrame(this, url, page_state); | 2077 delegate_->ViewSourceForFrame(this, url, page_state); |
2077 } | 2078 } |
2078 | 2079 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2115 uint32_t max_image_size, | 2116 uint32_t max_image_size, |
2116 const ImageDownloadCallback& callback) { | 2117 const ImageDownloadCallback& callback) { |
2117 RenderViewHost* host = GetRenderViewHost(); | 2118 RenderViewHost* host = GetRenderViewHost(); |
2118 int id = StartDownload( | 2119 int id = StartDownload( |
2119 host, url, is_favicon, preferred_image_size, max_image_size); | 2120 host, url, is_favicon, preferred_image_size, max_image_size); |
2120 image_download_map_[id] = callback; | 2121 image_download_map_[id] = callback; |
2121 return id; | 2122 return id; |
2122 } | 2123 } |
2123 | 2124 |
2124 bool WebContentsImpl::FocusLocationBarByDefault() { | 2125 bool WebContentsImpl::FocusLocationBarByDefault() { |
2125 NavigationEntry* entry = controller_.GetActiveEntry(); | 2126 NavigationEntry* entry = controller_.GetVisibleEntry(); |
2126 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) | 2127 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) |
2127 return true; | 2128 return true; |
2128 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); | 2129 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
2129 } | 2130 } |
2130 | 2131 |
2131 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { | 2132 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
2132 if (delegate_) | 2133 if (delegate_) |
2133 delegate_->SetFocusToLocationBar(select_all); | 2134 delegate_->SetFocusToLocationBar(select_all); |
2134 } | 2135 } |
2135 | 2136 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2912 NotificationService::current()->Notify( | 2913 NotificationService::current()->Notify( |
2913 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2914 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2914 Source<WebContents>(this), | 2915 Source<WebContents>(this), |
2915 Details<RenderViewHost>(render_view_host)); | 2916 Details<RenderViewHost>(render_view_host)); |
2916 | 2917 |
2917 // When we're creating views, we're still doing initial setup, so we always | 2918 // When we're creating views, we're still doing initial setup, so we always |
2918 // use the pending Web UI rather than any possibly existing committed one. | 2919 // use the pending Web UI rather than any possibly existing committed one. |
2919 if (render_manager_.pending_web_ui()) | 2920 if (render_manager_.pending_web_ui()) |
2920 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 2921 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
2921 | 2922 |
2922 NavigationEntry* entry = controller_.GetActiveEntry(); | 2923 NavigationEntry* entry = controller_.GetPendingEntry(); |
Charlie Reis
2013/09/16 23:10:54
Your reply said you were changing this to LastComm
nasko
2013/09/18 17:03:18
I did change it to LastCommitted, but that broke t
| |
2923 if (entry && entry->IsViewSourceMode()) { | 2924 if (entry && entry->IsViewSourceMode()) { |
2924 // Put the renderer in view source mode. | 2925 // Put the renderer in view source mode. |
2925 render_view_host->Send( | 2926 render_view_host->Send( |
2926 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 2927 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
2927 } | 2928 } |
2928 | 2929 |
2929 view_->RenderViewCreated(render_view_host); | 2930 view_->RenderViewCreated(render_view_host); |
2930 | 2931 |
2931 FOR_EACH_OBSERVER( | 2932 FOR_EACH_OBSERVER( |
2932 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 2933 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3077 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 3078 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
3078 // that is not recorded in the navigation history. For the purpose of | 3079 // that is not recorded in the navigation history. For the purpose of |
3079 // tracking navigation events, we treat this event as a sub frame navigation | 3080 // tracking navigation events, we treat this event as a sub frame navigation |
3080 // event. | 3081 // event. |
3081 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 3082 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
3082 PageTransition transition_type = params.transition; | 3083 PageTransition transition_type = params.transition; |
3083 // Whether or not a page transition was triggered by going backward or | 3084 // Whether or not a page transition was triggered by going backward or |
3084 // forward in the history is only stored in the navigation controller's | 3085 // forward in the history is only stored in the navigation controller's |
3085 // entry list. | 3086 // entry list. |
3086 if (did_navigate && | 3087 if (did_navigate && |
3087 (controller_.GetActiveEntry()->GetTransitionType() & | 3088 (controller_.GetLastCommittedEntry()->GetTransitionType() & |
3088 PAGE_TRANSITION_FORWARD_BACK)) { | 3089 PAGE_TRANSITION_FORWARD_BACK)) { |
3089 transition_type = PageTransitionFromInt( | 3090 transition_type = PageTransitionFromInt( |
3090 params.transition | PAGE_TRANSITION_FORWARD_BACK); | 3091 params.transition | PAGE_TRANSITION_FORWARD_BACK); |
3091 } | 3092 } |
3092 // Notify observers about the commit of the provisional load. | 3093 // Notify observers about the commit of the provisional load. |
3093 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3094 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3094 DidCommitProvisionalLoadForFrame(params.frame_id, | 3095 DidCommitProvisionalLoadForFrame(params.frame_id, |
3095 is_main_frame, params.url, transition_type, rvh)); | 3096 is_main_frame, params.url, transition_type, rvh)); |
3096 } | 3097 } |
3097 | 3098 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3508 const string16& source_id) { | 3509 const string16& source_id) { |
3509 if (!delegate_) | 3510 if (!delegate_) |
3510 return false; | 3511 return false; |
3511 return delegate_->AddMessageToConsole(this, level, message, line_no, | 3512 return delegate_->AddMessageToConsole(this, level, message, line_no, |
3512 source_id); | 3513 source_id); |
3513 } | 3514 } |
3514 | 3515 |
3515 WebPreferences WebContentsImpl::GetWebkitPrefs() { | 3516 WebPreferences WebContentsImpl::GetWebkitPrefs() { |
3516 // We want to base the page config off of the real URL, rather than the | 3517 // We want to base the page config off of the real URL, rather than the |
3517 // display URL. | 3518 // display URL. |
3518 GURL url = controller_.GetActiveEntry() | 3519 GURL url = controller_.GetLastCommittedEntry() |
3519 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); | 3520 ? controller_.GetLastCommittedEntry()->GetURL() : GURL::EmptyGURL(); |
3520 return GetWebkitPrefs(GetRenderViewHost(), url); | 3521 return GetWebkitPrefs(GetRenderViewHost(), url); |
3521 } | 3522 } |
3522 | 3523 |
3523 int WebContentsImpl::CreateSwappedOutRenderView( | 3524 int WebContentsImpl::CreateSwappedOutRenderView( |
3524 SiteInstance* instance) { | 3525 SiteInstance* instance) { |
3525 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, | 3526 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, |
3526 true, true); | 3527 true, true); |
3527 } | 3528 } |
3528 | 3529 |
3529 void WebContentsImpl::OnUserGesture() { | 3530 void WebContentsImpl::OnUserGesture() { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3833 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { | 3834 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { |
3834 gfx::Size size; | 3835 gfx::Size size; |
3835 if (delegate_) | 3836 if (delegate_) |
3836 size = delegate_->GetSizeForNewRenderView(this); | 3837 size = delegate_->GetSizeForNewRenderView(this); |
3837 if (size.IsEmpty()) | 3838 if (size.IsEmpty()) |
3838 size = view_->GetContainerSize(); | 3839 size = view_->GetContainerSize(); |
3839 return size; | 3840 return size; |
3840 } | 3841 } |
3841 | 3842 |
3842 } // namespace content | 3843 } // namespace content |
OLD | NEW |