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
|
// 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.
module tabs_api.mojom;
import "chrome/browser/ui/webui/tabs/tabs.mojom";
import "mojo/public/mojom/base/empty.mojom";
import "mojo/public/mojom/base/error.mojom";
import "url/mojom/url.mojom";
// References a tab object. The id can refer to different types of underlying
// resource. The |type| field can be used to differentiate between the type
// of underlying resources.
struct TabId {
// The type of object referenced by the id.
enum Type {
// An unknown type. This will never be returned by the service and usually
// indicates an invalid argument from the client.
kUnknown,
// A content tab.
kContent,
// A collection of tabs.
kCollection,
};
// An opaque string that uniquely identifies the underlying resource. This
// id will be unique across all resource types. Users should not try to
// extrapolate any sort of pattern from this string.
string id;
// The type of resource referenced by this id.
Type type;
};
struct Tab {
TabId id;
string title;
url.mojom.Url url;
// TODO(crbug.com/414630734). The favicon should be typemapped to ImageModel
// in c++. Leave this as a data uri for now.
url.mojom.Url favicon_url;
array<tabs.mojom.TabAlertState> alert_states;
tabs.mojom.TabNetworkState network_state;
};
// Position is an ephemeral object that should not be saved nor act as an
// identifier. It is purely used in this API to determine the position within
// the TabstripModel.
struct Position {
// TODO (crbug.com/412935316). Create a generic id that represents the parent
// collection id.
uint32 index;
};
// A snapshot of the current tabs in the tab strip.
struct TabsSnapshot {
array<Tab> tabs;
// Updates to tabs would be sent through this update stream. Clients may
// subscribe to this stream to receive update events.
// The interface is associated with the interface used to retrieve this
// stream. This means that the ordering of the message between the remote
// and the observation stream is preserved.
pending_associated_receiver<TabsObserver> stream;
};
// The TabStripService is an object that lives alongside the
// TabstripModel. It acts as the bridge between the model and any UI Dialog
// or client.
interface TabStripService {
// Gets the current state of the tab tree. This also returns a stream of
// future update events. Clients can implement the |TabsObserver| interface
// and receive all future updates from the snapshot. Note that all messages
// since the snapshot will be present in the stream, even if the client
// does not immediately register to the update stream.
[Sync]
GetTabs() => result<TabsSnapshot, mojo_base.mojom.Error>;
// Get a single tab.
[Sync]
GetTab(TabId id) => result<Tab, mojo_base.mojom.Error>;
// Creates a new tab.
// Position specifies the location of the Tab after creation. If position is
// empty, the new tab will be appended to the end of the Tabstrip.
// Url specifies what is loaded in the Tab. If url is empty, then the new
// tab-page is loaded instead.
// The newly created tab is immediately activated.
[Sync]
CreateTabAt(Position? pos, url.mojom.Url? url)
=> result<Tab, mojo_base.mojom.Error>;
// Closes a list of tabs. The accepted tab types are content and collection
// types. All the provided IDs must exist. If an ID could not be found, the
// invocation will be rejected with a |Code.kNotFound| error.
// If the method call succeeds, all of the tabs will have been closed.
[Sync]
CloseTabs(array<TabId> id)
=> result<mojo_base.mojom.Empty, mojo_base.mojom.Error>;
// Activates a tab. The only accepted id type for this method are |kContent|
// ids.
[Sync]
ActivateTab(TabId id)
=> result<mojo_base.mojom.Empty, mojo_base.mojom.Error>;
};
// TODO (crbug.com/411134070). Add in missing TabData.
struct OnTabsCreatedEvent {
// Tab ids of the newly created tabs.
array<TabId> tabs;
};
struct OnTabsClosedEvent {
// Tab ids of the closed tabs.
array<TabId> tabs;
};
// TODO (crbug.com/412955607)
// TabsObserver is not a CheckedObserver. There is a potential UaF if the
// observer list attempts to call a destroyed TabsObserver that hasn't removed
// itself from the list.
interface TabsObserver {
// When new tabs have been created on the tab strip.
OnTabsCreated(OnTabsCreatedEvent event);
// When tabs have been closed on the tab strip.
OnTabsClosed(OnTabsClosedEvent event);
};
|