blob: b82c8237d65642c9177643bf7c0cd362bd43890a [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2018 The Chromium Authors
Alexey Baskakov2f8bf8162018-07-17 01:06:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Song Fangzhen49468b22021-09-02 15:41:595#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_
6#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_
Alexey Baskakov2f8bf8162018-07-17 01:06:117
8#include <string>
9
Song Fangzhencda4af62021-09-09 05:24:0210#include "chrome/browser/web_applications/web_app_id.h"
Anton Bikineev46bbb972021-05-15 17:53:5311#include "third_party/abseil-cpp/absl/types/optional.h"
Alan Cuttere511d18a2021-08-04 23:10:3812#include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h"
Glen Robertson271d1332020-01-28 00:16:0213
Alexey Baskakov2f8bf8162018-07-17 01:06:1114class GURL;
Eric Willigersf5089bf2020-02-17 21:37:5815class Profile;
Alexey Baskakov2f8bf8162018-07-17 01:06:1116
17namespace web_app {
18
Alan Cutter3b063b22023-06-20 02:29:3919class WebApp;
20
Alexander Dunaev2193149f2022-01-05 18:13:4821extern const char kCrxAppPrefix[];
22
Alexey Baskakov2f8bf8162018-07-17 01:06:1123// Compute a deterministic name based on the URL. We use this pseudo name
24// as a key to store window location per application URLs in Browser and
25// as app id for BrowserWindow, shortcut and jump list.
26std::string GenerateApplicationNameFromURL(const GURL& url);
27
Alexey Baskakovf302efe2018-07-28 02:02:3228// Compute a deterministic name based on an apps's id.
Alexey Baskakovc9025c82018-10-09 04:33:5829std::string GenerateApplicationNameFromAppId(const AppId& app_id);
Alexey Baskakovf302efe2018-07-28 02:02:3230
31// Extracts the application id from the app name.
Alexey Baskakovc9025c82018-10-09 04:33:5832AppId GetAppIdFromApplicationName(const std::string& app_name);
Alexey Baskakovf302efe2018-07-28 02:02:3233
Daniel Murphy137effc2023-05-15 18:31:3834// Compute the AppId using the given start_url and optional manifest
35// id path, which is the path component of the manifest id defined by the spec.
36// This mimics what is given to the spec algorithm as the json manifest_id in
37// https://www.w3.org/TR/appmanifest/#id-member. The `manifest_id_path` can
38// include query arguments and/or fragments, although the fragment will be
39// removed. See the `AppId` type for more information.
Nigel Taod75446b2018-08-16 23:47:4740//
Daniel Murphy137effc2023-05-15 18:31:3841// This should only be used if a `Manifest` object is not available.
Nigel Taod75446b2018-08-16 23:47:4742//
Daniel Murphy137effc2023-05-15 18:31:3843// TODO(b/281881755): Change the optional parameter to required, and refactor
44// calls with absl::nullopt to `GenerateManifestIdFromStartUrlOnly`.
45AppId GenerateAppId(const absl::optional<std::string>& manifest_id_path,
Phillis Tangfca763e82021-06-23 21:52:1246 const GURL& start_url);
Phillis Tang8ced9bd42021-04-09 22:25:0147
Daniel Murphy137effc2023-05-15 18:31:3848// Returns a resolved manifest id given the relative `manifest_id_path`,
49// as per the spec algorithm at https://www.w3.org/TR/appmanifest/#id-member.
50// The `manifest_id_path` can include query arguments and/or fragments, although
51// the fragment will be removed. If there is no `manifest_id_path`, then
52// GenerateManifestIdFromStartUrlOnly can be used.
53//
54// This should only be used if a `Manifest` object is not available.
55ManifestId GenerateManifestId(const std::string& manifest_id_path,
56 const GURL& start_url);
Phillis Tang43184cce2021-08-17 23:45:0257
Daniel Murphy137effc2023-05-15 18:31:3858// Generates the chrome-specific `AppId` from the spec-defined manifest id. See
59// the `AppId` type for more information.
60AppId GenerateAppIdFromManifestId(const ManifestId& manifest_id);
61
62// Generates the chrome-specific `AppId` from the spec-defined manifest. See the
63// `AppId` type for more information. This will CHECK-fail if the `id` field is
64// not present on the manifest.
Alan Cuttere511d18a2021-08-04 23:10:3865AppId GenerateAppIdFromManifest(const blink::mojom::Manifest& manifest);
Nigel Taod75446b2018-08-16 23:47:4766
Daniel Murphy137effc2023-05-15 18:31:3867// Generates a manifest id by only the start_url, which matches the spec
68// algorithm in https://www.w3.org/TR/appmanifest/#id-member where the `id` json
69// member is not present or an empty string. To include an identifier path,
70// please use `GenerateManifestId`.
71//
72// This should only be used if a `Manifest` object is not available.
73ManifestId GenerateManifestIdFromStartUrlOnly(const GURL& start_url);
Phillis Tang3dd48fc2021-09-21 23:53:1274
Alexey Baskakov856744c2019-05-23 00:36:2475// Returns whether the given |app_url| is a valid web app url.
Alexey Baskakov20d192c82018-08-20 07:00:4176bool IsValidWebAppUrl(const GURL& app_url);
77
Eric Willigersf5089bf2020-02-17 21:37:5878// Searches for the first locally installed app id in the registry for which
79// the |url| is in scope. If |window_only| is specified, only apps that
80// open in app windows will be considered.
Anton Bikineev46bbb972021-05-15 17:53:5381absl::optional<AppId> FindInstalledAppWithUrlInScope(Profile* profile,
Eric Willigersf5089bf2020-02-17 21:37:5882 const GURL& url,
83 bool window_only = false);
84
Dibyajyoti Pal64fda1a2023-05-31 18:23:4885// Searches for the first app id in the registry which is not locally installed
86// and for which the |url| is in scope.
87bool IsNonLocallyInstalledAppWithUrlInScope(Profile* profile, const GURL& url);
88
Alan Cutter3b063b22023-06-20 02:29:3989// Tests if `app` is marked as a placeholder app or appears to be one despite
90// not being marked due to corruption, see: https://crbug.com/1427340
91bool LooksLikePlaceholder(const WebApp& app);
92
Alexey Baskakov2f8bf8162018-07-17 01:06:1193} // namespace web_app
94
Song Fangzhen49468b22021-09-02 15:41:5995#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_