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

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 1027863002: Move provisional navigation parameters to RenderFrame, and use the HistoryController to distribute … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years, 9 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
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 #if defined(OS_ANDROID) 323 #if defined(OS_ANDROID)
324 // Delay between tapping in content and launching the associated android intent. 324 // Delay between tapping in content and launching the associated android intent.
325 // Used to allow users see what has been recognized as content. 325 // Used to allow users see what has been recognized as content.
326 const size_t kContentIntentDelayMilliseconds = 700; 326 const size_t kContentIntentDelayMilliseconds = 700;
327 #endif 327 #endif
328 328
329 static RenderViewImpl* (*g_create_render_view_impl)(const ViewMsg_New_Params&) = 329 static RenderViewImpl* (*g_create_render_view_impl)(const ViewMsg_New_Params&) =
330 NULL; 330 NULL;
331 331
332 // static 332 // static
333 bool RenderViewImpl::IsReload(FrameMsg_Navigate_Type::Value navigation_type) {
334 return navigation_type == FrameMsg_Navigate_Type::RELOAD ||
335 navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
336 navigation_type == FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
337 }
338
339 // static
340 Referrer RenderViewImpl::GetReferrerFromRequest( 333 Referrer RenderViewImpl::GetReferrerFromRequest(
341 WebFrame* frame, 334 WebFrame* frame,
342 const WebURLRequest& request) { 335 const WebURLRequest& request) {
343 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), 336 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
344 request.referrerPolicy()); 337 request.referrerPolicy());
345 } 338 }
346 339
347 // static 340 // static
348 WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( 341 WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
349 WebNavigationPolicy policy) { 342 WebNavigationPolicy policy) {
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 &ssl_status.security_bits, 2067 &ssl_status.security_bits,
2075 &ssl_status.connection_status, 2068 &ssl_status.connection_status,
2076 &ssl_status.signed_certificate_timestamp_ids); 2069 &ssl_status.signed_certificate_timestamp_ids);
2077 return ssl_status; 2070 return ssl_status;
2078 } 2071 }
2079 2072
2080 const std::string& RenderViewImpl::GetAcceptLanguages() const { 2073 const std::string& RenderViewImpl::GetAcceptLanguages() const {
2081 return renderer_preferences_.accept_languages; 2074 return renderer_preferences_.accept_languages;
2082 } 2075 }
2083 2076
2084 void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame,
2085 WebDataSource* ds) {
2086 bool content_initiated = !pending_navigation_params_.get();
2087
2088 // Make sure any previous redirect URLs end up in our new data source.
2089 if (pending_navigation_params_.get()) {
2090 for (std::vector<GURL>::const_iterator i =
2091 pending_navigation_params_->request_params.redirects.begin();
2092 i != pending_navigation_params_->request_params.redirects.end(); ++i) {
2093 ds->appendRedirect(*i);
2094 }
2095 }
2096
2097 DocumentState* document_state = DocumentState::FromDataSource(ds);
2098 if (!document_state) {
2099 document_state = new DocumentState;
2100 ds->setExtraData(document_state);
2101 if (!content_initiated)
2102 PopulateDocumentStateFromPending(document_state);
2103 }
2104
2105 // Carry over the user agent override flag, if it exists.
2106 if (content_initiated && webview() && webview()->mainFrame() &&
2107 webview()->mainFrame()->isWebLocalFrame() &&
2108 webview()->mainFrame()->dataSource()) {
2109 DocumentState* old_document_state =
2110 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2111 if (old_document_state) {
2112 InternalDocumentStateData* internal_data =
2113 InternalDocumentStateData::FromDocumentState(document_state);
2114 InternalDocumentStateData* old_internal_data =
2115 InternalDocumentStateData::FromDocumentState(old_document_state);
2116 internal_data->set_is_overriding_user_agent(
2117 old_internal_data->is_overriding_user_agent());
2118 }
2119 }
2120
2121 // The rest of RenderView assumes that a WebDataSource will always have a
2122 // non-null NavigationState.
2123 if (content_initiated) {
2124 document_state->set_navigation_state(
2125 NavigationStateImpl::CreateContentInitiated());
2126 } else {
2127 document_state->set_navigation_state(CreateNavigationStateFromPending());
2128 pending_navigation_params_.reset();
2129 }
2130
2131 // DocumentState::referred_by_prefetcher_ is true if we are
2132 // navigating from a page that used prefetching using a link on that
2133 // page. We are early enough in the request process here that we
2134 // can still see the DocumentState of the previous page and set
2135 // this value appropriately.
2136 // TODO(gavinp): catch the important case of navigation in a new
2137 // renderer process.
2138 if (webview()) {
2139 if (WebFrame* old_frame = webview()->mainFrame()) {
2140 const WebURLRequest& original_request = ds->originalRequest();
2141 const GURL referrer(
2142 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2143 if (!referrer.is_empty() && old_frame->isWebLocalFrame() &&
2144 DocumentState::FromDataSource(old_frame->dataSource())
2145 ->was_prefetcher()) {
2146 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
2147 WebDataSource* old_frame_ds = old_frame->dataSource();
2148 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2149 document_state->set_was_referred_by_prefetcher(true);
2150 break;
2151 }
2152 }
2153 }
2154 }
2155 }
2156
2157 if (content_initiated) {
2158 const WebURLRequest& request = ds->request();
2159 switch (request.cachePolicy()) {
2160 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2161 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
2162 break;
2163 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2164 case WebURLRequest::ReloadBypassingCache: // end-to-end reload.
2165 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
2166 break;
2167 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2168 document_state->set_load_type(
2169 DocumentState::LINK_LOAD_CACHE_STALE_OK);
2170 break;
2171 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2172 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
2173 break;
2174 default:
2175 NOTREACHED();
2176 }
2177 }
2178
2179 FOR_EACH_OBSERVER(
2180 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
2181 }
2182
2183 void RenderViewImpl::PopulateDocumentStateFromPending(
2184 DocumentState* document_state) {
2185 document_state->set_request_time(
2186 pending_navigation_params_->request_params.request_time);
2187
2188 InternalDocumentStateData* internal_data =
2189 InternalDocumentStateData::FromDocumentState(document_state);
2190
2191 if (!pending_navigation_params_->common_params.url.SchemeIs(
2192 url::kJavaScriptScheme) &&
2193 pending_navigation_params_->common_params.navigation_type ==
2194 FrameMsg_Navigate_Type::RESTORE) {
2195 // We're doing a load of a page that was restored from the last session. By
2196 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2197 // can result in stale data for pages that are set to expire. We explicitly
2198 // override that by setting the policy here so that as necessary we load
2199 // from the network.
2200 //
2201 // TODO(davidben): Remove this in favor of passing a cache policy to the
2202 // loadHistoryItem call in OnNavigate. That requires not overloading
2203 // UseProtocolCachePolicy to mean both "normal load" and "determine cache
2204 // policy based on load type, etc".
2205 internal_data->set_cache_policy_override(
2206 WebURLRequest::UseProtocolCachePolicy);
2207 }
2208
2209 if (IsReload(pending_navigation_params_->common_params.navigation_type))
2210 document_state->set_load_type(DocumentState::RELOAD);
2211 else if (pending_navigation_params_->request_params.page_state.IsValid())
2212 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2213 else
2214 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2215
2216 internal_data->set_is_overriding_user_agent(
2217 pending_navigation_params_->request_params.is_overriding_user_agent);
2218 internal_data->set_must_reset_scroll_and_scale_state(
2219 pending_navigation_params_->common_params.navigation_type ==
2220 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
2221 document_state->set_can_load_local_resources(
2222 pending_navigation_params_->request_params.can_load_local_resources);
2223 }
2224
2225 NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
2226 // A navigation resulting from loading a javascript URL should not be treated
2227 // as a browser initiated event. Instead, we want it to look as if the page
2228 // initiated any load resulting from JS execution.
2229 if (!pending_navigation_params_->common_params.url.SchemeIs(
2230 url::kJavaScriptScheme)) {
2231 return NavigationStateImpl::CreateBrowserInitiated(
2232 pending_navigation_params_->common_params,
2233 pending_navigation_params_->start_params,
2234 pending_navigation_params_->request_params);
2235 }
2236 return NavigationStateImpl::CreateContentInitiated();
2237 }
2238
2239 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, 2077 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
2240 WebIconURL::Type icon_type) { 2078 WebIconURL::Type icon_type) {
2241 if (frame->parent()) 2079 if (frame->parent())
2242 return; 2080 return;
2243 2081
2244 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); 2082 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
2245 std::vector<FaviconURL> urls; 2083 std::vector<FaviconURL> urls;
2246 for (size_t i = 0; i < icon_urls.size(); i++) { 2084 for (size_t i = 0; i < icon_urls.size(); i++) {
2247 std::vector<gfx::Size> sizes; 2085 std::vector<gfx::Size> sizes;
2248 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 2086 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
3963 std::vector<gfx::Size> sizes; 3801 std::vector<gfx::Size> sizes;
3964 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 3802 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
3965 if (!url.isEmpty()) 3803 if (!url.isEmpty())
3966 urls.push_back( 3804 urls.push_back(
3967 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 3805 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
3968 } 3806 }
3969 SendUpdateFaviconURL(urls); 3807 SendUpdateFaviconURL(urls);
3970 } 3808 }
3971 3809
3972 } // namespace content 3810 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698