| 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_FAVICON_FAVICON_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "chrome/browser/common/web_contents_user_data.h" |
| 12 #include "chrome/browser/favicon/favicon_handler_delegate.h" | 13 #include "chrome/browser/favicon/favicon_handler_delegate.h" |
| 13 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
| 14 #include "chrome/common/favicon_url.h" | 15 #include "chrome/common/favicon_url.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Image; | 19 class Image; |
| 19 } | 20 } |
| 20 | 21 |
| 21 class GURL; | 22 class GURL; |
| 22 class FaviconHandler; | 23 class FaviconHandler; |
| 23 class Profile; | 24 class Profile; |
| 24 class SkBitmap; | 25 class SkBitmap; |
| 25 | 26 |
| 26 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. | 27 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. |
| 27 // | 28 // |
| 28 // FetchFavicon fetches the given page's icons. It requests the icons from the | 29 // FetchFavicon fetches the given page's icons. It requests the icons from the |
| 29 // history backend. If the icon is not available or expired, the icon will be | 30 // history backend. If the icon is not available or expired, the icon will be |
| 30 // downloaded and saved in the history backend. | 31 // downloaded and saved in the history backend. |
| 31 // | 32 // |
| 32 // DownloadImage downloads the specified icon and returns it through the given | 33 // DownloadImage downloads the specified icon and returns it through the given |
| 33 // callback. | 34 // callback. |
| 34 // | 35 // |
| 35 class FaviconTabHelper : public content::WebContentsObserver, | 36 class FaviconTabHelper : public content::WebContentsObserver, |
| 36 public FaviconHandlerDelegate { | 37 public FaviconHandlerDelegate, |
| 38 public WebContentsUserData<FaviconTabHelper> { |
| 37 public: | 39 public: |
| 38 explicit FaviconTabHelper(content::WebContents* web_contents); | |
| 39 virtual ~FaviconTabHelper(); | 40 virtual ~FaviconTabHelper(); |
| 40 | 41 |
| 41 // Initiates loading the favicon for the specified url. | 42 // Initiates loading the favicon for the specified url. |
| 42 void FetchFavicon(const GURL& url); | 43 void FetchFavicon(const GURL& url); |
| 43 | 44 |
| 44 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does | 45 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does |
| 45 // not have a favicon. The default implementation uses the current navigation | 46 // not have a favicon. The default implementation uses the current navigation |
| 46 // entry. This will return an empty bitmap if there are no navigation | 47 // entry. This will return an empty bitmap if there are no navigation |
| 47 // entries, which should rarely happen. | 48 // entries, which should rarely happen. |
| 48 gfx::Image GetFavicon() const; | 49 gfx::Image GetFavicon() const; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 // PrerenderContents. | 76 // PrerenderContents. |
| 76 void OnUpdateFaviconURL(int32 page_id, | 77 void OnUpdateFaviconURL(int32 page_id, |
| 77 const std::vector<FaviconURL>& candidates); | 78 const std::vector<FaviconURL>& candidates); |
| 78 | 79 |
| 79 // FaviconHandlerDelegate methods. | 80 // FaviconHandlerDelegate methods. |
| 80 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE; | 81 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE; |
| 81 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE; | 82 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE; |
| 82 virtual void NotifyFaviconUpdated() OVERRIDE; | 83 virtual void NotifyFaviconUpdated() OVERRIDE; |
| 83 | 84 |
| 84 private: | 85 private: |
| 86 explicit FaviconTabHelper(content::WebContents* web_contents); |
| 87 friend class WebContentsUserData<FaviconTabHelper>; |
| 88 |
| 85 // content::WebContentsObserver overrides. | 89 // content::WebContentsObserver overrides. |
| 86 virtual void NavigateToPendingEntry( | 90 virtual void NavigateToPendingEntry( |
| 87 const GURL& url, | 91 const GURL& url, |
| 88 content::NavigationController::ReloadType reload_type) OVERRIDE; | 92 content::NavigationController::ReloadType reload_type) OVERRIDE; |
| 89 virtual void DidNavigateMainFrame( | 93 virtual void DidNavigateMainFrame( |
| 90 const content::LoadCommittedDetails& details, | 94 const content::LoadCommittedDetails& details, |
| 91 const content::FrameNavigateParams& params) OVERRIDE; | 95 const content::FrameNavigateParams& params) OVERRIDE; |
| 92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 93 | 97 |
| 94 // Message handler for IconHostMsg_DidDownloadFavicon. | 98 // Message handler for IconHostMsg_DidDownloadFavicon. |
| 95 void OnDidDownloadFavicon(int id, | 99 void OnDidDownloadFavicon(int id, |
| 96 const GURL& image_url, | 100 const GURL& image_url, |
| 97 bool errored, | 101 bool errored, |
| 98 int requested_size, | 102 int requested_size, |
| 99 const std::vector<SkBitmap>& bitmaps); | 103 const std::vector<SkBitmap>& bitmaps); |
| 100 | 104 |
| 101 Profile* profile_; | 105 Profile* profile_; |
| 102 | 106 |
| 103 scoped_ptr<FaviconHandler> favicon_handler_; | 107 scoped_ptr<FaviconHandler> favicon_handler_; |
| 104 | 108 |
| 105 // Handles downloading touchicons. It is NULL if | 109 // Handles downloading touchicons. It is NULL if |
| 106 // browser_defaults::kEnableTouchIcon is false. | 110 // browser_defaults::kEnableTouchIcon is false. |
| 107 scoped_ptr<FaviconHandler> touch_icon_handler_; | 111 scoped_ptr<FaviconHandler> touch_icon_handler_; |
| 108 | 112 |
| 109 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); | 113 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); |
| 110 }; | 114 }; |
| 111 | 115 |
| 112 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ | 116 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
| OLD | NEW |