| 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_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "chrome/browser/sessions/session_service.h" | 11 #include "chrome/browser/sessions/session_service.h" |
| 12 #include "chrome/browser/sync/glue/session_model_associator.h" | 12 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/web_ui.h" |
| 15 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
| 16 | 17 |
| 17 namespace browser_sync { | 18 namespace browser_sync { |
| 18 | 19 |
| 19 class ForeignSessionHandler : public content::WebUIMessageHandler, | 20 class ForeignSessionHandler : public content::WebUIMessageHandler, |
| 20 public content::NotificationObserver { | 21 public content::NotificationObserver { |
| 21 public: | 22 public: |
| 23 // Invalid value, used to note that we don't have a tab or window number. |
| 24 static const int kInvalidId = -1; |
| 25 |
| 22 // WebUIMessageHandler implementation. | 26 // WebUIMessageHandler implementation. |
| 23 virtual void RegisterMessages() OVERRIDE; | 27 virtual void RegisterMessages() OVERRIDE; |
| 24 | 28 |
| 25 ForeignSessionHandler(); | 29 ForeignSessionHandler(); |
| 26 virtual ~ForeignSessionHandler() {} | 30 virtual ~ForeignSessionHandler() {} |
| 27 | 31 |
| 28 static void RegisterUserPrefs(PrefService* prefs); | 32 static void RegisterUserPrefs(PrefService* prefs); |
| 29 | 33 |
| 34 static void OpenForeignSession(content::WebUI* web_ui, |
| 35 const std::string& session_string_value, |
| 36 SessionID::id_type window_num, |
| 37 SessionID::id_type tab_id, |
| 38 const WindowOpenDisposition& disposition); |
| 39 |
| 40 // Helper method to create JSON compatible objects from Session objects. |
| 41 static bool SessionTabToValue(const SessionTab& tab, |
| 42 DictionaryValue* dictionary); |
| 43 |
| 44 // Returns a pointer to the current session model associator or NULL. |
| 45 static SessionModelAssociator* GetModelAssociator(content::WebUI* web_ui); |
| 46 |
| 30 private: | 47 private: |
| 31 // Used to register ForeignSessionHandler for notifications. | 48 // Used to register ForeignSessionHandler for notifications. |
| 32 void Init(); | 49 void Init(); |
| 33 | 50 |
| 34 // Determines how ForeignSessionHandler will interact with the new tab page. | 51 // Determines how ForeignSessionHandler will interact with the new tab page. |
| 35 virtual void Observe(int type, | 52 virtual void Observe(int type, |
| 36 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
| 37 const content::NotificationDetails& details) OVERRIDE; | 54 const content::NotificationDetails& details) OVERRIDE; |
| 38 | 55 |
| 39 // Returns a pointer to the current session model associator or NULL. | |
| 40 SessionModelAssociator* GetModelAssociator(); | |
| 41 | |
| 42 // Returns true if tab sync is enabled for this profile, otherwise false. | 56 // Returns true if tab sync is enabled for this profile, otherwise false. |
| 43 bool IsTabSyncEnabled(); | 57 bool IsTabSyncEnabled(); |
| 44 | 58 |
| 45 // Returns a string used to show the user when a session was last modified. | 59 // Returns a string used to show the user when a session was last modified. |
| 46 string16 FormatSessionTime(const base::Time& time); | 60 string16 FormatSessionTime(const base::Time& time); |
| 47 | 61 |
| 48 // Determines which session is to be opened, and then calls | 62 // Determines which session is to be opened, and then calls |
| 49 // OpenForeignSession, to begin the process of opening a new browser window. | 63 // OpenForeignSession, to begin the process of opening a new browser window. |
| 50 // This is a javascript callback handler. | 64 // This is a javascript callback handler. |
| 51 void HandleOpenForeignSession(const ListValue* args); | 65 void HandleOpenForeignSession(const ListValue* args); |
| 52 | 66 |
| 53 // Determines whether foreign sessions should be obtained from the sync model. | 67 // Determines whether foreign sessions should be obtained from the sync model. |
| 54 // This is a javascript callback handler, and it is also called when the sync | 68 // This is a javascript callback handler, and it is also called when the sync |
| 55 // model has changed and the new tab page needs to reflect the changes. | 69 // model has changed and the new tab page needs to reflect the changes. |
| 56 void HandleGetForeignSessions(const ListValue* args); | 70 void HandleGetForeignSessions(const ListValue* args); |
| 57 | 71 |
| 58 void HandleSetForeignSessionCollapsed(const ListValue* args); | 72 void HandleSetForeignSessionCollapsed(const ListValue* args); |
| 59 | 73 |
| 60 // Show a popup listing the devices's tabs. | 74 // Show a popup listing the devices's tabs. |
| 61 // This handler was introduced for NTP5. | 75 // This handler was introduced for NTP5. |
| 62 void HandleShowOtherDeviceSessionPopup(const ListValue* args); | 76 void HandleShowOtherDeviceSessionPopup(const ListValue* args); |
| 63 | 77 |
| 64 // Helper methods to create JSON compatible objects from Session objects. | 78 // Helper method to create JSON compatible objects from Session objects. |
| 65 bool SessionTabToValue(const SessionTab& tab, DictionaryValue* dictionary); | |
| 66 bool SessionWindowToValue(const SessionWindow& window, | 79 bool SessionWindowToValue(const SessionWindow& window, |
| 67 DictionaryValue* dictionary); | 80 DictionaryValue* dictionary); |
| 68 | 81 |
| 69 // The Registrar used to register ForeignSessionHandler for notifications. | 82 // The Registrar used to register ForeignSessionHandler for notifications. |
| 70 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
| 71 | 84 |
| 72 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler); | 85 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler); |
| 73 }; | 86 }; |
| 74 | 87 |
| 75 } // namespace browser_sync | 88 } // namespace browser_sync |
| 76 | 89 |
| 77 #endif // CHROME_BROWSER_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ | 90 #endif // CHROME_BROWSER_UI_WEBUI_NTP_FOREIGN_SESSION_HANDLER_H_ |
| OLD | NEW |