blob: 709418950e5a8b91e55f2ae13016880dca88c9fd [file] [log] [blame]
Alexey Baskakov2f8bf8162018-07-17 01:06:111// Copyright 2018 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
5#ifndef CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_
6#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_
7
8#include <string>
9
Glen Robertson271d1332020-01-28 00:16:0210#include "chrome/browser/web_applications/components/web_app_id.h"
Anton Bikineev46bbb972021-05-15 17:53:5311#include "third_party/abseil-cpp/absl/types/optional.h"
Alan Cutterdba42b32021-07-29 03:05:2312#include "third_party/blink/public/common/manifest/manifest.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
19// Compute a deterministic name based on the URL. We use this pseudo name
20// as a key to store window location per application URLs in Browser and
21// as app id for BrowserWindow, shortcut and jump list.
22std::string GenerateApplicationNameFromURL(const GURL& url);
23
Alexey Baskakovf302efe2018-07-28 02:02:3224// Compute a deterministic name based on an apps's id.
Alexey Baskakovc9025c82018-10-09 04:33:5825std::string GenerateApplicationNameFromAppId(const AppId& app_id);
Alexey Baskakovf302efe2018-07-28 02:02:3226
27// Extracts the application id from the app name.
Alexey Baskakovc9025c82018-10-09 04:33:5828AppId GetAppIdFromApplicationName(const std::string& app_name);
Alexey Baskakovf302efe2018-07-28 02:02:3229
Alexey Baskakovc9025c82018-10-09 04:33:5830// Compute the App ID (such as "fedbieoalmbobgfjapopkghdmhgncnaa") or
31// App Key, from a web app's URL. Both are derived from a hash of the
Nigel Taod75446b2018-08-16 23:47:4732// URL, but are subsequently encoded differently, for historical reasons. The
33// ID is a Base-16 encoded (a=0, b=1, ..., p=15) subset of the hash, and is
34// used as a directory name, sometimes on case-insensitive file systems
35// (Windows). The Key is a Base-64 encoding of the hash.
36//
37// For PWAs (progressive web apps), the URL should be the Start URL, explicitly
38// listed in the manifest.
39//
Alexey Baskakovc9025c82018-10-09 04:33:5840// For non-PWA web apps, also known as "shortcuts", the URL is just the
Nigel Taod75446b2018-08-16 23:47:4741// bookmark URL.
Alexey Baskakovc9025c82018-10-09 04:33:5842//
43// App ID and App Key match Extension ID and Extension Key for migration.
Phillis Tangfca763e82021-06-23 21:52:1244
Phillis Tangfca763e82021-06-23 21:52:1245// Generate App id using manfiest_id, if null, use start_url instead.
46AppId GenerateAppId(const absl::optional<std::string>& manifest_id,
47 const GURL& start_url);
Phillis Tangc6b383942021-06-21 20:15:4048std::string GenerateAppIdUnhashed(
49 const absl::optional<std::string>& manifest_id,
50 const GURL& start_url);
Phillis Tang8ced9bd42021-04-09 22:25:0151
Phillis Tangfca763e82021-06-23 21:52:1252AppId GenerateAppIdFromManifest(const blink::Manifest& manifest);
Nigel Taod75446b2018-08-16 23:47:4753
Alexey Baskakov856744c2019-05-23 00:36:2454// Returns whether the given |app_url| is a valid web app url.
Alexey Baskakov20d192c82018-08-20 07:00:4155bool IsValidWebAppUrl(const GURL& app_url);
56
Alexey Baskakov856744c2019-05-23 00:36:2457// Returns whether the given |app_url| is a valid extension url.
58bool IsValidExtensionUrl(const GURL& app_url);
59
Eric Willigersf5089bf2020-02-17 21:37:5860// Searches for the first locally installed app id in the registry for which
61// the |url| is in scope. If |window_only| is specified, only apps that
62// open in app windows will be considered.
Anton Bikineev46bbb972021-05-15 17:53:5363absl::optional<AppId> FindInstalledAppWithUrlInScope(Profile* profile,
Eric Willigersf5089bf2020-02-17 21:37:5864 const GURL& url,
65 bool window_only = false);
66
Alexey Baskakov2f8bf8162018-07-17 01:06:1167} // namespace web_app
68
69#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_