Chromium Code Reviews| 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 // All of the parameters except for the url are optional. However, the order of | |
|
Roger McFarlane (Chromium)
2015/03/17 20:41:01
abortive comment?
huangs
2015/03/18 22:54:12
Done.
| |
| 21 // | |
| 22 // Parameter: | |
| 23 // 'size' | |
| 24 // Positive integer to specify the large icon's size in pixels. | |
| 25 // 'url' | |
| 26 // String to specify the page URL of the large icon. | |
| 27 // | |
| 28 // Example: chrome://large-icon/48/http://www.google.com/ | |
| 29 // This requests a 48x48 large icon for http://www.google.com. | |
| 30 class LargeIconSource : public content::URLDataSource { | |
| 31 public: | |
| 32 explicit LargeIconSource(Profile* profile); | |
| 33 | |
| 34 ~LargeIconSource() override; | |
| 35 | |
| 36 // content::URLDataSource implementation. | |
| 37 std::string GetSource() const override; | |
| 38 void StartDataRequest( | |
| 39 const std::string& path, | |
| 40 int render_process_id, | |
| 41 int render_frame_id, | |
| 42 const content::URLDataSource::GotDataCallback& callback) override; | |
| 43 std::string GetMimeType(const std::string&) const override; | |
| 44 bool ShouldReplaceExistingSource() const override; | |
| 45 bool ShouldServiceRequest(const net::URLRequest* request) const override; | |
| 46 | |
| 47 protected: | |
| 48 struct IconRequest { | |
| 49 IconRequest(); | |
| 50 IconRequest(const content::URLDataSource::GotDataCallback& callback_in, | |
| 51 const GURL& path_in, | |
| 52 int size_in); | |
| 53 ~IconRequest(); | |
| 54 | |
| 55 content::URLDataSource::GotDataCallback callback; | |
| 56 GURL url; | |
| 57 int size; | |
| 58 }; | |
| 59 | |
| 60 private: | |
| 61 // Callback for icon data retrieval request. | |
| 62 void OnIconDataAvailable( | |
| 63 const IconRequest& request, | |
| 64 const favicon_base::FaviconRawBitmapResult& bitmap_result); | |
| 65 | |
| 66 // Handler for icon retrieval and resizing errors. If | |
| 67 // |render_fallback_on_failure_| then sends fallback icon, otherwise send | |
| 68 // "Not Found" response. | |
| 69 void OnIconDataError(const IconRequest& request); | |
| 70 | |
| 71 // Renders and returns a fallback icon. | |
|
beaudoin
2015/03/17 23:08:36
I don't like "returns" here since the method doesn
huangs
2015/03/18 22:54:12
Replacing "returns" with "sends". It's shorter, a
beaudoin
2015/03/19 01:50:18
Acknowledged.
| |
| 72 void SendFallbackIcon(const IconRequest& request); | |
| 73 | |
| 74 // Returns null to trigger "Not Found" response. | |
| 75 void SendNotFoundResponse( | |
| 76 const content::URLDataSource::GotDataCallback& callback); | |
| 77 | |
| 78 Profile* profile_; | |
| 79 | |
| 80 base::CancelableTaskTracker cancelable_task_tracker_; | |
| 81 | |
| 82 scoped_ptr<favicon_base::FallbackIconService> fallback_icon_service_; | |
| 83 | |
| 84 // Flag to control what to do when large icon lookup fails. | |
| 85 bool render_fallback_on_failure_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(LargeIconSource); | |
| 88 }; | |
| 89 | |
| 90 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ | |
| OLD | NEW |