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