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 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/sessions/session_id.h" | 15 #include "chrome/browser/sessions/session_id.h" |
| 16 #include "components/sessions/serialized_navigation_entry.h" |
16 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
17 #include "content/public/common/referrer.h" | |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "sync/protocol/session_specifics.pb.h" | 19 #include "sync/protocol/session_specifics.pb.h" |
20 #include "ui/base/ui_base_types.h" | 20 #include "ui/base/ui_base_types.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
23 class Pickle; | |
24 class PickleIterator; | |
25 | |
26 namespace content { | 23 namespace content { |
27 class BrowserContext; | 24 class BrowserContext; |
28 class NavigationEntry; | 25 class NavigationEntry; |
29 } | 26 } |
30 | 27 |
31 // TabNavigation ------------------------------------------------------------- | |
32 | |
33 // TabNavigation is a "freeze-dried" version of NavigationEntry. It | |
34 // contains the data needed to restore a NavigationEntry during | |
35 // session restore and tab restore, and it can also be pickled and | |
36 // unpickled. It is also convertible to a sync protocol buffer for | |
37 // session syncing. | |
38 // | |
39 // Default copy constructor and assignment operator welcome. | |
40 class TabNavigation { | |
41 public: | |
42 // Creates an invalid (index < 0) TabNavigation. | |
43 TabNavigation(); | |
44 ~TabNavigation(); | |
45 | |
46 // Construct a TabNavigation for a particular index from the given | |
47 // NavigationEntry. | |
48 static TabNavigation FromNavigationEntry( | |
49 int index, | |
50 const content::NavigationEntry& entry); | |
51 | |
52 // Construct a TabNavigation for a particular index from a sync | |
53 // protocol buffer. Note that the sync protocol buffer doesn't | |
54 // contain all TabNavigation fields. Also, the timestamp of the | |
55 // returned TabNavigation is nulled out, as we assume that the | |
56 // protocol buffer is from a foreign session. | |
57 static TabNavigation FromSyncData( | |
58 int index, | |
59 const sync_pb::TabNavigation& sync_data); | |
60 | |
61 // Note that not all TabNavigation fields are preserved. | |
62 void WriteToPickle(Pickle* pickle) const; | |
63 bool ReadFromPickle(PickleIterator* iterator); | |
64 | |
65 // Convert this TabNavigation into a NavigationEntry with the given | |
66 // page ID and context. The NavigationEntry will have a transition | |
67 // type of PAGE_TRANSITION_RELOAD and a new unique ID. | |
68 scoped_ptr<content::NavigationEntry> ToNavigationEntry( | |
69 int page_id, | |
70 content::BrowserContext* browser_context) const; | |
71 | |
72 // Convert this navigation into its sync protocol buffer equivalent. | |
73 // Note that the protocol buffer doesn't contain all TabNavigation | |
74 // fields. | |
75 sync_pb::TabNavigation ToSyncData() const; | |
76 | |
77 // The index in the NavigationController. This TabNavigation is | |
78 // valid only when the index is non-negative. | |
79 // | |
80 // This is used when determining the selected TabNavigation and only | |
81 // used by SessionService. | |
82 int index() const { return index_; } | |
83 void set_index(int index) { index_ = index; } | |
84 | |
85 // Accessors for some fields taken from NavigationEntry. | |
86 int unique_id() const { return unique_id_; } | |
87 const GURL& virtual_url() const { return virtual_url_; } | |
88 const string16& title() const { return title_; } | |
89 const std::string& content_state() const { return content_state_; } | |
90 const string16& search_terms() const { return search_terms_; } | |
91 const GURL& favicon_url() const { return favicon_url_; } | |
92 | |
93 // Converts a set of TabNavigations into a list of NavigationEntrys | |
94 // with sequential page IDs and the given context. The caller owns | |
95 // the returned NavigationEntrys. | |
96 static std::vector<content::NavigationEntry*> | |
97 CreateNavigationEntriesFromTabNavigations( | |
98 const std::vector<TabNavigation>& navigations, | |
99 content::BrowserContext* browser_context); | |
100 | |
101 private: | |
102 friend struct SessionTypesTestHelper; | |
103 | |
104 // Index in the NavigationController. | |
105 int index_; | |
106 | |
107 // Member variables corresponding to NavigationEntry fields. | |
108 int unique_id_; | |
109 content::Referrer referrer_; | |
110 GURL virtual_url_; | |
111 string16 title_; | |
112 std::string content_state_; | |
113 content::PageTransition transition_type_; | |
114 bool has_post_data_; | |
115 int64 post_id_; | |
116 GURL original_request_url_; | |
117 bool is_overriding_user_agent_; | |
118 base::Time timestamp_; | |
119 string16 search_terms_; | |
120 GURL favicon_url_; | |
121 }; | |
122 | |
123 // SessionTab ---------------------------------------------------------------- | 28 // SessionTab ---------------------------------------------------------------- |
124 | 29 |
125 // SessionTab corresponds to a NavigationController. | 30 // SessionTab corresponds to a NavigationController. |
126 struct SessionTab { | 31 struct SessionTab { |
127 SessionTab(); | 32 SessionTab(); |
128 ~SessionTab(); | 33 ~SessionTab(); |
129 | 34 |
130 // Since the current_navigation_index can be larger than the index for number | 35 // Since the current_navigation_index can be larger than the index for number |
131 // of navigations in the current sessions (chrome://newtab is not stored), we | 36 // of navigations in the current sessions (chrome://newtab is not stored), we |
132 // must perform bounds checking. | 37 // must perform bounds checking. |
133 // Returns a normalized bounds-checked navigation_index. | 38 // Returns a normalized bounds-checked navigation_index. |
134 int normalized_navigation_index() const { | 39 int normalized_navigation_index() const { |
135 return std::max(0, std::min(current_navigation_index, | 40 return std::max(0, std::min(current_navigation_index, |
136 static_cast<int>(navigations.size() - 1))); | 41 static_cast<int>(navigations.size() - 1))); |
137 } | 42 } |
138 | 43 |
139 // Set all the fields of this object from the given sync data and | 44 // Set all the fields of this object from the given sync data and |
140 // timestamp. Uses TabNavigation::FromSyncData to fill | 45 // timestamp. Uses SerializedNavigationEntry::FromSyncData to fill |
141 // |navigations|. Note that the sync protocol buffer doesn't | 46 // |navigations|. Note that the sync protocol buffer doesn't |
142 // contain all TabNavigation fields. | 47 // contain all SerializedNavigationEntry fields. |
143 void SetFromSyncData(const sync_pb::SessionTab& sync_data, | 48 void SetFromSyncData(const sync_pb::SessionTab& sync_data, |
144 base::Time timestamp); | 49 base::Time timestamp); |
145 | 50 |
146 // Convert this object into its sync protocol buffer equivalent. | 51 // Convert this object into its sync protocol buffer equivalent. |
147 // Uses TabNavigation::ToSyncData to convert |navigations|. Note | 52 // Uses SerializedNavigationEntry::ToSyncData to convert |navigations|. Note |
148 // that the protocol buffer doesn't contain all TabNavigation | 53 // that the protocol buffer doesn't contain all SerializedNavigationEntry |
149 // fields, and that the returned protocol buffer doesn't have any | 54 // fields, and that the returned protocol buffer doesn't have any |
150 // favicon data. | 55 // favicon data. |
151 sync_pb::SessionTab ToSyncData() const; | 56 sync_pb::SessionTab ToSyncData() const; |
152 | 57 |
153 // Unique id of the window. | 58 // Unique id of the window. |
154 SessionID window_id; | 59 SessionID window_id; |
155 | 60 |
156 // Unique if of the tab. | 61 // Unique if of the tab. |
157 SessionID tab_id; | 62 SessionID tab_id; |
158 | 63 |
159 // Visual index of the tab within its window. There may be gaps in these | 64 // Visual index of the tab within its window. There may be gaps in these |
160 // values. | 65 // values. |
161 // | 66 // |
162 // NOTE: this is really only useful for the SessionService during | 67 // NOTE: this is really only useful for the SessionService during |
163 // restore, others can likely ignore this and use the order of the | 68 // restore, others can likely ignore this and use the order of the |
164 // tabs in SessionWindow.tabs. | 69 // tabs in SessionWindow.tabs. |
165 int tab_visual_index; | 70 int tab_visual_index; |
166 | 71 |
167 // Identifies the index of the current navigation in navigations. For | 72 // Identifies the index of the current navigation in navigations. For |
168 // example, if this is 2 it means the current navigation is navigations[2]. | 73 // example, if this is 2 it means the current navigation is navigations[2]. |
169 // | 74 // |
170 // NOTE: when the service is creating SessionTabs, initially this | 75 // NOTE: when the service is creating SessionTabs, initially this corresponds |
171 // corresponds to TabNavigation.index, not the index in navigations. When done | 76 // to SerializedNavigationEntry.index, not the index in navigations. When done |
172 // creating though, this is set to the index in navigations. | 77 // creating though, this is set to the index in navigations. |
173 // | 78 // |
174 // NOTE 2: this value can be larger than the size of |navigations|, due to | 79 // NOTE 2: this value can be larger than the size of |navigations|, due to |
175 // only valid url's being stored (ie chrome://newtab is not stored). Bounds | 80 // only valid url's being stored (ie chrome://newtab is not stored). Bounds |
176 // checking must be performed before indexing into |navigations|. | 81 // checking must be performed before indexing into |navigations|. |
177 int current_navigation_index; | 82 int current_navigation_index; |
178 | 83 |
179 // True if the tab is pinned. | 84 // True if the tab is pinned. |
180 bool pinned; | 85 bool pinned; |
181 | 86 |
182 // If non-empty, this tab is an app tab and this is the id of the extension. | 87 // If non-empty, this tab is an app tab and this is the id of the extension. |
183 std::string extension_app_id; | 88 std::string extension_app_id; |
184 | 89 |
185 // If non-empty, this string is used as the user agent whenever the tab's | 90 // If non-empty, this string is used as the user agent whenever the tab's |
186 // NavigationEntries need it overridden. | 91 // NavigationEntries need it overridden. |
187 std::string user_agent_override; | 92 std::string user_agent_override; |
188 | 93 |
189 // Timestamp for when this tab was last modified. | 94 // Timestamp for when this tab was last modified. |
190 base::Time timestamp; | 95 base::Time timestamp; |
191 | 96 |
192 std::vector<TabNavigation> navigations; | 97 std::vector<sessions::SerializedNavigationEntry> navigations; |
193 | 98 |
194 // For reassociating sessionStorage. | 99 // For reassociating sessionStorage. |
195 std::string session_storage_persistent_id; | 100 std::string session_storage_persistent_id; |
196 | 101 |
197 private: | 102 private: |
198 DISALLOW_COPY_AND_ASSIGN(SessionTab); | 103 DISALLOW_COPY_AND_ASSIGN(SessionTab); |
199 }; | 104 }; |
200 | 105 |
201 // SessionWindow ------------------------------------------------------------- | 106 // SessionWindow ------------------------------------------------------------- |
202 | 107 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Is the window maximized, minimized, or normal? | 145 // Is the window maximized, minimized, or normal? |
241 ui::WindowShowState show_state; | 146 ui::WindowShowState show_state; |
242 | 147 |
243 std::string app_name; | 148 std::string app_name; |
244 | 149 |
245 private: | 150 private: |
246 DISALLOW_COPY_AND_ASSIGN(SessionWindow); | 151 DISALLOW_COPY_AND_ASSIGN(SessionWindow); |
247 }; | 152 }; |
248 | 153 |
249 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 154 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
OLD | NEW |