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

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

Powered by Google App Engine
This is Rietveld 408576698