| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "chrome/browser/cancelable_request.h" | 14 #include "chrome/browser/cancelable_request.h" |
| 15 #include "chrome/browser/favicon_service.h" | 15 #include "chrome/browser/favicon_service.h" |
| 16 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 16 #include "chrome/browser/tab_contents/web_navigation_observer.h" |
| 17 #include "chrome/common/ref_counted_util.h" | 17 #include "chrome/common/ref_counted_util.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 | 19 |
| 20 class NavigationEntry; | 20 class NavigationEntry; |
| 21 class Profile; | 21 class Profile; |
| 22 class RefCountedMemory; | 22 class RefCountedMemory; |
| 23 class SkBitmap; | 23 class SkBitmap; |
| 24 class TabContents; | 24 class TabContents; |
| 25 | 25 |
| 26 // FavIconHelper is used to fetch the favicon for TabContents. | 26 // FavIconHelper is used to fetch the favicon for TabContents. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // between page to favicon url. The callback for this is OnFavIconData. | 58 // between page to favicon url. The callback for this is OnFavIconData. |
| 59 // | 59 // |
| 60 // OnFavIconData either updates the favicon of the NavigationEntry (if the | 60 // OnFavIconData either updates the favicon of the NavigationEntry (if the |
| 61 // db knew about the favicon), or requests the renderer to download the | 61 // db knew about the favicon), or requests the renderer to download the |
| 62 // favicon. | 62 // favicon. |
| 63 // | 63 // |
| 64 // When the renderer downloads the favicon SetFavIconImageData is invoked, | 64 // When the renderer downloads the favicon SetFavIconImageData is invoked, |
| 65 // at which point we update the favicon of the NavigationEntry and notify | 65 // at which point we update the favicon of the NavigationEntry and notify |
| 66 // the database to save the favicon. | 66 // the database to save the favicon. |
| 67 | 67 |
| 68 class FavIconHelper : public RenderViewHostDelegate::FavIcon { | 68 class FavIconHelper : public WebNavigationObserver { |
| 69 public: | 69 public: |
| 70 explicit FavIconHelper(TabContents* tab_contents); | 70 explicit FavIconHelper(TabContents* tab_contents); |
| 71 virtual ~FavIconHelper(); | 71 virtual ~FavIconHelper(); |
| 72 | 72 |
| 73 // Initiates loading the favicon for the specified url. | 73 // Initiates loading the favicon for the specified url. |
| 74 void FetchFavIcon(const GURL& url); | 74 void FetchFavIcon(const GURL& url); |
| 75 | 75 |
| 76 // Initiates loading an image from given |image_url|. Returns a download id | 76 // Initiates loading an image from given |image_url|. Returns a download id |
| 77 // for caller to track the request. When download completes, |callback| is | 77 // for caller to track the request. When download completes, |callback| is |
| 78 // called with the three params: the download_id, a boolean flag to indicate | 78 // called with the three params: the download_id, a boolean flag to indicate |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 ImageDownloadCallback* callback) | 92 ImageDownloadCallback* callback) |
| 93 : url(url), | 93 : url(url), |
| 94 image_url(image_url), | 94 image_url(image_url), |
| 95 callback(callback) { } | 95 callback(callback) { } |
| 96 | 96 |
| 97 GURL url; | 97 GURL url; |
| 98 GURL image_url; | 98 GURL image_url; |
| 99 ImageDownloadCallback* callback; | 99 ImageDownloadCallback* callback; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // RenderViewHostDelegate::Favicon implementation. | 102 // WebNavigationObserver implementation. |
| 103 virtual void DidDownloadFavIcon(RenderViewHost* render_view_host, | 103 virtual bool OnMessageReceived(const IPC::Message& message); |
| 104 int id, | 104 |
| 105 const GURL& image_url, | 105 void OnDidDownloadFavIcon(int id, |
| 106 bool errored, | 106 const GURL& image_url, |
| 107 const SkBitmap& image); | 107 bool errored, |
| 108 virtual void UpdateFavIconURL(RenderViewHost* render_view_host, | 108 const SkBitmap& image); |
| 109 int32 page_id, | 109 void OnUpdateFavIconURL(int32 page_id, const GURL& icon_url); |
| 110 const GURL& icon_url); | |
| 111 | 110 |
| 112 // Return the NavigationEntry for the active entry, or NULL if the active | 111 // Return the NavigationEntry for the active entry, or NULL if the active |
| 113 // entries URL does not match that of the URL last passed to FetchFavIcon. | 112 // entries URL does not match that of the URL last passed to FetchFavIcon. |
| 114 NavigationEntry* GetEntry(); | 113 NavigationEntry* GetEntry(); |
| 115 | 114 |
| 116 Profile* profile(); | 115 Profile* profile(); |
| 117 | 116 |
| 118 FaviconService* GetFaviconService(); | 117 FaviconService* GetFaviconService(); |
| 119 | 118 |
| 120 // See description above class for details. | 119 // See description above class for details. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 bool fav_icon_expired_; | 182 bool fav_icon_expired_; |
| 184 | 183 |
| 185 // Requests to the renderer to download favicons. | 184 // Requests to the renderer to download favicons. |
| 186 typedef std::map<int, DownloadRequest> DownloadRequests; | 185 typedef std::map<int, DownloadRequest> DownloadRequests; |
| 187 DownloadRequests download_requests_; | 186 DownloadRequests download_requests_; |
| 188 | 187 |
| 189 DISALLOW_COPY_AND_ASSIGN(FavIconHelper); | 188 DISALLOW_COPY_AND_ASSIGN(FavIconHelper); |
| 190 }; | 189 }; |
| 191 | 190 |
| 192 #endif // CHROME_BROWSER_FAV_ICON_HELPER_H__ | 191 #endif // CHROME_BROWSER_FAV_ICON_HELPER_H__ |
| OLD | NEW |