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

Side by Side Diff: components/sessions/content/content_serialized_navigation_driver.cc

Issue 2166693002: [MD Settings] PROOF OF CONCEPT - DO NOT LAND - URL rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use existing hooks Created 4 years, 5 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 | « chrome/browser/ui/webui/md_history_ui.cc ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sessions/content/content_serialized_navigation_driver.h" 5 #include "components/sessions/content/content_serialized_navigation_driver.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "components/sessions/core/serialized_navigation_entry.h" 9 #include "components/sessions/core/serialized_navigation_entry.h"
10 #include "content/public/browser/browser_url_handler.h"
10 #include "content/public/common/page_state.h" 11 #include "content/public/common/page_state.h"
11 #include "content/public/common/referrer.h" 12 #include "content/public/common/referrer.h"
12 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
13 14
14 namespace sessions { 15 namespace sessions {
15 16
16 namespace { 17 namespace {
17 const int kObsoleteReferrerPolicyAlways = 0; 18 const int kObsoleteReferrerPolicyAlways = 0;
18 const int kObsoleteReferrerPolicyDefault = 1; 19 const int kObsoleteReferrerPolicyDefault = 1;
19 const int kObsoleteReferrerPolicyNever = 2; 20 const int kObsoleteReferrerPolicyNever = 2;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // No need to compare the policy, as it doesn't change during 107 // No need to compare the policy, as it doesn't change during
107 // sanitization. If there has been a change, the referrer needs to be 108 // sanitization. If there has been a change, the referrer needs to be
108 // stripped from the page state as well. 109 // stripped from the page state as well.
109 if (navigation->referrer_url_ != new_referrer.url) { 110 if (navigation->referrer_url_ != new_referrer.url) {
110 navigation->referrer_url_ = GURL(); 111 navigation->referrer_url_ = GURL();
111 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); 112 navigation->referrer_policy_ = GetDefaultReferrerPolicy();
112 navigation->encoded_page_state_ = 113 navigation->encoded_page_state_ =
113 StripReferrerFromPageState(navigation->encoded_page_state_); 114 StripReferrerFromPageState(navigation->encoded_page_state_);
114 } 115 }
115 116
117 // Rewrite any WebUI links that do not have an appropriate handler any more.
118 if (navigation->virtual_url_.SchemeIs(content::kChromeUIScheme)) {
119 // I'd like to check for "is handled by WebUI" here, so we don't
120 // unnecessarily rewrite - but oh well. It's not accessible.
121 // content::WebUI::TypeID type_id =
122 // content::WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
123 // nullptr, navigation->original_request_url_);
124 // if (type_id != content::WebUI::kNoWebUI) {
125 // in place of that, let's check if the original URL is a chrome:// URL as
126 // well.
127 if (navigation->original_request_url_.SchemeIs(content::kChromeUIScheme)) {
128 bool reverse_on_redirect;
129 navigation->original_request_url_ = navigation->virtual_url_;
130 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
131 &navigation->original_request_url_, nullptr, &reverse_on_redirect);
132 navigation->encoded_page_state_ =
133 content::PageState::CreateFromURL(navigation->original_request_url_)
134 .ToEncodedData();
135 }
136 }
137
116 #if defined(OS_ANDROID) 138 #if defined(OS_ANDROID)
117 // Rewrite the old new tab and welcome page URLs to the new NTP URL. 139 // Rewrite the old new tab and welcome page URLs to the new NTP URL.
118 if (navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) && 140 if (navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) &&
119 (navigation->virtual_url_.host() == "welcome" || 141 (navigation->virtual_url_.host() == "welcome" ||
120 navigation->virtual_url_.host() == "newtab")) { 142 navigation->virtual_url_.host() == "newtab")) {
121 navigation->virtual_url_ = GURL("chrome-native://newtab/"); 143 navigation->virtual_url_ = GURL("chrome-native://newtab/");
122 navigation->original_request_url_ = navigation->virtual_url_; 144 navigation->original_request_url_ = navigation->virtual_url_;
123 navigation->encoded_page_state_ = content::PageState::CreateFromURL( 145 navigation->encoded_page_state_ = content::PageState::CreateFromURL(
124 navigation->virtual_url_).ToEncodedData(); 146 navigation->virtual_url_).ToEncodedData();
125 } 147 }
126 #endif // defined(OS_ANDROID) 148 #endif // defined(OS_ANDROID)
127 } 149 }
128 150
129 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( 151 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState(
130 const std::string& page_state) const { 152 const std::string& page_state) const {
131 return content::PageState::CreateFromEncodedData(page_state) 153 return content::PageState::CreateFromEncodedData(page_state)
132 .RemoveReferrer() 154 .RemoveReferrer()
133 .ToEncodedData(); 155 .ToEncodedData();
134 } 156 }
135 157
136 } // namespace sessions 158 } // namespace sessions
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698