File: compose.mojom

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (230 lines) | stat: -rw-r--r-- 8,595 bytes parent folder | download | duplicates (6)
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
230
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module compose.mojom;

import "components/compose/core/browser/compose_enums.mojom";

// Interface for setting up connection to allow calls between the untrusted
// compose dialog web page and native code.
interface ComposeSessionUntrustedPageHandlerFactory {
  // Called from untrusted dialog compose JS to set up native handler.
  CreateComposeSessionUntrustedPageHandler(
      pending_receiver<ComposeClientUntrustedPageHandler> client_handler,
      pending_receiver<ComposeSessionUntrustedPageHandler> handler,
      pending_remote<ComposeUntrustedDialog> dialog);
};

enum InputMode {
  kUnset,
  kPolish,
  kElaborate,
  kFormalize,
};

enum StyleModifier {
  kUnset,
  kFormal,
  kCasual,
  kLonger,
  kShorter,
  kRetry,
};

// The response to compose requests. `result` is only valid if `status`
// is kOk.
struct ComposeResponse {
  ComposeStatus status;
  string result;
  // Whether undo is possible to a prior state before this response.
  bool undo_available;
  // Whether redo is possible to a later state before this response.
  bool redo_available;
  // True if the result stored in this response came from a user edit and false
  // if it came from the server.
  bool provided_by_user;
  // Whether the response was generated on-device.
  bool on_device_evaluation_used;
  // Whether the request producing this response came from a modifier action.
  bool triggered_from_modifier;
};

// An intermediate compose response, which is available before the final
// response is complete.
struct PartialComposeResponse {
  string result;
};

// Snapshot of state that can describe current state or be used to
// fully restore a previous state.
struct ComposeState {
  // TODO(crbug.com/40285814): Change this field to a type that's opaque and
  // non-trivial to use from untrustworthy processes.
  // State for the WebUI session. This should be considered opaque and is
  // unsafe to parse in the browser process.
  string webui_state;
  // Response from compose service. This is not present if the request
  // has not been completed. The response is present if the request has
  // completed, even if the response status is an error.
  ComposeResponse? response;
  // Whether a request is pending. False can also mean that the
  // request was not made.
  bool has_pending_request;
  // Whether the user has pressed the thumbs up/down feedback buttons.
  UserFeedback feedback;
};

// Parameters used to configure the WebUI. These params are passed from the
// browser to the WebUI as part of OpenMetadata when the dialog opens. The
// values may be configured through Finch.
struct ConfigurableParams {
  // Word and character limits on the text input for the request.
  int32 min_word_limit;
  int32 max_word_limit;
  int32 max_character_limit;
};

// Information needed by the WebUI to show a new or restored
// compose dialog.
struct OpenMetadata {
  bool fre_complete;
  bool msbb_state;
  // Renderer provided text selection.
  string initial_input;
  // Whether or not the user selected text when opening the dialog.
  bool text_selected;
  ComposeState compose_state;
  ConfigurableParams configurable_params;
};

// The trigger for dismissing the compose dialog.
enum CloseReason {
  // The X button on the upper-right of the FRE dialog.
  kFirstRunCloseButton,
  // The X button on the upper-right of the main app dialog.
  kCloseButton,
  // The Insert button of the dialog.
  kInsertButton,
  // The MSBB dialog was shown and dismissed.
  kMSBBCloseButton,
};

//TODO(b/311697865) move this to a common location.
enum UserFeedback {
  // Unspecified.
  kUserFeedbackUnspecified,
  // A thumbs down.
  kUserFeedbackNegative,
  // A thumbs up.
  kUserFeedbackPositive,
};

// Interface for calls from the untrusted Compose dialog JS into the Browser
// process.
interface ComposeSessionUntrustedPageHandler {
  // Asks the browser to track a cancel edit action for logging purposes.
  LogCancelEdit();

  // Asks the Browser to compose `input`, informing the Browser of the input
  // mode used for the request and if the compose call was based on the user
  // input being 'edited' in the dialog after the initial compose response.
  Compose(string input, InputMode mode, bool edited);

  // Asks the Browser to rewrite the last response. `style` specifies how the
  // response should be changed.
  // changes to the tone or length.
  Rewrite(StyleModifier style);

  // Asks the browser to track an edit input action for logging purposes.
  LogEditInput();

  // Asks the native handler to store `webui_state` for the last field the user
  // selected compose on.
  // TODO(crbug.com/40285814): Change this field to a type that's opaque and
  // non-trivial to use from untrustworthy processes.
  // State for the WebUI session. This should be considered opaque and is
  // unsafe to parse in the browser process.
  SaveWebUIState(string webui_state);

  // Inform the Browser that the response has been accepted by the user.
  // Should only be called if the ComposeResponse received is valid.
  // Boolean success indicates if the result was accepted successfully.
  AcceptComposeResult() => (bool success);

  // Asks the native handler for state information needed for opening the
  // compose dialog for the last field the user selected compose on.
  RequestInitialState() => (OpenMetadata initial_state);

  // Asks the native handler to return the `last_state`. A null return means
  // that there are no undoable states remaining. Calling `Undo()` and
  // simultaneously closing the dialog (i.e., disconnecting the IPC pipe) may
  // result in the state being undone, or remaining the same. This depends on
  // which action executes first. If the IPC pipe disconnects, the Promise will
  // reject/fail, which should not be confused with a null return. In that case,
  // an undoable state may exist, but the call failed due to the broken pipe.
  Undo() => (ComposeState? last_state);

  // Asks the native handler to revert to and return the saved state directly
  // preceding a filtered error state. A null return means that there is no such
  // valid state. No-op on rejected promise.
  RecoverFromErrorState() => (ComposeState? state_before_error);

  // Asks the native handler to move to and return the `next_state` in the saved
  // state history. This represents the state that the user saw previous to the
  // last Undo action. A null return means there is no redoable state available.
  // No-op on rejected promise.
  Redo() => (ComposeState? next_state);

  // Asks the Browser to open a new tab navigated to the Compose bug report
  // Buganizer.
  OpenBugReportingLink();

  // Asks the Browser to open a new tab navigated to the Compose Learn More
  // page.
  OpenComposeLearnMorePage();

  // Asks the Browser to open a new tab navigated to the Dogfood feedback
  // survey.
  OpenFeedbackSurveyLink();

  // Asks the Browser to open a new tab navigated to the sign in page.
  OpenSignInPage();

  // Asks the native handler to store the user feedback supplied by the user.
  SetUserFeedback(UserFeedback feedback);

  // Tells the native handler that the user has updated the compose results
  // to `new_result`. `is_edited` indicates whether the result text was
  // changed by the edit.
  EditResult(string new_result) => (bool is_edited);
};

// Interface for calls from the untrusted Compose dialog JS into the Browser
// process.
interface ComposeClientUntrustedPageHandler {
  // Asks the receiver to show the compose dialog.
  ShowUI();
  // Asks the receiver to close the compose dialog. `reason` describes
  // the user action that triggered the close.
  CloseUI(CloseReason reason);
  // Notifies the browser that the FRE was completed.
  CompleteFirstRun();
  // Asks the Browser to open a new tab navigated to the Compose-related Chrome
  // settings page.
  OpenComposeSettings();
};

// Interface for calls from the Browser process into the untrusted Compose
// dialog JS.
interface ComposeUntrustedDialog {
  // Called when a compose request is fulfilled, either by the model execution
  // service or due to an error. Because compose requests can outlive this
  // WebUI, this is an event rather than a callback on the original `Compose`
  // call above.
  ResponseReceived(ComposeResponse response);

  // Called when a compose request is not yet fulfilled, but a partial response
  // is available.
  PartialResponseReceived(PartialComposeResponse partial_response);
};