File: shortcut_info.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (187 lines) | stat: -rw-r--r-- 6,385 bytes parent folder | download
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
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_WEBAPPS_BROWSER_ANDROID_SHORTCUT_INFO_H_
#define COMPONENTS_WEBAPPS_BROWSER_ANDROID_SHORTCUT_INFO_H_

#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "components/webapps/browser/android/webapp_icon.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "services/device/public/mojom/screen_orientation_lock_types.mojom-shared.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h"

namespace webapps {

// https://wicg.github.io/web-share-target/level-2/#sharetargetfiles-and-its-members
struct ShareTargetParamsFile {
  std::u16string name;
  std::vector<std::u16string> accept;
  ShareTargetParamsFile();
  ShareTargetParamsFile(const ShareTargetParamsFile& other);
  ~ShareTargetParamsFile();
};

// https://wicg.github.io/web-share-target/#dom-sharetargetparams
struct ShareTargetParams {
  std::u16string title;
  std::u16string text;
  std::u16string url;
  std::vector<ShareTargetParamsFile> files;
  ShareTargetParams();
  ShareTargetParams(const ShareTargetParams& other);
  ~ShareTargetParams();
};

// https://wicg.github.io/web-share-target/#dom-sharetarget
struct ShareTarget {
  GURL action;
  blink::mojom::ManifestShareTarget_Method method;
  blink::mojom::ManifestShareTarget_Enctype enctype;
  ShareTargetParams params;
  ShareTarget();
  ~ShareTarget();
};

// Information needed to create a shortcut via ShortcutHelper.
struct ShortcutInfo {
  // Creates a ShortcutInfo struct suitable for adding a shortcut to the home
  // screen.
  static std::unique_ptr<ShortcutInfo> CreateShortcutInfo(
      const GURL& manifest_url,
      const blink::mojom::Manifest& manifest,
      const GURL& primary_icon_url,
      bool primary_icon_maskable);

  // This enum is used to back a UMA histogram, and must be treated as
  // append-only.
  // A Java counterpart will be generated for this enum.
  // Some enum values are duplicated in
  // org.chromium.webapk.lib.common.WebApkConstants.
  // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.webapps
  // GENERATED_JAVA_CLASS_NAME_OVERRIDE: ShortcutSource
  enum Source {
    SOURCE_UNKNOWN = 0,
    SOURCE_ADD_TO_HOMESCREEN_DEPRECATED = 1,

    // Used for legacy PWAs added via the banner.
    SOURCE_APP_BANNER = 2,
    SOURCE_BOOKMARK_NAVIGATOR_WIDGET = 3,
    // unused
    // SOURCE_BOOKMARK_SHORTCUT_WIDGET = 4,

    // Used for legacy and WebAPKs launched from a notification.
    SOURCE_NOTIFICATION = 5,

    // Used for WebAPKs added via the menu item.
    SOURCE_ADD_TO_HOMESCREEN_PWA = 6,

    // Used for legacy PWAs added via the menu item.
    SOURCE_ADD_TO_HOMESCREEN_STANDALONE = 7,

    // Used for bookmark-type shortcuts that launch the tabbed browser.
    SOURCE_ADD_TO_HOMESCREEN_SHORTCUT = 8,

    // Used for WebAPKs launched via an external intent and not from Chrome.
    SOURCE_EXTERNAL_INTENT = 9,

    // Used for WebAPK PWAs added via the banner.
    SOURCE_APP_BANNER_WEBAPK = 10,

    // Used for WebAPK PWAs whose install source info was lost.
    SOURCE_WEBAPK_UNKNOWN = 11,

    // Used for Trusted Web Activities launched from third party Android apps.
    SOURCE_TRUSTED_WEB_ACTIVITY = 12,

    // Used for WebAPK intents received as a result of text sharing events.
    SOURCE_WEBAPK_SHARE_TARGET = 13,

    // Used for WebAPKs launched via an external intent from this Chrome APK.
    // WebAPKs launched from a different Chrome APK (e.g. Chrome Canary) will
    // report SOURCE_EXTERNAL_INTENT.
    SOURCE_EXTERNAL_INTENT_FROM_CHROME = 14,

    // Used for WebAPK intents received as a result of binary file sharing
    // events.
    SOURCE_WEBAPK_SHARE_TARGET_FILE = 15,

    // Used for WebAPKs added by the Chrome Android service after the
    // install was requested by another app.
    SOURCE_CHROME_SERVICE = 16,

    SOURCE_INSTALL_RETRY = 17,

    SOURCE_COUNT = 18
  };

  explicit ShortcutInfo(const GURL& shortcut_url);
  ShortcutInfo(const ShortcutInfo& other);
  ~ShortcutInfo();

  // Updates the info based on the given web page metadata.
  void UpdateFromWebPageMetadata(
      const mojom::WebPageMetadata& web_page_metadata);

  // Updates the info based on the given |manifest|.
  void UpdateFromManifest(const blink::mojom::Manifest& manifest);

  // Update the splash screen icon URL based on the given |manifest| for the
  // later download.
  void UpdateBestSplashIcon(const blink::mojom::Manifest& manifest);

  // Update the display mode based on whether the web app is webapk_compatible.
  void UpdateDisplayMode(bool webapk_compatible);

  // Updates the source of the shortcut.
  void UpdateSource(const Source source);

  // Returns a vector of icons including |best_primary_icon_url|,
  // |splash_image_url| and |best_shortcut_icon_urls| if they are not empty
  std::vector<WebappIcon> GetWebApkIcons();

  GURL manifest_url;
  GURL url;
  GURL scope;
  std::u16string user_title;
  std::u16string name;
  std::u16string short_name;
  std::u16string description;
  std::vector<std::u16string> categories;
  blink::mojom::DisplayMode display = blink::mojom::DisplayMode::kBrowser;
  device::mojom::ScreenOrientationLockType orientation =
      device::mojom::ScreenOrientationLockType::DEFAULT;
  Source source = SOURCE_ADD_TO_HOMESCREEN_SHORTCUT;
  absl::optional<SkColor> theme_color;
  absl::optional<SkColor> background_color;
  int ideal_splash_image_size_in_px = 0;
  int minimum_splash_image_size_in_px = 0;
  GURL best_primary_icon_url;
  bool is_primary_icon_maskable = false;
  GURL splash_image_url;
  bool is_splash_image_maskable = false;
  std::vector<std::string> icon_urls;
  std::vector<GURL> screenshot_urls;
  absl::optional<ShareTarget> share_target;
  absl::optional<SkColor> dark_theme_color;
  absl::optional<SkColor> dark_background_color;

  // Id specified in the manifest.
  GURL manifest_id;

  // Both shortcut item related vectors have the same size.
  std::vector<blink::Manifest::ShortcutItem> shortcut_items;
  std::vector<GURL> best_shortcut_icon_urls;
};

}  // namespace webapps

#endif  // COMPONENTS_WEBAPPS_BROWSER_ANDROID_SHORTCUT_INFO_H_