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