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/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(int32 page_id, | |
sky
2012/10/30 21:39:09
nit: wrap page_id to next line so that it aligns w
sky
2012/10/30 21:39:09
Move implementation to match position.
Cait (Slow)
2012/10/31 19:26:32
Done.
Cait (Slow)
2012/10/31 19:26:32
Done.
| |
64 const std::vector<FaviconURL>& candidates) OVERRIDE; | |
65 | |
58 // Saves the favicon for the current page. | 66 // Saves the favicon for the current page. |
59 void SaveFavicon(); | 67 void SaveFavicon(); |
60 | 68 |
61 // Initiates loading an image from given |image_url|. Returns a download id | 69 // Initiates loading an image from given |image_url|. Returns a download id |
62 // for caller to track the request. When download completes, |callback| is | 70 // 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 | 71 // 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. | 72 // 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 | 73 // 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, | 74 // downloaded image is not resized to the given image_size. If 0 is passed, |
67 // the first frame of the image is returned. | 75 // the first frame of the image is returned. |
68 typedef base::Callback<void(int, bool, const SkBitmap&)> | 76 typedef base::Callback<void(int, bool, const SkBitmap&)> |
69 ImageDownloadCallback; | 77 ImageDownloadCallback; |
70 int DownloadImage(const GURL& image_url, | 78 int DownloadImage(const GURL& image_url, |
71 int image_size, | 79 int image_size, |
72 history::IconType icon_type, | 80 history::IconType icon_type, |
73 const ImageDownloadCallback& callback); | 81 const ImageDownloadCallback& callback); |
74 | 82 |
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. | 83 // FaviconHandlerDelegate methods. |
81 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE; | 84 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE; |
82 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE; | 85 virtual int StartDownload(const GURL& url, int image_size) OVERRIDE; |
83 virtual void NotifyFaviconUpdated() OVERRIDE; | 86 virtual void NotifyFaviconUpdated() OVERRIDE; |
84 | 87 |
85 private: | 88 private: |
86 explicit FaviconTabHelper(content::WebContents* web_contents); | 89 explicit FaviconTabHelper(content::WebContents* web_contents); |
87 friend class content::WebContentsUserData<FaviconTabHelper>; | 90 friend class content::WebContentsUserData<FaviconTabHelper>; |
88 | 91 |
89 // content::WebContentsObserver overrides. | 92 // content::WebContentsObserver overrides. |
90 virtual void NavigateToPendingEntry( | 93 virtual void NavigateToPendingEntry( |
91 const GURL& url, | 94 const GURL& url, |
92 content::NavigationController::ReloadType reload_type) OVERRIDE; | 95 content::NavigationController::ReloadType reload_type) OVERRIDE; |
93 virtual void DidNavigateMainFrame( | 96 virtual void DidNavigateMainFrame( |
94 const content::LoadCommittedDetails& details, | 97 const content::LoadCommittedDetails& details, |
95 const content::FrameNavigateParams& params) OVERRIDE; | 98 const content::FrameNavigateParams& params) OVERRIDE; |
96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
97 | 99 |
98 // Message handler for IconHostMsg_DidDownloadFavicon. | 100 // FaviconDownloadHelperDelegate overrides. |
99 void OnDidDownloadFavicon(int id, | 101 virtual void OnDidDownloadFavicon( |
100 const GURL& image_url, | 102 int id, |
101 bool errored, | 103 const GURL& image_url, |
102 int requested_size, | 104 bool errored, |
103 const std::vector<SkBitmap>& bitmaps); | 105 int requested_size, |
106 const std::vector<SkBitmap>& bitmaps) OVERRIDE; | |
104 | 107 |
105 Profile* profile_; | 108 Profile* profile_; |
106 | 109 |
110 scoped_ptr<FaviconDownloadHelper> favicon_download_helper_; | |
111 | |
107 scoped_ptr<FaviconHandler> favicon_handler_; | 112 scoped_ptr<FaviconHandler> favicon_handler_; |
108 | 113 |
109 // Handles downloading touchicons. It is NULL if | 114 // Handles downloading touchicons. It is NULL if |
110 // browser_defaults::kEnableTouchIcon is false. | 115 // browser_defaults::kEnableTouchIcon is false. |
111 scoped_ptr<FaviconHandler> touch_icon_handler_; | 116 scoped_ptr<FaviconHandler> touch_icon_handler_; |
112 | 117 |
113 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); | 118 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); |
114 }; | 119 }; |
115 | 120 |
116 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ | 121 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
OLD | NEW |