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

Side by Side Diff: chrome/browser/favicon/favicon_tab_helper.h

Issue 11195010: Extract Favicon Download logic from FaviconTabHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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 | Annotate | Revision Log
OLDNEW
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/favicon/favicon_download_helper_delegate.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 #include "content/public/browser/web_contents_user_data.h" 17 #include "content/public/browser/web_contents_user_data.h"
17 18
18 namespace gfx { 19 namespace gfx {
19 class Image; 20 class Image;
20 } 21 }
21 22
22 class GURL; 23 class GURL;
23 class FaviconHandler; 24 class FaviconHandler;
24 class Profile; 25 class Profile;
25 class SkBitmap; 26 class SkBitmap;
26 27
27 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. 28 // FaviconTabHelper works with FaviconHandlers to fetch the favicons.
28 // 29 //
29 // FetchFavicon fetches the given page's icons. It requests the icons from the 30 // FetchFavicon fetches the given page's icons. It requests the icons from the
30 // history backend. If the icon is not available or expired, the icon will be 31 // history backend. If the icon is not available or expired, the icon will be
31 // downloaded and saved in the history backend. 32 // downloaded and saved in the history backend.
32 // 33 //
33 // DownloadImage downloads the specified icon and returns it through the given 34 // DownloadImage downloads the specified icon and returns it through the given
34 // callback. 35 // callback.
35 // 36 //
36 class FaviconTabHelper : public content::WebContentsObserver, 37 class FaviconTabHelper : public content::WebContentsObserver,
37 public FaviconHandlerDelegate, 38 public FaviconHandlerDelegate,
39 public FaviconDownloadHelperDelegate,
38 public content::WebContentsUserData<FaviconTabHelper> { 40 public content::WebContentsUserData<FaviconTabHelper> {
39 public: 41 public:
40 virtual ~FaviconTabHelper(); 42 virtual ~FaviconTabHelper();
41 43
42 // Initiates loading the favicon for the specified url. 44 // Initiates loading the favicon for the specified url.
43 void FetchFavicon(const GURL& url); 45 void FetchFavicon(const GURL& url);
44 46
45 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does 47 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
46 // not have a favicon. The default implementation uses the current navigation 48 // not have a favicon. The default implementation uses the current navigation
47 // entry. This will return an empty bitmap if there are no navigation 49 // entry. This will return an empty bitmap if there are no navigation
48 // entries, which should rarely happen. 50 // entries, which should rarely happen.
49 gfx::Image GetFavicon() const; 51 gfx::Image GetFavicon() const;
50 52
51 // Returns true if we have the favicon for the page. 53 // Returns true if we have the favicon for the page.
52 bool FaviconIsValid() const; 54 bool FaviconIsValid() const;
53 55
54 // Returns whether the favicon should be displayed. If this returns false, no 56 // Returns whether the favicon should be displayed. If this returns false, no
55 // space is provided for the favicon, and the favicon is never displayed. 57 // space is provided for the favicon, and the favicon is never displayed.
56 virtual bool ShouldDisplayFavicon(); 58 virtual bool ShouldDisplayFavicon();
57 59
60 // Message Handler. Must be public, because also called from
61 // PrerenderContents.
62 virtual void OnUpdateFaviconURL(int32 page_id,
63 const std::vector<FaviconURL>& candidates) OVERRIDE;
64
58 // Saves the favicon for the current page. 65 // Saves the favicon for the current page.
59 void SaveFavicon(); 66 void SaveFavicon();
60 67
61 // Initiates loading an image from given |image_url|. Returns a download id 68 // Initiates loading an image from given |image_url|. Returns a download id
62 // for caller to track the request. When download completes, |callback| is 69 // for caller to track the request. When download completes, |callback| is
63 // called with the three params: the download_id, a boolean flag to indicate 70 // called with the three params: the download_id, a boolean flag to indicate
64 // whether the download succeeds and a SkBitmap as the downloaded image. 71 // whether the download succeeds and a SkBitmap as the downloaded image.
65 // Note that |image_size| is a hint for images with multiple sizes. The 72 // Note that |image_size| is a hint for images with multiple sizes. The
66 // downloaded image is not resized to the given image_size. If 0 is passed, 73 // downloaded image is not resized to the given image_size. If 0 is passed,
67 // the first frame of the image is returned. 74 // the first frame of the image is returned.
68 typedef base::Callback<void(int, bool, const SkBitmap&)> 75 typedef base::Callback<void(int, bool, const SkBitmap&)>
69 ImageDownloadCallback; 76 ImageDownloadCallback;
70 int DownloadImage(const GURL& image_url, 77 int DownloadImage(const GURL& image_url,
71 int image_size, 78 int image_size,
72 history::IconType icon_type, 79 history::IconType icon_type,
73 const ImageDownloadCallback& callback); 80 const ImageDownloadCallback& callback);
74 81
75 // Message Handler. Must be public, because also called from
76 // PrerenderContents.
77 void OnUpdateFaviconURL(int32 page_id,
78 const std::vector<FaviconURL>& candidates);
79
80 // FaviconHandlerDelegate methods. 82 // FaviconHandlerDelegate methods.
81 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE; 83 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE;
82 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE; 84 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE;
83 virtual void NotifyFaviconUpdated() OVERRIDE; 85 virtual void NotifyFaviconUpdated() OVERRIDE;
84 86
85 private: 87 private:
86 explicit FaviconTabHelper(content::WebContents* web_contents); 88 explicit FaviconTabHelper(content::WebContents* web_contents);
87 friend class content::WebContentsUserData<FaviconTabHelper>; 89 friend class content::WebContentsUserData<FaviconTabHelper>;
88 90
89 // content::WebContentsObserver overrides. 91 // content::WebContentsObserver overrides.
90 virtual void NavigateToPendingEntry( 92 virtual void NavigateToPendingEntry(
91 const GURL& url, 93 const GURL& url,
92 content::NavigationController::ReloadType reload_type) OVERRIDE; 94 content::NavigationController::ReloadType reload_type) OVERRIDE;
93 virtual void DidNavigateMainFrame( 95 virtual void DidNavigateMainFrame(
94 const content::LoadCommittedDetails& details, 96 const content::LoadCommittedDetails& details,
95 const content::FrameNavigateParams& params) OVERRIDE; 97 const content::FrameNavigateParams& params) OVERRIDE;
96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
97 98
98 // Message handler for IconHostMsg_DidDownloadFavicon. 99 // FaviconDownloadHelperDelegate overrides.
99 void OnDidDownloadFavicon(int id, 100 virtual void OnDidDownloadFavicon(
100 const GURL& image_url, 101 int id,
101 bool errored, 102 const GURL& image_url,
102 int requested_size, 103 bool errored,
103 const std::vector<SkBitmap>& bitmaps); 104 int requested_size,
105 const std::vector<SkBitmap>& bitmaps) OVERRIDE;
104 106
105 Profile* profile_; 107 Profile* profile_;
106 108
107 scoped_ptr<FaviconHandler> favicon_handler_; 109 scoped_ptr<FaviconHandler> favicon_handler_;
108 110
109 // Handles downloading touchicons. It is NULL if 111 // Handles downloading touchicons. It is NULL if
110 // browser_defaults::kEnableTouchIcon is false. 112 // browser_defaults::kEnableTouchIcon is false.
111 scoped_ptr<FaviconHandler> touch_icon_handler_; 113 scoped_ptr<FaviconHandler> touch_icon_handler_;
112 114
113 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); 115 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper);
114 }; 116 };
115 117
116 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ 118 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698