manifest.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // Copyright 2014 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. #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_MANIFEST_MANIFEST_H_
  5. #define THIRD_PARTY_BLINK_PUBLIC_COMMON_MANIFEST_MANIFEST_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <vector>
  9. #include "base/optional.h"
  10. #include "base/strings/string16.h"
  11. #include "services/device/public/mojom/screen_orientation_lock_types.mojom-shared.h"
  12. #include "third_party/blink/public/common/common_export.h"
  13. #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
  14. #include "third_party/skia/include/core/SkColor.h"
  15. #include "ui/gfx/geometry/size.h"
  16. #include "url/gurl.h"
  17. namespace blink {
  18. // The Manifest structure is an internal representation of the Manifest file
  19. // described in the "Manifest for Web Application" document:
  20. // http://w3c.github.io/manifest/
  21. struct BLINK_COMMON_EXPORT Manifest {
  22. // Structure representing an icon as per the Manifest specification, see:
  23. // https://w3c.github.io/manifest/#dom-imageresource
  24. struct BLINK_COMMON_EXPORT ImageResource {
  25. enum class Purpose {
  26. ANY = 0,
  27. MONOCHROME,
  28. MASKABLE,
  29. IMAGE_RESOURCE_PURPOSE_LAST = MASKABLE,
  30. };
  31. ImageResource();
  32. ImageResource(const ImageResource& other);
  33. ~ImageResource();
  34. bool operator==(const ImageResource& other) const;
  35. // MUST be a valid url. If an icon doesn't have a valid URL, it will not be
  36. // successfully parsed, thus will not be represented in the Manifest.
  37. GURL src;
  38. // Empty if the parsing failed or the field was not present. The type can be
  39. // any string and doesn't have to be a valid image MIME type at this point.
  40. // It is up to the consumer of the object to check if the type matches a
  41. // supported type.
  42. base::string16 type;
  43. // Empty if the parsing failed, the field was not present or empty.
  44. // The special value "any" is represented by gfx::Size(0, 0).
  45. std::vector<gfx::Size> sizes;
  46. // Never empty. Defaults to a vector with a single value, IconPurpose::ANY,
  47. // if not explicitly specified in the manifest.
  48. std::vector<Purpose> purpose;
  49. };
  50. // Structure representing a shortcut as per the Manifest specification, see:
  51. // https://w3c.github.io/manifest/#shortcuts-member
  52. struct BLINK_COMMON_EXPORT ShortcutItem {
  53. ShortcutItem();
  54. ~ShortcutItem();
  55. base::string16 name;
  56. base::Optional<base::string16> short_name;
  57. base::Optional<base::string16> description;
  58. GURL url;
  59. std::vector<ImageResource> icons;
  60. };
  61. struct BLINK_COMMON_EXPORT FileFilter {
  62. base::string16 name;
  63. std::vector<base::string16> accept;
  64. };
  65. // Structure representing a Web Share target's query parameter keys.
  66. struct BLINK_COMMON_EXPORT ShareTargetParams {
  67. ShareTargetParams();
  68. ~ShareTargetParams();
  69. base::Optional<base::string16> title;
  70. base::Optional<base::string16> text;
  71. base::Optional<base::string16> url;
  72. std::vector<FileFilter> files;
  73. };
  74. // Structure representing how a Web Share target handles an incoming share.
  75. struct BLINK_COMMON_EXPORT ShareTarget {
  76. enum class Method {
  77. kGet,
  78. kPost,
  79. };
  80. enum class Enctype {
  81. kFormUrlEncoded,
  82. kMultipartFormData,
  83. };
  84. ShareTarget();
  85. ~ShareTarget();
  86. // The URL used for sharing. Query parameters are added to this comprised of
  87. // keys from |params| and values from the shared data.
  88. GURL action;
  89. // The HTTP request method for the web share target.
  90. Method method;
  91. // The way that share data is encoded in "POST" request.
  92. Enctype enctype;
  93. ShareTargetParams params;
  94. };
  95. // Structure representing a File Handler.
  96. struct BLINK_COMMON_EXPORT FileHandler {
  97. // The URL which will be opened when the file handler is invoked.
  98. GURL action;
  99. base::string16 name;
  100. std::map<base::string16, std::vector<base::string16>> accept;
  101. };
  102. // Structure representing a Protocol Handler.
  103. struct BLINK_COMMON_EXPORT ProtocolHandler {
  104. base::string16 protocol;
  105. GURL url;
  106. };
  107. // Structure representing a related application.
  108. struct BLINK_COMMON_EXPORT RelatedApplication {
  109. RelatedApplication();
  110. ~RelatedApplication();
  111. // The platform on which the application can be found. This can be any
  112. // string, and is interpreted by the consumer of the object. Empty if the
  113. // parsing failed.
  114. base::Optional<base::string16> platform;
  115. // URL at which the application can be found. One of |url| and |id| must be
  116. // present. Empty if the parsing failed or the field was not present.
  117. GURL url;
  118. // An id which is used to represent the application on the platform. One of
  119. // |url| and |id| must be present. Empty if the parsing failed or the field
  120. // was not present.
  121. base::Optional<base::string16> id;
  122. };
  123. Manifest();
  124. Manifest(const Manifest& other);
  125. ~Manifest();
  126. // Returns whether this Manifest had no attribute set. A newly created
  127. // Manifest is always empty.
  128. bool IsEmpty() const;
  129. // Null if the parsing failed or the field was not present.
  130. base::Optional<base::string16> name;
  131. // Null if the parsing failed or the field was not present.
  132. base::Optional<base::string16> short_name;
  133. // Empty if the parsing failed or the field was not present.
  134. GURL start_url;
  135. // Set to DisplayMode::kUndefined if the parsing failed or the field was not
  136. // present.
  137. blink::mojom::DisplayMode display = blink::mojom::DisplayMode::kUndefined;
  138. // Empty if the parsing failed, the field was not present, or all the
  139. // values inside the JSON array were invalid.
  140. std::vector<blink::mojom::DisplayMode> display_override;
  141. // Set to device::mojom::ScreenOrientationLockType::DEFAULT if the parsing
  142. // failed or the field was not present.
  143. device::mojom::ScreenOrientationLockType orientation =
  144. device::mojom::ScreenOrientationLockType::DEFAULT;
  145. // Empty if the parsing failed, the field was not present, or all the
  146. // icons inside the JSON array were invalid.
  147. std::vector<ImageResource> icons;
  148. // Empty if the parsing failed, the field was not present, or all the
  149. // icons inside the JSON array were invalid.
  150. std::vector<ShortcutItem> shortcuts;
  151. // Null if parsing failed or the field was not present.
  152. base::Optional<ShareTarget> share_target;
  153. // Empty if parsing failed or the field was not present.
  154. // TODO(crbug.com/829689): This field is non-standard and part of a Chrome
  155. // experiment. See:
  156. // https://github.com/WICG/file-handling/blob/master/explainer.md
  157. std::vector<FileHandler> file_handlers;
  158. // Empty if parsing failed or the field was not present.
  159. // TODO(crbug.com/1019239): This is going into the mainline manifest spec,
  160. // remove the TODO once that PR goes in.
  161. // The URLProtocolHandler explainer can be found here:
  162. // https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/URLProtocolHandler/explainer.md
  163. std::vector<ProtocolHandler> protocol_handlers;
  164. // Empty if the parsing failed, the field was not present, empty or all the
  165. // applications inside the array were invalid. The order of the array
  166. // indicates the priority of the application to use.
  167. std::vector<RelatedApplication> related_applications;
  168. // A boolean that is used as a hint for the user agent to say that related
  169. // applications should be preferred over the web application. False if missing
  170. // or there is a parsing failure.
  171. bool prefer_related_applications = false;
  172. // Null if field is not present or parsing failed.
  173. base::Optional<SkColor> theme_color;
  174. // Null if field is not present or parsing failed.
  175. base::Optional<SkColor> background_color;
  176. // This is a proprietary extension of the web Manifest, double-check that it
  177. // is okay to use this entry.
  178. // Null if parsing failed or the field was not present.
  179. base::Optional<base::string16> gcm_sender_id;
  180. // Empty if the parsing failed. Otherwise defaults to the start URL (or
  181. // document URL if start URL isn't present) with filename, query, and fragment
  182. // removed.
  183. GURL scope;
  184. };
  185. } // namespace blink
  186. #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_MANIFEST_MANIFEST_H_