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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 | 887 |
888 renderer_preferences_.user_agent_override = override; | 888 renderer_preferences_.user_agent_override = override; |
889 | 889 |
890 // Send the new override string to the renderer. | 890 // Send the new override string to the renderer. |
891 RenderViewHost* host = GetRenderViewHost(); | 891 RenderViewHost* host = GetRenderViewHost(); |
892 if (host) | 892 if (host) |
893 host->SyncRendererPrefs(); | 893 host->SyncRendererPrefs(); |
894 | 894 |
895 // Reload the page if a load is currently in progress to avoid having | 895 // Reload the page if a load is currently in progress to avoid having |
896 // different parts of the page loaded using different user agents. | 896 // different parts of the page loaded using different user agents. |
897 NavigationEntry* entry = controller_.GetActiveEntry(); | 897 NavigationEntry* entry = controller_.GetVisibleEntry(); |
898 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) | 898 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) |
899 controller_.ReloadIgnoringCache(true); | 899 controller_.ReloadIgnoringCache(true); |
900 | 900 |
901 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 901 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
902 UserAgentOverrideSet(override)); | 902 UserAgentOverrideSet(override)); |
903 } | 903 } |
904 | 904 |
905 const std::string& WebContentsImpl::GetUserAgentOverride() const { | 905 const std::string& WebContentsImpl::GetUserAgentOverride() const { |
906 return renderer_preferences_.user_agent_override; | 906 return renderer_preferences_.user_agent_override; |
907 } | 907 } |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 if (!GetURL().is_valid()) | 1949 if (!GetURL().is_valid()) |
1950 return; | 1950 return; |
1951 bool is_main_frame = (url == GetURL()); | 1951 bool is_main_frame = (url == GetURL()); |
1952 | 1952 |
1953 DownloadManager* dlm = | 1953 DownloadManager* dlm = |
1954 BrowserContext::GetDownloadManager(GetBrowserContext()); | 1954 BrowserContext::GetDownloadManager(GetBrowserContext()); |
1955 if (!dlm) | 1955 if (!dlm) |
1956 return; | 1956 return; |
1957 int64 post_id = -1; | 1957 int64 post_id = -1; |
1958 if (is_main_frame) { | 1958 if (is_main_frame) { |
1959 const NavigationEntry* entry = controller_.GetActiveEntry(); | 1959 const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
1960 if (entry) | 1960 if (entry) |
1961 post_id = entry->GetPostID(); | 1961 post_id = entry->GetPostID(); |
1962 } | 1962 } |
1963 scoped_ptr<DownloadUrlParameters> params( | 1963 scoped_ptr<DownloadUrlParameters> params( |
1964 DownloadUrlParameters::FromWebContents(this, url)); | 1964 DownloadUrlParameters::FromWebContents(this, url)); |
1965 params->set_referrer(referrer); | 1965 params->set_referrer(referrer); |
1966 params->set_post_id(post_id); | 1966 params->set_post_id(post_id); |
1967 params->set_prefer_cache(true); | 1967 params->set_prefer_cache(true); |
1968 if (post_id >= 0) | 1968 if (post_id >= 0) |
1969 params->set_method("POST"); | 1969 params->set_method("POST"); |
1970 params->set_prompt(true); | 1970 params->set_prompt(true); |
1971 dlm->DownloadUrl(params.Pass()); | 1971 dlm->DownloadUrl(params.Pass()); |
1972 } | 1972 } |
1973 | 1973 |
1974 void WebContentsImpl::GenerateMHTML( | 1974 void WebContentsImpl::GenerateMHTML( |
1975 const base::FilePath& file, | 1975 const base::FilePath& file, |
1976 const base::Callback<void(int64)>& callback) { | 1976 const base::Callback<void(int64)>& callback) { |
1977 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); | 1977 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); |
1978 } | 1978 } |
1979 | 1979 |
| 1980 // TODO(nasko): Rename this method to IsVisibleEntry. |
1980 bool WebContentsImpl::IsActiveEntry(int32 page_id) { | 1981 bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
1981 NavigationEntryImpl* active_entry = | 1982 NavigationEntryImpl* visible_entry = |
1982 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); | 1983 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry()); |
1983 return (active_entry != NULL && | 1984 return (visible_entry != NULL && |
1984 active_entry->site_instance() == GetSiteInstance() && | 1985 visible_entry->site_instance() == GetSiteInstance() && |
1985 active_entry->GetPageID() == page_id); | 1986 visible_entry->GetPageID() == page_id); |
1986 } | 1987 } |
1987 | 1988 |
1988 const std::string& WebContentsImpl::GetContentsMimeType() const { | 1989 const std::string& WebContentsImpl::GetContentsMimeType() const { |
1989 return contents_mime_type_; | 1990 return contents_mime_type_; |
1990 } | 1991 } |
1991 | 1992 |
1992 bool WebContentsImpl::WillNotifyDisconnection() const { | 1993 bool WebContentsImpl::WillNotifyDisconnection() const { |
1993 return notify_disconnection_; | 1994 return notify_disconnection_; |
1994 } | 1995 } |
1995 | 1996 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | 2058 HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
2058 if (!zoom_map) | 2059 if (!zoom_map) |
2059 return 0; | 2060 return 0; |
2060 | 2061 |
2061 double zoom_level; | 2062 double zoom_level; |
2062 if (temporary_zoom_settings_) { | 2063 if (temporary_zoom_settings_) { |
2063 zoom_level = zoom_map->GetTemporaryZoomLevel( | 2064 zoom_level = zoom_map->GetTemporaryZoomLevel( |
2064 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | 2065 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
2065 } else { | 2066 } else { |
2066 GURL url; | 2067 GURL url; |
2067 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2068 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
2068 // Since zoom map is updated using rewritten URL, use rewritten URL | 2069 // Since zoom map is updated using rewritten URL, use rewritten URL |
2069 // to get the zoom level. | 2070 // to get the zoom level. |
2070 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); | 2071 url = entry ? entry->GetURL() : GURL::EmptyGURL(); |
2071 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | 2072 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), |
2072 net::GetHostOrSpecFromURL(url)); | 2073 net::GetHostOrSpecFromURL(url)); |
2073 } | 2074 } |
2074 return zoom_level; | 2075 return zoom_level; |
2075 } | 2076 } |
2076 | 2077 |
2077 int WebContentsImpl::GetZoomPercent(bool* enable_increment, | 2078 int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
2078 bool* enable_decrement) const { | 2079 bool* enable_decrement) const { |
2079 *enable_decrement = *enable_increment = false; | 2080 *enable_decrement = *enable_increment = false; |
2080 // Calculate the zoom percent from the factor. Round up to the nearest whole | 2081 // Calculate the zoom percent from the factor. Round up to the nearest whole |
2081 // number. | 2082 // number. |
2082 int percent = static_cast<int>( | 2083 int percent = static_cast<int>( |
2083 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); | 2084 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
2084 *enable_decrement = percent > minimum_zoom_percent_; | 2085 *enable_decrement = percent > minimum_zoom_percent_; |
2085 *enable_increment = percent < maximum_zoom_percent_; | 2086 *enable_increment = percent < maximum_zoom_percent_; |
2086 return percent; | 2087 return percent; |
2087 } | 2088 } |
2088 | 2089 |
2089 void WebContentsImpl::ViewSource() { | 2090 void WebContentsImpl::ViewSource() { |
2090 if (!delegate_) | 2091 if (!delegate_) |
2091 return; | 2092 return; |
2092 | 2093 |
2093 NavigationEntry* active_entry = GetController().GetActiveEntry(); | 2094 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
2094 if (!active_entry) | 2095 if (!entry) |
2095 return; | 2096 return; |
2096 | 2097 |
2097 delegate_->ViewSourceForTab(this, active_entry->GetURL()); | 2098 delegate_->ViewSourceForTab(this, entry->GetURL()); |
2098 } | 2099 } |
2099 | 2100 |
2100 void WebContentsImpl::ViewFrameSource(const GURL& url, | 2101 void WebContentsImpl::ViewFrameSource(const GURL& url, |
2101 const PageState& page_state) { | 2102 const PageState& page_state) { |
2102 if (!delegate_) | 2103 if (!delegate_) |
2103 return; | 2104 return; |
2104 | 2105 |
2105 delegate_->ViewSourceForFrame(this, url, page_state); | 2106 delegate_->ViewSourceForFrame(this, url, page_state); |
2106 } | 2107 } |
2107 | 2108 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 bool is_favicon, | 2143 bool is_favicon, |
2143 uint32_t max_bitmap_size, | 2144 uint32_t max_bitmap_size, |
2144 const ImageDownloadCallback& callback) { | 2145 const ImageDownloadCallback& callback) { |
2145 RenderViewHost* host = GetRenderViewHost(); | 2146 RenderViewHost* host = GetRenderViewHost(); |
2146 int id = StartDownload(host, url, is_favicon, max_bitmap_size); | 2147 int id = StartDownload(host, url, is_favicon, max_bitmap_size); |
2147 image_download_map_[id] = callback; | 2148 image_download_map_[id] = callback; |
2148 return id; | 2149 return id; |
2149 } | 2150 } |
2150 | 2151 |
2151 bool WebContentsImpl::FocusLocationBarByDefault() { | 2152 bool WebContentsImpl::FocusLocationBarByDefault() { |
2152 NavigationEntry* entry = controller_.GetActiveEntry(); | 2153 NavigationEntry* entry = controller_.GetVisibleEntry(); |
2153 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) | 2154 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) |
2154 return true; | 2155 return true; |
2155 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); | 2156 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
2156 } | 2157 } |
2157 | 2158 |
2158 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { | 2159 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
2159 if (delegate_) | 2160 if (delegate_) |
2160 delegate_->SetFocusToLocationBar(select_all); | 2161 delegate_->SetFocusToLocationBar(select_all); |
2161 } | 2162 } |
2162 | 2163 |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2940 NotificationService::current()->Notify( | 2941 NotificationService::current()->Notify( |
2941 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2942 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2942 Source<WebContents>(this), | 2943 Source<WebContents>(this), |
2943 Details<RenderViewHost>(render_view_host)); | 2944 Details<RenderViewHost>(render_view_host)); |
2944 | 2945 |
2945 // When we're creating views, we're still doing initial setup, so we always | 2946 // When we're creating views, we're still doing initial setup, so we always |
2946 // use the pending Web UI rather than any possibly existing committed one. | 2947 // use the pending Web UI rather than any possibly existing committed one. |
2947 if (render_manager_.pending_web_ui()) | 2948 if (render_manager_.pending_web_ui()) |
2948 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 2949 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
2949 | 2950 |
2950 NavigationEntry* entry = controller_.GetActiveEntry(); | 2951 NavigationEntry* entry = controller_.GetPendingEntry(); |
2951 if (entry && entry->IsViewSourceMode()) { | 2952 if (entry && entry->IsViewSourceMode()) { |
2952 // Put the renderer in view source mode. | 2953 // Put the renderer in view source mode. |
2953 render_view_host->Send( | 2954 render_view_host->Send( |
2954 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 2955 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
2955 } | 2956 } |
2956 | 2957 |
2957 view_->RenderViewCreated(render_view_host); | 2958 view_->RenderViewCreated(render_view_host); |
2958 | 2959 |
2959 FOR_EACH_OBSERVER( | 2960 FOR_EACH_OBSERVER( |
2960 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 2961 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3105 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 3106 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
3106 // that is not recorded in the navigation history. For the purpose of | 3107 // that is not recorded in the navigation history. For the purpose of |
3107 // tracking navigation events, we treat this event as a sub frame navigation | 3108 // tracking navigation events, we treat this event as a sub frame navigation |
3108 // event. | 3109 // event. |
3109 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 3110 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
3110 PageTransition transition_type = params.transition; | 3111 PageTransition transition_type = params.transition; |
3111 // Whether or not a page transition was triggered by going backward or | 3112 // Whether or not a page transition was triggered by going backward or |
3112 // forward in the history is only stored in the navigation controller's | 3113 // forward in the history is only stored in the navigation controller's |
3113 // entry list. | 3114 // entry list. |
3114 if (did_navigate && | 3115 if (did_navigate && |
3115 (controller_.GetActiveEntry()->GetTransitionType() & | 3116 (controller_.GetLastCommittedEntry()->GetTransitionType() & |
3116 PAGE_TRANSITION_FORWARD_BACK)) { | 3117 PAGE_TRANSITION_FORWARD_BACK)) { |
3117 transition_type = PageTransitionFromInt( | 3118 transition_type = PageTransitionFromInt( |
3118 params.transition | PAGE_TRANSITION_FORWARD_BACK); | 3119 params.transition | PAGE_TRANSITION_FORWARD_BACK); |
3119 } | 3120 } |
3120 // Notify observers about the commit of the provisional load. | 3121 // Notify observers about the commit of the provisional load. |
3121 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3122 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3122 DidCommitProvisionalLoadForFrame(params.frame_id, | 3123 DidCommitProvisionalLoadForFrame(params.frame_id, |
3123 is_main_frame, params.url, transition_type, rvh)); | 3124 is_main_frame, params.url, transition_type, rvh)); |
3124 } | 3125 } |
3125 | 3126 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3534 const string16& source_id) { | 3535 const string16& source_id) { |
3535 if (!delegate_) | 3536 if (!delegate_) |
3536 return false; | 3537 return false; |
3537 return delegate_->AddMessageToConsole(this, level, message, line_no, | 3538 return delegate_->AddMessageToConsole(this, level, message, line_no, |
3538 source_id); | 3539 source_id); |
3539 } | 3540 } |
3540 | 3541 |
3541 WebPreferences WebContentsImpl::GetWebkitPrefs() { | 3542 WebPreferences WebContentsImpl::GetWebkitPrefs() { |
3542 // We want to base the page config off of the real URL, rather than the | 3543 // We want to base the page config off of the real URL, rather than the |
3543 // display URL. | 3544 // display URL. |
3544 GURL url = controller_.GetActiveEntry() | 3545 GURL url = controller_.GetLastCommittedEntry() |
3545 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); | 3546 ? controller_.GetLastCommittedEntry()->GetURL() : GURL::EmptyGURL(); |
3546 return GetWebkitPrefs(GetRenderViewHost(), url); | 3547 return GetWebkitPrefs(GetRenderViewHost(), url); |
3547 } | 3548 } |
3548 | 3549 |
3549 int WebContentsImpl::CreateSwappedOutRenderView( | 3550 int WebContentsImpl::CreateSwappedOutRenderView( |
3550 SiteInstance* instance) { | 3551 SiteInstance* instance) { |
3551 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, | 3552 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, |
3552 true, true); | 3553 true, true); |
3553 } | 3554 } |
3554 | 3555 |
3555 void WebContentsImpl::OnUserGesture() { | 3556 void WebContentsImpl::OnUserGesture() { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3859 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { | 3860 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { |
3860 gfx::Size size; | 3861 gfx::Size size; |
3861 if (delegate_) | 3862 if (delegate_) |
3862 size = delegate_->GetSizeForNewRenderView(this); | 3863 size = delegate_->GetSizeForNewRenderView(this); |
3863 if (size.IsEmpty()) | 3864 if (size.IsEmpty()) |
3864 size = view_->GetContainerSize(); | 3865 size = view_->GetContainerSize(); |
3865 return size; | 3866 return size; |
3866 } | 3867 } |
3867 | 3868 |
3868 } // namespace content | 3869 } // namespace content |
OLD | NEW |