Alexey Baskakov | 2f8bf816 | 2018-07-17 01:06:11 | [diff] [blame] | 1 | // 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 Robertson | 271d133 | 2020-01-28 00:16:02 | [diff] [blame] | 10 | #include "chrome/browser/web_applications/components/web_app_id.h" |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 11 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Alan Cutter | dba42b3 | 2021-07-29 03:05:23 | [diff] [blame] | 12 | #include "third_party/blink/public/common/manifest/manifest.h" |
Glen Robertson | 271d133 | 2020-01-28 00:16:02 | [diff] [blame] | 13 | |
Alexey Baskakov | 2f8bf816 | 2018-07-17 01:06:11 | [diff] [blame] | 14 | class GURL; |
Eric Willigers | f5089bf | 2020-02-17 21:37:58 | [diff] [blame] | 15 | class Profile; |
Alexey Baskakov | 2f8bf816 | 2018-07-17 01:06:11 | [diff] [blame] | 16 | |
| 17 | namespace 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. |
| 22 | std::string GenerateApplicationNameFromURL(const GURL& url); |
| 23 | |
Alexey Baskakov | f302efe | 2018-07-28 02:02:32 | [diff] [blame] | 24 | // Compute a deterministic name based on an apps's id. |
Alexey Baskakov | c9025c8 | 2018-10-09 04:33:58 | [diff] [blame] | 25 | std::string GenerateApplicationNameFromAppId(const AppId& app_id); |
Alexey Baskakov | f302efe | 2018-07-28 02:02:32 | [diff] [blame] | 26 | |
| 27 | // Extracts the application id from the app name. |
Alexey Baskakov | c9025c8 | 2018-10-09 04:33:58 | [diff] [blame] | 28 | AppId GetAppIdFromApplicationName(const std::string& app_name); |
Alexey Baskakov | f302efe | 2018-07-28 02:02:32 | [diff] [blame] | 29 | |
Alexey Baskakov | c9025c8 | 2018-10-09 04:33:58 | [diff] [blame] | 30 | // 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 Tao | d75446b | 2018-08-16 23:47:47 | [diff] [blame] | 32 | // 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 Baskakov | c9025c8 | 2018-10-09 04:33:58 | [diff] [blame] | 40 | // For non-PWA web apps, also known as "shortcuts", the URL is just the |
Nigel Tao | d75446b | 2018-08-16 23:47:47 | [diff] [blame] | 41 | // bookmark URL. |
Alexey Baskakov | c9025c8 | 2018-10-09 04:33:58 | [diff] [blame] | 42 | // |
| 43 | // App ID and App Key match Extension ID and Extension Key for migration. |
Phillis Tang | fca763e8 | 2021-06-23 21:52:12 | [diff] [blame] | 44 | |
Phillis Tang | fca763e8 | 2021-06-23 21:52:12 | [diff] [blame] | 45 | // Generate App id using manfiest_id, if null, use start_url instead. |
| 46 | AppId GenerateAppId(const absl::optional<std::string>& manifest_id, |
| 47 | const GURL& start_url); |
Phillis Tang | c6b38394 | 2021-06-21 20:15:40 | [diff] [blame] | 48 | std::string GenerateAppIdUnhashed( |
| 49 | const absl::optional<std::string>& manifest_id, |
| 50 | const GURL& start_url); |
Phillis Tang | 8ced9bd4 | 2021-04-09 22:25:01 | [diff] [blame] | 51 | |
Phillis Tang | fca763e8 | 2021-06-23 21:52:12 | [diff] [blame] | 52 | AppId GenerateAppIdFromManifest(const blink::Manifest& manifest); |
Nigel Tao | d75446b | 2018-08-16 23:47:47 | [diff] [blame] | 53 | |
Alexey Baskakov | 856744c | 2019-05-23 00:36:24 | [diff] [blame] | 54 | // Returns whether the given |app_url| is a valid web app url. |
Alexey Baskakov | 20d192c8 | 2018-08-20 07:00:41 | [diff] [blame] | 55 | bool IsValidWebAppUrl(const GURL& app_url); |
| 56 | |
Alexey Baskakov | 856744c | 2019-05-23 00:36:24 | [diff] [blame] | 57 | // Returns whether the given |app_url| is a valid extension url. |
| 58 | bool IsValidExtensionUrl(const GURL& app_url); |
| 59 | |
Eric Willigers | f5089bf | 2020-02-17 21:37:58 | [diff] [blame] | 60 | // 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 Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 63 | absl::optional<AppId> FindInstalledAppWithUrlInScope(Profile* profile, |
Eric Willigers | f5089bf | 2020-02-17 21:37:58 | [diff] [blame] | 64 | const GURL& url, |
| 65 | bool window_only = false); |
| 66 | |
Alexey Baskakov | 2f8bf816 | 2018-07-17 01:06:11 | [diff] [blame] | 67 | } // namespace web_app |
| 68 | |
| 69 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_ |