| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_FAVICON_HELPER_H__ | 5 #ifndef CHROME_BROWSER_FAVICON_TAB_HELPER_H__ |
| 6 #define CHROME_BROWSER_FAVICON_HELPER_H__ | 6 #define CHROME_BROWSER_FAVICON_TAB_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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/favicon_service.h" | 14 #include "chrome/browser/favicon_service.h" |
| 15 #include "chrome/common/ref_counted_util.h" | |
| 16 #include "content/browser/cancelable_request.h" | 15 #include "content/browser/cancelable_request.h" |
| 17 #include "content/browser/tab_contents/tab_contents_observer.h" | 16 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 19 | 18 |
| 20 class NavigationEntry; | 19 class NavigationEntry; |
| 21 class Profile; | |
| 22 class RefCountedMemory; | 20 class RefCountedMemory; |
| 23 class SkBitmap; | 21 class SkBitmap; |
| 24 class TabContents; | 22 class TabContents; |
| 25 | 23 |
| 26 // FaviconHelper is used to fetch the favicon for TabContents. | 24 // FaviconTabHelper is used to fetch the favicon for TabContents. |
| 27 // | 25 // |
| 28 // FetchFavicon requests the favicon from the favicon service which in turn | 26 // FetchFavicon requests the favicon from the favicon service which in turn |
| 29 // requests the favicon from the history database. At this point | 27 // requests the favicon from the history database. At this point |
| 30 // we only know the URL of the page, and not necessarily the url of the | 28 // we only know the URL of the page, and not necessarily the url of the |
| 31 // favicon. To ensure we handle reloading stale favicons as well as | 29 // favicon. To ensure we handle reloading stale favicons as well as |
| 32 // reloading a favicon on page reload we always request the favicon from | 30 // reloading a favicon on page reload we always request the favicon from |
| 33 // history regardless of whether the NavigationEntry has a favicon. | 31 // history regardless of whether the NavigationEntry has a favicon. |
| 34 // | 32 // |
| 35 // After the navigation two types of events are delivered (which is | 33 // After the navigation two types of events are delivered (which is |
| 36 // first depends upon who is faster): notification from the history | 34 // first depends upon who is faster): notification from the history |
| (...skipping 21 matching lines...) Expand all Loading... |
| 58 // between page to favicon url. The callback for this is OnFaviconData. | 56 // between page to favicon url. The callback for this is OnFaviconData. |
| 59 // | 57 // |
| 60 // OnFaviconData either updates the favicon of the NavigationEntry (if the | 58 // OnFaviconData either updates the favicon of the NavigationEntry (if the |
| 61 // db knew about the favicon), or requests the renderer to download the | 59 // db knew about the favicon), or requests the renderer to download the |
| 62 // favicon. | 60 // favicon. |
| 63 // | 61 // |
| 64 // When the renderer downloads the favicon SetFaviconImageData is invoked, | 62 // When the renderer downloads the favicon SetFaviconImageData is invoked, |
| 65 // at which point we update the favicon of the NavigationEntry and notify | 63 // at which point we update the favicon of the NavigationEntry and notify |
| 66 // the database to save the favicon. | 64 // the database to save the favicon. |
| 67 | 65 |
| 68 class FaviconHelper : public TabContentsObserver { | 66 class FaviconTabHelper : public TabContentsObserver { |
| 69 public: | 67 public: |
| 70 explicit FaviconHelper(TabContents* tab_contents); | 68 explicit FaviconTabHelper(TabContents* tab_contents); |
| 71 virtual ~FaviconHelper(); | 69 virtual ~FaviconTabHelper(); |
| 72 | 70 |
| 73 // Initiates loading the favicon for the specified url. | 71 // Returns the favicon for this tab, or an isNull() bitmap if the tab does not |
| 74 void FetchFavicon(const GURL& url); | 72 // have a favicon. The default implementation uses the current navigation |
| 73 // entry. |
| 74 SkBitmap GetFavicon() const; |
| 75 |
| 76 // Returns true if we are not using the default favicon. |
| 77 bool FaviconIsValid() const; |
| 78 |
| 79 // Returns whether the favicon should be displayed. If this returns false, no |
| 80 // space is provided for the favicon, and the favicon is never displayed. |
| 81 virtual bool ShouldDisplayFavicon(); |
| 82 |
| 83 // Saves the favicon for the current page. |
| 84 void SaveFavicon(); |
| 75 | 85 |
| 76 // Initiates loading an image from given |image_url|. Returns a download id | 86 // Initiates loading an image from given |image_url|. Returns a download id |
| 77 // for caller to track the request. When download completes, |callback| is | 87 // 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 | 88 // called with the three params: the download_id, a boolean flag to indicate |
| 79 // whether the download succeeds and a SkBitmap as the downloaded image. | 89 // whether the download succeeds and a SkBitmap as the downloaded image. |
| 80 // Note that |image_size| is a hint for images with multiple sizes. The | 90 // Note that |image_size| is a hint for images with multiple sizes. The |
| 81 // downloaded image is not resized to the given image_size. If 0 is passed, | 91 // downloaded image is not resized to the given image_size. If 0 is passed, |
| 82 // the first frame of the image is returned. | 92 // the first frame of the image is returned. |
| 83 typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback; | 93 typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback; |
| 84 int DownloadImage(const GURL& image_url, int image_size, | 94 int DownloadImage(const GURL& image_url, int image_size, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 ImageDownloadCallback* callback) | 106 ImageDownloadCallback* callback) |
| 97 : url(url), | 107 : url(url), |
| 98 image_url(image_url), | 108 image_url(image_url), |
| 99 callback(callback) {} | 109 callback(callback) {} |
| 100 | 110 |
| 101 GURL url; | 111 GURL url; |
| 102 GURL image_url; | 112 GURL image_url; |
| 103 ImageDownloadCallback* callback; | 113 ImageDownloadCallback* callback; |
| 104 }; | 114 }; |
| 105 | 115 |
| 106 // TabContentsObserver implementation. | 116 // TabContentsObserver overrides. |
| 107 virtual bool OnMessageReceived(const IPC::Message& message); | 117 virtual void NavigateToPendingEntry( |
| 118 const GURL& url, |
| 119 NavigationController::ReloadType reload_type) OVERRIDE; |
| 120 virtual void DidNavigateMainFramePostCommit( |
| 121 const NavigationController::LoadCommittedDetails& details, |
| 122 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; |
| 123 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 108 | 124 |
| 109 void OnDidDownloadFavicon(int id, | 125 void OnDidDownloadFavicon(int id, |
| 110 const GURL& image_url, | 126 const GURL& image_url, |
| 111 bool errored, | 127 bool errored, |
| 112 const SkBitmap& image); | 128 const SkBitmap& image); |
| 113 | 129 |
| 130 // Initiates loading the favicon for the specified url. |
| 131 void FetchFavicon(const GURL& url); |
| 132 |
| 114 // Return the NavigationEntry for the active entry, or NULL if the active | 133 // Return the NavigationEntry for the active entry, or NULL if the active |
| 115 // entries URL does not match that of the URL last passed to FetchFavicon. | 134 // entries URL does not match that of the URL last passed to FetchFavicon. |
| 116 NavigationEntry* GetEntry(); | 135 NavigationEntry* GetEntry(); |
| 117 | 136 |
| 118 Profile* profile(); | |
| 119 | |
| 120 FaviconService* GetFaviconService(); | 137 FaviconService* GetFaviconService(); |
| 121 | 138 |
| 122 // See description above class for details. | 139 // See description above class for details. |
| 123 void OnFaviconDataForInitialURL(FaviconService::Handle handle, | 140 void OnFaviconDataForInitialURL(FaviconService::Handle handle, |
| 124 history::FaviconData favicon); | 141 history::FaviconData favicon); |
| 125 | 142 |
| 126 // If the favicon has expired, asks the renderer to download the favicon. | 143 // If the favicon has expired, asks the renderer to download the favicon. |
| 127 // Otherwise asks history to update the mapping between page url and icon | 144 // Otherwise asks history to update the mapping between page url and icon |
| 128 // url with a callback to OnFaviconData when done. | 145 // url with a callback to OnFaviconData when done. |
| 129 void DownloadFaviconOrAskHistory(NavigationEntry* entry); | 146 void DownloadFaviconOrAskHistory(NavigationEntry* entry); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Whether the favicon is out of date. If true, it means history knows about | 189 // Whether the favicon is out of date. If true, it means history knows about |
| 173 // the favicon, but we need to download the favicon because the icon has | 190 // the favicon, but we need to download the favicon because the icon has |
| 174 // expired. | 191 // expired. |
| 175 // See "Favicon Details" in tab_contents.cc for more details. | 192 // See "Favicon Details" in tab_contents.cc for more details. |
| 176 bool favicon_expired_; | 193 bool favicon_expired_; |
| 177 | 194 |
| 178 // Requests to the renderer to download favicons. | 195 // Requests to the renderer to download favicons. |
| 179 typedef std::map<int, DownloadRequest> DownloadRequests; | 196 typedef std::map<int, DownloadRequest> DownloadRequests; |
| 180 DownloadRequests download_requests_; | 197 DownloadRequests download_requests_; |
| 181 | 198 |
| 182 DISALLOW_COPY_AND_ASSIGN(FaviconHelper); | 199 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); |
| 183 }; | 200 }; |
| 184 | 201 |
| 185 #endif // CHROME_BROWSER_FAVICON_HELPER_H__ | 202 #endif // CHROME_BROWSER_FAVICON_TAB_HELPER_H__ |
| OLD | NEW |