OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "components/favicon/core/fallback_icon_service.h" | |
10 #include "content/public/browser/url_data_source.h" | 11 #include "content/public/browser/url_data_source.h" |
11 | 12 |
| 13 class FallbackIconService; |
| 14 class GURL; |
| 15 |
| 16 namespace favicon_base { |
| 17 struct FallbackIconStyle; |
| 18 } |
| 19 |
12 // FallbackIconSource services explicit chrome:// requests for fallback icons. | 20 // FallbackIconSource services explicit chrome:// requests for fallback icons. |
13 // | 21 // |
14 // Format: | 22 // Format: |
15 // chrome://fallback-icon/size,bc,tc,fsr,r/url | 23 // chrome://fallback-icon/size,bc,tc,fsr,r/url |
16 // All of the parameters except for the url are optional. However, the order of | 24 // All of the parameters except for the url are optional. However, the order of |
17 // the parameters is not interchangeable, and all "," must be in place. | 25 // the parameters is not interchangeable, and all "," must be in place. |
18 // | 26 // |
19 // Parameter: | 27 // Parameter: |
20 // 'size' | 28 // 'size' |
21 // Positive integer to specify the fallback icon's size in pixels. | 29 // Positive integer to specify the fallback icon's size in pixels. |
(...skipping 12 matching lines...) Expand all Loading... |
34 // values specify a rounded square icon. | 42 // values specify a rounded square icon. |
35 // 'url' | 43 // 'url' |
36 // String to specify the page URL of the fallback icon. | 44 // String to specify the page URL of the fallback icon. |
37 // | 45 // |
38 // Example: chrome://fallback-icon/32,red,#000,0.5,1.0/http://www.google.com/ | 46 // Example: chrome://fallback-icon/32,red,#000,0.5,1.0/http://www.google.com/ |
39 // This requests a 32x32 fallback icon for http://www.google.com, using | 47 // This requests a 32x32 fallback icon for http://www.google.com, using |
40 // red as the background color, #000 as the text color, with font size of | 48 // red as the background color, #000 as the text color, with font size of |
41 // 32 * 0.5 = 16, and the icon's background shape is a circle. | 49 // 32 * 0.5 = 16, and the icon's background shape is a circle. |
42 class FallbackIconSource : public content::URLDataSource { | 50 class FallbackIconSource : public content::URLDataSource { |
43 public: | 51 public: |
44 FallbackIconSource(); | 52 // |fallback_icon_service| is owned by caller, and may be null. |
| 53 explicit FallbackIconSource(FallbackIconService* fallback_icon_service); |
45 | 54 |
46 ~FallbackIconSource() override; | 55 ~FallbackIconSource() override; |
47 | 56 |
48 // content::URLDataSource implementation. | 57 // content::URLDataSource implementation. |
49 std::string GetSource() const override; | 58 std::string GetSource() const override; |
50 void StartDataRequest( | 59 void StartDataRequest( |
51 const std::string& path, | 60 const std::string& path, |
52 int render_process_id, | 61 int render_process_id, |
53 int render_frame_id, | 62 int render_frame_id, |
54 const content::URLDataSource::GotDataCallback& callback) override; | 63 const content::URLDataSource::GotDataCallback& callback) override; |
55 std::string GetMimeType(const std::string&) const override; | 64 std::string GetMimeType(const std::string&) const override; |
56 bool ShouldReplaceExistingSource() const override; | 65 bool ShouldReplaceExistingSource() const override; |
57 bool ShouldServiceRequest(const net::URLRequest* request) const override; | 66 bool ShouldServiceRequest(const net::URLRequest* request) const override; |
58 | 67 |
59 private: | 68 private: |
| 69 void SendFallbackIconHelper( |
| 70 const GURL& url, |
| 71 int size_in_pixels, |
| 72 const favicon_base::FallbackIconStyle& style, |
| 73 const content::URLDataSource::GotDataCallback& callback); |
| 74 |
60 // Sends the default fallback icon. | 75 // Sends the default fallback icon. |
61 void SendDefaultResponse( | 76 void SendDefaultResponse( |
62 const content::URLDataSource::GotDataCallback& callback); | 77 const content::URLDataSource::GotDataCallback& callback); |
63 | 78 |
64 scoped_ptr<FallbackIconService> fallback_icon_service_; | 79 FallbackIconService* fallback_icon_service_; |
65 | 80 |
66 DISALLOW_COPY_AND_ASSIGN(FallbackIconSource); | 81 DISALLOW_COPY_AND_ASSIGN(FallbackIconSource); |
67 }; | 82 }; |
68 | 83 |
69 #endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ | 84 #endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ |
OLD | NEW |