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

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

Issue 2423233002: Preserving extra http request headers in OpenURL navigation path [relanding]. (Closed)
Patch Set: This patchset is copied from https://crrev.com/2355023002 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"
24 #include "base/sys_info.h" 25 #include "base/sys_info.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/time/time.h" 27 #include "base/time/time.h"
27 #include "base/timer/elapsed_timer.h" 28 #include "base/timer/elapsed_timer.h"
28 #include "base/values.h" 29 #include "base/values.h"
29 #include "chrome/browser/chrome_notification_types.h" 30 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/net/prediction_options.h" 31 #include "chrome/browser/net/prediction_options.h"
31 #include "chrome/browser/prerender/prerender_contents.h" 32 #include "chrome/browser/prerender/prerender_contents.h"
32 #include "chrome/browser/prerender/prerender_field_trial.h" 33 #include "chrome/browser/prerender/prerender_field_trial.h"
33 #include "chrome/browser/prerender/prerender_final_status.h" 34 #include "chrome/browser/prerender/prerender_final_status.h"
(...skipping 19 matching lines...) Expand all
53 #include "content/public/browser/render_frame_host.h" 54 #include "content/public/browser/render_frame_host.h"
54 #include "content/public/browser/render_process_host.h" 55 #include "content/public/browser/render_process_host.h"
55 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.h"
56 #include "content/public/browser/resource_request_details.h" 57 #include "content/public/browser/resource_request_details.h"
57 #include "content/public/browser/session_storage_namespace.h" 58 #include "content/public/browser/session_storage_namespace.h"
58 #include "content/public/browser/site_instance.h" 59 #include "content/public/browser/site_instance.h"
59 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
60 #include "content/public/browser/web_contents_delegate.h" 61 #include "content/public/browser/web_contents_delegate.h"
61 #include "content/public/common/url_constants.h" 62 #include "content/public/common/url_constants.h"
62 #include "extensions/common/constants.h" 63 #include "extensions/common/constants.h"
64 #include "net/http/http_request_headers.h"
63 #include "ui/gfx/geometry/rect.h" 65 #include "ui/gfx/geometry/rect.h"
64 66
65 using content::BrowserThread; 67 using content::BrowserThread;
66 using content::RenderViewHost; 68 using content::RenderViewHost;
67 using content::SessionStorageNamespace; 69 using content::SessionStorageNamespace;
68 using content::WebContents; 70 using content::WebContents;
69 using namespace chrome_browser_net; 71 using namespace chrome_browser_net;
70 72
71 namespace prerender { 73 namespace prerender {
72 74
73 namespace { 75 namespace {
74 76
75 // Time interval at which periodic cleanups are performed. 77 // Time interval at which periodic cleanups are performed.
76 const int kPeriodicCleanupIntervalMs = 1000; 78 const int kPeriodicCleanupIntervalMs = 1000;
77 79
78 // Length of prerender history, for display in chrome://net-internals 80 // Length of prerender history, for display in chrome://net-internals
79 const int kHistoryLength = 100; 81 const int kHistoryLength = 100;
80 82
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
81 } // namespace 99 } // namespace
82 100
83 class PrerenderManager::OnCloseWebContentsDeleter 101 class PrerenderManager::OnCloseWebContentsDeleter
84 : public content::WebContentsDelegate, 102 : public content::WebContentsDelegate,
85 public base::SupportsWeakPtr< 103 public base::SupportsWeakPtr<
86 PrerenderManager::OnCloseWebContentsDeleter> { 104 PrerenderManager::OnCloseWebContentsDeleter> {
87 public: 105 public:
88 OnCloseWebContentsDeleter(PrerenderManager* manager, 106 OnCloseWebContentsDeleter(PrerenderManager* manager,
89 std::unique_ptr<WebContents> tab) 107 std::unique_ptr<WebContents> tab)
90 : manager_(manager), tab_(std::move(tab)), suppressed_dialog_(false) { 108 : manager_(manager), tab_(std::move(tab)), suppressed_dialog_(false) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 310 }
293 } 311 }
294 312
295 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url, 313 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url,
296 chrome::NavigateParams* params) { 314 chrome::NavigateParams* params) {
297 DCHECK_CURRENTLY_ON(BrowserThread::UI); 315 DCHECK_CURRENTLY_ON(BrowserThread::UI);
298 316
299 WebContents* web_contents = params->target_contents; 317 WebContents* web_contents = params->target_contents;
300 DCHECK(!IsWebContentsPrerendering(web_contents, nullptr)); 318 DCHECK(!IsWebContentsPrerendering(web_contents, nullptr));
301 319
302 // Don't prerender if the navigation involves some special parameters. 320 // Don't prerender if the navigation involves some special parameters that
303 if (params->uses_post || !params->extra_headers.empty()) 321 // are different from what was used by PrerenderContents::StartPrerendering
322 // (which always uses GET method and doesn't specify any extra headers when
323 // calling content::NavigationController::LoadURLWithParams).
324 if (params->uses_post ||
325 !AreExtraHeadersCompatibleWithPrerenderContents(params->extra_headers)) {
304 return false; 326 return false;
327 }
305 328
306 DeleteOldEntries(); 329 DeleteOldEntries();
307 to_delete_prerenders_.clear(); 330 to_delete_prerenders_.clear();
308 331
309 // First, try to find prerender data with the correct session storage 332 // First, try to find prerender data with the correct session storage
310 // namespace. 333 // namespace.
311 // TODO(ajwong): This doesn't handle isolated apps correctly. 334 // TODO(ajwong): This doesn't handle isolated apps correctly.
312 PrerenderData* prerender_data = FindPrerenderData( 335 PrerenderData* prerender_data = FindPrerenderData(
313 url, 336 url,
314 web_contents->GetController().GetDefaultSessionStorageNamespace()); 337 web_contents->GetController().GetDefaultSessionStorageNamespace());
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 DCHECK_EQ(1u, erased); 1377 DCHECK_EQ(1u, erased);
1355 } 1378 }
1356 1379
1357 void PrerenderManager::SetPrerenderContentsFactoryForTest( 1380 void PrerenderManager::SetPrerenderContentsFactoryForTest(
1358 PrerenderContents::Factory* prerender_contents_factory) { 1381 PrerenderContents::Factory* prerender_contents_factory) {
1359 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1382 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1360 prerender_contents_factory_.reset(prerender_contents_factory); 1383 prerender_contents_factory_.reset(prerender_contents_factory);
1361 } 1384 }
1362 1385
1363 } // namespace prerender 1386 } // 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