File: web_app_helpers.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (118 lines) | stat: -rw-r--r-- 5,174 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_

#include <optional>
#include <string>

#include "base/functional/callback_helpers.h"
#include "components/webapps/common/web_app_id.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h"
#include "url/gurl.h"

class GURL;
class Profile;

namespace web_app {

class WebApp;

extern const char kCrxAppPrefix[];

// Compute a deterministic name based on the URL. We use this pseudo name
// as a key to store window location per application URLs in Browser and
// as app id for BrowserWindow, shortcut and jump list.
std::string GenerateApplicationNameFromURL(const GURL& url);

// Compute a deterministic name based on an apps's id.
std::string GenerateApplicationNameFromAppId(const webapps::AppId& app_id);

// Extracts the application id from the app name.
webapps::AppId GetAppIdFromApplicationName(const std::string& app_name);

// Compute the webapps::AppId using the given start_url and optional manifest
// id path, which is the path component of the manifest id defined by the spec.
// This mimics what is given to the spec algorithm as the json manifest_id in
// https://www.w3.org/TR/appmanifest/#id-member. The `manifest_id_path` can
// include query arguments and/or fragments, although the fragment will be
// removed. See the `webapps::AppId` type for more information.
//
// This should only be used if a `Manifest` object is not available.
//
// TODO(b/281881755): Change the optional parameter to required, and refactor
// calls with std::nullopt to `GenerateManifestIdFromStartUrlOnly`.
webapps::AppId GenerateAppId(const std::optional<std::string>& manifest_id_path,
                             const GURL& start_url,
                             const std::optional<webapps::ManifestId>&
                                 parent_manifest_id = std::nullopt);

// Generates the chrome-specific `webapps::AppId` from the spec-defined
// manifest. See the `webapps::AppId` type for more information. This will
// CHECK-fail if the `id` field is not present on the manifest.
webapps::AppId GenerateAppIdFromManifest(
    const blink::mojom::Manifest& manifest,
    const std::optional<webapps::ManifestId>& parent_manifest_id =
        std::nullopt);

// Generates the chrome-specific `webapps::AppId` from the spec-defined manifest
// id. See the `webapps::AppId` type for more information.
webapps::AppId GenerateAppIdFromManifestId(

    const webapps::ManifestId& manifest_id,
    const std::optional<webapps::ManifestId>& parent_manifest_id =
        std::nullopt);

// Generates a manifest id by only the start_url, which matches the spec
// algorithm in https://www.w3.org/TR/appmanifest/#id-member where the `id` json
// member is not present or an empty string. To include an identifier path,
// please use `GenerateManifestId`.
//
// This should only be used if a `Manifest` object is not available.
webapps::ManifestId GenerateManifestIdFromStartUrlOnly(const GURL& start_url);

// Returns a resolved manifest id given the relative `manifest_id_path`,
// as per the spec algorithm at https://www.w3.org/TR/appmanifest/#id-member.
// The `manifest_id_path` can include query arguments and/or fragments, although
// the fragment will be removed. If there is no `manifest_id_path`, then
// GenerateManifestIdFromStartUrlOnly can be used.
//
// This should only be used if a `Manifest` object is not available.
webapps::ManifestId GenerateManifestId(const std::string& manifest_id_path,
                                       const GURL& start_url);

// Same as above but does not CHECK that the resulting id is valid. Only used
// for sync parsing to avoid crashes, and ignore bad sync data.
webapps::ManifestId GenerateManifestIdUnsafe(
    const std::string& manifest_id_path,
    const GURL& start_url);

// Returns whether the given |app_url| is a valid web app url.
bool IsValidWebAppUrl(const GURL& app_url);

// Adds chrome://`host` as an origin that IsValidWebAppUrl will consider valid.
// The returned ScopedClosureRunner undoes this registration.
base::ScopedClosureRunner AddValidWebAppChromeUrlHostForTesting(
    const std::string& host);

// Searches for the first locally installed app id in the registry for which
// the |url| is in scope. If |window_only| is specified, only apps that
// open in app windows will be considered.
std::optional<webapps::AppId> FindInstalledAppWithUrlInScope(
    Profile* profile,
    const GURL& url,
    bool window_only = false);

// Searches for the first app id in the registry which is not locally installed
// and for which the |url| is in scope.
bool IsNonLocallyInstalledAppWithUrlInScope(Profile* profile, const GURL& url);

// Tests if `app` is marked as a placeholder app or appears to be one despite
// not being marked due to corruption, see: https://crbug.com/1427340
bool LooksLikePlaceholder(const WebApp& app);

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_HELPERS_H_