Chromium Code Reviews| 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" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 // static | 34 // static |
| 35 TabNavigation TabNavigation::FromNavigationEntry( | 35 TabNavigation TabNavigation::FromNavigationEntry( |
| 36 int index, | 36 int index, |
| 37 const NavigationEntry& entry) { | 37 const NavigationEntry& entry) { |
| 38 TabNavigation navigation; | 38 TabNavigation navigation; |
| 39 navigation.index_ = index; | 39 navigation.index_ = index; |
| 40 navigation.unique_id_ = entry.GetUniqueID(); | 40 navigation.unique_id_ = entry.GetUniqueID(); |
| 41 navigation.referrer_ = entry.GetReferrer(); | 41 navigation.referrer_ = entry.GetReferrer(); |
| 42 navigation.virtual_url_ = entry.GetVirtualURL(); | 42 navigation.virtual_url_ = entry.GetVirtualURL(); |
| 43 navigation.title_ = entry.GetTitle(); | 43 navigation.title_ = entry.GetTitle(); |
| 44 navigation.search_terms_ = entry.GetSearchTerms(); | |
| 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(); |
| 51 return navigation; | 52 return navigation; |
| 52 } | 53 } |
| 53 | 54 |
| 54 TabNavigation TabNavigation::FromSyncData( | 55 TabNavigation TabNavigation::FromSyncData( |
| 55 int index, | 56 int index, |
| 56 const sync_pb::TabNavigation& sync_data) { | 57 const sync_pb::TabNavigation& sync_data) { |
| 57 TabNavigation navigation; | 58 TabNavigation navigation; |
| 58 navigation.index_ = index; | 59 navigation.index_ = index; |
| 59 navigation.unique_id_ = sync_data.unique_id(); | 60 navigation.unique_id_ = sync_data.unique_id(); |
| 60 navigation.referrer_ = | 61 navigation.referrer_ = |
| 61 content::Referrer(GURL(sync_data.referrer()), | 62 content::Referrer(GURL(sync_data.referrer()), |
| 62 WebKit::WebReferrerPolicyDefault); | 63 WebKit::WebReferrerPolicyDefault); |
| 63 navigation.virtual_url_ = GURL(sync_data.virtual_url()); | 64 navigation.virtual_url_ = GURL(sync_data.virtual_url()); |
| 64 navigation.title_ = UTF8ToUTF16(sync_data.title()); | 65 navigation.title_ = UTF8ToUTF16(sync_data.title()); |
| 66 navigation.search_terms_ = UTF8ToUTF16(sync_data.search_terms()); | |
| 65 navigation.content_state_ = sync_data.state(); | 67 navigation.content_state_ = sync_data.state(); |
| 66 | 68 |
| 67 uint32 transition = 0; | 69 uint32 transition = 0; |
| 68 if (sync_data.has_page_transition()) { | 70 if (sync_data.has_page_transition()) { |
| 69 switch (sync_data.page_transition()) { | 71 switch (sync_data.page_transition()) { |
| 70 case sync_pb::SyncEnums_PageTransition_LINK: | 72 case sync_pb::SyncEnums_PageTransition_LINK: |
| 71 transition = content::PAGE_TRANSITION_LINK; | 73 transition = content::PAGE_TRANSITION_LINK; |
| 72 break; | 74 break; |
| 73 case sync_pb::SyncEnums_PageTransition_TYPED: | 75 case sync_pb::SyncEnums_PageTransition_TYPED: |
| 74 transition = content::PAGE_TRANSITION_TYPED; | 76 transition = content::PAGE_TRANSITION_TYPED; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 HAS_POST_DATA = 1 | 186 HAS_POST_DATA = 1 |
| 185 }; | 187 }; |
| 186 | 188 |
| 187 } // namespace | 189 } // namespace |
| 188 | 190 |
| 189 // Pickle order: | 191 // Pickle order: |
| 190 // | 192 // |
| 191 // index_ | 193 // index_ |
| 192 // virtual_url_ | 194 // virtual_url_ |
| 193 // title_ | 195 // title_ |
| 196 // search_terms_ | |
| 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_ |
| 204 | 207 |
| 205 void TabNavigation::WriteToPickle(Pickle* pickle) const { | 208 void TabNavigation::WriteToPickle(Pickle* pickle) const { |
| 206 pickle->WriteInt(index_); | 209 pickle->WriteInt(index_); |
| 207 | 210 |
| 208 // We only allow navigations up to 63k (which should be completely | 211 // 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 | 212 // reasonable). On the off chance we get one that is too big, try to |
| 210 // keep the url. | 213 // keep the url. |
| 211 | 214 |
| 212 // Bound the string data (which is variable length) to | 215 // Bound the string data (which is variable length) to |
| 213 // |max_state_size bytes| bytes. | 216 // |max_state_size bytes| bytes. |
| 214 static const size_t max_state_size = | 217 static const size_t max_state_size = |
| 215 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 218 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
| 216 int bytes_written = 0; | 219 int bytes_written = 0; |
| 217 | 220 |
| 218 WriteStringToPickle(pickle, &bytes_written, max_state_size, | 221 WriteStringToPickle(pickle, &bytes_written, max_state_size, |
| 219 virtual_url_.spec()); | 222 virtual_url_.spec()); |
| 220 | 223 |
| 221 WriteString16ToPickle(pickle, &bytes_written, max_state_size, title_); | 224 WriteString16ToPickle(pickle, &bytes_written, max_state_size, title_); |
| 222 | 225 |
| 226 WriteString16ToPickle(pickle, &bytes_written, max_state_size, search_terms_); | |
| 227 | |
| 223 std::string content_state = content_state_; | 228 std::string content_state = content_state_; |
| 224 if (has_post_data_) { | 229 if (has_post_data_) { |
| 225 content_state = | 230 content_state = |
| 226 webkit_glue::RemovePasswordDataFromHistoryState(content_state); | 231 webkit_glue::RemovePasswordDataFromHistoryState(content_state); |
| 227 } | 232 } |
| 228 WriteStringToPickle(pickle, &bytes_written, max_state_size, content_state); | 233 WriteStringToPickle(pickle, &bytes_written, max_state_size, content_state); |
| 229 | 234 |
| 230 pickle->WriteInt(transition_type_); | 235 pickle->WriteInt(transition_type_); |
| 231 | 236 |
| 232 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0; | 237 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 247 pickle->WriteInt64(timestamp_.ToInternalValue()); | 252 pickle->WriteInt64(timestamp_.ToInternalValue()); |
| 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_) || |
| 262 !iterator->ReadString16(&search_terms_) || | |
|
akalin
2012/12/05 19:40:27
this isn't backwards compatible. it needs to go l
Mathieu
2012/12/05 20:42:16
Done. Let me know if this is the way to do it.
| |
| 257 !iterator->ReadString(&content_state_) || | 263 !iterator->ReadString(&content_state_) || |
| 258 !iterator->ReadInt(&transition_type_int)) | 264 !iterator->ReadInt(&transition_type_int)) |
| 259 return false; | 265 return false; |
| 260 virtual_url_ = GURL(virtual_url_spec); | 266 virtual_url_ = GURL(virtual_url_spec); |
| 261 transition_type_ = static_cast<content::PageTransition>(transition_type_int); | 267 transition_type_ = static_cast<content::PageTransition>(transition_type_int); |
| 262 | 268 |
| 263 // type_mask did not always exist in the written stream. As such, we | 269 // type_mask did not always exist in the written stream. As such, we |
| 264 // don't fail if it can't be read. | 270 // don't fail if it can't be read. |
| 265 int type_mask = 0; | 271 int type_mask = 0; |
| 266 bool has_type_mask = iterator->ReadInt(&type_mask); | 272 bool has_type_mask = iterator->ReadInt(&type_mask); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 referrer_, | 318 referrer_, |
| 313 // Use a transition type of reload so that we don't incorrectly | 319 // Use a transition type of reload so that we don't incorrectly |
| 314 // increase the typed count. | 320 // increase the typed count. |
| 315 content::PAGE_TRANSITION_RELOAD, | 321 content::PAGE_TRANSITION_RELOAD, |
| 316 false, | 322 false, |
| 317 // The extra headers are not sync'ed across sessions. | 323 // The extra headers are not sync'ed across sessions. |
| 318 std::string(), | 324 std::string(), |
| 319 browser_context)); | 325 browser_context)); |
| 320 | 326 |
| 321 entry->SetTitle(title_); | 327 entry->SetTitle(title_); |
| 328 entry->SetSearchTerms(search_terms_); | |
| 322 entry->SetContentState(content_state_); | 329 entry->SetContentState(content_state_); |
| 323 entry->SetPageID(page_id); | 330 entry->SetPageID(page_id); |
| 324 entry->SetHasPostData(has_post_data_); | 331 entry->SetHasPostData(has_post_data_); |
| 325 entry->SetPostID(post_id_); | 332 entry->SetPostID(post_id_); |
| 326 entry->SetOriginalRequestURL(original_request_url_); | 333 entry->SetOriginalRequestURL(original_request_url_); |
| 327 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 334 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
| 328 entry->SetTimestamp(timestamp_); | 335 entry->SetTimestamp(timestamp_); |
| 329 | 336 |
| 330 return entry.Pass(); | 337 return entry.Pass(); |
| 331 } | 338 } |
| 332 | 339 |
| 333 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 340 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
| 334 // See http://crbug.com/67068. | 341 // See http://crbug.com/67068. |
| 335 sync_pb::TabNavigation TabNavigation::ToSyncData() const { | 342 sync_pb::TabNavigation TabNavigation::ToSyncData() const { |
| 336 sync_pb::TabNavigation sync_data; | 343 sync_pb::TabNavigation sync_data; |
| 337 sync_data.set_virtual_url(virtual_url_.spec()); | 344 sync_data.set_virtual_url(virtual_url_.spec()); |
| 338 // FIXME(zea): Support referrer policy? | 345 // FIXME(zea): Support referrer policy? |
| 339 sync_data.set_referrer(referrer_.url.spec()); | 346 sync_data.set_referrer(referrer_.url.spec()); |
| 340 sync_data.set_title(UTF16ToUTF8(title_)); | 347 sync_data.set_title(UTF16ToUTF8(title_)); |
| 348 sync_data.set_search_terms(UTF16ToUTF8(search_terms_)) | |
| 341 | 349 |
| 342 // Page transition core. | 350 // Page transition core. |
| 343 COMPILE_ASSERT(content::PAGE_TRANSITION_LAST_CORE == | 351 COMPILE_ASSERT(content::PAGE_TRANSITION_LAST_CORE == |
| 344 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 352 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
| 345 PageTransitionCoreBounds); | 353 PageTransitionCoreBounds); |
| 346 switch (PageTransitionStripQualifier(transition_type_)) { | 354 switch (PageTransitionStripQualifier(transition_type_)) { |
| 347 case content::PAGE_TRANSITION_LINK: | 355 case content::PAGE_TRANSITION_LINK: |
| 348 sync_data.set_page_transition( | 356 sync_data.set_page_transition( |
| 349 sync_pb::SyncEnums_PageTransition_LINK); | 357 sync_pb::SyncEnums_PageTransition_LINK); |
| 350 break; | 358 break; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 SessionWindow::SessionWindow() | 494 SessionWindow::SessionWindow() |
| 487 : selected_tab_index(-1), | 495 : selected_tab_index(-1), |
| 488 type(Browser::TYPE_TABBED), | 496 type(Browser::TYPE_TABBED), |
| 489 is_constrained(true), | 497 is_constrained(true), |
| 490 show_state(ui::SHOW_STATE_DEFAULT) { | 498 show_state(ui::SHOW_STATE_DEFAULT) { |
| 491 } | 499 } |
| 492 | 500 |
| 493 SessionWindow::~SessionWindow() { | 501 SessionWindow::~SessionWindow() { |
| 494 STLDeleteElements(&tabs); | 502 STLDeleteElements(&tabs); |
| 495 } | 503 } |
| OLD | NEW |