blob: 323deebd5a4cdb6df3b66d3c4dba4ce26df40714 [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"
Phillis Tang8ced9bd42021-04-09 22:25:0111#include "chrome/browser/web_applications/components/web_application_info.h"
Anton Bikineev46bbb972021-05-15 17:53:5312#include "third_party/abseil-cpp/absl/types/optional.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
Alexey Baskakovf302efe2018-07-28 02:02:3227// 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.
44AppId GenerateAppIdFromURL(const GURL& url);
Phillis Tangc6b383942021-06-21 20:15:4045std::string GenerateAppIdUnhashed(
46 const absl::optional<std::string>& manifest_id,
47 const GURL& start_url);
Anton Bikineev46bbb972021-05-15 17:53:5348AppId GenerateAppId(const absl::optional<std::string>& manifest_id,
Phillis Tang8ced9bd42021-04-09 22:25:0149 const GURL& start_url);
50
Alexey Baskakovc9025c82018-10-09 04:33:5851std::string GenerateAppKeyFromURL(const GURL& url);
Nigel Taod75446b2018-08-16 23:47:4752
Alexey Baskakov856744c2019-05-23 00:36:2453// Returns whether the given |app_url| is a valid web app url.
Alexey Baskakov20d192c82018-08-20 07:00:4154bool IsValidWebAppUrl(const GURL& app_url);
55
Alexey Baskakov856744c2019-05-23 00:36:2456// Returns whether the given |app_url| is a valid extension url.
57bool IsValidExtensionUrl(const GURL& app_url);
58
Eric Willigersf5089bf2020-02-17 21:37:5859// Searches for the first locally installed app id in the registry for which
60// the |url| is in scope. If |window_only| is specified, only apps that
61// open in app windows will be considered.
Anton Bikineev46bbb972021-05-15 17:53:5362absl::optional<AppId> FindInstalledAppWithUrlInScope(Profile* profile,
Eric Willigersf5089bf2020-02-17 21:37:5863 const GURL& url,
64 bool window_only = false);
65
Alexey Baskakov2f8bf8162018-07-17 01:06:1166} // namespace web_app
67
68#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_