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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
// 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.
module extensions.mojom;
import "mojo/public/mojom/base/uuid.mojom";
import "extensions/common/mojom/code_injection.mojom";
import "extensions/common/mojom/context_type.mojom";
import "extensions/common/mojom/extra_response_data.mojom";
import "extensions/common/mojom/host_id.mojom";
import "extensions/common/mojom/injection_type.mojom";
import "extensions/common/mojom/match_origin_as_fallback.mojom";
import "extensions/common/mojom/message_port.mojom";
import "extensions/common/mojom/run_location.mojom";
import "extensions/common/mojom/stack_frame.mojom";
import "extensions/common/mojom/view_type.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/values.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "url/mojom/url.mojom";
import "third_party/blink/public/mojom/devtools/console_message.mojom";
// Allows an extension to execute code in a tab.
struct ExecuteCodeParams {
// The ID of the requesting injection host.
HostID host_id;
// The CSS or JS to inject into the target.
CodeInjection injection;
// The webview guest source who calls to execute code.
url.mojom.Url webview_src;
// Behavior for frames where the URL cannot be matched directly.
MatchOriginAsFallbackBehavior match_origin_as_fallback_behavior;
// When to inject the code.
RunLocation run_at;
// Whether the request is coming from a <webview>.
bool is_web_view;
};
// Parameters structure for LocalFrameHost.Request().
struct RequestParams {
// Message name.
string name;
// List of message arguments.
mojo_base.mojom.ListValue arguments;
// Extension ID this request was sent from. This can be empty, in the case
// where we expose APIs to normal web pages using the extension function
// system.
string extension_id;
// URL of the frame the request was sent from. This isn't necessarily an
// extension url. Extension requests can also originate from content scripts,
// in which case extension_id will indicate the ID of the associated
// extension. Or, they can originate from hosted apps or normal web pages.
url.mojom.Url source_url;
// The context type associated with the sender. Note that this is *not* to
// be treated as a security boundary (since it might come from a compromised
// renderer), but can be used to differentiate between different types of
// contexts within the same renderer (e.g. content script vs web page).
ContextType context_type;
// Unique request id to match requests and responses.
int32 request_id;
// True if request has a callback specified.
bool has_callback;
// True if request is executed in response to an explicit user gesture.
bool user_gesture;
// If this API call is for a service worker, then this is the worker thread
// id. Otherwise, this is kMainThreadId.
int32 worker_thread_id;
// If this API call is for a service worker, then this is the service
// worker version id. Otherwise, this is set to
// blink::mojom::kInvalidServiceWorkerVersionId.
int64 service_worker_version_id;
// Contains the JS call stack when an extension API method is invoked.
// This field is collected for telemetry purposes only and is only populated
// for a subset of extension API (for e.g., some chrome.tabs API methods).
// For all other API methods, this field is empty.
array<StackFrame>? js_callstack;
};
// Implemented in the renderer, this interface defines the local frame specific
// methods.
interface LocalFrame {
// Sets the top-level frame to the provided name.
SetFrameName(string frame_name);
// Enables or disables spatial navigation.
SetSpatialNavigationEnabled(bool spatial_nav_enabled);
// Tells the render view what its tab ID is.
SetTabId(int32 tab_id);
// Notifies the renderer that its window has closed.
AppWindowClosed(bool send_onclosed);
// Tells the renderer which type this view is.
NotifyRenderViewType(ViewType view_type);
// Asks the renderer to invoke |function_name| with |args| in |module_name|.
// If |extension_id| is non-empty, the function will be invoked only in
// contexts owned by the extension. |args| is a list of primitive Value types
// that are passed to the function.
MessageInvoke(string extension_id,
string module_name,
string function_name,
mojo_base.mojom.ListValue args);
// Notifies the renderer that it should run some JavaScript code. The reply
// is sent back to the browser to return the script running result. An empty
// |error| implies success. |url| is the URL that the code executed on. It may
// be empty if it's unsuccessful. We use an optional for |result| to
// differentiate between no result (such as in the case of an error) and a
// null result.
ExecuteCode(ExecuteCodeParams param) =>
(string error, url.mojom.Url url, mojo_base.mojom.Value? result);
// Trigger to execute declarative content script under browser control.
ExecuteDeclarativeScript(int32 tab_id,
string extension_id,
string script_id,
url.mojom.Url url);
// Tell the render view which browser window it's being attached to.
UpdateBrowserWindowId(int32 window_id);
// Dispatch the Port.onConnect event for message channels.
DispatchOnConnect(
extensions.mojom.PortId port_id,
extensions.mojom.ChannelType channel_type,
string channel_name,
extensions.mojom.TabConnectionInfo tab_info,
extensions.mojom.ExternalConnectionInfo external_connection_info,
pending_associated_receiver<extensions.mojom.MessagePort> port,
pending_associated_remote<extensions.mojom.MessagePortHost> port_host) =>
(bool success);
};
// Implemented in the browser, this interface defines the local frame host
// specific methods.
interface LocalFrameHost {
// Requests permission for a script injection from the renderer to the
// browser.
// The reply is sent back to the renderer with |granted| for granting
// permission for a script to run. If |granted| is false, the permission
// should not be handled.
RequestScriptInjectionPermission(string extension_id,
InjectionType script_type,
RunLocation run_location) => (bool granted);
// Gets the install state for the app when a web page is checking if its app
// is installed. The reply is sent back to the renderer with |state|.
GetAppInstallState(url.mojom.Url url) => (string state);
// Sends an extension API request to the browser.
// The reply is sent back to the renderer with the response data (if any) is
// one of the base::Value types, wrapped as the first element in a LIST
// typed Value.
[UnlimitedSize]
Request(RequestParams params)
=> (bool success,
mojo_base.mojom.ListValue response_wrapper,
string error,
ExtraResponseData? extra_data);
// An "ack" sent from the renderer that it received the response.
// This is only sent for certain API functions (where the browser needs to
// know the renderer received the response).
ResponseAck(mojo_base.mojom.Uuid request_uuid);
// Notifies the browser process that a tab has started or stopped matching
// certain conditions. This method is called by response to several events:
//
// * The WatchPages Mojo method was called, updating the set of
// * conditions. A new page is loaded. This will be invoked after
// mojom::FrameHost::DidCommitProvisionalLoad. Currently this only fires for
// the main frame.
// * Something changed on an existing frame causing the set of matching
// searches to change.
WatchedPageChange(array<string> css_selectors);
// Tells listeners that a detailed message was reported to the console.
DetailedConsoleMessageAdded(mojo_base.mojom.String16 message,
mojo_base.mojom.String16 source,
array<StackFrame> stack_trace,
blink.mojom.ConsoleMessageLevel level);
// Notifies the browser that content scripts are running in the renderer
// that the IPC originated from.
ContentScriptsExecuting(map<string, array<string>> extension_id_to_scripts,
url.mojom.Url frame_url);
// Informs the browser to increment the keepalive count for the lazy
// background page, keeping it alive.
IncrementLazyKeepaliveCount();
// Informs the browser there is one less thing keeping the lazy background
// page alive.
DecrementLazyKeepaliveCount();
// Notify the browser that an app window is ready and can resume resource
// requests.
AppWindowReady();
// Open a channel to all listening contexts owned by the extension with
// the given ID.
OpenChannelToExtension(
extensions.mojom.ExternalConnectionInfo info,
extensions.mojom.ChannelType channel_type,
string channel_name, extensions.mojom.PortId port_id,
pending_associated_remote<extensions.mojom.MessagePort> port,
pending_associated_receiver<extensions.mojom.MessagePortHost> port_host);
// Get a port handle to the native application. The handle can be used for
// sending messages to the extension.
OpenChannelToNativeApp(
string native_app_name, extensions.mojom.PortId port_id,
pending_associated_remote<extensions.mojom.MessagePort> port,
pending_associated_receiver<extensions.mojom.MessagePortHost> port_host);
// Get a port handle to the given tab. The handle can be used for sending
// messages to the extension.
OpenChannelToTab(
int32 tab_id, int32 frame_id, string? document_id,
extensions.mojom.ChannelType channel_type,
string channel_name, extensions.mojom.PortId port_id,
pending_associated_remote<extensions.mojom.MessagePort> port,
pending_associated_receiver<extensions.mojom.MessagePortHost> port_host);
};
|