File: installable_data.h

package info (click to toggle)
chromium 135.0.7049.95-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,959,392 kB
  • sloc: cpp: 34,198,526; ansic: 7,100,035; javascript: 3,985,800; python: 1,395,489; asm: 896,754; xml: 722,891; pascal: 180,504; sh: 94,909; perl: 88,388; objc: 79,739; sql: 53,020; cs: 41,358; fortran: 24,137; makefile: 22,501; php: 13,699; tcl: 10,142; yacc: 8,822; ruby: 7,350; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; awk: 197; sed: 36
file content (103 lines) | stat: -rw-r--r-- 3,945 bytes parent folder | download | duplicates (9)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_WEBAPPS_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_
#define COMPONENTS_WEBAPPS_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_

#include <map>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "url/gurl.h"

namespace webapps {

struct Screenshot {
  Screenshot(SkBitmap image, std::optional<std::u16string> label);
  Screenshot(const Screenshot&);
  Screenshot& operator=(const Screenshot&);

  ~Screenshot();

  SkBitmap image;

  // Label for accessibility.
  std::optional<std::u16string> label;
};

// This struct contains the results of an InstallableManager::GetData call and
// is passed to an InstallableCallback. Each pointer and reference is owned by
// InstallableManager, and callers should copy any objects which they wish to
// use later. Fields not requested in GetData may or may not be set.
struct InstallableData {
  InstallableData(std::vector<InstallableStatusCode> errors,
                  const GURL& manifest_url,
                  const blink::mojom::Manifest& manifest,
                  const mojom::WebPageMetadata& metadata,
                  const GURL& primary_icon_url,
                  const SkBitmap* primary_icon,
                  bool has_maskable_primary_icon,
                  const std::vector<Screenshot>& screenshots,
                  bool installable_check_passed);

  InstallableData(const InstallableData&) = delete;
  InstallableData& operator=(const InstallableData&) = delete;

  ~InstallableData();

  // Returns the first error if any one exist. Otherwise returns
  // NO_ERROR_DETECTED.
  InstallableStatusCode GetFirstError() const;

  // Contains all errors encountered during the InstallableManager::GetData
  // call. Empty if no errors were encountered.
  std::vector<InstallableStatusCode> errors;

  // The URL of the the web app manifest. Empty if the site has no
  // <link rel="manifest"> tag.
  const raw_ref<const GURL, DanglingUntriaged> manifest_url;

  // The parsed web app manifest.
  const raw_ref<const blink::mojom::Manifest, DanglingUntriaged> manifest;

  // Manifest data provided by the HTML document.
  const raw_ref<const mojom::WebPageMetadata, DanglingUntriaged>
      web_page_metadata;

  // The URL of the chosen primary icon.
  const raw_ref<const GURL, DanglingUntriaged> primary_icon_url;

  // nullptr if the most appropriate primary icon couldn't be determined or
  // downloaded. The underlying primary icon is owned by the InstallableManager;
  // clients must copy the bitmap if they want to to use it.
  raw_ptr<const SkBitmap, DanglingUntriaged> primary_icon;

  // Whether the primary icon had the 'maskable' purpose, meaningless if no
  // primary_icon was requested.
  const bool has_maskable_primary_icon;

  // The screenshots to show in the install UI.
  const raw_ref<const std::vector<Screenshot>, DanglingUntriaged> screenshots;

  // Whether the site has provided sufficient info for installing the web app.
  // i.e. a valid, installable web app manifest. The result might be different
  // depending on the task's |params|. If |installable_check_passed| was true
  // and the site isn't installable, the reason will be in |errors|.
  const bool installable_check_passed = false;
};

using InstallableCallback = base::OnceCallback<void(const InstallableData&)>;

}  // namespace webapps

#endif  // COMPONENTS_WEBAPPS_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_