blob: f7d82c802a97ad1872002ad2a31bd856d3b0275a [file] [log] [blame]
// 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 "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);
// 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 |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);
// Updates the source of the shortcut.
void UpdateSource(const Source source);
// Returns a set of icons including |best_primary_icon_url|,
// |splash_image_url| and |best_shortcut_icon_urls| if they are not empty
std::set<GURL> 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 splash_image_url;
bool is_splash_image_maskable = false;
GURL best_primary_icon_url;
std::vector<std::string> icon_urls;
std::vector<GURL> screenshot_urls;
absl::optional<ShareTarget> share_target;
// 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_