1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/sessions/session_types.h" 6 7 #include "base/string_util.h" 8 #include "chrome/browser/ui/browser.h" 9 #include "content/browser/tab_contents/navigation_controller.h" 10 #include "content/browser/tab_contents/navigation_entry.h" 11 12 // TabNavigation -------------------------------------------------------------- 13 14 TabNavigation::TabNavigation() 15 : transition_(PageTransition::TYPED), 16 type_mask_(0), 17 index_(-1) { 18 } 19 20 TabNavigation::TabNavigation(int index, 21 const GURL& virtual_url, 22 const GURL& referrer, 23 const string16& title, 24 const std::string& state, 25 PageTransition::Type transition) 26 : virtual_url_(virtual_url), 27 referrer_(referrer), 28 title_(title), 29 state_(state), 30 transition_(transition), 31 type_mask_(0), 32 index_(index) { 33 } 34 35 TabNavigation::TabNavigation(const TabNavigation& tab) 36 : virtual_url_(tab.virtual_url_), 37 referrer_(tab.referrer_), 38 title_(tab.title_), 39 state_(tab.state_), 40 transition_(tab.transition_), 41 type_mask_(tab.type_mask_), 42 index_(tab.index_) { 43 } 44 45 TabNavigation::~TabNavigation() { 46 } 47 48 TabNavigation& TabNavigation::operator=(const TabNavigation& tab) { 49 virtual_url_ = tab.virtual_url_; 50 referrer_ = tab.referrer_; 51 title_ = tab.title_; 52 state_ = tab.state_; 53 transition_ = tab.transition_; 54 type_mask_ = tab.type_mask_; 55 index_ = tab.index_; 56 return *this; 57 } 58 59 // static 60 NavigationEntry* TabNavigation::ToNavigationEntry(int page_id, 61 Profile *profile) const { 62 NavigationEntry* entry = NavigationController::CreateNavigationEntry( 63 virtual_url_, 64 referrer_, 65 // Use a transition type of reload so that we don't incorrectly 66 // increase the typed count. 67 PageTransition::RELOAD, 68 profile); 69 70 entry->set_page_id(page_id); 71 entry->set_title(title_); 72 entry->set_content_state(state_); 73 entry->set_has_post_data(type_mask_ & TabNavigation::HAS_POST_DATA); 74 75 return entry; 76 } 77 78 void TabNavigation::SetFromNavigationEntry(const NavigationEntry& entry) { 79 virtual_url_ = entry.virtual_url(); 80 referrer_ = entry.referrer(); 81 title_ = entry.title(); 82 state_ = entry.content_state(); 83 transition_ = entry.transition_type(); 84 type_mask_ = entry.has_post_data() ? TabNavigation::HAS_POST_DATA : 0; 85 } 86 87 // SessionTab ----------------------------------------------------------------- 88 89 SessionTab::SessionTab() 90 : tab_visual_index(-1), 91 current_navigation_index(-1), 92 pinned(false) { 93 } 94 95 SessionTab::~SessionTab() { 96 } 97 98 // SessionWindow --------------------------------------------------------------- 99 100 SessionWindow::SessionWindow() 101 : selected_tab_index(-1), 102 type(Browser::TYPE_NORMAL), 103 is_constrained(true), 104 is_maximized(false) { 105 } 106 107 SessionWindow::~SessionWindow() { 108 STLDeleteElements(&tabs); 109 } 110 111 // ForeignSession -------------------------------------------------------------- 112 113 ForeignSession::ForeignSession() : foreign_session_tag("invalid") { 114 } 115 116 ForeignSession::~ForeignSession() { 117 STLDeleteElements(&windows); 118 } 119 120