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_LARGE_ICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | 9 |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "base/task/cancelable_task_tracker.h" | 11 #include "base/task/cancelable_task_tracker.h" |
13 #include "components/favicon/core/fallback_icon_service.h" | 12 #include "components/favicon/core/fallback_icon_service.h" |
14 #include "components/favicon_base/favicon_types.h" | |
15 #include "content/public/browser/url_data_source.h" | 13 #include "content/public/browser/url_data_source.h" |
16 #include "third_party/skia/include/core/SkColor.h" | |
17 | 14 |
18 namespace favicon { | 15 namespace favicon { |
19 class FallbackIconService; | 16 class FallbackIconService; |
20 class FaviconService; | 17 class LargeIconService; |
| 18 } |
| 19 |
| 20 namespace favicon_base { |
| 21 struct LargeIconResult; |
21 } | 22 } |
22 | 23 |
23 // LargeIconSource services explicit chrome:// requests for large icons. | 24 // LargeIconSource services explicit chrome:// requests for large icons. |
24 // | 25 // |
25 // Format: | 26 // Format: |
26 // chrome://large-icon/size/url | 27 // chrome://large-icon/size/url |
27 // | 28 // |
28 // Parameter: | 29 // Parameter: |
29 // 'size' Required (including trailing '/') | 30 // 'size' Required (including trailing '/') |
30 // Positive integer to specify the large icon's size in pixels. | 31 // Positive integer to specify the large icon's size in pixels. |
31 // 'url' Optional | 32 // 'url' Optional |
32 // String to specify the page URL of the large icon. | 33 // String to specify the page URL of the large icon. |
33 // | 34 // |
34 // Example: chrome://large-icon/48/http://www.google.com/ | 35 // Example: chrome://large-icon/48/http://www.google.com/ |
35 // This requests a 48x48 large icon for http://www.google.com. | 36 // This requests a 48x48 large icon for http://www.google.com. |
36 class LargeIconSource : public content::URLDataSource { | 37 class LargeIconSource : public content::URLDataSource { |
37 public: | 38 public: |
38 // |favicon_service| and |fallback_icon_service| are owned by caller and may | 39 // |fallback_icon_service| and |large_icon_service| are owned by caller and |
39 // be null. | 40 // may be null. |
40 LargeIconSource(favicon::FaviconService* favicon_service, | 41 LargeIconSource(favicon::FallbackIconService* fallback_icon_service, |
41 favicon::FallbackIconService* fallback_icon_service); | 42 favicon::LargeIconService* large_icon_service); |
42 | 43 |
43 ~LargeIconSource() override; | 44 ~LargeIconSource() override; |
44 | 45 |
45 // content::URLDataSource implementation. | 46 // content::URLDataSource implementation. |
46 std::string GetSource() const override; | 47 std::string GetSource() const override; |
47 void StartDataRequest( | 48 void StartDataRequest( |
48 const std::string& path, | 49 const std::string& path, |
49 int render_process_id, | 50 int render_process_id, |
50 int render_frame_id, | 51 int render_frame_id, |
51 const content::URLDataSource::GotDataCallback& callback) override; | 52 const content::URLDataSource::GotDataCallback& callback) override; |
52 std::string GetMimeType(const std::string&) const override; | 53 std::string GetMimeType(const std::string&) const override; |
53 bool ShouldReplaceExistingSource() const override; | 54 bool ShouldReplaceExistingSource() const override; |
54 bool ShouldServiceRequest(const net::URLRequest* request) const override; | 55 bool ShouldServiceRequest(const net::URLRequest* request) const override; |
55 | 56 |
56 protected: | |
57 struct IconRequest { | |
58 IconRequest(); | |
59 IconRequest(const content::URLDataSource::GotDataCallback& callback_in, | |
60 const GURL& path_in, | |
61 int size_in); | |
62 ~IconRequest(); | |
63 | |
64 content::URLDataSource::GotDataCallback callback; | |
65 GURL url; | |
66 int size; | |
67 }; | |
68 | |
69 private: | 57 private: |
70 // Callback for icon data retrieval request. | 58 // Called with results of large icon retrieval request. |
71 void OnIconDataAvailable( | 59 void OnLargeIconDataAvailable( |
72 const IconRequest& request, | 60 const content::URLDataSource::GotDataCallback& callback, |
73 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 61 const GURL& url, |
74 | 62 int size, |
75 // Renders and sends a default fallback icon. This is used when there is no | 63 const favicon_base::LargeIconResult& bitmap_result); |
76 // known text and/or foreground color to use for the generated icon (it | |
77 // defaults to a light text color on a dark gray background). | |
78 void SendDefaultFallbackIcon(const IconRequest& request); | |
79 | |
80 // Renders and sends a fallback icon using the given colors. | |
81 void SendFallbackIcon(const IconRequest& request, | |
82 SkColor text_color, | |
83 SkColor background_color); | |
84 | 64 |
85 // Returns null to trigger "Not Found" response. | 65 // Returns null to trigger "Not Found" response. |
86 void SendNotFoundResponse( | 66 void SendNotFoundResponse( |
87 const content::URLDataSource::GotDataCallback& callback); | 67 const content::URLDataSource::GotDataCallback& callback); |
88 | 68 |
89 base::CancelableTaskTracker cancelable_task_tracker_; | 69 base::CancelableTaskTracker cancelable_task_tracker_; |
90 | 70 |
91 favicon::FaviconService* favicon_service_; | 71 // Owned by client. |
92 | |
93 favicon::FallbackIconService* fallback_icon_service_; | 72 favicon::FallbackIconService* fallback_icon_service_; |
94 | 73 |
95 // A pre-populated list of the types of icon files to consider when looking | 74 // Owned by client. |
96 // for the largest matching icon. | 75 favicon::LargeIconService* large_icon_service_; |
97 // Note: this is simply an optimization over populating an icon type vector | |
98 // on each request. | |
99 std::vector<int> large_icon_types_; | |
100 | 76 |
101 DISALLOW_COPY_AND_ASSIGN(LargeIconSource); | 77 DISALLOW_COPY_AND_ASSIGN(LargeIconSource); |
102 }; | 78 }; |
103 | 79 |
104 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ | 80 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
OLD | NEW |