OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/task/cancelable_task_tracker.h" |
| 10 #include "components/favicon_base/fallback_icon_service.h" |
| 11 #include "components/favicon_base/favicon_types.h" |
| 12 #include "content/public/browser/url_data_source.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 // LargeIconSource services explicit chrome:// requests for large icons. |
| 17 // |
| 18 // Format: |
| 19 // chrome://large-icon/size/url |
| 20 // |
| 21 // Parameter: |
| 22 // 'size' Required (including trailing '/') |
| 23 // Positive integer to specify the large icon's size in pixels. |
| 24 // 'url' Optional |
| 25 // String to specify the page URL of the large icon. |
| 26 // |
| 27 // Example: chrome://large-icon/48/http://www.google.com/ |
| 28 // This requests a 48x48 large icon for http://www.google.com. |
| 29 class LargeIconSource : public content::URLDataSource { |
| 30 public: |
| 31 explicit LargeIconSource(Profile* profile); |
| 32 |
| 33 ~LargeIconSource() override; |
| 34 |
| 35 // content::URLDataSource implementation. |
| 36 std::string GetSource() const override; |
| 37 void StartDataRequest( |
| 38 const std::string& path, |
| 39 int render_process_id, |
| 40 int render_frame_id, |
| 41 const content::URLDataSource::GotDataCallback& callback) override; |
| 42 std::string GetMimeType(const std::string&) const override; |
| 43 bool ShouldReplaceExistingSource() const override; |
| 44 bool ShouldServiceRequest(const net::URLRequest* request) const override; |
| 45 |
| 46 protected: |
| 47 struct IconRequest { |
| 48 IconRequest(); |
| 49 IconRequest(const content::URLDataSource::GotDataCallback& callback_in, |
| 50 const GURL& path_in, |
| 51 int size_in); |
| 52 ~IconRequest(); |
| 53 |
| 54 content::URLDataSource::GotDataCallback callback; |
| 55 GURL url; |
| 56 int size; |
| 57 }; |
| 58 |
| 59 private: |
| 60 // Callback for icon data retrieval request. |
| 61 void OnIconDataAvailable( |
| 62 const IconRequest& request, |
| 63 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 64 |
| 65 // Renders and sends a fallback icon. |
| 66 void SendFallbackIcon(const IconRequest& request); |
| 67 |
| 68 // Returns null to trigger "Not Found" response. |
| 69 void SendNotFoundResponse( |
| 70 const content::URLDataSource::GotDataCallback& callback); |
| 71 |
| 72 Profile* profile_; |
| 73 |
| 74 base::CancelableTaskTracker cancelable_task_tracker_; |
| 75 |
| 76 scoped_ptr<favicon_base::FallbackIconService> fallback_icon_service_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(LargeIconSource); |
| 79 }; |
| 80 |
| 81 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ |
OLD | NEW |