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/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 Loading... | |
| 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 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2072 &ssl_status.security_bits, | 2065 &ssl_status.security_bits, |
| 2073 &ssl_status.connection_status, | 2066 &ssl_status.connection_status, |
| 2074 &ssl_status.signed_certificate_timestamp_ids); | 2067 &ssl_status.signed_certificate_timestamp_ids); |
| 2075 return ssl_status; | 2068 return ssl_status; |
| 2076 } | 2069 } |
| 2077 | 2070 |
| 2078 const std::string& RenderViewImpl::GetAcceptLanguages() const { | 2071 const std::string& RenderViewImpl::GetAcceptLanguages() const { |
| 2079 return renderer_preferences_.accept_languages; | 2072 return renderer_preferences_.accept_languages; |
| 2080 } | 2073 } |
| 2081 | 2074 |
| 2082 void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame, | |
| 2083 WebDataSource* ds) { | |
| 2084 bool content_initiated = !pending_navigation_params_.get(); | |
| 2085 | |
| 2086 // Make sure any previous redirect URLs end up in our new data source. | |
| 2087 if (pending_navigation_params_.get()) { | |
| 2088 for (std::vector<GURL>::const_iterator i = | |
| 2089 pending_navigation_params_->commit_params.redirects.begin(); | |
| 2090 i != pending_navigation_params_->commit_params.redirects.end(); ++i) { | |
| 2091 ds->appendRedirect(*i); | |
| 2092 } | |
| 2093 } | |
| 2094 | |
| 2095 DocumentState* document_state = DocumentState::FromDataSource(ds); | |
| 2096 if (!document_state) { | |
| 2097 document_state = new DocumentState; | |
| 2098 ds->setExtraData(document_state); | |
| 2099 if (!content_initiated) | |
| 2100 PopulateDocumentStateFromPending(document_state); | |
| 2101 } | |
| 2102 | |
| 2103 // Carry over the user agent override flag, if it exists. | |
| 2104 if (content_initiated && webview() && webview()->mainFrame() && | |
| 2105 webview()->mainFrame()->isWebLocalFrame() && | |
| 2106 webview()->mainFrame()->dataSource()) { | |
| 2107 DocumentState* old_document_state = | |
| 2108 DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); | |
| 2109 if (old_document_state) { | |
| 2110 InternalDocumentStateData* internal_data = | |
| 2111 InternalDocumentStateData::FromDocumentState(document_state); | |
| 2112 InternalDocumentStateData* old_internal_data = | |
| 2113 InternalDocumentStateData::FromDocumentState(old_document_state); | |
| 2114 internal_data->set_is_overriding_user_agent( | |
| 2115 old_internal_data->is_overriding_user_agent()); | |
| 2116 } | |
| 2117 } | |
| 2118 | |
| 2119 // The rest of RenderView assumes that a WebDataSource will always have a | |
| 2120 // non-null NavigationState. | |
| 2121 if (content_initiated) { | |
| 2122 document_state->set_navigation_state( | |
| 2123 NavigationStateImpl::CreateContentInitiated()); | |
| 2124 } else { | |
| 2125 document_state->set_navigation_state(CreateNavigationStateFromPending()); | |
| 2126 pending_navigation_params_.reset(); | |
| 2127 } | |
| 2128 | |
| 2129 // DocumentState::referred_by_prefetcher_ is true if we are | |
| 2130 // navigating from a page that used prefetching using a link on that | |
| 2131 // page. We are early enough in the request process here that we | |
| 2132 // can still see the DocumentState of the previous page and set | |
| 2133 // this value appropriately. | |
| 2134 // TODO(gavinp): catch the important case of navigation in a new | |
| 2135 // renderer process. | |
| 2136 if (webview()) { | |
| 2137 if (WebFrame* old_frame = webview()->mainFrame()) { | |
| 2138 const WebURLRequest& original_request = ds->originalRequest(); | |
| 2139 const GURL referrer( | |
| 2140 original_request.httpHeaderField(WebString::fromUTF8("Referer"))); | |
| 2141 if (!referrer.is_empty() && old_frame->isWebLocalFrame() && | |
| 2142 DocumentState::FromDataSource(old_frame->dataSource()) | |
| 2143 ->was_prefetcher()) { | |
| 2144 for (; old_frame; old_frame = old_frame->traverseNext(false)) { | |
| 2145 WebDataSource* old_frame_ds = old_frame->dataSource(); | |
| 2146 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { | |
| 2147 document_state->set_was_referred_by_prefetcher(true); | |
| 2148 break; | |
| 2149 } | |
| 2150 } | |
| 2151 } | |
| 2152 } | |
| 2153 } | |
| 2154 | |
| 2155 if (content_initiated) { | |
| 2156 const WebURLRequest& request = ds->request(); | |
| 2157 switch (request.cachePolicy()) { | |
| 2158 case WebURLRequest::UseProtocolCachePolicy: // normal load. | |
| 2159 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); | |
| 2160 break; | |
| 2161 case WebURLRequest::ReloadIgnoringCacheData: // reload. | |
| 2162 case WebURLRequest::ReloadBypassingCache: // end-to-end reload. | |
| 2163 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); | |
| 2164 break; | |
| 2165 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. | |
| 2166 document_state->set_load_type( | |
| 2167 DocumentState::LINK_LOAD_CACHE_STALE_OK); | |
| 2168 break; | |
| 2169 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. | |
| 2170 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); | |
| 2171 break; | |
| 2172 default: | |
| 2173 NOTREACHED(); | |
| 2174 } | |
| 2175 } | |
| 2176 | |
| 2177 FOR_EACH_OBSERVER( | |
| 2178 RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); | |
|
Charlie Reis
2015/03/23 22:23:02
Nice! Happy to see dead code going away, since no
Avi (use Gerrit)
2015/03/24 20:33:46
Acknowledged.
| |
| 2179 } | |
| 2180 | |
| 2181 void RenderViewImpl::PopulateDocumentStateFromPending( | |
| 2182 DocumentState* document_state) { | |
| 2183 document_state->set_request_time( | |
| 2184 pending_navigation_params_->commit_params.request_time); | |
| 2185 | |
| 2186 InternalDocumentStateData* internal_data = | |
| 2187 InternalDocumentStateData::FromDocumentState(document_state); | |
| 2188 | |
| 2189 if (!pending_navigation_params_->common_params.url.SchemeIs( | |
| 2190 url::kJavaScriptScheme) && | |
| 2191 pending_navigation_params_->common_params.navigation_type == | |
| 2192 FrameMsg_Navigate_Type::RESTORE) { | |
| 2193 // We're doing a load of a page that was restored from the last session. By | |
| 2194 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which | |
| 2195 // can result in stale data for pages that are set to expire. We explicitly | |
| 2196 // override that by setting the policy here so that as necessary we load | |
| 2197 // from the network. | |
| 2198 // | |
| 2199 // TODO(davidben): Remove this in favor of passing a cache policy to the | |
| 2200 // loadHistoryItem call in OnNavigate. That requires not overloading | |
| 2201 // UseProtocolCachePolicy to mean both "normal load" and "determine cache | |
| 2202 // policy based on load type, etc". | |
| 2203 internal_data->set_cache_policy_override( | |
| 2204 WebURLRequest::UseProtocolCachePolicy); | |
| 2205 } | |
| 2206 | |
| 2207 if (IsReload(pending_navigation_params_->common_params.navigation_type)) | |
| 2208 document_state->set_load_type(DocumentState::RELOAD); | |
| 2209 else if (pending_navigation_params_->history_params.page_state.IsValid()) | |
| 2210 document_state->set_load_type(DocumentState::HISTORY_LOAD); | |
| 2211 else | |
| 2212 document_state->set_load_type(DocumentState::NORMAL_LOAD); | |
| 2213 | |
| 2214 internal_data->set_is_overriding_user_agent( | |
| 2215 pending_navigation_params_->commit_params.is_overriding_user_agent); | |
| 2216 internal_data->set_must_reset_scroll_and_scale_state( | |
| 2217 pending_navigation_params_->common_params.navigation_type == | |
| 2218 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); | |
| 2219 document_state->set_can_load_local_resources( | |
| 2220 pending_navigation_params_->commit_params.can_load_local_resources); | |
| 2221 } | |
| 2222 | |
| 2223 NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { | |
| 2224 // A navigation resulting from loading a javascript URL should not be treated | |
| 2225 // as a browser initiated event. Instead, we want it to look as if the page | |
| 2226 // initiated any load resulting from JS execution. | |
| 2227 if (!pending_navigation_params_->common_params.url.SchemeIs( | |
| 2228 url::kJavaScriptScheme)) { | |
| 2229 return NavigationStateImpl::CreateBrowserInitiated( | |
| 2230 pending_navigation_params_->common_params, | |
| 2231 pending_navigation_params_->start_params, | |
| 2232 pending_navigation_params_->history_params); | |
| 2233 } | |
| 2234 return NavigationStateImpl::CreateContentInitiated(); | |
| 2235 } | |
| 2236 | 2075 |
| 2237 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, | 2076 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, |
| 2238 WebIconURL::Type icon_type) { | 2077 WebIconURL::Type icon_type) { |
| 2239 if (frame->parent()) | 2078 if (frame->parent()) |
| 2240 return; | 2079 return; |
| 2241 | 2080 |
| 2242 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | 2081 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 2243 std::vector<FaviconURL> urls; | 2082 std::vector<FaviconURL> urls; |
| 2244 for (size_t i = 0; i < icon_urls.size(); i++) { | 2083 for (size_t i = 0; i < icon_urls.size(); i++) { |
| 2245 std::vector<gfx::Size> sizes; | 2084 std::vector<gfx::Size> sizes; |
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3961 std::vector<gfx::Size> sizes; | 3800 std::vector<gfx::Size> sizes; |
| 3962 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); | 3801 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); |
| 3963 if (!url.isEmpty()) | 3802 if (!url.isEmpty()) |
| 3964 urls.push_back( | 3803 urls.push_back( |
| 3965 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); | 3804 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); |
| 3966 } | 3805 } |
| 3967 SendUpdateFaviconURL(urls); | 3806 SendUpdateFaviconURL(urls); |
| 3968 } | 3807 } |
| 3969 | 3808 |
| 3970 } // namespace content | 3809 } // namespace content |
| OLD | NEW |