| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FAVICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
| 14 #include "chrome/common/cancelable_task_tracker.h" | 14 #include "chrome/common/cancelable_task_tracker.h" |
| 15 #include "content/public/browser/url_data_source.h" | 15 #include "content/public/browser/url_data_source.h" |
| 16 #include "ui/gfx/favicon_size.h" | 16 #include "ui/gfx/favicon_size.h" |
| 17 | 17 |
| 18 class Profile; | 18 class Profile; |
| 19 | 19 |
| 20 // FaviconSource is the gateway between network-level chrome: | 20 // FaviconSource is the gateway between network-level chrome: |
| 21 // requests for favicons and the history backend that serves these. | 21 // requests for favicons and the history backend that serves these. |
| 22 // |
| 23 // Format: |
| 24 // chrome://favicon/size&scalefactor/urlmodifier/url |
| 25 // Some parameters are optional as described below. However, the order of the |
| 26 // parameters is not interchangeable. |
| 27 // |
| 28 // Parameter: |
| 29 // 'url' Required |
| 30 // Specifies the page URL of the requested favicon. If the 'urlmodifier' |
| 31 // parameter is 'iconurl', the URL refers to the URL of the favicon image |
| 32 // instead. |
| 33 // 'size&scalefactor' Optional size/aa@bx/ |
| 34 // Specifies the requested favicon's size in DIP (aa) and the requested |
| 35 // favicon's scale factor. (b). |
| 36 // The supported requested DIP sizes are: 16x16, 32x32 and 64x64. |
| 37 // If the parameter is unspecified, the requested favicon's size defaults to |
| 38 // 16 and the requested scale factor defaults to 1x. |
| 39 // Example: chrome://favicon/size/16@2x/http://www.google.com/ |
| 40 // 'urlmodifier' Optional |
| 41 // Values: ['iconurl', 'origin'] |
| 42 // 'iconurl': Specifies that the url parameter refers to the URL of |
| 43 // the favicon image as opposed to the URL of the page that the favicon is |
| 44 // on. |
| 45 // Example: chrome://favicon/iconurl/http://www.google.com/favicon.ico |
| 46 // 'origin': Specifies that the URL should be converted to a form with |
| 47 // an empty path and a valid scheme. The converted URL will be used to |
| 48 // request the favicon from the favicon service. |
| 49 // Examples: |
| 50 // chrome://favicon/origin/http://example.com/a |
| 51 // chrome://favicon/origin/example.com |
| 52 // Both URLs request the favicon for http://example.com from the |
| 53 // favicon service. |
| 22 class FaviconSource : public content::URLDataSource { | 54 class FaviconSource : public content::URLDataSource { |
| 23 public: | 55 public: |
| 24 // Defines the type of icon the FaviconSource will provide. | 56 // Defines the type of icon the FaviconSource will provide. |
| 25 enum IconType { | 57 enum IconType { |
| 26 FAVICON, | 58 FAVICON, |
| 27 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON, | 59 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON, |
| 28 // FAVICON, and default favicon. | 60 // FAVICON, and default favicon. |
| 29 ANY | 61 ANY |
| 30 }; | 62 }; |
| 31 | 63 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 SIZE_32, | 105 SIZE_32, |
| 74 SIZE_64, | 106 SIZE_64, |
| 75 NUM_SIZES | 107 NUM_SIZES |
| 76 }; | 108 }; |
| 77 | 109 |
| 78 // Called when favicon data is available from the history backend. | 110 // Called when favicon data is available from the history backend. |
| 79 void OnFaviconDataAvailable( | 111 void OnFaviconDataAvailable( |
| 80 const IconRequest& request, | 112 const IconRequest& request, |
| 81 const history::FaviconBitmapResult& bitmap_result); | 113 const history::FaviconBitmapResult& bitmap_result); |
| 82 | 114 |
| 115 // Sends the 16x16 DIP 1x default favicon. |
| 116 void SendDefaultResponse( |
| 117 const content::URLDataSource::GotDataCallback& callback); |
| 118 |
| 83 // Sends the default favicon. | 119 // Sends the default favicon. |
| 84 void SendDefaultResponse(const IconRequest& request); | 120 void SendDefaultResponse(const IconRequest& request); |
| 85 | 121 |
| 86 CancelableTaskTracker cancelable_task_tracker_; | 122 CancelableTaskTracker cancelable_task_tracker_; |
| 87 | 123 |
| 88 // Raw PNG representations of favicons of each size to show when the favicon | 124 // Raw PNG representations of favicons of each size to show when the favicon |
| 89 // database doesn't have a favicon for a webpage. Indexed by IconSize values. | 125 // database doesn't have a favicon for a webpage. Indexed by IconSize values. |
| 90 scoped_refptr<base::RefCountedMemory> default_favicons_[NUM_SIZES]; | 126 scoped_refptr<base::RefCountedMemory> default_favicons_[NUM_SIZES]; |
| 91 | 127 |
| 92 // The history::IconTypes of icon that this FaviconSource handles. | 128 // The history::IconTypes of icon that this FaviconSource handles. |
| 93 int icon_types_; | 129 int icon_types_; |
| 94 | 130 |
| 95 DISALLOW_COPY_AND_ASSIGN(FaviconSource); | 131 DISALLOW_COPY_AND_ASSIGN(FaviconSource); |
| 96 }; | 132 }; |
| 97 | 133 |
| 98 #endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ | 134 #endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
| OLD | NEW |