| // 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 <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 "base/types/optional_ref.h" | |
| #include "components/webapps/browser/installable/installable_logging.h" | |
| #include "components/webapps/common/web_page_metadata.mojom.h" | |
| #include "third_party/skia/include/core/SkBitmap.h" | |
| #include "url/gurl.h" | |
| namespace blink { | |
| class Manifest; | |
| } | |
| 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, | |
| base::optional_ref<const blink::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, or nullptr if no manifest was found or an | |
| // error occurred. | |
| raw_ptr<const blink::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. | |
| // This can be populated whether or not it was asked for in the params (as we | |
| // populated it if anyone asked for it in the past for a page). | |
| 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. | |
| // This can be populated whether or not it was asked for in the params (as we | |
| // populated it if anyone asked for it in the past for a page). | |
| // TODO(https://crbug.com/468037835): This is sometimes invalid vs the | |
| // requesting params, as the first icon fetched is cached and always used. | |
| raw_ptr<const SkBitmap, DanglingUntriaged> primary_icon; | |
| // Whether the primary icon had the 'maskable' purpose, meaningless if no | |
| // primary_icon was requested. | |
| // This can be populated whether or not it was asked for in the params (as we | |
| // populated it if anyone asked for it in the past for a page). | |
| // TODO(https://crbug.com/468037835): This is sometimes invalid vs the | |
| // requesting params, as the first icon fetch configuration is cached and | |
| // always used. | |
| 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|. | |
| // If the criteria was webapps::InstallableCriteria::kDoNotCheck, then this is | |
| // always `true`. | |
| const bool installable_check_passed = false; | |
| }; | |
| using InstallableCallback = base::OnceCallback<void(const InstallableData&)>; | |
| } // namespace webapps | |
| #endif // COMPONENTS_WEBAPPS_BROWSER_INSTALLABLE_INSTALLABLE_DATA_H_ |