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
|
// 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.
#ifndef CHROME_BROWSER_APPS_BROWSER_INSTANCE_BROWSER_APP_INSTANCE_H_
#define CHROME_BROWSER_APPS_BROWSER_INSTANCE_BROWSER_APP_INSTANCE_H_
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/unguessable_token.h"
#include "components/services/app_service/public/cpp/browser_app_instance_update.h"
#include "components/services/app_service/public/cpp/browser_window_instance_update.h"
namespace aura {
class Window;
}
namespace content {
class WebContents;
}
namespace apps {
// An instance of an app running in WebContents, either a tab or a window (PWA,
// SWA, hosted app, packaged v1 app).
struct BrowserAppInstance {
using Type = BrowserAppInstanceUpdate::Type;
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);
~BrowserAppInstance();
BrowserAppInstance(const BrowserAppInstance&) = delete;
BrowserAppInstance& operator=(const BrowserAppInstance&) = delete;
// Updates mutable attributes and returns true if any were updated.
bool 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);
BrowserAppInstanceUpdate ToUpdate() const;
// Checks if `window` is the active window.
bool is_browser_active() const;
const base::UnguessableToken id;
const Type type;
const std::string app_id;
// Window may change for an app tab when a window gets dragged, but stays the
// same for an app window.
raw_ptr<aura::Window> window;
std::string title;
// TODO(b/332628771): Remove this in M127.
// Use `is_browser_activated()` instead.
bool is_browser_active_deprecated;
// If a tab is active in the browser's tab strip. Only applicable to instances
// with type kAppTab. Always set to true for app instances of type kAppWindow.
bool is_web_contents_active;
uint32_t browser_session_id;
uint32_t restored_browser_session_id;
};
// An instance representing a single Chrome browser window.
struct 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);
BrowserWindowInstance(BrowserWindowInstanceUpdate update,
aura::Window* window);
~BrowserWindowInstance();
BrowserWindowInstance(const BrowserWindowInstance&) = delete;
BrowserWindowInstance& operator=(const BrowserWindowInstance&) = delete;
bool MaybeUpdate(bool new_is_active);
BrowserWindowInstanceUpdate ToUpdate() const;
std::string GetAppId() const;
// Checks if `window` is the active window.
bool is_active() const;
const base::UnguessableToken id;
const raw_ptr<aura::Window> window;
const uint32_t browser_session_id;
const uint32_t restored_browser_session_id;
const bool is_incognito;
// TODO(b/332628771): Remove this in M127.
// Do not add code which uses this state but use `is_active()` instead.
bool is_active_deprecated;
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_BROWSER_INSTANCE_BROWSER_APP_INSTANCE_H_
|