1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 7 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/stl_util-inl.h" 13 #include "base/string16.h" 14 #include "base/time.h" 15 #include "chrome/browser/sessions/session_id.h" 16 #include "content/common/page_transition_types.h" 17 #include "googleurl/src/gurl.h" 18 #include "ui/gfx/rect.h" 19 20 class NavigationEntry; 21 class Profile; 22 23 // TabNavigation ------------------------------------------------------------- 24 25 // TabNavigation corresponds to the parts of NavigationEntry needed to restore 26 // the NavigationEntry during session restore and tab restore. 27 // 28 // TabNavigation is cheap and supports copy semantics. 29 class TabNavigation { 30 public: 31 enum TypeMask { 32 HAS_POST_DATA = 1 33 }; 34 35 TabNavigation(); 36 TabNavigation(int index, 37 const GURL& virtual_url, 38 const GURL& referrer, 39 const string16& title, 40 const std::string& state, 41 PageTransition::Type transition); 42 TabNavigation(const TabNavigation& tab); 43 ~TabNavigation(); 44 TabNavigation& operator=(const TabNavigation& tab); 45 46 // Converts this TabNavigation into a NavigationEntry with a page id of 47 // |page_id|. The caller owns the returned NavigationEntry. 48 NavigationEntry* ToNavigationEntry(int page_id, Profile* profile) const; 49 50 // Resets this TabNavigation from |entry|. 51 void SetFromNavigationEntry(const NavigationEntry& entry); 52 53 // Virtual URL of the page. See NavigationEntry::virtual_url() for details. set_virtual_url(const GURL & url)54 void set_virtual_url(const GURL& url) { virtual_url_ = url; } virtual_url()55 const GURL& virtual_url() const { return virtual_url_; } 56 57 // The referrer. referrer()58 const GURL& referrer() const { return referrer_; } 59 60 // The title of the page. title()61 const string16& title() const { return title_; } 62 63 // State bits. state()64 const std::string& state() const { return state_; } 65 66 // Transition type. set_transition(PageTransition::Type transition)67 void set_transition(PageTransition::Type transition) { 68 transition_ = transition; 69 } transition()70 PageTransition::Type transition() const { return transition_; } 71 72 // A mask used for arbitrary boolean values needed to represent a 73 // NavigationEntry. Currently only contains HAS_POST_DATA or 0. set_type_mask(int type_mask)74 void set_type_mask(int type_mask) { type_mask_ = type_mask; } type_mask()75 int type_mask() const { return type_mask_; } 76 77 // The index in the NavigationController. If this is -1, it means this 78 // TabNavigation is bogus. 79 // 80 // This is used when determining the selected TabNavigation and only useful 81 // by BaseSessionService and SessionService. set_index(int index)82 void set_index(int index) { index_ = index; } index()83 int index() const { return index_; } 84 85 private: 86 friend class BaseSessionService; 87 88 GURL virtual_url_; 89 GURL referrer_; 90 string16 title_; 91 std::string state_; 92 PageTransition::Type transition_; 93 int type_mask_; 94 95 int index_; 96 }; 97 98 // SessionTab ---------------------------------------------------------------- 99 100 // SessionTab corresponds to a NavigationController. 101 struct SessionTab { 102 SessionTab(); 103 ~SessionTab(); 104 105 // Unique id of the window. 106 SessionID window_id; 107 108 // Unique if of the tab. 109 SessionID tab_id; 110 111 // Visual index of the tab within its window. There may be gaps in these 112 // values. 113 // 114 // NOTE: this is really only useful for the SessionService during 115 // restore, others can likely ignore this and use the order of the 116 // tabs in SessionWindow.tabs. 117 int tab_visual_index; 118 119 // Identifies the index of the current navigation in navigations. For 120 // example, if this is 2 it means the current navigation is navigations[2]. 121 // 122 // NOTE: when the service is creating SessionTabs, initially this 123 // corresponds to TabNavigation.index, not the index in navigations. When done 124 // creating though, this is set to the index in navigations. 125 // 126 // NOTE 2: this value can be larger than the size of |navigations|, due to 127 // only valid url's being stored (ie chrome://newtab is not stored). Bounds 128 // checking must be performed before indexing into |navigations|. 129 int current_navigation_index; 130 131 // True if the tab is pinned. 132 bool pinned; 133 134 // If non-empty, this tab is an app tab and this is the id of the extension. 135 std::string extension_app_id; 136 137 // Timestamp for when this tab was last modified. 138 base::Time timestamp; 139 140 std::vector<TabNavigation> navigations; 141 142 private: 143 DISALLOW_COPY_AND_ASSIGN(SessionTab); 144 }; 145 146 // SessionWindow ------------------------------------------------------------- 147 148 // Describes a saved window. 149 struct SessionWindow { 150 SessionWindow(); 151 ~SessionWindow(); 152 153 // Identifier of the window. 154 SessionID window_id; 155 156 // Bounds of the window. 157 gfx::Rect bounds; 158 159 // Index of the selected tab in tabs; -1 if no tab is selected. After restore 160 // this value is guaranteed to be a valid index into tabs. 161 // 162 // NOTE: when the service is creating SessionWindows, initially this 163 // corresponds to SessionTab.tab_visual_index, not the index in 164 // tabs. When done creating though, this is set to the index in 165 // tabs. 166 int selected_tab_index; 167 168 // Type of the browser. Currently we only store browsers of type 169 // TYPE_NORMAL and TYPE_POPUP. 170 // This would be Browser::Type, but that would cause a circular dependency. 171 int type; 172 173 // If true, the window is constrained. 174 // 175 // Currently SessionService prunes all constrained windows so that session 176 // restore does not attempt to restore them. 177 bool is_constrained; 178 179 // Timestamp for when this window was last modified. 180 base::Time timestamp; 181 182 // The tabs, ordered by visual order. 183 std::vector<SessionTab*> tabs; 184 185 // Is the window maximized? 186 bool is_maximized; 187 188 private: 189 DISALLOW_COPY_AND_ASSIGN(SessionWindow); 190 }; 191 192 // Defines a foreign session for session sync. A foreign session is a session 193 // on a remote chrome instance. 194 struct ForeignSession { 195 ForeignSession(); 196 ~ForeignSession(); 197 198 // Unique tag for each session. 199 std::string foreign_session_tag; 200 std::vector<SessionWindow*> windows; 201 }; 202 203 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 204