1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/task/cancelable_task_tracker.h"
12 #include "components/favicon/core/fallback_icon_service.h"
13 #include "components/favicon_base/favicon_types.h"
14 #include "content/public/browser/url_data_source.h"
17 class FallbackIconService
;
21 // LargeIconSource services explicit chrome:// requests for large icons.
24 // chrome://large-icon/size/url
27 // 'size' Required (including trailing '/')
28 // Positive integer to specify the large icon's size in pixels.
30 // String to specify the page URL of the large icon.
32 // Example: chrome://large-icon/48/http://www.google.com/
33 // This requests a 48x48 large icon for http://www.google.com.
34 class LargeIconSource
: public content::URLDataSource
{
36 // |favicon_service| and |fallback_icon_service| are owned by caller and may
38 LargeIconSource(favicon::FaviconService
* favicon_service
,
39 favicon::FallbackIconService
* fallback_icon_service
);
41 ~LargeIconSource() override
;
43 // content::URLDataSource implementation.
44 std::string
GetSource() const override
;
45 void StartDataRequest(
46 const std::string
& path
,
47 int render_process_id
,
49 const content::URLDataSource::GotDataCallback
& callback
) override
;
50 std::string
GetMimeType(const std::string
&) const override
;
51 bool ShouldReplaceExistingSource() const override
;
52 bool ShouldServiceRequest(const net::URLRequest
* request
) const override
;
57 IconRequest(const content::URLDataSource::GotDataCallback
& callback_in
,
62 content::URLDataSource::GotDataCallback callback
;
68 // Callback for icon data retrieval request.
69 void OnIconDataAvailable(
70 const IconRequest
& request
,
71 const favicon_base::FaviconRawBitmapResult
& bitmap_result
);
73 // Renders and sends a fallback icon.
74 void SendFallbackIcon(const IconRequest
& request
);
76 // Returns null to trigger "Not Found" response.
77 void SendNotFoundResponse(
78 const content::URLDataSource::GotDataCallback
& callback
);
80 base::CancelableTaskTracker cancelable_task_tracker_
;
82 favicon::FaviconService
* favicon_service_
;
84 favicon::FallbackIconService
* fallback_icon_service_
;
86 DISALLOW_COPY_AND_ASSIGN(LargeIconSource
);
89 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_