blob: e0a06275406a3dda6f67290110bfed6fa2f230e6 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/favicon/core/fallback_icon_service.h"
#include "content/public/browser/url_data_source.h"
namespace favicon {
class FallbackIconService;
class LargeIconService;
namespace favicon_base {
struct LargeIconResult;
// LargeIconSource services explicit chrome:// requests for large icons.
// Format:
// chrome://large-icon/size/url
// Parameter:
// 'size' Required (including trailing '/')
// Positive integer to specify the large icon's size in pixels.
// 'url' Optional
// String to specify the page URL of the large icon.
// Example: chrome://large-icon/48/
// This requests a 48x48 large icon for
class LargeIconSource : public content::URLDataSource {
// |fallback_icon_service| and |large_icon_service| are owned by caller and
// may be null.
LargeIconSource(favicon::FallbackIconService* fallback_icon_service,
favicon::LargeIconService* large_icon_service);
~LargeIconSource() override;
// content::URLDataSource implementation.
std::string GetSource() const override;
void StartDataRequest(
const std::string& path,
int render_process_id,
int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) override;
std::string GetMimeType(const std::string&) const override;
bool ShouldReplaceExistingSource() const override;
bool ShouldServiceRequest(const net::URLRequest* request) const override;
// Called with results of large icon retrieval request.
void OnLargeIconDataAvailable(
const content::URLDataSource::GotDataCallback& callback,
const GURL& url,
int size,
const favicon_base::LargeIconResult& bitmap_result);
// Returns null to trigger "Not Found" response.
void SendNotFoundResponse(
const content::URLDataSource::GotDataCallback& callback);
base::CancelableTaskTracker cancelable_task_tracker_;
// Owned by client.
favicon::FallbackIconService* fallback_icon_service_;
// Owned by client.
favicon::LargeIconService* large_icon_service_;