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

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 2419093002: Revert of Preserving Content-Type header from http request in OpenURL path. (Closed)
Patch Set: Manually resolved conflicts with r425338 in navigator_impl.cc. Created 4 years, 2 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 | « no previous file | content/browser/frame_host/navigator.h » ('j') | 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 "chrome/browser/prerender/prerender_manager.h" 5 #include "chrome/browser/prerender/prerender_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h" 21 #include "base/metrics/field_trial.h"
22 #include "base/metrics/histogram_macros.h" 22 #include "base/metrics/histogram_macros.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/strings/string_util.h"
25 #include "base/sys_info.h" 24 #include "base/sys_info.h"
26 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h" 26 #include "base/time/time.h"
28 #include "base/timer/elapsed_timer.h" 27 #include "base/timer/elapsed_timer.h"
29 #include "base/values.h" 28 #include "base/values.h"
30 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
31 #include "chrome/browser/net/prediction_options.h" 30 #include "chrome/browser/net/prediction_options.h"
32 #include "chrome/browser/prerender/prerender_contents.h" 31 #include "chrome/browser/prerender/prerender_contents.h"
33 #include "chrome/browser/prerender/prerender_field_trial.h" 32 #include "chrome/browser/prerender/prerender_field_trial.h"
34 #include "chrome/browser/prerender/prerender_final_status.h" 33 #include "chrome/browser/prerender/prerender_final_status.h"
(...skipping 19 matching lines...) Expand all
54 #include "content/public/browser/render_frame_host.h" 53 #include "content/public/browser/render_frame_host.h"
55 #include "content/public/browser/render_process_host.h" 54 #include "content/public/browser/render_process_host.h"
56 #include "content/public/browser/render_view_host.h" 55 #include "content/public/browser/render_view_host.h"
57 #include "content/public/browser/resource_request_details.h" 56 #include "content/public/browser/resource_request_details.h"
58 #include "content/public/browser/session_storage_namespace.h" 57 #include "content/public/browser/session_storage_namespace.h"
59 #include "content/public/browser/site_instance.h" 58 #include "content/public/browser/site_instance.h"
60 #include "content/public/browser/web_contents.h" 59 #include "content/public/browser/web_contents.h"
61 #include "content/public/browser/web_contents_delegate.h" 60 #include "content/public/browser/web_contents_delegate.h"
62 #include "content/public/common/url_constants.h" 61 #include "content/public/common/url_constants.h"
63 #include "extensions/common/constants.h" 62 #include "extensions/common/constants.h"
64 #include "net/http/http_request_headers.h"
65 #include "ui/gfx/geometry/rect.h" 63 #include "ui/gfx/geometry/rect.h"
66 64
67 using content::BrowserThread; 65 using content::BrowserThread;
68 using content::RenderViewHost; 66 using content::RenderViewHost;
69 using content::SessionStorageNamespace; 67 using content::SessionStorageNamespace;
70 using content::WebContents; 68 using content::WebContents;
71 using namespace chrome_browser_net; 69 using namespace chrome_browser_net;
72 70
73 namespace prerender { 71 namespace prerender {
74 72
75 namespace { 73 namespace {
76 74
77 // Time interval at which periodic cleanups are performed. 75 // Time interval at which periodic cleanups are performed.
78 const int kPeriodicCleanupIntervalMs = 1000; 76 const int kPeriodicCleanupIntervalMs = 1000;
79 77
80 // Length of prerender history, for display in chrome://net-internals 78 // Length of prerender history, for display in chrome://net-internals
81 const int kHistoryLength = 100; 79 const int kHistoryLength = 100;
82 80
83 // Check if |extra_headers| requested via chrome::NavigateParams::extra_headers
84 // are the same as what the HTTP server saw when serving prerendered contents.
85 // PrerenderContents::StartPrerendering doesn't specify any extra headers when
86 // calling content::NavigationController::LoadURLWithParams, but in reality
87 // Blink will always add an Upgrade-Insecure-Requests http request header, so
88 // that HTTP request for prerendered contents always includes this header.
89 // Because of this, it is okay to show prerendered contents even if
90 // |extra_headers| contains "Upgrade-Insecure-Requests" header.
91 bool AreExtraHeadersCompatibleWithPrerenderContents(
92 const std::string& extra_headers) {
93 net::HttpRequestHeaders parsed_headers;
94 parsed_headers.AddHeadersFromString(extra_headers);
95 parsed_headers.RemoveHeader("upgrade-insecure-requests");
96 return parsed_headers.IsEmpty();
97 }
98
99 } // namespace 81 } // namespace
100 82
101 class PrerenderManager::OnCloseWebContentsDeleter 83 class PrerenderManager::OnCloseWebContentsDeleter
102 : public content::WebContentsDelegate, 84 : public content::WebContentsDelegate,
103 public base::SupportsWeakPtr< 85 public base::SupportsWeakPtr<
104 PrerenderManager::OnCloseWebContentsDeleter> { 86 PrerenderManager::OnCloseWebContentsDeleter> {
105 public: 87 public:
106 OnCloseWebContentsDeleter(PrerenderManager* manager, 88 OnCloseWebContentsDeleter(PrerenderManager* manager,
107 std::unique_ptr<WebContents> tab) 89 std::unique_ptr<WebContents> tab)
108 : manager_(manager), tab_(std::move(tab)), suppressed_dialog_(false) { 90 : manager_(manager), tab_(std::move(tab)), suppressed_dialog_(false) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 291 }
310 } 292 }
311 293
312 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url, 294 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url,
313 chrome::NavigateParams* params) { 295 chrome::NavigateParams* params) {
314 DCHECK_CURRENTLY_ON(BrowserThread::UI); 296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
315 297
316 WebContents* web_contents = params->target_contents; 298 WebContents* web_contents = params->target_contents;
317 DCHECK(!IsWebContentsPrerendering(web_contents, nullptr)); 299 DCHECK(!IsWebContentsPrerendering(web_contents, nullptr));
318 300
319 // Don't prerender if the navigation involves some special parameters that 301 // Don't prerender if the navigation involves some special parameters.
320 // are different from what was used by PrerenderContents::StartPrerendering 302 if (params->uses_post || !params->extra_headers.empty())
321 // (which always uses GET method and doesn't specify any extra headers when
322 // calling content::NavigationController::LoadURLWithParams).
323 if (params->uses_post ||
324 !AreExtraHeadersCompatibleWithPrerenderContents(params->extra_headers)) {
325 return false; 303 return false;
326 }
327 304
328 DeleteOldEntries(); 305 DeleteOldEntries();
329 to_delete_prerenders_.clear(); 306 to_delete_prerenders_.clear();
330 307
331 // First, try to find prerender data with the correct session storage 308 // First, try to find prerender data with the correct session storage
332 // namespace. 309 // namespace.
333 // TODO(ajwong): This doesn't handle isolated apps correctly. 310 // TODO(ajwong): This doesn't handle isolated apps correctly.
334 PrerenderData* prerender_data = FindPrerenderData( 311 PrerenderData* prerender_data = FindPrerenderData(
335 url, 312 url,
336 web_contents->GetController().GetDefaultSessionStorageNamespace()); 313 web_contents->GetController().GetDefaultSessionStorageNamespace());
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 DCHECK_EQ(1u, erased); 1343 DCHECK_EQ(1u, erased);
1367 } 1344 }
1368 1345
1369 void PrerenderManager::SetPrerenderContentsFactoryForTest( 1346 void PrerenderManager::SetPrerenderContentsFactoryForTest(
1370 PrerenderContents::Factory* prerender_contents_factory) { 1347 PrerenderContents::Factory* prerender_contents_factory) {
1371 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1348 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1372 prerender_contents_factory_.reset(prerender_contents_factory); 1349 prerender_contents_factory_.reset(prerender_contents_factory);
1373 } 1350 }
1374 1351
1375 } // namespace prerender 1352 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698