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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "components/favicon_base/fallback_icon_service.h" | |
10 #include "content/public/browser/url_data_source.h" | 9 #include "content/public/browser/url_data_source.h" |
11 | 10 |
| 11 class GURL; |
| 12 class Profile; |
| 13 |
| 14 namespace favicon_base { |
| 15 struct FallbackIconStyle; |
| 16 } // namespace favicon_base |
| 17 |
12 // FallbackIconSource services explicit chrome:// requests for fallback icons. | 18 // FallbackIconSource services explicit chrome:// requests for fallback icons. |
13 // | 19 // |
14 // Format: | 20 // Format: |
15 // chrome://fallback-icon/size,bc,tc,fsr,r/url | 21 // chrome://fallback-icon/size,bc,tc,fsr,r/url |
16 // All of the parameters except for the url are optional. However, the order of | 22 // 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. | 23 // the parameters is not interchangeable, and all "," must be in place. |
18 // | 24 // |
19 // Parameter: | 25 // Parameter: |
20 // 'size' | 26 // 'size' |
21 // Positive integer to specify the fallback icon's size in pixels. | 27 // 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. | 40 // values specify a rounded square icon. |
35 // 'url' | 41 // 'url' |
36 // String to specify the page URL of the fallback icon. | 42 // String to specify the page URL of the fallback icon. |
37 // | 43 // |
38 // Example: chrome://fallback-icon/32,red,#000,0.5,1.0/http://www.google.com/ | 44 // 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 | 45 // 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 | 46 // 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. | 47 // 32 * 0.5 = 16, and the icon's background shape is a circle. |
42 class FallbackIconSource : public content::URLDataSource { | 48 class FallbackIconSource : public content::URLDataSource { |
43 public: | 49 public: |
44 FallbackIconSource(); | 50 explicit FallbackIconSource(Profile* profile); |
45 | 51 |
46 ~FallbackIconSource() override; | 52 ~FallbackIconSource() override; |
47 | 53 |
48 // content::URLDataSource implementation. | 54 // content::URLDataSource implementation. |
49 std::string GetSource() const override; | 55 std::string GetSource() const override; |
50 void StartDataRequest( | 56 void StartDataRequest( |
51 const std::string& path, | 57 const std::string& path, |
52 int render_process_id, | 58 int render_process_id, |
53 int render_frame_id, | 59 int render_frame_id, |
54 const content::URLDataSource::GotDataCallback& callback) override; | 60 const content::URLDataSource::GotDataCallback& callback) override; |
55 std::string GetMimeType(const std::string&) const override; | 61 std::string GetMimeType(const std::string&) const override; |
56 bool ShouldReplaceExistingSource() const override; | 62 bool ShouldReplaceExistingSource() const override; |
57 bool ShouldServiceRequest(const net::URLRequest* request) const override; | 63 bool ShouldServiceRequest(const net::URLRequest* request) const override; |
58 | 64 |
59 private: | 65 private: |
| 66 void SendFallbackIconHelper( |
| 67 const GURL& url, |
| 68 int size_in_pixels, |
| 69 const favicon_base::FallbackIconStyle& style, |
| 70 const content::URLDataSource::GotDataCallback& callback); |
| 71 |
60 // Sends the default fallback icon. | 72 // Sends the default fallback icon. |
61 void SendDefaultResponse( | 73 void SendDefaultResponse( |
62 const content::URLDataSource::GotDataCallback& callback); | 74 const content::URLDataSource::GotDataCallback& callback); |
63 | 75 |
64 scoped_ptr<favicon_base::FallbackIconService> fallback_icon_service_; | 76 |
| 77 Profile* profile_; |
65 | 78 |
66 DISALLOW_COPY_AND_ASSIGN(FallbackIconSource); | 79 DISALLOW_COPY_AND_ASSIGN(FallbackIconSource); |
67 }; | 80 }; |
68 | 81 |
69 #endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ | 82 #endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ |
OLD | NEW |