OLD | NEW |
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/sessions/session_types.h" | 5 #include "chrome/browser/sessions/session_types.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.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/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/sessions/session_command.h" | 12 #include "chrome/browser/sessions/session_command.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "sync/util/time.h" | 16 #include "sync/util/time.h" |
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h
" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h
" |
18 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
19 | 19 |
20 using content::NavigationEntry; | 20 using content::NavigationEntry; |
21 | 21 |
22 // TabNavigation -------------------------------------------------------------- | 22 // TabNavigation -------------------------------------------------------------- |
23 | 23 |
24 TabNavigation::TabNavigation() | 24 TabNavigation::TabNavigation() |
25 : index_(-1), | 25 : index_(-1), |
26 unique_id_(0), | 26 unique_id_(0), |
27 transition_type_(content::PAGE_TRANSITION_TYPED), | 27 transition_type_(content::PAGE_TRANSITION_TYPED), |
28 has_post_data_(false), | 28 has_post_data_(false), |
29 post_id_(-1), | 29 post_id_(-1), |
30 is_overriding_user_agent_(false) {} | 30 is_overriding_user_agent_(false), |
| 31 http_status_code_(0) {} |
31 | 32 |
32 TabNavigation::~TabNavigation() {} | 33 TabNavigation::~TabNavigation() {} |
33 | 34 |
34 // static | 35 // static |
35 TabNavigation TabNavigation::FromNavigationEntry( | 36 TabNavigation TabNavigation::FromNavigationEntry( |
36 int index, | 37 int index, |
37 const NavigationEntry& entry) { | 38 const NavigationEntry& entry) { |
38 TabNavigation navigation; | 39 TabNavigation navigation; |
39 navigation.index_ = index; | 40 navigation.index_ = index; |
40 navigation.unique_id_ = entry.GetUniqueID(); | 41 navigation.unique_id_ = entry.GetUniqueID(); |
41 navigation.referrer_ = entry.GetReferrer(); | 42 navigation.referrer_ = entry.GetReferrer(); |
42 navigation.virtual_url_ = entry.GetVirtualURL(); | 43 navigation.virtual_url_ = entry.GetVirtualURL(); |
43 navigation.title_ = entry.GetTitle(); | 44 navigation.title_ = entry.GetTitle(); |
44 navigation.content_state_ = entry.GetContentState(); | 45 navigation.content_state_ = entry.GetContentState(); |
45 navigation.transition_type_ = entry.GetTransitionType(); | 46 navigation.transition_type_ = entry.GetTransitionType(); |
46 navigation.has_post_data_ = entry.GetHasPostData(); | 47 navigation.has_post_data_ = entry.GetHasPostData(); |
47 navigation.post_id_ = entry.GetPostID(); | 48 navigation.post_id_ = entry.GetPostID(); |
48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); | 49 navigation.original_request_url_ = entry.GetOriginalRequestURL(); |
49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 50 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); |
50 navigation.timestamp_ = entry.GetTimestamp(); | 51 navigation.timestamp_ = entry.GetTimestamp(); |
| 52 navigation.http_status_code_ = entry.GetHttpStatusCode(); |
51 return navigation; | 53 return navigation; |
52 } | 54 } |
53 | 55 |
54 TabNavigation TabNavigation::FromSyncData( | 56 TabNavigation TabNavigation::FromSyncData( |
55 int index, | 57 int index, |
56 const sync_pb::TabNavigation& sync_data) { | 58 const sync_pb::TabNavigation& sync_data) { |
57 TabNavigation navigation; | 59 TabNavigation navigation; |
58 navigation.index_ = index; | 60 navigation.index_ = index; |
59 navigation.unique_id_ = sync_data.unique_id(); | 61 navigation.unique_id_ = sync_data.unique_id(); |
60 navigation.referrer_ = | 62 navigation.referrer_ = |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 transition |= content::PAGE_TRANSITION_HOME_PAGE; | 127 transition |= content::PAGE_TRANSITION_HOME_PAGE; |
126 if (sync_data.navigation_chain_start()) | 128 if (sync_data.navigation_chain_start()) |
127 transition |= content::PAGE_TRANSITION_CHAIN_START; | 129 transition |= content::PAGE_TRANSITION_CHAIN_START; |
128 if (sync_data.navigation_chain_end()) | 130 if (sync_data.navigation_chain_end()) |
129 transition |= content::PAGE_TRANSITION_CHAIN_END; | 131 transition |= content::PAGE_TRANSITION_CHAIN_END; |
130 | 132 |
131 navigation.transition_type_ = | 133 navigation.transition_type_ = |
132 static_cast<content::PageTransition>(transition); | 134 static_cast<content::PageTransition>(transition); |
133 | 135 |
134 navigation.timestamp_ = base::Time(); | 136 navigation.timestamp_ = base::Time(); |
| 137 navigation.http_status_code_ = sync_data.http_status_code(); |
135 | 138 |
136 return navigation; | 139 return navigation; |
137 } | 140 } |
138 | 141 |
139 namespace { | 142 namespace { |
140 | 143 |
141 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to | 144 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to |
142 // |pickle|, if and only if |str| fits within (|max_bytes| - | 145 // |pickle|, if and only if |str| fits within (|max_bytes| - |
143 // |*bytes_written|). |bytes_written| is incremented to reflect the | 146 // |*bytes_written|). |bytes_written| is incremented to reflect the |
144 // data written. | 147 // data written. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // content_state_ | 197 // content_state_ |
195 // transition_type_ | 198 // transition_type_ |
196 // | 199 // |
197 // Added on later: | 200 // Added on later: |
198 // | 201 // |
199 // type_mask (has_post_data_) | 202 // type_mask (has_post_data_) |
200 // referrer_ | 203 // referrer_ |
201 // original_request_url_ | 204 // original_request_url_ |
202 // is_overriding_user_agent_ | 205 // is_overriding_user_agent_ |
203 // timestamp_ | 206 // timestamp_ |
| 207 // http_status_code_ |
204 | 208 |
205 void TabNavigation::WriteToPickle(Pickle* pickle) const { | 209 void TabNavigation::WriteToPickle(Pickle* pickle) const { |
206 pickle->WriteInt(index_); | 210 pickle->WriteInt(index_); |
207 | 211 |
208 // We only allow navigations up to 63k (which should be completely | 212 // We only allow navigations up to 63k (which should be completely |
209 // reasonable). On the off chance we get one that is too big, try to | 213 // reasonable). On the off chance we get one that is too big, try to |
210 // keep the url. | 214 // keep the url. |
211 | 215 |
212 // Bound the string data (which is variable length) to | 216 // Bound the string data (which is variable length) to |
213 // |max_state_size bytes| bytes. | 217 // |max_state_size bytes| bytes. |
(...skipping 24 matching lines...) Expand all Loading... |
238 | 242 |
239 pickle->WriteInt(referrer_.policy); | 243 pickle->WriteInt(referrer_.policy); |
240 | 244 |
241 // Save info required to override the user agent. | 245 // Save info required to override the user agent. |
242 WriteStringToPickle( | 246 WriteStringToPickle( |
243 pickle, &bytes_written, max_state_size, | 247 pickle, &bytes_written, max_state_size, |
244 original_request_url_.is_valid() ? | 248 original_request_url_.is_valid() ? |
245 original_request_url_.spec() : std::string()); | 249 original_request_url_.spec() : std::string()); |
246 pickle->WriteBool(is_overriding_user_agent_); | 250 pickle->WriteBool(is_overriding_user_agent_); |
247 pickle->WriteInt64(timestamp_.ToInternalValue()); | 251 pickle->WriteInt64(timestamp_.ToInternalValue()); |
| 252 pickle->WriteInt(http_status_code_); |
248 } | 253 } |
249 | 254 |
250 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { | 255 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { |
251 *this = TabNavigation(); | 256 *this = TabNavigation(); |
252 std::string virtual_url_spec; | 257 std::string virtual_url_spec; |
253 int transition_type_int = 0; | 258 int transition_type_int = 0; |
254 if (!iterator->ReadInt(&index_) || | 259 if (!iterator->ReadInt(&index_) || |
255 !iterator->ReadString(&virtual_url_spec) || | 260 !iterator->ReadString(&virtual_url_spec) || |
256 !iterator->ReadString16(&title_) || | 261 !iterator->ReadString16(&title_) || |
257 !iterator->ReadString(&content_state_) || | 262 !iterator->ReadString(&content_state_) || |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // Default to not overriding the user agent if we don't have info. | 296 // Default to not overriding the user agent if we don't have info. |
292 if (!iterator->ReadBool(&is_overriding_user_agent_)) | 297 if (!iterator->ReadBool(&is_overriding_user_agent_)) |
293 is_overriding_user_agent_ = false; | 298 is_overriding_user_agent_ = false; |
294 | 299 |
295 int64 timestamp_internal_value = 0; | 300 int64 timestamp_internal_value = 0; |
296 if (iterator->ReadInt64(×tamp_internal_value)) { | 301 if (iterator->ReadInt64(×tamp_internal_value)) { |
297 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value); | 302 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value); |
298 } else { | 303 } else { |
299 timestamp_ = base::Time(); | 304 timestamp_ = base::Time(); |
300 } | 305 } |
| 306 |
| 307 if (!iterator->ReadInt(&http_status_code_)) |
| 308 http_status_code_ = 0; |
301 } | 309 } |
302 | 310 |
303 return true; | 311 return true; |
304 } | 312 } |
305 | 313 |
306 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( | 314 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( |
307 int page_id, | 315 int page_id, |
308 content::BrowserContext* browser_context) const { | 316 content::BrowserContext* browser_context) const { |
309 scoped_ptr<NavigationEntry> entry( | 317 scoped_ptr<NavigationEntry> entry( |
310 content::NavigationController::CreateNavigationEntry( | 318 content::NavigationController::CreateNavigationEntry( |
311 virtual_url_, | 319 virtual_url_, |
312 referrer_, | 320 referrer_, |
313 // Use a transition type of reload so that we don't incorrectly | 321 // Use a transition type of reload so that we don't incorrectly |
314 // increase the typed count. | 322 // increase the typed count. |
315 content::PAGE_TRANSITION_RELOAD, | 323 content::PAGE_TRANSITION_RELOAD, |
316 false, | 324 false, |
317 // The extra headers are not sync'ed across sessions. | 325 // The extra headers are not sync'ed across sessions. |
318 std::string(), | 326 std::string(), |
319 browser_context)); | 327 browser_context)); |
320 | 328 |
321 entry->SetTitle(title_); | 329 entry->SetTitle(title_); |
322 entry->SetContentState(content_state_); | 330 entry->SetContentState(content_state_); |
323 entry->SetPageID(page_id); | 331 entry->SetPageID(page_id); |
324 entry->SetHasPostData(has_post_data_); | 332 entry->SetHasPostData(has_post_data_); |
325 entry->SetPostID(post_id_); | 333 entry->SetPostID(post_id_); |
326 entry->SetOriginalRequestURL(original_request_url_); | 334 entry->SetOriginalRequestURL(original_request_url_); |
327 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 335 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
328 entry->SetTimestamp(timestamp_); | 336 entry->SetTimestamp(timestamp_); |
| 337 entry->SetHttpStatusCode(http_status_code_); |
329 | 338 |
330 return entry.Pass(); | 339 return entry.Pass(); |
331 } | 340 } |
332 | 341 |
333 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 342 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
334 // See http://crbug.com/67068. | 343 // See http://crbug.com/67068. |
335 sync_pb::TabNavigation TabNavigation::ToSyncData() const { | 344 sync_pb::TabNavigation TabNavigation::ToSyncData() const { |
336 sync_pb::TabNavigation sync_data; | 345 sync_pb::TabNavigation sync_data; |
337 sync_data.set_virtual_url(virtual_url_.spec()); | 346 sync_data.set_virtual_url(virtual_url_.spec()); |
338 // FIXME(zea): Support referrer policy? | 347 // FIXME(zea): Support referrer policy? |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 (transition_type_ & content::PAGE_TRANSITION_HOME_PAGE) != 0); | 419 (transition_type_ & content::PAGE_TRANSITION_HOME_PAGE) != 0); |
411 sync_data.set_navigation_chain_start( | 420 sync_data.set_navigation_chain_start( |
412 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0); | 421 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0); |
413 sync_data.set_navigation_chain_end( | 422 sync_data.set_navigation_chain_end( |
414 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0); | 423 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0); |
415 | 424 |
416 sync_data.set_unique_id(unique_id_); | 425 sync_data.set_unique_id(unique_id_); |
417 // TODO(akalin): Don't lose resolution, i.e. define a new timestamp | 426 // TODO(akalin): Don't lose resolution, i.e. define a new timestamp |
418 // field with microsecond resolution and use that. | 427 // field with microsecond resolution and use that. |
419 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); | 428 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); |
| 429 sync_data.set_http_status_code(http_status_code_); |
420 | 430 |
421 return sync_data; | 431 return sync_data; |
422 } | 432 } |
423 | 433 |
424 // static | 434 // static |
425 std::vector<NavigationEntry*> | 435 std::vector<NavigationEntry*> |
426 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 436 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
427 const std::vector<TabNavigation>& navigations, | 437 const std::vector<TabNavigation>& navigations, |
428 content::BrowserContext* browser_context) { | 438 content::BrowserContext* browser_context) { |
429 int page_id = 0; | 439 int page_id = 0; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 SessionWindow::SessionWindow() | 496 SessionWindow::SessionWindow() |
487 : selected_tab_index(-1), | 497 : selected_tab_index(-1), |
488 type(Browser::TYPE_TABBED), | 498 type(Browser::TYPE_TABBED), |
489 is_constrained(true), | 499 is_constrained(true), |
490 show_state(ui::SHOW_STATE_DEFAULT) { | 500 show_state(ui::SHOW_STATE_DEFAULT) { |
491 } | 501 } |
492 | 502 |
493 SessionWindow::~SessionWindow() { | 503 SessionWindow::~SessionWindow() { |
494 STLDeleteElements(&tabs); | 504 STLDeleteElements(&tabs); |
495 } | 505 } |
OLD | NEW |