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" | |
| 8 #include "base/pickle.h" | |
| 9 #include "base/stl_util.h" | |
| 7 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/sessions/session_command.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "sync/util/time.h" | |
| 17 #include "webkit/glue/webkit_glue.h" | |
| 12 | 18 |
| 13 using content::NavigationEntry; | 19 using content::NavigationEntry; |
| 14 | 20 |
| 15 // TabNavigation -------------------------------------------------------------- | 21 // TabNavigation -------------------------------------------------------------- |
| 16 | 22 |
| 17 TabNavigation::TabNavigation() | 23 TabNavigation::TabNavigation() |
| 18 : transition_(content::PAGE_TRANSITION_TYPED), | 24 : index_(-1), |
| 19 type_mask_(0), | 25 unique_id_(0), |
| 26 transition_type_(content::PAGE_TRANSITION_TYPED), | |
| 27 has_post_data_(false), | |
| 20 post_id_(-1), | 28 post_id_(-1), |
| 21 index_(-1), | 29 is_overriding_user_agent_(false) {} |
| 22 is_overriding_user_agent_(false) { | 30 |
| 23 } | 31 TabNavigation::~TabNavigation() {} |
| 24 | |
| 25 TabNavigation::TabNavigation(int index, | |
| 26 const GURL& virtual_url, | |
| 27 const content::Referrer& referrer, | |
| 28 const string16& title, | |
| 29 const std::string& state, | |
| 30 content::PageTransition transition) | |
| 31 : virtual_url_(virtual_url), | |
| 32 referrer_(referrer), | |
| 33 title_(title), | |
| 34 state_(state), | |
| 35 transition_(transition), | |
| 36 type_mask_(0), | |
| 37 post_id_(-1), | |
| 38 index_(index), | |
| 39 is_overriding_user_agent_(false) { | |
| 40 } | |
| 41 | |
| 42 TabNavigation::TabNavigation(const TabNavigation& tab) | |
| 43 : virtual_url_(tab.virtual_url_), | |
| 44 referrer_(tab.referrer_), | |
| 45 title_(tab.title_), | |
| 46 state_(tab.state_), | |
| 47 transition_(tab.transition_), | |
| 48 type_mask_(tab.type_mask_), | |
| 49 post_id_(-1), | |
| 50 index_(tab.index_), | |
| 51 original_request_url_(tab.original_request_url_), | |
| 52 is_overriding_user_agent_(tab.is_overriding_user_agent_) { | |
| 53 } | |
| 54 | |
| 55 TabNavigation::~TabNavigation() { | |
| 56 } | |
| 57 | |
| 58 TabNavigation& TabNavigation::operator=(const TabNavigation& tab) { | |
| 59 virtual_url_ = tab.virtual_url_; | |
| 60 referrer_ = tab.referrer_; | |
| 61 title_ = tab.title_; | |
| 62 state_ = tab.state_; | |
| 63 transition_ = tab.transition_; | |
| 64 type_mask_ = tab.type_mask_; | |
| 65 post_id_ = tab.post_id_; | |
| 66 index_ = tab.index_; | |
| 67 original_request_url_ = tab.original_request_url_; | |
| 68 is_overriding_user_agent_ = tab.is_overriding_user_agent_; | |
| 69 return *this; | |
| 70 } | |
| 71 | 32 |
| 72 // static | 33 // static |
| 73 NavigationEntry* TabNavigation::ToNavigationEntry( | 34 TabNavigation TabNavigation::FromNavigationEntry( |
| 74 int page_id, Profile *profile) const { | 35 int index, |
| 75 NavigationEntry* entry = content::NavigationController::CreateNavigationEntry( | 36 const NavigationEntry& entry, |
| 76 virtual_url_, | 37 base::Time timestamp) { |
| 77 referrer_, | 38 TabNavigation navigation; |
| 78 // Use a transition type of reload so that we don't incorrectly | 39 navigation.index_ = index; |
| 79 // increase the typed count. | 40 navigation.unique_id_ = entry.GetUniqueID(); |
| 80 content::PAGE_TRANSITION_RELOAD, | 41 navigation.referrer_ = entry.GetReferrer(); |
| 81 false, | 42 navigation.virtual_url_ = entry.GetVirtualURL(); |
| 82 // The extra headers are not sync'ed across sessions. | 43 navigation.title_ = entry.GetTitle(); |
| 83 std::string(), | 44 navigation.content_state_ = entry.GetContentState(); |
| 84 profile); | 45 navigation.transition_type_ = entry.GetTransitionType(); |
| 85 | 46 navigation.has_post_data_ = entry.GetHasPostData(); |
| 47 navigation.post_id_ = entry.GetPostID(); | |
| 48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); | |
| 49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | |
| 50 navigation.timestamp_ = timestamp; | |
| 51 return navigation; | |
| 52 } | |
| 53 | |
| 54 TabNavigation TabNavigation::FromSyncData( | |
| 55 int index, | |
| 56 const sync_pb::TabNavigation& specifics) { | |
| 57 TabNavigation navigation; | |
| 58 navigation.index_ = index; | |
| 59 if (specifics.has_unique_id()) { | |
| 60 navigation.unique_id_ = specifics.unique_id(); | |
| 61 } | |
| 62 if (specifics.has_referrer()) { | |
| 63 navigation.referrer_ = | |
| 64 content::Referrer(GURL(specifics.referrer()), | |
| 65 WebKit::WebReferrerPolicyDefault); | |
| 66 } | |
| 67 if (specifics.has_virtual_url()) | |
| 68 navigation.virtual_url_ = GURL(specifics.virtual_url()); | |
| 69 if (specifics.has_title()) | |
| 70 navigation.title_ = UTF8ToUTF16(specifics.title()); | |
| 71 if (specifics.has_state()) | |
| 72 navigation.content_state_ = specifics.state(); | |
| 73 navigation.transition_type_ = content::PAGE_TRANSITION_LINK; | |
| 74 if (specifics.has_page_transition() || | |
| 75 specifics.has_navigation_qualifier()) { | |
| 76 switch (specifics.page_transition()) { | |
| 77 case sync_pb::SyncEnums_PageTransition_LINK: | |
| 78 navigation.transition_type_ = content::PAGE_TRANSITION_LINK; | |
| 79 break; | |
| 80 case sync_pb::SyncEnums_PageTransition_TYPED: | |
| 81 navigation.transition_type_ = content::PAGE_TRANSITION_TYPED; | |
| 82 break; | |
| 83 case sync_pb::SyncEnums_PageTransition_AUTO_BOOKMARK: | |
| 84 navigation.transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK; | |
| 85 break; | |
| 86 case sync_pb::SyncEnums_PageTransition_AUTO_SUBFRAME: | |
| 87 navigation.transition_type_ = content::PAGE_TRANSITION_AUTO_SUBFRAME; | |
| 88 break; | |
| 89 case sync_pb::SyncEnums_PageTransition_MANUAL_SUBFRAME: | |
| 90 navigation.transition_type_ = content::PAGE_TRANSITION_MANUAL_SUBFRAME; | |
| 91 break; | |
| 92 case sync_pb::SyncEnums_PageTransition_GENERATED: | |
| 93 navigation.transition_type_ = content::PAGE_TRANSITION_GENERATED; | |
| 94 break; | |
| 95 case sync_pb::SyncEnums_PageTransition_AUTO_TOPLEVEL: | |
| 96 navigation.transition_type_ = content::PAGE_TRANSITION_AUTO_TOPLEVEL; | |
| 97 break; | |
| 98 case sync_pb::SyncEnums_PageTransition_FORM_SUBMIT: | |
| 99 navigation.transition_type_ = content::PAGE_TRANSITION_FORM_SUBMIT; | |
| 100 break; | |
| 101 case sync_pb::SyncEnums_PageTransition_RELOAD: | |
| 102 navigation.transition_type_ = content::PAGE_TRANSITION_RELOAD; | |
| 103 break; | |
| 104 case sync_pb::SyncEnums_PageTransition_KEYWORD: | |
| 105 navigation.transition_type_ = content::PAGE_TRANSITION_KEYWORD; | |
| 106 break; | |
| 107 case sync_pb::SyncEnums_PageTransition_KEYWORD_GENERATED: | |
| 108 navigation.transition_type_ = | |
| 109 content::PAGE_TRANSITION_KEYWORD_GENERATED; | |
| 110 break; | |
| 111 case sync_pb::SyncEnums_PageTransition_CHAIN_START: | |
| 112 navigation.transition_type_ = content::PAGE_TRANSITION_CHAIN_START; | |
| 113 break; | |
| 114 case sync_pb::SyncEnums_PageTransition_CHAIN_END: | |
| 115 navigation.transition_type_ = content::PAGE_TRANSITION_CHAIN_END; | |
| 116 break; | |
| 117 default: | |
| 118 switch (specifics.navigation_qualifier()) { | |
| 119 case sync_pb::SyncEnums_PageTransitionQualifier_CLIENT_REDIRECT: | |
| 120 navigation.transition_type_ = | |
| 121 content::PAGE_TRANSITION_CLIENT_REDIRECT; | |
| 122 break; | |
| 123 case sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT: | |
| 124 navigation.transition_type_ = | |
| 125 content::PAGE_TRANSITION_SERVER_REDIRECT; | |
| 126 break; | |
| 127 default: | |
| 128 navigation.transition_type_ = content::PAGE_TRANSITION_TYPED; | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 if (specifics.has_timestamp()) { | |
| 133 navigation.timestamp_ = syncer::ProtoTimeToTime(specifics.timestamp()); | |
| 134 } | |
| 135 return navigation; | |
| 136 } | |
| 137 | |
| 138 namespace { | |
| 139 | |
| 140 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to | |
| 141 // |pickle|, if and only if |str| fits within (|max_bytes| - | |
| 142 // |*bytes_written|). |bytes_written| is incremented to reflect the | |
| 143 // data written. | |
| 144 // | |
| 145 // TODO(akalin): Unify this with the same function in | |
| 146 // base_session_service.cc. | |
| 147 void WriteStringToPickle(Pickle* pickle, int* bytes_written, int max_bytes, | |
|
sky
2012/09/17 14:03:36
Each param on its own line. Any how about a templa
akalin
2012/09/17 23:24:32
Put them on their own lines. Can't template, sinc
| |
| 148 const std::string& str) { | |
| 149 int num_bytes = str.size() * sizeof(char); | |
| 150 if (*bytes_written + num_bytes < max_bytes) { | |
| 151 *bytes_written += num_bytes; | |
| 152 pickle->WriteString(str); | |
| 153 } else { | |
| 154 pickle->WriteString(std::string()); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 // string16 version of WriteStringToPickle. | |
| 159 // | |
| 160 // TODO(akalin): Unify this, too. | |
| 161 void WriteString16ToPickle(Pickle* pickle, int* bytes_written, int max_bytes, | |
| 162 const string16& str) { | |
| 163 int num_bytes = str.size() * sizeof(char16); | |
| 164 if (*bytes_written + num_bytes < max_bytes) { | |
| 165 *bytes_written += num_bytes; | |
| 166 pickle->WriteString16(str); | |
| 167 } else { | |
| 168 pickle->WriteString16(string16()); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 // A mask used for arbitrary boolean values needed to represent a | |
| 173 // NavigationEntry. Currently only contains HAS_POST_DATA. | |
| 174 // | |
| 175 // NOTE(akalin): We may want to just serialize |has_post_data_| | |
| 176 // directly. Other bools (|is_overriding_user_agent_|) haven't been | |
| 177 // added to this mask. | |
| 178 enum TypeMask { | |
| 179 HAS_POST_DATA = 1 | |
| 180 }; | |
| 181 | |
| 182 } // namespace | |
| 183 | |
| 184 // Pickle order: | |
| 185 // | |
| 186 // index_ | |
| 187 // virtual_url_ | |
| 188 // title_ | |
| 189 // content_state_ | |
| 190 // transition_type_ | |
| 191 // | |
| 192 // Added on later: | |
| 193 // | |
| 194 // type_mask (has_post_data_) | |
| 195 // referrer_ | |
| 196 // original_request_url_ | |
| 197 // is_overriding_user_agent_ | |
| 198 | |
| 199 void TabNavigation::WriteToPickle(Pickle* pickle) const { | |
| 200 pickle->WriteInt(index_); | |
| 201 | |
| 202 // We only allow navigations up to 63k (which should be completely | |
| 203 // reasonable). On the off chance we get one that is too big, try to | |
| 204 // keep the url. | |
| 205 | |
| 206 // Bound the string data (which is variable length) to | |
| 207 // |max_state_size bytes| bytes. | |
| 208 static const size_t max_state_size = | |
| 209 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | |
| 210 int bytes_written = 0; | |
| 211 | |
| 212 WriteStringToPickle(pickle, &bytes_written, max_state_size, | |
| 213 virtual_url_.spec()); | |
| 214 | |
| 215 WriteString16ToPickle(pickle, &bytes_written, max_state_size, title_); | |
| 216 | |
| 217 std::string content_state = content_state_; | |
| 218 if (has_post_data_) { | |
| 219 content_state = | |
| 220 webkit_glue::RemovePasswordDataFromHistoryState(content_state); | |
| 221 } | |
| 222 WriteStringToPickle(pickle, &bytes_written, max_state_size, content_state); | |
| 223 | |
| 224 pickle->WriteInt(transition_type_); | |
| 225 | |
| 226 int type_mask = 0; | |
|
sky
2012/09/17 14:03:36
nit: type_mask = has_post_data ? HAS_POST_DATA : 0
akalin
2012/09/17 23:24:32
Done.
| |
| 227 if (has_post_data_) { | |
|
sky
2012/09/17 14:03:36
no {}
akalin
2012/09/17 23:24:32
moot
| |
| 228 type_mask |= HAS_POST_DATA; | |
| 229 } | |
| 230 pickle->WriteInt(type_mask); | |
| 231 | |
| 232 WriteStringToPickle( | |
| 233 pickle, &bytes_written, max_state_size, | |
| 234 referrer_.url.is_valid() ? referrer_.url.spec() : std::string()); | |
| 235 | |
| 236 pickle->WriteInt(referrer_.policy); | |
| 237 | |
| 238 // Save info required to override the user agent. | |
| 239 WriteStringToPickle( | |
| 240 pickle, &bytes_written, max_state_size, | |
| 241 original_request_url_.is_valid() ? | |
| 242 original_request_url_.spec() : std::string()); | |
| 243 pickle->WriteBool(is_overriding_user_agent_); | |
| 244 | |
| 245 // TODO(akalin): Persist timestamp. | |
| 246 } | |
| 247 | |
| 248 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { | |
| 249 *this = TabNavigation(); | |
| 250 std::string virtual_url_spec; | |
| 251 int transition_type_int = 0; | |
| 252 if (!iterator->ReadInt(&index_) || | |
| 253 !iterator->ReadString(&virtual_url_spec) || | |
| 254 !iterator->ReadString16(&title_) || | |
| 255 !iterator->ReadString(&content_state_) || | |
| 256 !iterator->ReadInt(&transition_type_int)) | |
| 257 return false; | |
| 258 virtual_url_ = GURL(virtual_url_spec); | |
| 259 transition_type_ = static_cast<content::PageTransition>(transition_type_int); | |
| 260 | |
| 261 // type_mask did not always exist in the written stream. As such, we | |
| 262 // don't fail if it can't be read. | |
| 263 int type_mask = 0; | |
| 264 bool has_type_mask = iterator->ReadInt(&type_mask); | |
| 265 | |
| 266 if (has_type_mask) { | |
| 267 has_post_data_ = type_mask & HAS_POST_DATA; | |
| 268 // the "referrer" property was added after type_mask to the written | |
| 269 // stream. As such, we don't fail if it can't be read. | |
| 270 std::string referrer_spec; | |
| 271 if (!iterator->ReadString(&referrer_spec)) | |
| 272 referrer_spec = std::string(); | |
| 273 // The "referrer policy" property was added even later, so we fall back to | |
| 274 // the default policy if the property is not present. | |
| 275 int policy_int; | |
| 276 WebKit::WebReferrerPolicy policy; | |
| 277 if (iterator->ReadInt(&policy_int)) | |
| 278 policy = static_cast<WebKit::WebReferrerPolicy>(policy_int); | |
| 279 else | |
| 280 policy = WebKit::WebReferrerPolicyDefault; | |
| 281 referrer_ = content::Referrer(GURL(referrer_spec), policy); | |
| 282 | |
| 283 // If the original URL can't be found, leave it empty. | |
| 284 std::string original_request_url_spec; | |
| 285 if (!iterator->ReadString(&original_request_url_spec)) | |
| 286 original_request_url_spec = std::string(); | |
| 287 original_request_url_ = GURL(original_request_url_spec); | |
| 288 | |
| 289 // Default to not overriding the user agent if we don't have info. | |
| 290 if (!iterator->ReadBool(&is_overriding_user_agent_)) { | |
|
sky
2012/09/17 14:03:36
no {}
akalin
2012/09/17 23:24:32
Done.
| |
| 291 is_overriding_user_agent_ = false; | |
| 292 } | |
| 293 } | |
| 294 | |
| 295 // TODO(akalin): Restore timestamp when it is persisted. | |
| 296 return true; | |
| 297 } | |
| 298 | |
| 299 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( | |
| 300 int page_id, | |
| 301 content::BrowserContext* browser_context) const { | |
| 302 scoped_ptr<NavigationEntry> entry( | |
| 303 content::NavigationController::CreateNavigationEntry( | |
| 304 virtual_url_, | |
| 305 referrer_, | |
| 306 // Use a transition type of reload so that we don't incorrectly | |
| 307 // increase the typed count. | |
| 308 content::PAGE_TRANSITION_RELOAD, | |
| 309 false, | |
| 310 // The extra headers are not sync'ed across sessions. | |
| 311 std::string(), | |
| 312 browser_context)); | |
| 313 | |
| 314 entry->SetTitle(title_); | |
| 315 entry->SetContentState(content_state_); | |
| 86 entry->SetPageID(page_id); | 316 entry->SetPageID(page_id); |
| 87 entry->SetTitle(title_); | 317 entry->SetHasPostData(has_post_data_); |
| 88 entry->SetContentState(state_); | |
| 89 entry->SetHasPostData(type_mask_ & TabNavigation::HAS_POST_DATA); | |
| 90 entry->SetPostID(post_id_); | 318 entry->SetPostID(post_id_); |
| 91 entry->SetOriginalRequestURL(original_request_url_); | 319 entry->SetOriginalRequestURL(original_request_url_); |
| 92 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 320 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
| 93 | 321 |
| 94 return entry; | 322 // TODO(akalin): Set |entry|'s timestamp once NavigationEntry has a |
| 95 } | 323 // field for it. |
| 96 | 324 |
| 97 void TabNavigation::SetFromNavigationEntry(const NavigationEntry& entry) { | 325 return entry.Pass(); |
| 98 virtual_url_ = entry.GetVirtualURL(); | 326 } |
| 99 referrer_ = entry.GetReferrer(); | 327 |
| 100 title_ = entry.GetTitle(); | 328 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
| 101 state_ = entry.GetContentState(); | 329 // See http://crbug.com/67068. |
| 102 transition_ = entry.GetTransitionType(); | 330 sync_pb::TabNavigation TabNavigation::ToSyncData() const { |
| 103 type_mask_ = entry.GetHasPostData() ? TabNavigation::HAS_POST_DATA : 0; | 331 sync_pb::TabNavigation sync_data; |
| 104 post_id_ = entry.GetPostID(); | 332 sync_data.set_virtual_url(virtual_url_.spec()); |
| 105 original_request_url_ = entry.GetOriginalRequestURL(); | 333 // FIXME(zea): Support referrer policy? |
| 106 is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 334 sync_data.set_referrer(referrer_.url.spec()); |
| 335 sync_data.set_title(UTF16ToUTF8(title_)); | |
| 336 switch (transition_type_) { | |
| 337 case content::PAGE_TRANSITION_LINK: | |
| 338 sync_data.set_page_transition( | |
| 339 sync_pb::SyncEnums_PageTransition_LINK); | |
| 340 break; | |
| 341 case content::PAGE_TRANSITION_TYPED: | |
| 342 sync_data.set_page_transition( | |
| 343 sync_pb::SyncEnums_PageTransition_TYPED); | |
| 344 break; | |
| 345 case content::PAGE_TRANSITION_AUTO_BOOKMARK: | |
| 346 sync_data.set_page_transition( | |
| 347 sync_pb::SyncEnums_PageTransition_AUTO_BOOKMARK); | |
| 348 break; | |
| 349 case content::PAGE_TRANSITION_AUTO_SUBFRAME: | |
| 350 sync_data.set_page_transition( | |
| 351 sync_pb::SyncEnums_PageTransition_AUTO_SUBFRAME); | |
| 352 break; | |
| 353 case content::PAGE_TRANSITION_MANUAL_SUBFRAME: | |
| 354 sync_data.set_page_transition( | |
| 355 sync_pb::SyncEnums_PageTransition_MANUAL_SUBFRAME); | |
| 356 break; | |
| 357 case content::PAGE_TRANSITION_GENERATED: | |
| 358 sync_data.set_page_transition( | |
| 359 sync_pb::SyncEnums_PageTransition_GENERATED); | |
| 360 break; | |
| 361 case content::PAGE_TRANSITION_AUTO_TOPLEVEL: | |
| 362 sync_data.set_page_transition( | |
| 363 sync_pb::SyncEnums_PageTransition_AUTO_TOPLEVEL); | |
| 364 break; | |
| 365 case content::PAGE_TRANSITION_FORM_SUBMIT: | |
| 366 sync_data.set_page_transition( | |
| 367 sync_pb::SyncEnums_PageTransition_FORM_SUBMIT); | |
| 368 break; | |
| 369 case content::PAGE_TRANSITION_RELOAD: | |
| 370 sync_data.set_page_transition( | |
| 371 sync_pb::SyncEnums_PageTransition_RELOAD); | |
| 372 break; | |
| 373 case content::PAGE_TRANSITION_KEYWORD: | |
| 374 sync_data.set_page_transition( | |
| 375 sync_pb::SyncEnums_PageTransition_KEYWORD); | |
| 376 break; | |
| 377 case content::PAGE_TRANSITION_KEYWORD_GENERATED: | |
| 378 sync_data.set_page_transition( | |
| 379 sync_pb::SyncEnums_PageTransition_KEYWORD_GENERATED); | |
| 380 break; | |
| 381 case content::PAGE_TRANSITION_CHAIN_START: | |
| 382 sync_data.set_page_transition( | |
| 383 sync_pb::SyncEnums_PageTransition_CHAIN_START); | |
| 384 break; | |
| 385 case content::PAGE_TRANSITION_CHAIN_END: | |
| 386 sync_data.set_page_transition( | |
| 387 sync_pb::SyncEnums_PageTransition_CHAIN_END); | |
| 388 break; | |
| 389 case content::PAGE_TRANSITION_CLIENT_REDIRECT: | |
| 390 sync_data.set_navigation_qualifier( | |
| 391 sync_pb::SyncEnums_PageTransitionQualifier_CLIENT_REDIRECT); | |
| 392 break; | |
| 393 case content::PAGE_TRANSITION_SERVER_REDIRECT: | |
| 394 sync_data.set_navigation_qualifier( | |
| 395 sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT); | |
| 396 break; | |
| 397 default: | |
| 398 sync_data.set_page_transition( | |
| 399 sync_pb::SyncEnums_PageTransition_TYPED); | |
| 400 } | |
| 401 sync_data.set_unique_id(unique_id_); | |
| 402 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); | |
| 403 return sync_data; | |
| 107 } | 404 } |
| 108 | 405 |
| 109 // static | 406 // static |
| 110 void TabNavigation::CreateNavigationEntriesFromTabNavigations( | 407 std::vector<NavigationEntry*> |
| 111 Profile* profile, | 408 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 112 const std::vector<TabNavigation>& navigations, | 409 const std::vector<TabNavigation>& navigations, |
| 113 std::vector<NavigationEntry*>* entries) { | 410 content::BrowserContext* browser_context) { |
| 114 int page_id = 0; | 411 int page_id = 0; |
| 115 for (std::vector<TabNavigation>::const_iterator i = | 412 std::vector<NavigationEntry*> entries; |
| 116 navigations.begin(); i != navigations.end(); ++i, ++page_id) { | 413 for (std::vector<TabNavigation>::const_iterator it = navigations.begin(); |
| 117 entries->push_back(i->ToNavigationEntry(page_id, profile)); | 414 it != navigations.end(); ++it) { |
| 118 } | 415 entries.push_back( |
| 416 it->ToNavigationEntry(page_id, browser_context).release()); | |
| 417 ++page_id; | |
| 418 } | |
| 419 return entries; | |
| 420 } | |
| 421 | |
| 422 TabNavigation TabNavigation::CreateForTest(const std::string& virtual_url, | |
| 423 const std::string& title) { | |
| 424 TabNavigation navigation; | |
| 425 navigation.index_ = 0; | |
| 426 navigation.referrer_ = | |
| 427 content::Referrer(GURL("http://www.referrer.com"), | |
| 428 WebKit::WebReferrerPolicyDefault); | |
| 429 navigation.virtual_url_ = GURL(virtual_url); | |
| 430 navigation.title_ = UTF8ToUTF16(title); | |
| 431 navigation.content_state_ = "fake_state"; | |
| 432 navigation.timestamp_ = base::Time::Now(); | |
| 433 return navigation; | |
| 434 } | |
| 435 | |
| 436 const content::Referrer& TabNavigation::GetReferrerForTest() const { | |
| 437 return referrer_; | |
| 438 } | |
| 439 | |
| 440 content::PageTransition TabNavigation::GetTransitionTypeForTest() const { | |
| 441 return transition_type_; | |
| 442 } | |
| 443 | |
| 444 bool TabNavigation::GetHasPostDataForTest() const { | |
| 445 return has_post_data_; | |
| 446 } | |
| 447 | |
| 448 int64 TabNavigation::GetPostIdForTest() const { | |
| 449 return post_id_; | |
| 450 } | |
| 451 | |
| 452 const GURL& TabNavigation::GetOriginalRequestURLForTest() const { | |
| 453 return original_request_url_; | |
| 454 } | |
| 455 | |
| 456 bool TabNavigation::GetIsOverridingUserAgentForTest() const { | |
| 457 return is_overriding_user_agent_; | |
| 458 } | |
| 459 | |
| 460 void TabNavigation::SetContentStateForTest(const std::string& content_state) { | |
| 461 content_state_ = content_state; | |
| 462 } | |
| 463 | |
| 464 void TabNavigation::SetTransitionTypeForTest( | |
| 465 content::PageTransition transition_type) { | |
| 466 transition_type_ = transition_type; | |
| 467 } | |
| 468 | |
| 469 void TabNavigation::SetOriginalRequestURLForTest( | |
| 470 const GURL& original_request_url) { | |
| 471 original_request_url_ = original_request_url; | |
| 472 } | |
| 473 | |
| 474 void TabNavigation::SetHasPostDataForTest(bool has_post_data) { | |
| 475 has_post_data_ = has_post_data; | |
| 476 } | |
| 477 | |
| 478 void TabNavigation::SetIsOverridingUserAgentForTest( | |
| 479 bool is_overriding_user_agent) { | |
| 480 is_overriding_user_agent_ = is_overriding_user_agent; | |
| 119 } | 481 } |
| 120 | 482 |
| 121 // SessionTab ----------------------------------------------------------------- | 483 // SessionTab ----------------------------------------------------------------- |
| 122 | 484 |
| 123 SessionTab::SessionTab() | 485 SessionTab::SessionTab() |
| 124 : tab_visual_index(-1), | 486 : tab_visual_index(-1), |
| 125 current_navigation_index(-1), | 487 current_navigation_index(-1), |
| 126 pinned(false) { | 488 pinned(false) { |
| 127 } | 489 } |
| 128 | 490 |
| 129 SessionTab::~SessionTab() { | 491 SessionTab::~SessionTab() { |
| 130 } | 492 } |
| 131 | 493 |
| 132 // SessionWindow --------------------------------------------------------------- | 494 // SessionWindow --------------------------------------------------------------- |
| 133 | 495 |
| 134 SessionWindow::SessionWindow() | 496 SessionWindow::SessionWindow() |
| 135 : selected_tab_index(-1), | 497 : selected_tab_index(-1), |
| 136 type(Browser::TYPE_TABBED), | 498 type(Browser::TYPE_TABBED), |
| 137 is_constrained(true), | 499 is_constrained(true), |
| 138 show_state(ui::SHOW_STATE_DEFAULT) { | 500 show_state(ui::SHOW_STATE_DEFAULT) { |
| 139 } | 501 } |
| 140 | 502 |
| 141 SessionWindow::~SessionWindow() { | 503 SessionWindow::~SessionWindow() { |
| 142 STLDeleteElements(&tabs); | 504 STLDeleteElements(&tabs); |
| 143 } | 505 } |
| OLD | NEW |