#include "components/webapps/browser/installable/installable_icon_fetcher.h"
#include "base/check_is_test.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "build/android_buildflags.h"
#include "components/favicon/content/large_icon_service_getter.h"
#include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/favicon_types.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/browser/installable/installable_evaluator.h"
#include "content/public/browser/manifest_icon_downloader.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/common/manifest/manifest_icon_selector.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/webapps/browser/android/webapps_icon_utils.h"
#endif
namespace webapps {
namespace {
const int kMinimumPrimaryAdaptiveLauncherIconSizeInPx = …;
IconPurpose;
int GetIdealPrimaryIconSizeInPx(IconPurpose purpose) { … }
int GetMinimumPrimaryIconSizeInPx(IconPurpose purpose) { … }
int GetMinimumFaviconForPrimaryIconSizeInPx() { … }
void ProcessFaviconInBackground(
const favicon_base::FaviconRawBitmapResult& bitmap_result,
scoped_refptr<base::SequencedTaskRunner> ui_thread_task_runner,
base::OnceCallback<void(const SkBitmap&)> success_callback,
base::OnceCallback<void(InstallableStatusCode)> failed_callback) { … }
#if BUILDFLAG(IS_DESKTOP_ANDROID)
void GenerateHomeScreenIconInBackground(
const GURL& page_url,
scoped_refptr<base::SequencedTaskRunner> ui_thread_task_runner,
base::OnceCallback<void(const GURL& url, const SkBitmap&)> callback) {
SkBitmap bitmap =
WebappsIconUtils::GenerateHomeScreenIconInBackground(page_url);
ui_thread_task_runner->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), page_url, bitmap));
}
#endif
}
namespace test {
int g_minimum_favicon_size_for_testing = …;
}
InstallableIconFetcher::InstallableIconFetcher(
content::WebContents* web_contents,
InstallablePageData& data,
const std::vector<blink::Manifest::ImageResource>& manifest_icons,
bool prefer_maskable,
bool fetch_favicon,
base::OnceCallback<void(InstallableStatusCode)> finish_callback)
: … { … }
InstallableIconFetcher::~InstallableIconFetcher() = default;
void InstallableIconFetcher::TryFetchingNextIcon() { … }
void InstallableIconFetcher::OnManifestIconFetched(const GURL& icon_url,
const IconPurpose purpose,
const SkBitmap& bitmap) { … }
void InstallableIconFetcher::FetchFavicon() { … }
void InstallableIconFetcher::OnFaviconFetched(
const favicon_base::LargeIconResult& result) { … }
void InstallableIconFetcher::OnIconFetched(const GURL& icon_url,
const IconPurpose purpose,
const SkBitmap& bitmap) { … }
void InstallableIconFetcher::MaybeEndWithError(InstallableStatusCode code) { … }
void InstallableIconFetcher::EndWithError(InstallableStatusCode code) { … }
#if BUILDFLAG(IS_DESKTOP_ANDROID)
void InstallableIconFetcher::OnHomeScreenIconGenerated(const GURL& page_url,
const SkBitmap& bitmap) {
if (bitmap.drawsNothing()) {
EndWithError(InstallableStatusCode::NO_ACCEPTABLE_ICON);
return;
}
OnIconFetched(page_url, IconPurpose::ANY, bitmap);
}
#endif
}