| 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/instant/instant_controller.h" |
| 12 #include "chrome/browser/sessions/session_command.h" | 13 #include "chrome/browser/sessions/session_command.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 16 #include "sync/util/time.h" | 17 #include "sync/util/time.h" |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h
" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h
" |
| 18 #include "webkit/glue/glue_serialize.h" | 19 #include "webkit/glue/glue_serialize.h" |
| 19 | 20 |
| 20 using content::NavigationEntry; | 21 using content::NavigationEntry; |
| 21 | 22 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 entry.GetExtraData(InstantController::kSearchTermsKey, |
| 53 &navigation.search_terms_); |
| 54 |
| 51 return navigation; | 55 return navigation; |
| 52 } | 56 } |
| 53 | 57 |
| 54 TabNavigation TabNavigation::FromSyncData( | 58 TabNavigation TabNavigation::FromSyncData( |
| 55 int index, | 59 int index, |
| 56 const sync_pb::TabNavigation& sync_data) { | 60 const sync_pb::TabNavigation& sync_data) { |
| 57 TabNavigation navigation; | 61 TabNavigation navigation; |
| 58 navigation.index_ = index; | 62 navigation.index_ = index; |
| 59 navigation.unique_id_ = sync_data.unique_id(); | 63 navigation.unique_id_ = sync_data.unique_id(); |
| 60 navigation.referrer_ = | 64 navigation.referrer_ = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 transition |= content::PAGE_TRANSITION_HOME_PAGE; | 129 transition |= content::PAGE_TRANSITION_HOME_PAGE; |
| 126 if (sync_data.navigation_chain_start()) | 130 if (sync_data.navigation_chain_start()) |
| 127 transition |= content::PAGE_TRANSITION_CHAIN_START; | 131 transition |= content::PAGE_TRANSITION_CHAIN_START; |
| 128 if (sync_data.navigation_chain_end()) | 132 if (sync_data.navigation_chain_end()) |
| 129 transition |= content::PAGE_TRANSITION_CHAIN_END; | 133 transition |= content::PAGE_TRANSITION_CHAIN_END; |
| 130 | 134 |
| 131 navigation.transition_type_ = | 135 navigation.transition_type_ = |
| 132 static_cast<content::PageTransition>(transition); | 136 static_cast<content::PageTransition>(transition); |
| 133 | 137 |
| 134 navigation.timestamp_ = base::Time(); | 138 navigation.timestamp_ = base::Time(); |
| 139 navigation.search_terms_ = UTF8ToUTF16(sync_data.search_terms()); |
| 135 | 140 |
| 136 return navigation; | 141 return navigation; |
| 137 } | 142 } |
| 138 | 143 |
| 139 namespace { | 144 namespace { |
| 140 | 145 |
| 141 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to | 146 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to |
| 142 // |pickle|, if and only if |str| fits within (|max_bytes| - | 147 // |pickle|, if and only if |str| fits within (|max_bytes| - |
| 143 // |*bytes_written|). |bytes_written| is incremented to reflect the | 148 // |*bytes_written|). |bytes_written| is incremented to reflect the |
| 144 // data written. | 149 // data written. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // content_state_ | 199 // content_state_ |
| 195 // transition_type_ | 200 // transition_type_ |
| 196 // | 201 // |
| 197 // Added on later: | 202 // Added on later: |
| 198 // | 203 // |
| 199 // type_mask (has_post_data_) | 204 // type_mask (has_post_data_) |
| 200 // referrer_ | 205 // referrer_ |
| 201 // original_request_url_ | 206 // original_request_url_ |
| 202 // is_overriding_user_agent_ | 207 // is_overriding_user_agent_ |
| 203 // timestamp_ | 208 // timestamp_ |
| 209 // search_terms_ |
| 204 | 210 |
| 205 void TabNavigation::WriteToPickle(Pickle* pickle) const { | 211 void TabNavigation::WriteToPickle(Pickle* pickle) const { |
| 206 pickle->WriteInt(index_); | 212 pickle->WriteInt(index_); |
| 207 | 213 |
| 208 // We only allow navigations up to 63k (which should be completely | 214 // 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 | 215 // reasonable). On the off chance we get one that is too big, try to |
| 210 // keep the url. | 216 // keep the url. |
| 211 | 217 |
| 212 // Bound the string data (which is variable length) to | 218 // Bound the string data (which is variable length) to |
| 213 // |max_state_size bytes| bytes. | 219 // |max_state_size bytes| bytes. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 238 | 244 |
| 239 pickle->WriteInt(referrer_.policy); | 245 pickle->WriteInt(referrer_.policy); |
| 240 | 246 |
| 241 // Save info required to override the user agent. | 247 // Save info required to override the user agent. |
| 242 WriteStringToPickle( | 248 WriteStringToPickle( |
| 243 pickle, &bytes_written, max_state_size, | 249 pickle, &bytes_written, max_state_size, |
| 244 original_request_url_.is_valid() ? | 250 original_request_url_.is_valid() ? |
| 245 original_request_url_.spec() : std::string()); | 251 original_request_url_.spec() : std::string()); |
| 246 pickle->WriteBool(is_overriding_user_agent_); | 252 pickle->WriteBool(is_overriding_user_agent_); |
| 247 pickle->WriteInt64(timestamp_.ToInternalValue()); | 253 pickle->WriteInt64(timestamp_.ToInternalValue()); |
| 254 |
| 255 WriteString16ToPickle(pickle, &bytes_written, max_state_size, search_terms_); |
| 248 } | 256 } |
| 249 | 257 |
| 250 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { | 258 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { |
| 251 *this = TabNavigation(); | 259 *this = TabNavigation(); |
| 252 std::string virtual_url_spec; | 260 std::string virtual_url_spec; |
| 253 int transition_type_int = 0; | 261 int transition_type_int = 0; |
| 254 if (!iterator->ReadInt(&index_) || | 262 if (!iterator->ReadInt(&index_) || |
| 255 !iterator->ReadString(&virtual_url_spec) || | 263 !iterator->ReadString(&virtual_url_spec) || |
| 256 !iterator->ReadString16(&title_) || | 264 !iterator->ReadString16(&title_) || |
| 257 !iterator->ReadString(&content_state_) || | 265 !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. | 299 // Default to not overriding the user agent if we don't have info. |
| 292 if (!iterator->ReadBool(&is_overriding_user_agent_)) | 300 if (!iterator->ReadBool(&is_overriding_user_agent_)) |
| 293 is_overriding_user_agent_ = false; | 301 is_overriding_user_agent_ = false; |
| 294 | 302 |
| 295 int64 timestamp_internal_value = 0; | 303 int64 timestamp_internal_value = 0; |
| 296 if (iterator->ReadInt64(×tamp_internal_value)) { | 304 if (iterator->ReadInt64(×tamp_internal_value)) { |
| 297 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value); | 305 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value); |
| 298 } else { | 306 } else { |
| 299 timestamp_ = base::Time(); | 307 timestamp_ = base::Time(); |
| 300 } | 308 } |
| 309 |
| 310 // If the search terms field can't be found, leave it empty. |
| 311 if (!iterator->ReadString16(&search_terms_)) |
| 312 search_terms_ = string16(); |
| 301 } | 313 } |
| 302 | 314 |
| 303 return true; | 315 return true; |
| 304 } | 316 } |
| 305 | 317 |
| 306 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( | 318 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( |
| 307 int page_id, | 319 int page_id, |
| 308 content::BrowserContext* browser_context) const { | 320 content::BrowserContext* browser_context) const { |
| 309 scoped_ptr<NavigationEntry> entry( | 321 scoped_ptr<NavigationEntry> entry( |
| 310 content::NavigationController::CreateNavigationEntry( | 322 content::NavigationController::CreateNavigationEntry( |
| 311 virtual_url_, | 323 virtual_url_, |
| 312 referrer_, | 324 referrer_, |
| 313 // Use a transition type of reload so that we don't incorrectly | 325 // Use a transition type of reload so that we don't incorrectly |
| 314 // increase the typed count. | 326 // increase the typed count. |
| 315 content::PAGE_TRANSITION_RELOAD, | 327 content::PAGE_TRANSITION_RELOAD, |
| 316 false, | 328 false, |
| 317 // The extra headers are not sync'ed across sessions. | 329 // The extra headers are not sync'ed across sessions. |
| 318 std::string(), | 330 std::string(), |
| 319 browser_context)); | 331 browser_context)); |
| 320 | 332 |
| 321 entry->SetTitle(title_); | 333 entry->SetTitle(title_); |
| 322 entry->SetContentState(content_state_); | 334 entry->SetContentState(content_state_); |
| 323 entry->SetPageID(page_id); | 335 entry->SetPageID(page_id); |
| 324 entry->SetHasPostData(has_post_data_); | 336 entry->SetHasPostData(has_post_data_); |
| 325 entry->SetPostID(post_id_); | 337 entry->SetPostID(post_id_); |
| 326 entry->SetOriginalRequestURL(original_request_url_); | 338 entry->SetOriginalRequestURL(original_request_url_); |
| 327 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 339 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
| 328 entry->SetTimestamp(timestamp_); | 340 entry->SetTimestamp(timestamp_); |
| 341 entry->SetExtraData(InstantController::kSearchTermsKey, search_terms_); |
| 329 | 342 |
| 330 return entry.Pass(); | 343 return entry.Pass(); |
| 331 } | 344 } |
| 332 | 345 |
| 333 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 346 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
| 334 // See http://crbug.com/67068. | 347 // See http://crbug.com/67068. |
| 335 sync_pb::TabNavigation TabNavigation::ToSyncData() const { | 348 sync_pb::TabNavigation TabNavigation::ToSyncData() const { |
| 336 sync_pb::TabNavigation sync_data; | 349 sync_pb::TabNavigation sync_data; |
| 337 sync_data.set_virtual_url(virtual_url_.spec()); | 350 sync_data.set_virtual_url(virtual_url_.spec()); |
| 338 // FIXME(zea): Support referrer policy? | 351 // FIXME(zea): Support referrer policy? |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 sync_data.set_navigation_chain_start( | 424 sync_data.set_navigation_chain_start( |
| 412 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0); | 425 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0); |
| 413 sync_data.set_navigation_chain_end( | 426 sync_data.set_navigation_chain_end( |
| 414 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0); | 427 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0); |
| 415 | 428 |
| 416 sync_data.set_unique_id(unique_id_); | 429 sync_data.set_unique_id(unique_id_); |
| 417 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); | 430 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); |
| 418 // The full-resolution timestamp works as a global ID. | 431 // The full-resolution timestamp works as a global ID. |
| 419 sync_data.set_global_id(timestamp_.ToInternalValue()); | 432 sync_data.set_global_id(timestamp_.ToInternalValue()); |
| 420 | 433 |
| 434 sync_data.set_search_terms(UTF16ToUTF8(search_terms_)); |
| 435 |
| 421 return sync_data; | 436 return sync_data; |
| 422 } | 437 } |
| 423 | 438 |
| 424 // static | 439 // static |
| 425 std::vector<NavigationEntry*> | 440 std::vector<NavigationEntry*> |
| 426 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 441 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 427 const std::vector<TabNavigation>& navigations, | 442 const std::vector<TabNavigation>& navigations, |
| 428 content::BrowserContext* browser_context) { | 443 content::BrowserContext* browser_context) { |
| 429 int page_id = 0; | 444 int page_id = 0; |
| 430 std::vector<NavigationEntry*> entries; | 445 std::vector<NavigationEntry*> entries; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 SessionWindow::SessionWindow() | 501 SessionWindow::SessionWindow() |
| 487 : selected_tab_index(-1), | 502 : selected_tab_index(-1), |
| 488 type(Browser::TYPE_TABBED), | 503 type(Browser::TYPE_TABBED), |
| 489 is_constrained(true), | 504 is_constrained(true), |
| 490 show_state(ui::SHOW_STATE_DEFAULT) { | 505 show_state(ui::SHOW_STATE_DEFAULT) { |
| 491 } | 506 } |
| 492 | 507 |
| 493 SessionWindow::~SessionWindow() { | 508 SessionWindow::~SessionWindow() { |
| 494 STLDeleteElements(&tabs); | 509 STLDeleteElements(&tabs); |
| 495 } | 510 } |
| OLD | NEW |