OLD | NEW |
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/common/content_features.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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 #if defined(OS_ANDROID) | 132 #if defined(OS_ANDROID) |
132 // Rewrite the old new tab and welcome page URLs to the new NTP URL. | 133 // Rewrite the old new tab and welcome page URLs to the new NTP URL. |
133 if (navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) && | 134 if (navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) && |
134 (navigation->virtual_url_.host_piece() == "welcome" || | 135 (navigation->virtual_url_.host_piece() == "welcome" || |
135 navigation->virtual_url_.host_piece() == "newtab")) { | 136 navigation->virtual_url_.host_piece() == "newtab")) { |
136 navigation->virtual_url_ = GURL("chrome-native://newtab/"); | 137 navigation->virtual_url_ = GURL("chrome-native://newtab/"); |
137 navigation->original_request_url_ = navigation->virtual_url_; | 138 navigation->original_request_url_ = navigation->virtual_url_; |
138 navigation->encoded_page_state_ = content::PageState::CreateFromURL( | 139 navigation->encoded_page_state_ = content::PageState::CreateFromURL( |
139 navigation->virtual_url_).ToEncodedData(); | 140 navigation->virtual_url_).ToEncodedData(); |
140 } | 141 } |
| 142 |
| 143 if (base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) && |
| 144 navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) && |
| 145 (navigation->virtual_url_.host_piece() == content::kChromeUIHistoryHost || |
| 146 navigation->virtual_url_.host_piece() == |
| 147 content::kChromeUIHistoryFrameHost)) { |
| 148 // Rewrite the old history Web UI to the new android native history. |
| 149 navigation->virtual_url_ = GURL(content::kChromeUINativeHistoryURL); |
| 150 navigation->original_request_url_ = navigation->virtual_url_; |
| 151 navigation->encoded_page_state_ = content::PageState::CreateFromURL( |
| 152 navigation->virtual_url_).ToEncodedData(); |
| 153 } else if ( |
| 154 !base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) && |
| 155 navigation->virtual_url_.SchemeIs(content::kChromeNativeUIScheme) && |
| 156 navigation->virtual_url_.host_piece() == content::kChromeUIHistoryHost) { |
| 157 // If the android native history UI has been disabled, redirect |
| 158 // chrome-native://history to the old web UI. |
| 159 navigation->virtual_url_ = GURL(content::kChromeUIHistoryURL); |
| 160 navigation->original_request_url_ = navigation->virtual_url_; |
| 161 navigation->encoded_page_state_ = std::string(); |
| 162 } |
141 #endif // defined(OS_ANDROID) | 163 #endif // defined(OS_ANDROID) |
142 } | 164 } |
143 | 165 |
144 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( | 166 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( |
145 const std::string& page_state) const { | 167 const std::string& page_state) const { |
146 return content::PageState::CreateFromEncodedData(page_state) | 168 return content::PageState::CreateFromEncodedData(page_state) |
147 .RemoveReferrer() | 169 .RemoveReferrer() |
148 .ToEncodedData(); | 170 .ToEncodedData(); |
149 } | 171 } |
150 | 172 |
151 void ContentSerializedNavigationDriver::RegisterExtendedInfoHandler( | 173 void ContentSerializedNavigationDriver::RegisterExtendedInfoHandler( |
152 const std::string& key, | 174 const std::string& key, |
153 std::unique_ptr<ExtendedInfoHandler> handler) { | 175 std::unique_ptr<ExtendedInfoHandler> handler) { |
154 DCHECK(!key.empty()); | 176 DCHECK(!key.empty()); |
155 DCHECK(!extended_info_handler_map_.count(key)); | 177 DCHECK(!extended_info_handler_map_.count(key)); |
156 DCHECK(handler.get()); | 178 DCHECK(handler.get()); |
157 extended_info_handler_map_[key] = std::move(handler); | 179 extended_info_handler_map_[key] = std::move(handler); |
158 } | 180 } |
159 | 181 |
160 const ContentSerializedNavigationDriver::ExtendedInfoHandlerMap& | 182 const ContentSerializedNavigationDriver::ExtendedInfoHandlerMap& |
161 ContentSerializedNavigationDriver::GetAllExtendedInfoHandlers() const { | 183 ContentSerializedNavigationDriver::GetAllExtendedInfoHandlers() const { |
162 return extended_info_handler_map_; | 184 return extended_info_handler_map_; |
163 } | 185 } |
164 | 186 |
165 } // namespace sessions | 187 } // namespace sessions |
OLD | NEW |