| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_SESSION_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "components/sessions/session_id.h" | 9 #include "components/sessions/session_id.h" |
| 10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 11 #include "content/public/browser/web_contents_user_data.h" | 11 #include "content/public/browser/web_contents_user_data.h" |
| 12 | 12 |
| 13 // This class keeps the extension API's windowID up-to-date with the current | 13 // This class keeps the extension API's windowID up-to-date with the current |
| 14 // window of the tab. | 14 // window of the tab. |
| 15 class SessionTabHelper : public content::WebContentsObserver, | 15 class SessionTabHelper : public content::WebContentsObserver, |
| 16 public content::WebContentsUserData<SessionTabHelper> { | 16 public content::WebContentsUserData<SessionTabHelper> { |
| 17 public: | 17 public: |
| 18 virtual ~SessionTabHelper(); | 18 ~SessionTabHelper() override; |
| 19 | 19 |
| 20 // Returns the identifier used by session restore for this tab. | 20 // Returns the identifier used by session restore for this tab. |
| 21 const SessionID& session_id() const { return session_id_; } | 21 const SessionID& session_id() const { return session_id_; } |
| 22 | 22 |
| 23 // Identifier of the window the tab is in. | 23 // Identifier of the window the tab is in. |
| 24 void SetWindowID(const SessionID& id); | 24 void SetWindowID(const SessionID& id); |
| 25 const SessionID& window_id() const { return window_id_; } | 25 const SessionID& window_id() const { return window_id_; } |
| 26 | 26 |
| 27 // If the specified WebContents has a SessionTabHelper (probably because it | 27 // If the specified WebContents has a SessionTabHelper (probably because it |
| 28 // was used as the contents of a tab), returns a tab id. This value is | 28 // was used as the contents of a tab), returns a tab id. This value is |
| 29 // immutable for a given tab. It will be unique across Chrome within the | 29 // immutable for a given tab. It will be unique across Chrome within the |
| 30 // current session, but may be re-used across sessions. Returns -1 | 30 // current session, but may be re-used across sessions. Returns -1 |
| 31 // for a NULL WebContents or if the WebContents has no SessionTabHelper. | 31 // for a NULL WebContents or if the WebContents has no SessionTabHelper. |
| 32 static SessionID::id_type IdForTab(const content::WebContents* tab); | 32 static SessionID::id_type IdForTab(const content::WebContents* tab); |
| 33 | 33 |
| 34 // If the specified WebContents has a SessionTabHelper (probably because it | 34 // If the specified WebContents has a SessionTabHelper (probably because it |
| 35 // was used as the contents of a tab), and has ever been attached to a Browser | 35 // was used as the contents of a tab), and has ever been attached to a Browser |
| 36 // window, returns Browser::session_id().id() for that Browser. If the tab is | 36 // window, returns Browser::session_id().id() for that Browser. If the tab is |
| 37 // being dragged between Browser windows, returns the old window's id value. | 37 // being dragged between Browser windows, returns the old window's id value. |
| 38 // If the WebContents has a SessionTabHelper but has never been attached to a | 38 // If the WebContents has a SessionTabHelper but has never been attached to a |
| 39 // Browser window, returns an id value that is different from that of any | 39 // Browser window, returns an id value that is different from that of any |
| 40 // Browser. Returns -1 for a NULL WebContents or if the WebContents has no | 40 // Browser. Returns -1 for a NULL WebContents or if the WebContents has no |
| 41 // SessionTabHelper. | 41 // SessionTabHelper. |
| 42 static SessionID::id_type IdForWindowContainingTab( | 42 static SessionID::id_type IdForWindowContainingTab( |
| 43 const content::WebContents* tab); | 43 const content::WebContents* tab); |
| 44 | 44 |
| 45 // content::WebContentsObserver: | 45 // content::WebContentsObserver: |
| 46 #if defined(ENABLE_EXTENSIONS) | 46 #if defined(ENABLE_EXTENSIONS) |
| 47 virtual void RenderViewCreated( | 47 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 48 content::RenderViewHost* render_view_host) override; | |
| 49 #endif | 48 #endif |
| 50 virtual void UserAgentOverrideSet(const std::string& user_agent) override; | 49 void UserAgentOverrideSet(const std::string& user_agent) override; |
| 51 | 50 |
| 52 private: | 51 private: |
| 53 explicit SessionTabHelper(content::WebContents* contents); | 52 explicit SessionTabHelper(content::WebContents* contents); |
| 54 friend class content::WebContentsUserData<SessionTabHelper>; | 53 friend class content::WebContentsUserData<SessionTabHelper>; |
| 55 | 54 |
| 56 // Unique identifier of the tab for session restore. This id is only unique | 55 // Unique identifier of the tab for session restore. This id is only unique |
| 57 // within the current session, and is not guaranteed to be unique across | 56 // within the current session, and is not guaranteed to be unique across |
| 58 // sessions. | 57 // sessions. |
| 59 const SessionID session_id_; | 58 const SessionID session_id_; |
| 60 | 59 |
| 61 // Unique identifier of the window the tab is in. | 60 // Unique identifier of the window the tab is in. |
| 62 SessionID window_id_; | 61 SessionID window_id_; |
| 63 | 62 |
| 64 DISALLOW_COPY_AND_ASSIGN(SessionTabHelper); | 63 DISALLOW_COPY_AND_ASSIGN(SessionTabHelper); |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 #endif // CHROME_BROWSER_SESSIONS_SESSION_TAB_HELPER_H_ | 66 #endif // CHROME_BROWSER_SESSIONS_SESSION_TAB_HELPER_H_ |
| OLD | NEW |