File: foreign_session_handler.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (121 lines) | stat: -rw-r--r-- 4,193 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_HISTORY_FOREIGN_SESSION_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_HISTORY_FOREIGN_SESSION_HANDLER_H_

#include <memory>
#include <string>
#include <vector>

#include "base/callback_list.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/sessions/session_service.h"
#include "components/sync_sessions/open_tabs_ui_delegate.h"
#include "content/public/browser/web_ui_message_handler.h"

namespace content {
class WebUI;
}

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace browser_sync {

// Keep in sync with //chrome/browser/resources/history/constants.js.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SyncedTabsHistogram {
  INITIALIZED = 0,
  SHOW_MENU_DEPRECATED = 1,
  LINK_CLICKED = 2,
  LINK_RIGHT_CLICKED = 3,
  SESSION_NAME_RIGHT_CLICKED_DEPRECATED = 4,
  SHOW_SESSION_MENU = 5,
  COLLAPSE_SESSION = 6,
  EXPAND_SESSION = 7,
  OPEN_ALL = 8,
  HAS_FOREIGN_DATA = 9,
  HIDE_FOR_NOW = 10,
  OPENED_LINK_VIA_CONTEXT_MENU = 11,
  LIMIT = 12  // Should always be the last one.
};

class ForeignSessionHandler : public content::WebUIMessageHandler {
 public:
  // WebUIMessageHandler implementation.
  void RegisterMessages() override;
  void OnJavascriptAllowed() override;
  void OnJavascriptDisallowed() override;

  ForeignSessionHandler();

  ForeignSessionHandler(const ForeignSessionHandler&) = delete;
  ForeignSessionHandler& operator=(const ForeignSessionHandler&) = delete;

  ~ForeignSessionHandler() override;

  void InitializeForeignSessions();

  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

  static void OpenForeignSessionTab(content::WebUI* web_ui,
                                    const std::string& session_string_value,
                                    SessionID tab_id,
                                    const WindowOpenDisposition& disposition);

  static void OpenForeignSessionWindows(
      content::WebUI* web_ui,
      const std::string& session_string_value);

  // Returns a pointer to the current session model associator or nullptr.
  static sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate(
      content::WebUI* web_ui);

  void SetWebUIForTesting(content::WebUI* web_ui) { set_web_ui(web_ui); }

 private:
  FRIEND_TEST_ALL_PREFIXES(ForeignSessionHandlerTest,
                           HandleOpenForeignSessionAllTabs);
  FRIEND_TEST_ALL_PREFIXES(ForeignSessionHandlerTest,
                           HandleOpenForeignSessionTab);

  void OnForeignSessionUpdated();

  base::Value::List GetForeignSessions();

  // Returns a string used to show the user when a session was last modified.
  std::u16string FormatSessionTime(const base::Time& time);

  // Opens all the tabs of a foreign session, potentially spanning multiple
  // windows. This as a javascript callback handler.
  void HandleOpenForeignSessionAllTabs(const base::Value::List& args);

  // Opens a single foreign session tab. This is a javascript callback handler.
  void HandleOpenForeignSessionTab(const base::Value::List& args);

  // Determines whether foreign sessions should be obtained from the sync model.
  // This is a javascript callback handler, and it is also called when the sync
  // model has changed and the new tab page needs to reflect the changes.
  void HandleGetForeignSessions(const base::Value::List& args);

  // Delete a foreign session. This will remove it from the list of foreign
  // sessions on all devices. It will reappear if the session is re-activated
  // on the original device.
  // This is a javascript callback handler.
  void HandleDeleteForeignSession(const base::Value::List& args);

  void HandleSetForeignSessionCollapsed(const base::Value::List& args);

  std::optional<base::Value::List> initial_session_list_;

  base::CallbackListSubscription foreign_session_updated_subscription_;
};

}  // namespace browser_sync

#endif  // CHROME_BROWSER_UI_WEBUI_HISTORY_FOREIGN_SESSION_HANDLER_H_