OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sessions/base_session_service.h" | 5 #include "chrome/browser/sessions/base_session_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/sessions/session_backend.h" | 13 #include "chrome/browser/sessions/session_backend.h" |
14 #include "chrome/browser/sessions/session_types.h" | 14 #include "chrome/browser/sessions/session_types.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "content/browser/tab_contents/navigation_entry.h" | 16 #include "content/browser/tab_contents/navigation_entry.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebReferrerPolicy.h" |
17 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
18 | 19 |
| 20 using WebKit::WebReferrerPolicy; |
| 21 |
19 // InternalGetCommandsRequest ------------------------------------------------- | 22 // InternalGetCommandsRequest ------------------------------------------------- |
20 | 23 |
21 BaseSessionService::InternalGetCommandsRequest::~InternalGetCommandsRequest() { | 24 BaseSessionService::InternalGetCommandsRequest::~InternalGetCommandsRequest() { |
22 STLDeleteElements(&commands); | 25 STLDeleteElements(&commands); |
23 } | 26 } |
24 | 27 |
25 // BaseSessionService --------------------------------------------------------- | 28 // BaseSessionService --------------------------------------------------------- |
26 | 29 |
27 namespace { | 30 namespace { |
28 | 31 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } else { | 174 } else { |
172 WriteStringToPickle(pickle, &bytes_written, max_state_size, | 175 WriteStringToPickle(pickle, &bytes_written, max_state_size, |
173 entry.content_state()); | 176 entry.content_state()); |
174 } | 177 } |
175 | 178 |
176 pickle.WriteInt(entry.transition_type()); | 179 pickle.WriteInt(entry.transition_type()); |
177 int type_mask = entry.has_post_data() ? TabNavigation::HAS_POST_DATA : 0; | 180 int type_mask = entry.has_post_data() ? TabNavigation::HAS_POST_DATA : 0; |
178 pickle.WriteInt(type_mask); | 181 pickle.WriteInt(type_mask); |
179 | 182 |
180 WriteStringToPickle(pickle, &bytes_written, max_state_size, | 183 WriteStringToPickle(pickle, &bytes_written, max_state_size, |
181 entry.referrer().is_valid() ? entry.referrer().spec() : std::string()); | 184 entry.referrer().url.is_valid() ? |
| 185 entry.referrer().url.spec() : std::string()); |
| 186 pickle.WriteInt(entry.referrer().policy); |
182 | 187 |
183 // Adding more data? Be sure and update TabRestoreService too. | 188 // Adding more data? Be sure and update TabRestoreService too. |
184 return new SessionCommand(command_id, pickle); | 189 return new SessionCommand(command_id, pickle); |
185 } | 190 } |
186 | 191 |
187 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( | 192 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( |
188 SessionID::id_type command_id, | 193 SessionID::id_type command_id, |
189 SessionID::id_type tab_id, | 194 SessionID::id_type tab_id, |
190 const std::string& extension_id) { | 195 const std::string& extension_id) { |
191 // Use pickle to handle marshalling. | 196 // Use pickle to handle marshalling. |
(...skipping 30 matching lines...) Expand all Loading... |
222 return false; | 227 return false; |
223 // type_mask did not always exist in the written stream. As such, we | 228 // type_mask did not always exist in the written stream. As such, we |
224 // don't fail if it can't be read. | 229 // don't fail if it can't be read. |
225 bool has_type_mask = pickle->ReadInt(&iterator, &(navigation->type_mask_)); | 230 bool has_type_mask = pickle->ReadInt(&iterator, &(navigation->type_mask_)); |
226 | 231 |
227 if (has_type_mask) { | 232 if (has_type_mask) { |
228 // the "referrer" property was added after type_mask to the written | 233 // the "referrer" property was added after type_mask to the written |
229 // stream. As such, we don't fail if it can't be read. | 234 // stream. As such, we don't fail if it can't be read. |
230 std::string referrer_spec; | 235 std::string referrer_spec; |
231 pickle->ReadString(&iterator, &referrer_spec); | 236 pickle->ReadString(&iterator, &referrer_spec); |
232 if (!referrer_spec.empty()) | 237 // The "referrer policy" property was added even later, so we fall back to |
233 navigation->referrer_ = GURL(referrer_spec); | 238 // the default policy if the property is not present. |
| 239 int policy_int; |
| 240 WebReferrerPolicy policy; |
| 241 if (pickle->ReadInt(&iterator, &policy_int)) |
| 242 policy = static_cast<WebReferrerPolicy>(policy_int); |
| 243 else |
| 244 policy = WebKit::WebReferrerPolicyDefault; |
| 245 navigation->referrer_ = content::Referrer( |
| 246 referrer_spec.empty() ? GURL() : GURL(referrer_spec), |
| 247 policy); |
234 } | 248 } |
235 | 249 |
236 navigation->virtual_url_ = GURL(url_spec); | 250 navigation->virtual_url_ = GURL(url_spec); |
237 return true; | 251 return true; |
238 } | 252 } |
239 | 253 |
240 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( | 254 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( |
241 const SessionCommand& command, | 255 const SessionCommand& command, |
242 SessionID::id_type* tab_id, | 256 SessionID::id_type* tab_id, |
243 std::string* extension_app_id) { | 257 std::string* extension_app_id) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 if (backend_thread()) { | 295 if (backend_thread()) { |
282 backend_thread()->message_loop()->PostTask( | 296 backend_thread()->message_loop()->PostTask( |
283 FROM_HERE, | 297 FROM_HERE, |
284 base::Bind(&SessionBackend::ReadCurrentSessionCommands, backend(), | 298 base::Bind(&SessionBackend::ReadCurrentSessionCommands, backend(), |
285 request_wrapper)); | 299 request_wrapper)); |
286 } else { | 300 } else { |
287 backend()->ReadCurrentSessionCommands(request); | 301 backend()->ReadCurrentSessionCommands(request); |
288 } | 302 } |
289 return request->handle(); | 303 return request->handle(); |
290 } | 304 } |
OLD | NEW |