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