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 138 139 140
|
// Copyright 2025 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_ASH_BROWSER_DELEGATE_BROWSER_DELEGATE_H_
#define CHROME_BROWSER_ASH_BROWSER_DELEGATE_BROWSER_DELEGATE_H_
#include "chrome/browser/ash/browser_delegate/browser_type.h"
#include "components/account_id/account_id.h"
#include "components/sessions/core/session_id.h"
#include "components/webapps/common/web_app_id.h"
#include "ui/gfx/geometry/rect.h"
class Browser;
class GURL;
namespace aura {
class Window;
} // namespace aura
namespace content {
class WebContents;
} // namespace content
namespace tab_groups {
struct TabGroupInfo;
} // namespace tab_groups
namespace ash {
// Abstraction of the `Browser` class from chrome/browser/ui/browser.h for use
// by ChromeOS feature code. See README.md.
class BrowserDelegate {
public:
// Returns the underlying raw browser instance.
// NOTE: This function is here only temporarily to facilitate transitioning
// code from Browser to BrowserDelegate incrementally. See also
// BrowserController::GetDelegate.
virtual Browser& GetBrowser() const = 0;
// Returns the browser's type.
virtual BrowserType GetType() const = 0;
// Returns the browser's unique ID for the current session.
virtual SessionID GetSessionID() const = 0;
// Returns the account id associated with the browser. In production, this id
// should always be valid (see AccountId::is_valid).
virtual const AccountId& GetAccountId() const = 0;
// Returns whether the browser is off the record, i.e. incognito or in a guest
// session.
virtual bool IsOffTheRecord() const = 0;
// Returns the browser window's current bounds.
virtual gfx::Rect GetBounds() const = 0;
// Returns the active contents. Can be nullptr, e.g. when the tab strip is
// being initialized or destroyed.
virtual content::WebContents* GetActiveWebContents() const = 0;
// Returns the number of web contents.
virtual size_t GetWebContentsCount() const = 0;
// Returns the contents for the given index, or nullptr if out of bounds. Can
// be nullptr even if index is in bounds, just like GetActiveWebContents().
virtual content::WebContents* GetWebContentsAt(size_t index) const = 0;
// Returns the native window. Can be nullptr, e.g. when the browser is being
// closed.
virtual aura::Window* GetNativeWindow() const = 0;
// Returns the browser application id, if applicable.
virtual std::optional<webapps::AppId> GetAppId() const = 0;
// Returns whether the browser is a web app window/pop-up.
virtual bool IsWebApp() const = 0;
// Returns whether the browser is in the process of being closed and deleted.
virtual bool IsClosing() const = 0;
// Returns whether the browser window is active.
virtual bool IsActive() const = 0;
// Shows the browser window, or activates it if it's already visible.
virtual void Show() = 0;
// Shows the window, but does not activate it. Does nothing if the window is
// already visible.
virtual void ShowInactive() = 0;
// Activates the browser window.
virtual void Activate() = 0;
// Minimizes the browser window.
virtual void Minimize() = 0;
// Closes the browser as soon as possible.
virtual void Close() = 0;
// Load the given URL in a new tab.
// If the `url` is empty the new tab-page is loaded.
// If an `index` is given, the tab is placed at the corresponding position in
// the tab strip. Otherwise it is added to the end.
enum class TabDisposition { kForeground, kBackground };
virtual void AddTab(const GURL& url,
std::optional<size_t> index,
TabDisposition disposition) = 0;
// Navigates the browser to the given URL.
// The browser must be of `kApp` or `kAppPopup` type.
// In the case of a tabbed web app (e.g. ChromeOS Terminal), performs tab
// pinning as requested and ensures that home tab URL navigation happens in
// the home tab.
enum class TabPinning { kYes, kNo };
virtual content::WebContents* NavigateWebApp(const GURL& url,
TabPinning pin_tab) = 0;
// Creates the specified tab group.
virtual void CreateTabGroup(const tab_groups::TabGroupInfo& tab_group) = 0;
// Pins the given tab.
virtual void PinTab(size_t tab_index) = 0;
// Moves the given tab to the given `target_browser`, where it's placed at the
// end of the tab strip.
virtual void MoveTab(size_t tab_index, BrowserDelegate& target_browser) = 0;
protected:
~BrowserDelegate() = default;
private:
// BrowserDelegateImpl assumes it's the only implementation.
BrowserDelegate() = default;
friend class BrowserDelegateImpl;
};
} // namespace ash
#endif // CHROME_BROWSER_ASH_BROWSER_DELEGATE_BROWSER_DELEGATE_H_
|