File: browser_app_instance.cc

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 (137 lines) | stat: -rw-r--r-- 4,914 bytes parent folder | download | duplicates (5)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/apps/browser_instance/browser_app_instance.h"

#include <utility>

#include "components/app_constants/constants.h"
#include "components/exo/shell_surface_util.h"
#include "ui/wm/core/window_util.h"

namespace apps {

namespace {

std::string GetWindowUniqueId(aura::Window* window) {
  const std::string* id = exo::GetShellApplicationId(window);
  return id ? *id : "";
}

}  // namespace

BrowserAppInstance::BrowserAppInstance(base::UnguessableToken id,
                                       Type type,
                                       std::string app_id,
                                       aura::Window* window,
                                       std::string title,
                                       bool is_browser_active,
                                       bool is_web_contents_active,
                                       uint32_t browser_session_id,
                                       uint32_t restored_browser_session_id)
    : id(id),
      type(type),
      app_id(app_id),
      window(window),
      title(title),
      is_browser_active_deprecated(is_browser_active),
      is_web_contents_active(is_web_contents_active),
      browser_session_id(browser_session_id),
      restored_browser_session_id(restored_browser_session_id) {}

BrowserAppInstance::~BrowserAppInstance() = default;

bool BrowserAppInstance::MaybeUpdate(aura::Window* new_window,
                                     std::string new_title,
                                     bool new_is_browser_active,
                                     bool new_is_web_contents_active,
                                     uint32_t new_browser_session_id,
                                     uint32_t new_restored_browser_session_id) {
  if (window == new_window && title == new_title &&
      is_browser_active_deprecated == new_is_browser_active &&
      is_web_contents_active == new_is_web_contents_active &&
      browser_session_id == new_browser_session_id &&
      restored_browser_session_id == new_restored_browser_session_id) {
    return false;
  }
  window = new_window;
  title = std::move(new_title);
  is_browser_active_deprecated = new_is_browser_active;
  is_web_contents_active = new_is_web_contents_active;
  browser_session_id = new_browser_session_id;
  restored_browser_session_id = new_restored_browser_session_id;
  return true;
}

BrowserAppInstanceUpdate BrowserAppInstance::ToUpdate() const {
  BrowserAppInstanceUpdate update;
  update.id = id;
  update.type = type;
  update.app_id = app_id;
  update.window_id = GetWindowUniqueId(window);
  update.title = title;
  update.is_browser_active = is_browser_active_deprecated;
  update.is_web_contents_active = is_web_contents_active;
  update.browser_session_id = browser_session_id;
  update.restored_browser_session_id = restored_browser_session_id;
  return update;
}

bool BrowserAppInstance::is_browser_active() const {
  return wm::IsActiveWindow(window);
}

BrowserWindowInstance::BrowserWindowInstance(
    base::UnguessableToken id,
    aura::Window* window,
    uint32_t browser_session_id,
    uint32_t restored_browser_session_id,
    bool is_incognito,
    bool is_active)
    : id(id),
      window(window),
      browser_session_id(browser_session_id),
      restored_browser_session_id(restored_browser_session_id),
      is_incognito(is_incognito),
      is_active_deprecated(is_active) {}

BrowserWindowInstance::BrowserWindowInstance(BrowserWindowInstanceUpdate update,
                                             aura::Window* window)
    : id(update.id),
      window(window),
      browser_session_id(update.browser_session_id),
      restored_browser_session_id(update.restored_browser_session_id),
      is_incognito(update.is_incognito),
      is_active_deprecated(update.is_active) {}

BrowserWindowInstance::~BrowserWindowInstance() = default;

bool BrowserWindowInstance::MaybeUpdate(bool new_is_active) {
  if (is_active_deprecated == new_is_active) {
    return false;
  }
  is_active_deprecated = new_is_active;
  return true;
}

BrowserWindowInstanceUpdate BrowserWindowInstance::ToUpdate() const {
  return BrowserWindowInstanceUpdate{id,
                                     GetWindowUniqueId(window),
                                     is_active_deprecated,
                                     browser_session_id,
                                     restored_browser_session_id,
                                     is_incognito};
}

// TODO(crbug.com/373972275): This function is now constant and could be
// removed.
std::string BrowserWindowInstance::GetAppId() const {
  return app_constants::kChromeAppId;
}

bool BrowserWindowInstance::is_active() const {
  return wm::IsActiveWindow(window);
}

}  // namespace apps