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