1 // Copyright 2017 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_INSTALLABLE_INSTALLABLE_DATA_H_
6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_
7 
8 #include <vector>
9 
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "chrome/browser/installable/installable_logging.h"
13 #include "third_party/blink/public/common/manifest/manifest.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "url/gurl.h"
16 
17 // This struct contains the results of an InstallableManager::GetData call and
18 // is passed to an InstallableCallback. Each pointer and reference is owned by
19 // InstallableManager, and callers should copy any objects which they wish to
20 // use later. Fields not requested in GetData may or may not be set.
21 struct InstallableData {
22   InstallableData(std::vector<InstallableStatusCode> errors,
23                   const GURL& manifest_url,
24                   const blink::Manifest* manifest,
25                   const GURL& primary_icon_url,
26                   const SkBitmap* primary_icon,
27                   bool has_maskable_primary_icon,
28                   const GURL& splash_icon_url,
29                   const SkBitmap* splash_icon,
30                   bool valid_manifest,
31                   bool has_worker);
32   ~InstallableData();
33 
34   // Contains all errors encountered during the InstallableManager::GetData
35   // call. Empty if no errors were encountered.
36   std::vector<InstallableStatusCode> errors;
37 
38   // The URL of the the web app manifest. Empty if the site has no
39   // <link rel="manifest"> tag.
40   const GURL& manifest_url;
41 
42   // The parsed web app manifest. nullptr if the site has an unparseable
43   // manifest.
44   const blink::Manifest* manifest;
45 
46   // The URL of the chosen primary icon.
47   const GURL& primary_icon_url;
48 
49   // nullptr if the most appropriate primary icon couldn't be determined or
50   // downloaded. The underlying primary icon is owned by the InstallableManager;
51   // clients must copy the bitmap if they want to to use it.
52   const SkBitmap* primary_icon;
53 
54   // Whether the primary icon had the 'maskable' purpose, meaningless if no
55   // primary_icon was requested.
56   const bool has_maskable_primary_icon;
57 
58   // The URL of the chosen splash icon.
59   const GURL& splash_icon_url;
60 
61   // nullptr if the most appropriate splash icon couldn't be determined or
62   // downloaded. The underlying splash icon is owned by the InstallableManager;
63   // clients must copy the bitmap if they want to use it. Since the splash
64   // icon is optional, no error code is set if it cannot be fetched, and clients
65   // specifying |valid_splash_icon| must check that the bitmap exists before
66   // using it.
67   const SkBitmap* splash_icon;
68 
69   // true if the site has a valid, installable web app manifest. If
70   // |valid_manifest| or |has_worker| was true and the site isn't installable,
71   // the reason will be in |errors|.
72   const bool valid_manifest = false;
73 
74   // true if the site has a service worker with a fetch handler.
75   const bool has_worker = false;
76 
77  private:
78   DISALLOW_COPY_AND_ASSIGN(InstallableData);
79 };
80 
81 using InstallableCallback = base::OnceCallback<void(const InstallableData&)>;
82 
83 #endif  // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_
84