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_FALLBACK_ICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/url_data_source.h"
15 namespace favicon_base
{
16 struct FallbackIconStyle
;
20 class FallbackIconService
;
23 // FallbackIconSource services explicit chrome:// requests for fallback icons.
26 // chrome://fallback-icon/size,bc,tc,fsr,r/url
27 // All of the parameters except for the url are optional. However, the order of
28 // the parameters is not interchangeable, and all "," must be in place.
32 // Positive integer to specify the fallback icon's size in pixels.
34 // Fallback icon's background color, as named CSS color, or RGB / ARGB /
35 // RRGGBB / AARRGGBB hex formats (no leading "#").
37 // Fallback icon text color, as named CSS color, or RGB / ARGB / RRGGBB /
38 // AARRGGBB hex formats (no leading "#").
40 // Number in [0.0, 1.0] to specify the fallback icon's font size (pixels)
41 // as a ratio to the icon's size.
43 // Number in [0.0, 1.0] to specify the fallback icon's roundness.
44 // 0.0 specifies a square icon; 1.0 specifies a circle icon; intermediate
45 // values specify a rounded square icon.
47 // String to specify the page URL of the fallback icon.
49 // Example: chrome://fallback-icon/32,red,#000,0.5,1.0/http://www.google.com/
50 // This requests a 32x32 fallback icon for http://www.google.com, using
51 // red as the background color, #000 as the text color, with font size of
52 // 32 * 0.5 = 16, and the icon's background shape is a circle.
53 class FallbackIconSource
: public content::URLDataSource
{
55 // |fallback_icon_service| is owned by caller, and may be null.
56 explicit FallbackIconSource(
57 favicon::FallbackIconService
* fallback_icon_service
);
59 ~FallbackIconSource() override
;
61 // content::URLDataSource implementation.
62 std::string
GetSource() const override
;
63 void StartDataRequest(
64 const std::string
& path
,
65 int render_process_id
,
67 const content::URLDataSource::GotDataCallback
& callback
) override
;
68 std::string
GetMimeType(const std::string
&) const override
;
69 bool ShouldReplaceExistingSource() const override
;
70 bool ShouldServiceRequest(const net::URLRequest
* request
) const override
;
73 void SendFallbackIconHelper(
76 const favicon_base::FallbackIconStyle
& style
,
77 const content::URLDataSource::GotDataCallback
& callback
);
79 // Sends the default fallback icon.
80 void SendDefaultResponse(
81 const content::URLDataSource::GotDataCallback
& callback
);
83 favicon::FallbackIconService
* fallback_icon_service_
;
85 DISALLOW_COPY_AND_ASSIGN(FallbackIconSource
);
88 #endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_