| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/stl_util.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "content/public/common/page_transition_types.h" | 15 #include "content/public/common/page_transition_types.h" |
| 16 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "sync/protocol/session_specifics.pb.h" |
| 18 #include "ui/base/ui_base_types.h" | 19 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 20 | 21 |
| 21 class Profile; | 22 class Pickle; |
| 23 class PickleIterator; |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 26 class BrowserContext; |
| 24 class NavigationEntry; | 27 class NavigationEntry; |
| 25 } | 28 } |
| 26 | 29 |
| 27 // TabNavigation ------------------------------------------------------------- | 30 // TabNavigation ------------------------------------------------------------- |
| 28 | 31 |
| 29 // TabNavigation corresponds to the parts of NavigationEntry needed to restore | 32 // TabNavigation is a "freeze-dried" version of NavigationEntry. It |
| 30 // the NavigationEntry during session restore and tab restore. | 33 // contains the data needed to restore a NavigationEntry during |
| 34 // session restore and tab restore, and it can also be pickled and |
| 35 // unpickled. It is also convertible to a sync protocol buffer for |
| 36 // session syncing. |
| 31 // | 37 // |
| 32 // TabNavigation is cheap and supports copy semantics. | 38 // Default copy constructor and assignment operator welcome. |
| 33 class TabNavigation { | 39 class TabNavigation { |
| 34 public: | 40 public: |
| 35 enum TypeMask { | 41 // Creates an invalid (index < 0) TabNavigation. |
| 36 HAS_POST_DATA = 1 | 42 TabNavigation(); |
| 37 }; | 43 ~TabNavigation(); |
| 38 | 44 |
| 39 TabNavigation(); | 45 // Construct a TabNavigation for a particular index from a |
| 40 TabNavigation(int index, | 46 // NavigationEntry with the given timestamp. |
| 41 const GURL& virtual_url, | 47 // |
| 42 const content::Referrer& referrer, | 48 // TODO(akalin): Add a timestamp field to |
| 43 const string16& title, | 49 // navigation::NavigationEntry and use that instead of passing a |
| 44 const std::string& state, | 50 // separate timestamp. |
| 45 content::PageTransition transition); | 51 static TabNavigation FromNavigationEntry( |
| 46 TabNavigation(const TabNavigation& tab); | 52 int index, |
| 47 virtual ~TabNavigation(); | 53 const content::NavigationEntry& entry, |
| 48 TabNavigation& operator=(const TabNavigation& tab); | 54 base::Time timestamp); |
| 49 | 55 |
| 50 // Converts this TabNavigation into a NavigationEntry with a page id of | 56 // Construct a TabNavigation for a particular index from a sync |
| 51 // |page_id|. The caller owns the returned NavigationEntry. | 57 // protocol buffer. Note that the sync protocol buffer doesn't |
| 52 content::NavigationEntry* ToNavigationEntry(int page_id, | 58 // contain all TabNavigation fields. |
| 53 Profile* profile) const; | 59 static TabNavigation FromSyncData( |
| 60 int index, |
| 61 const sync_pb::TabNavigation& specifics); |
| 54 | 62 |
| 55 // Resets this TabNavigation from |entry|. | 63 // Note that not all TabNavigation fields are preserved. |
| 56 void SetFromNavigationEntry(const content::NavigationEntry& entry); | 64 void WriteToPickle(Pickle* pickle) const; |
| 65 bool ReadFromPickle(PickleIterator* iterator); |
| 57 | 66 |
| 58 // Virtual URL of the page. See NavigationEntry::GetVirtualURL() for details. | 67 // Convert this TabNavigation into a NavigationEntry with the given |
| 59 void set_virtual_url(const GURL& url) { virtual_url_ = url; } | 68 // page ID and context. The NavigationEntry will have a transition |
| 69 // type of PAGE_TRANSITION_RELOAD and a new unique ID. |
| 70 scoped_ptr<content::NavigationEntry> ToNavigationEntry( |
| 71 int page_id, |
| 72 content::BrowserContext* browser_context) const; |
| 73 |
| 74 // Convert this navigation into its sync protocol buffer equivalent. |
| 75 // Note that the protocol buffer doesn't contain all TabNavigation |
| 76 // fields. |
| 77 sync_pb::TabNavigation ToSyncData() const; |
| 78 |
| 79 // The index in the NavigationController. This TabNavigation is |
| 80 // valid only when the index is non-negative. |
| 81 // |
| 82 // This is used when determining the selected TabNavigation and only |
| 83 // used by SessionService. |
| 84 int index() const { return index_; } |
| 85 void set_index(int index) { index_ = index; } |
| 86 |
| 87 // Accessors for some fields taken from NavigationEntry. |
| 88 int unique_id() const { return unique_id_; } |
| 60 const GURL& virtual_url() const { return virtual_url_; } | 89 const GURL& virtual_url() const { return virtual_url_; } |
| 90 const string16& title() const { return title_; } |
| 91 const std::string& content_state() const { return content_state_; } |
| 61 | 92 |
| 62 // The referrer. | 93 // Timestamp this navigation occurred. |
| 63 const content::Referrer& referrer() const { return referrer_; } | 94 base::Time timestamp() const { return timestamp_; } |
| 64 | 95 |
| 65 // The title of the page. | 96 // Converts a set of TabNavigations into a list of NavigationEntrys |
| 66 void set_title(const string16& title) { title_ = title; } | 97 // with sequential page IDs and the given context. The caller owns |
| 67 const string16& title() const { return title_; } | 98 // the returned NavigationEntrys. |
| 68 | 99 static std::vector<content::NavigationEntry*> |
| 69 // State bits. | 100 CreateNavigationEntriesFromTabNavigations( |
| 70 const std::string& state() const { return state_; } | |
| 71 | |
| 72 // Transition type. | |
| 73 void set_transition(content::PageTransition transition) { | |
| 74 transition_ = transition; | |
| 75 } | |
| 76 content::PageTransition transition() const { return transition_; } | |
| 77 | |
| 78 // A mask used for arbitrary boolean values needed to represent a | |
| 79 // NavigationEntry. Currently only contains HAS_POST_DATA or 0. | |
| 80 void set_type_mask(int type_mask) { type_mask_ = type_mask; } | |
| 81 int type_mask() const { return type_mask_; } | |
| 82 | |
| 83 // The index in the NavigationController. If this is -1, it means this | |
| 84 // TabNavigation is bogus. | |
| 85 // | |
| 86 // This is used when determining the selected TabNavigation and only useful | |
| 87 // by BaseSessionService and SessionService. | |
| 88 void set_index(int index) { index_ = index; } | |
| 89 int index() const { return index_; } | |
| 90 | |
| 91 // The URL that initially spawned the NavigationEntry. | |
| 92 const GURL& original_request_url() const { return original_request_url_; } | |
| 93 void set_original_request_url(const GURL& url) { | |
| 94 original_request_url_ = url; | |
| 95 } | |
| 96 | |
| 97 // Whether or not we're overriding the standard user agent. | |
| 98 bool is_overriding_user_agent() const { return is_overriding_user_agent_; } | |
| 99 void set_is_overriding_user_agent(bool state) { | |
| 100 is_overriding_user_agent_ = state; | |
| 101 } | |
| 102 | |
| 103 // Converts a set of TabNavigations into a set of NavigationEntrys. The | |
| 104 // caller owns the NavigationEntrys. | |
| 105 static void CreateNavigationEntriesFromTabNavigations( | |
| 106 Profile* profile, | |
| 107 const std::vector<TabNavigation>& navigations, | 101 const std::vector<TabNavigation>& navigations, |
| 108 std::vector<content::NavigationEntry*>* entries); | 102 content::BrowserContext* browser_context); |
| 109 | 103 |
| 110 private: | 104 private: |
| 111 friend class BaseSessionService; | 105 friend struct SessionTypesTestHelper; |
| 112 | 106 |
| 107 // Index in the NavigationController. |
| 108 int index_; |
| 109 |
| 110 // Member variables corresponding to NavigationEntry fields. |
| 111 int unique_id_; |
| 112 content::Referrer referrer_; |
| 113 GURL virtual_url_; | 113 GURL virtual_url_; |
| 114 content::Referrer referrer_; | |
| 115 string16 title_; | 114 string16 title_; |
| 116 std::string state_; | 115 std::string content_state_; |
| 117 content::PageTransition transition_; | 116 content::PageTransition transition_type_; |
| 118 int type_mask_; | 117 bool has_post_data_; |
| 119 int64 post_id_; | 118 int64 post_id_; |
| 120 | |
| 121 int index_; | |
| 122 GURL original_request_url_; | 119 GURL original_request_url_; |
| 123 bool is_overriding_user_agent_; | 120 bool is_overriding_user_agent_; |
| 121 |
| 122 // Timestamp when the navigation occurred. |
| 123 // |
| 124 // TODO(akalin): Add a timestamp field to NavigationEntry. |
| 125 base::Time timestamp_; |
| 124 }; | 126 }; |
| 125 | 127 |
| 126 // SessionTab ---------------------------------------------------------------- | 128 // SessionTab ---------------------------------------------------------------- |
| 127 | 129 |
| 128 // SessionTab corresponds to a NavigationController. | 130 // SessionTab corresponds to a NavigationController. |
| 129 struct SessionTab { | 131 struct SessionTab { |
| 130 SessionTab(); | 132 SessionTab(); |
| 131 virtual ~SessionTab(); | 133 virtual ~SessionTab(); |
| 132 | 134 |
| 133 // Since the current_navigation_index can be larger than the index for number | 135 // Since the current_navigation_index can be larger than the index for number |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // Is the window maximized, minimized, or normal? | 231 // Is the window maximized, minimized, or normal? |
| 230 ui::WindowShowState show_state; | 232 ui::WindowShowState show_state; |
| 231 | 233 |
| 232 std::string app_name; | 234 std::string app_name; |
| 233 | 235 |
| 234 private: | 236 private: |
| 235 DISALLOW_COPY_AND_ASSIGN(SessionWindow); | 237 DISALLOW_COPY_AND_ASSIGN(SessionWindow); |
| 236 }; | 238 }; |
| 237 | 239 |
| 238 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 240 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
| OLD | NEW |