Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: chrome/browser/fav_icon_helper.h

Issue 482003: Get web app icon via FavIconHelper and auto repair/update (Closed)
Patch Set: miranda's review 1 Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/fav_icon_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_FAV_ICON_HELPER_H__ 5 #ifndef CHROME_BROWSER_FAV_ICON_HELPER_H__
6 #define CHROME_BROWSER_FAV_ICON_HELPER_H__ 6 #define CHROME_BROWSER_FAV_ICON_HELPER_H__
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // db knew about the favicon), or requests the renderer to download the 60 // db knew about the favicon), or requests the renderer to download the
61 // favicon. 61 // favicon.
62 // 62 //
63 // When the renderer downloads the favicon SetFavIconImageData is invoked, 63 // When the renderer downloads the favicon SetFavIconImageData is invoked,
64 // at which point we update the favicon of the NavigationEntry and notify 64 // at which point we update the favicon of the NavigationEntry and notify
65 // the database to save the favicon. 65 // the database to save the favicon.
66 66
67 class FavIconHelper : public RenderViewHostDelegate::FavIcon { 67 class FavIconHelper : public RenderViewHostDelegate::FavIcon {
68 public: 68 public:
69 explicit FavIconHelper(TabContents* tab_contents); 69 explicit FavIconHelper(TabContents* tab_contents);
70 virtual ~FavIconHelper();
70 71
71 // Initiates loading the favicon for the specified url. 72 // Initiates loading the favicon for the specified url.
72 void FetchFavIcon(const GURL& url); 73 void FetchFavIcon(const GURL& url);
73 74
74 // Sets the image data for the favicon. This is invoked asynchronously after 75 // Initiates loading an image from given |image_url|. Returns a download id
75 // we request the TabContents to download the favicon. 76 // for caller to track the request. When download completes, |callback| is
76 void SetFavIcon(int download_id, 77 // called with the three params: the download_id, a boolean flag to indicate
77 const GURL& icon_url, 78 // whether the download succeeds and a SkBitmap as the downloaded image.
78 const SkBitmap& image); 79 // Note that |image_size| is a hint for images with multiple sizes. The
79 80 // downloaded image is not resized to the given image_size. If 0 is passed,
80 // Invoked when a request to download the favicon failed. 81 // the first frame of the image is returned.
81 void FavIconDownloadFailed(int download_id); 82 typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback;
82 83 int DownloadImage(const GURL& image_url, int image_size,
83 // Converts the image data to an SkBitmap and sets it on the NavigationEntry. 84 ImageDownloadCallback* callback);
84 // If the TabContents has a delegate, it is notified of the new favicon
85 // (INVALIDATE_FAVICON).
86 void UpdateFavIcon(NavigationEntry* entry,
87 const std::vector<unsigned char>& data);
88 void UpdateFavIcon(NavigationEntry* entry, const SkBitmap& image);
89 85
90 private: 86 private:
91 struct DownloadRequest { 87 struct DownloadRequest {
92 DownloadRequest() {} 88 DownloadRequest() {}
93 DownloadRequest(const GURL& url, 89 DownloadRequest(const GURL& url,
94 const GURL& fav_icon_url) 90 const GURL& image_url,
91 ImageDownloadCallback* callback)
95 : url(url), 92 : url(url),
96 fav_icon_url(fav_icon_url) { } 93 image_url(image_url),
94 callback(callback) { }
97 95
98 GURL url; 96 GURL url;
99 GURL fav_icon_url; 97 GURL image_url;
98 ImageDownloadCallback* callback;
100 }; 99 };
101 100
102 // RenderViewHostDelegate::Favicon implementation. 101 // RenderViewHostDelegate::Favicon implementation.
103 virtual void DidDownloadFavIcon(RenderViewHost* render_view_host, 102 virtual void DidDownloadFavIcon(RenderViewHost* render_view_host,
104 int id, 103 int id,
105 const GURL& image_url, 104 const GURL& image_url,
106 bool errored, 105 bool errored,
107 const SkBitmap& image); 106 const SkBitmap& image);
108 virtual void UpdateFavIconURL(RenderViewHost* render_view_host, 107 virtual void UpdateFavIconURL(RenderViewHost* render_view_host,
109 int32 page_id, 108 int32 page_id,
(...skipping 21 matching lines...) Expand all
131 130
132 // See description above class for details. 131 // See description above class for details.
133 void OnFavIconData(FaviconService::Handle handle, 132 void OnFavIconData(FaviconService::Handle handle,
134 bool know_favicon, 133 bool know_favicon,
135 scoped_refptr<RefCountedBytes> data, 134 scoped_refptr<RefCountedBytes> data,
136 bool expired, 135 bool expired,
137 GURL icon_url); 136 GURL icon_url);
138 137
139 // Schedules a download for the specified entry. This adds the request to 138 // Schedules a download for the specified entry. This adds the request to
140 // download_requests_. 139 // download_requests_.
141 void ScheduleDownload(NavigationEntry* entry); 140 int ScheduleDownload(const GURL& url, const GURL& image_url, int image_size,
141 ImageDownloadCallback* callback);
142
143 // Sets the image data for the favicon. This is invoked asynchronously after
144 // we request the TabContents to download the favicon.
145 void SetFavIcon(const GURL& url, const GURL& icon_url, const SkBitmap& image);
146
147 // Converts the image data to an SkBitmap and sets it on the NavigationEntry.
148 // If the TabContents has a delegate, it is notified of the new favicon
149 // (INVALIDATE_FAVICON).
150 void UpdateFavIcon(NavigationEntry* entry,
151 const std::vector<unsigned char>& data);
152 void UpdateFavIcon(NavigationEntry* entry, const SkBitmap& image);
142 153
143 // Scales the image such that either the width and/or height is 16 pixels 154 // Scales the image such that either the width and/or height is 16 pixels
144 // wide. Does nothing if the image is empty. 155 // wide. Does nothing if the image is empty.
145 SkBitmap ConvertToFavIconSize(const SkBitmap& image); 156 SkBitmap ConvertToFavIconSize(const SkBitmap& image);
146 157
147 // Hosting TabContents. We callback into this when done. 158 // Hosting TabContents. We callback into this when done.
148 TabContents* tab_contents_; 159 TabContents* tab_contents_;
149 160
150 // Used for history requests. 161 // Used for history requests.
151 CancelableRequestConsumer cancelable_consumer_; 162 CancelableRequestConsumer cancelable_consumer_;
(...skipping 16 matching lines...) Expand all
168 bool fav_icon_expired_; 179 bool fav_icon_expired_;
169 180
170 // Requests to the renderer to download favicons. 181 // Requests to the renderer to download favicons.
171 typedef std::map<int, DownloadRequest> DownloadRequests; 182 typedef std::map<int, DownloadRequest> DownloadRequests;
172 DownloadRequests download_requests_; 183 DownloadRequests download_requests_;
173 184
174 DISALLOW_EVIL_CONSTRUCTORS(FavIconHelper); 185 DISALLOW_EVIL_CONSTRUCTORS(FavIconHelper);
175 }; 186 };
176 187
177 #endif // CHROME_BROWSER_FAV_ICON_HELPER_H__ 188 #endif // CHROME_BROWSER_FAV_ICON_HELPER_H__
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/fav_icon_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698