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
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/favicon/chrome_favicon_client.h"
#include "base/functional/bind.h"
#include "base/memory/singleton.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/common/url_constants.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/dom_distiller/core/url_utils.h"
#include "extensions/buildflags/buildflags.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#endif
namespace {
void RunFaviconCallbackIfNotCanceled(
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled_cb,
favicon_base::FaviconResultsCallback original_callback,
const std::vector<favicon_base::FaviconRawBitmapResult>& results) {
if (!is_canceled_cb.Run())
std::move(original_callback).Run(results);
}
} // namespace
ChromeFaviconClient::ChromeFaviconClient(Profile* profile) : profile_(profile) {
}
ChromeFaviconClient::~ChromeFaviconClient() = default;
bool ChromeFaviconClient::IsNativeApplicationURL(const GURL& url) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
if (url.SchemeIs(extensions::kExtensionScheme))
return true;
#endif
#if !BUILDFLAG(IS_ANDROID)
if (url.SchemeIs(chrome::kIsolatedAppScheme)) {
return true;
}
#endif
return url.SchemeIs(content::kChromeUIScheme);
}
bool ChromeFaviconClient::IsReaderModeURL(const GURL& url) {
return url.SchemeIs(dom_distiller::kDomDistillerScheme);
}
const GURL ChromeFaviconClient::GetOriginalUrlFromReaderModeUrl(
const GURL& url) {
DCHECK(IsReaderModeURL(url));
return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(url);
}
base::CancelableTaskTracker::TaskId
ChromeFaviconClient::GetFaviconForNativeApplicationURL(
const GURL& url,
const std::vector<int>& desired_sizes_in_pixel,
favicon_base::FaviconResultsCallback callback,
base::CancelableTaskTracker* tracker) {
DCHECK(tracker);
DCHECK(IsNativeApplicationURL(url));
base::CancelableTaskTracker::IsCanceledCallback is_canceled_cb;
base::CancelableTaskTracker::TaskId task_id =
tracker->NewTrackedTaskId(&is_canceled_cb);
if (task_id != base::CancelableTaskTracker::kBadTaskId) {
ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
profile_, url, desired_sizes_in_pixel,
base::BindOnce(&RunFaviconCallbackIfNotCanceled, is_canceled_cb,
std::move(callback)));
}
return task_id;
}
|