1// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5module blink.mojom;
6
7import "services/device/public/mojom/screen_orientation_lock_types.mojom";
8import "mojo/public/mojom/base/string16.mojom";
9import "third_party/blink/public/mojom/manifest/display_mode.mojom";
10import "ui/gfx/geometry/mojom/geometry.mojom";
11import "url/mojom/url.mojom";
12import "url/mojom/origin.mojom";
13
14
15// The Manifest structure is an internal representation of the Manifest file
16// described in the "Manifest for Web Application" document:
17// http://w3c.github.io/manifest/
18[JavaClassName="WebManifest"]
19struct Manifest {
20  mojo_base.mojom.String16? name;
21
22  mojo_base.mojom.String16? short_name;
23
24  mojo_base.mojom.String16? description;
25
26  array<mojo_base.mojom.String16> categories;
27
28  url.mojom.Url start_url;
29
30  DisplayMode display;
31
32  array<DisplayMode> display_override;
33
34  device.mojom.ScreenOrientationLockType orientation;
35
36  array<ManifestImageResource> icons;
37
38  array<ManifestImageResource> screenshots;
39
40  array<ManifestShortcutItem> shortcuts;
41
42  ManifestShareTarget? share_target;
43
44  // TODO(crbug.com/829689): This field is non-standard and part of a Chrome
45  // experiment. See:
46  // https://github.com/WICG/file-handling/blob/master/explainer.md
47  // As such, this field should not be exposed to the drive-by web.
48  array<ManifestFileHandler> file_handlers;
49
50  // TODO(crbug.com/1019239): This is going into the mainline manifest spec,
51  // remove the TODO once that PR goes in.
52  // The URLProtocolHandler explainer can be found here:
53  // https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/URLProtocolHandler/explainer.md
54  array<ManifestProtocolHandler> protocol_handlers;
55
56  array<ManifestUrlHandler> url_handlers;
57
58  array<ManifestRelatedApplication> related_applications;
59
60  // A boolean that is used as a hint for the user agent to say that related
61  // applications should be preferred over the web application. False if missing
62  // or there is a parsing failure.
63  bool prefer_related_applications;
64
65  // TODO(https://crbug.com/657632): Numeric types are not nullable. =(
66  bool has_theme_color;
67  uint32 theme_color;
68
69  // TODO(https://crbug.com/657632): Numeric types are not nullable. =(
70  bool has_background_color;
71  uint32 background_color;
72
73  mojo_base.mojom.String16? gcm_sender_id;
74
75  url.mojom.Url scope;
76};
77
78// Structure representing a Shortcut Item per the Manifest specification, see:
79// https://w3c.github.io/manifest/#shortcutitem-and-its-members
80struct ManifestShortcutItem {
81  // name is required
82  mojo_base.mojom.String16 name;
83
84  mojo_base.mojom.String16? short_name;
85
86  mojo_base.mojom.String16? description;
87
88  // URL at which the shortcut can be found.
89  // MUST be a valid url. If a shortcut doesn't have a valid URL, it will not be
90  // successfully parsed, thus will not be represented in the Manifest.
91  url.mojom.Url url;
92
93  array<ManifestImageResource> icons;
94};
95
96// Structure representing an icon as per the Manifest specification, see:
97// https://w3c.github.io/manifest/#dom-imageresource
98struct ManifestImageResource {
99  enum Purpose {
100    ANY = 0,
101    MONOCHROME,
102    MASKABLE,
103  };
104
105  // MUST be a valid url. If an icon doesn't have a valid URL, it will not be
106  // successfully parsed, thus will not be represented in the Manifest.
107  url.mojom.Url src;
108
109  // The type can be any string and doesn't have to be a valid image MIME type
110  // at this point. It is up to the consumer of the object to check if the type
111  // matches a supported type.
112  mojo_base.mojom.String16? type;
113
114  // The special value "any" is represented by gfx::Size(0, 0).
115  array<gfx.mojom.Size> sizes;
116
117  // Never empty. Defaults to a vector with a single value, IconPurpose::ANY,
118  // if not explicitly specified in the manifest.
119  array<Purpose> purpose;
120};
121
122// Structure representing a share target file.
123struct ManifestFileFilter {
124  mojo_base.mojom.String16? name;
125
126  // A sequence of accepted MIME types.
127  array<mojo_base.mojom.String16> accept;
128};
129
130// Structure representing a URL protocol handler.
131struct ManifestProtocolHandler {
132  mojo_base.mojom.String16 protocol;
133  url.mojom.Url url;
134};
135
136struct ManifestUrlHandler {
137  url.mojom.Origin origin;
138};
139
140// Structure representing a related application.
141struct ManifestRelatedApplication {
142  // The platform on which the application can be found. This can be any
143  // string, and is interpreted by the consumer of the object.
144  mojo_base.mojom.String16? platform;
145
146  // URL at which the application can be found. One of |url| or |id| must be
147  // present.
148  url.mojom.Url? url;
149
150  // An id which is used to represent the application on the platform. One of
151  // |url| or |id| must be present.
152  mojo_base.mojom.String16? id;
153};
154
155
156// Structure representing how a Web Share target fills query parameters of an
157// incoming share. These fields contain the names of the query parameters that
158// will hold the value of the corresponding share data.
159struct ManifestShareTargetParams {
160  mojo_base.mojom.String16? title;
161  mojo_base.mojom.String16? text;
162  mojo_base.mojom.String16? url;
163
164  // An array of share target files, which is represented by two members:
165  // name and accept.
166  array<ManifestFileFilter>? files;
167};
168
169// Structure representing how a Web Share target handles an incoming share.
170struct ManifestShareTarget {
171  // This enum corresponds to HTTP methods, where kGet corresponds to GET
172  // and kPost corresponds to POST.
173  enum Method {
174    kGet,
175    kPost,
176  };
177
178  // This enum corresponds to HTTP enctype, where kApplication corresponds
179  // to application/x-www-url-encoded and kMultipart corresponds to
180  // multipart/form-data.
181  enum Enctype {
182    kFormUrlEncoded,
183    kMultipartFormData,
184  };
185
186  // The URL that will be opened when the share target is invoked.
187  url.mojom.Url action;
188
189  // The method that specifies the HTTP request method for web share target.
190  Method method;
191
192  // The enctype that specifies how share data is encoded in a POST request.
193  // It is ignored when method is "GET".
194  Enctype enctype;
195
196  ManifestShareTargetParams params;
197};
198
199struct ManifestFileHandler {
200  // The URL that will be opened when the file handler is invoked.
201  url.mojom.Url action;
202  mojo_base.mojom.String16 name;
203  // A mapping of a MIME types to a corresponding list of file extensions.
204  map<mojo_base.mojom.String16, array<mojo_base.mojom.String16>> accept;
205};
206
207// Debug information for a parsed manifest.
208struct ManifestDebugInfo {
209  array<ManifestError> errors;
210
211  string raw_manifest;
212};
213
214// An individual manifest parsing error.
215struct ManifestError {
216  string message;
217  bool critical;
218  uint32 line;
219  uint32 column;
220};
221