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 "base/observer_list.h" |
12 #include "components/favicon/core/browser/favicon_client.h" | 13 #include "components/favicon/core/browser/favicon_client.h" |
13 #include "components/favicon/core/favicon_driver.h" | 14 #include "components/favicon/core/favicon_driver.h" |
14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
16 #include "content/public/common/favicon_url.h" | 17 #include "content/public/common/favicon_url.h" |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 class Image; | 20 class Image; |
20 } | 21 } |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 struct FaviconStatus; | 24 struct FaviconStatus; |
24 } | 25 } |
25 | 26 |
26 class GURL; | 27 class GURL; |
27 class FaviconHandler; | 28 class FaviconHandler; |
| 29 class FaviconTabHelperObserver; |
28 class Profile; | 30 class Profile; |
29 class SkBitmap; | 31 class SkBitmap; |
30 | 32 |
31 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. | 33 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. |
32 // | 34 // |
33 // FetchFavicon fetches the given page's icons. It requests the icons from the | 35 // FetchFavicon fetches the given page's icons. It requests the icons from the |
34 // history backend. If the icon is not available or expired, the icon will be | 36 // history backend. If the icon is not available or expired, the icon will be |
35 // downloaded and saved in the history backend. | 37 // downloaded and saved in the history backend. |
36 // | 38 // |
37 class FaviconTabHelper : public content::WebContentsObserver, | 39 class FaviconTabHelper : public content::WebContentsObserver, |
(...skipping 25 matching lines...) Expand all Loading... |
63 } | 65 } |
64 | 66 |
65 // content::WebContentsObserver override. Must be public, because also | 67 // content::WebContentsObserver override. Must be public, because also |
66 // called from PrerenderContents. | 68 // called from PrerenderContents. |
67 void DidUpdateFaviconURL( | 69 void DidUpdateFaviconURL( |
68 const std::vector<content::FaviconURL>& candidates) override; | 70 const std::vector<content::FaviconURL>& candidates) override; |
69 | 71 |
70 // Saves the favicon for the current page. | 72 // Saves the favicon for the current page. |
71 void SaveFavicon(); | 73 void SaveFavicon(); |
72 | 74 |
| 75 void AddObserver(FaviconTabHelperObserver* observer); |
| 76 void RemoveObserver(FaviconTabHelperObserver* observer); |
| 77 |
73 // FaviconDriver methods. | 78 // FaviconDriver methods. |
74 int StartDownload(const GURL& url, int max_bitmap_size) override; | 79 int StartDownload(const GURL& url, int max_bitmap_size) override; |
75 void NotifyFaviconUpdated(bool icon_url_changed) override; | |
76 bool IsOffTheRecord() override; | 80 bool IsOffTheRecord() override; |
77 const gfx::Image GetActiveFaviconImage() override; | 81 const gfx::Image GetActiveFaviconImage() override; |
78 const GURL GetActiveFaviconURL() override; | 82 const GURL GetActiveFaviconURL() override; |
79 bool GetActiveFaviconValidity() override; | 83 bool GetActiveFaviconValidity() override; |
80 const GURL GetActiveURL() override; | 84 const GURL GetActiveURL() override; |
81 void SetActiveFaviconImage(gfx::Image image) override; | 85 void OnFaviconAvailable(const gfx::Image& image, |
82 void SetActiveFaviconURL(GURL url) override; | 86 const GURL& url, |
83 void SetActiveFaviconValidity(bool validity) override; | 87 bool is_active_favicon) override; |
84 | 88 |
85 // Favicon download callback. | 89 // Favicon download callback. |
86 void DidDownloadFavicon( | 90 void DidDownloadFavicon( |
87 int id, | 91 int id, |
88 int http_status_code, | 92 int http_status_code, |
89 const GURL& image_url, | 93 const GURL& image_url, |
90 const std::vector<SkBitmap>& bitmaps, | 94 const std::vector<SkBitmap>& bitmaps, |
91 const std::vector<gfx::Size>& original_bitmap_sizes); | 95 const std::vector<gfx::Size>& original_bitmap_sizes); |
92 | 96 |
93 private: | 97 private: |
94 explicit FaviconTabHelper(content::WebContents* web_contents); | 98 explicit FaviconTabHelper(content::WebContents* web_contents); |
95 friend class content::WebContentsUserData<FaviconTabHelper>; | 99 friend class content::WebContentsUserData<FaviconTabHelper>; |
96 | 100 |
97 // content::WebContentsObserver overrides. | 101 // content::WebContentsObserver overrides. |
98 void DidStartNavigationToPendingEntry( | 102 void DidStartNavigationToPendingEntry( |
99 const GURL& url, | 103 const GURL& url, |
100 content::NavigationController::ReloadType reload_type) override; | 104 content::NavigationController::ReloadType reload_type) override; |
101 void DidNavigateMainFrame( | 105 void DidNavigateMainFrame( |
102 const content::LoadCommittedDetails& details, | 106 const content::LoadCommittedDetails& details, |
103 const content::FrameNavigateParams& params) override; | 107 const content::FrameNavigateParams& params) override; |
104 | 108 |
| 109 // Sets whether the page's favicon is valid (if false, the default favicon is |
| 110 // being used). Requires GetActiveURL() to be valid. |
| 111 void SetActiveFaviconValidity(bool validity); |
| 112 |
| 113 // Sets the URL of the favicon's bitmap. |
| 114 void SetActiveFaviconURL(GURL url); |
| 115 |
| 116 // Sets the bitmap of the current page's favicon. |
| 117 void SetActiveFaviconImage(gfx::Image image); |
| 118 |
105 // Helper method that returns the active navigation entry's favicon. | 119 // Helper method that returns the active navigation entry's favicon. |
106 content::FaviconStatus& GetFaviconStatus(); | 120 content::FaviconStatus& GetFaviconStatus(); |
107 | 121 |
108 Profile* profile_; | 122 Profile* profile_; |
109 | 123 |
110 FaviconClient* client_; | 124 FaviconClient* client_; |
111 | 125 |
112 std::vector<content::FaviconURL> favicon_urls_; | 126 std::vector<content::FaviconURL> favicon_urls_; |
113 | 127 |
114 scoped_ptr<FaviconHandler> favicon_handler_; | 128 scoped_ptr<FaviconHandler> favicon_handler_; |
115 | 129 |
116 // Handles downloading touchicons. It is NULL if | 130 // Handles downloading touchicons. It is NULL if |
117 // browser_defaults::kEnableTouchIcon is false. | 131 // browser_defaults::kEnableTouchIcon is false. |
118 scoped_ptr<FaviconHandler> touch_icon_handler_; | 132 scoped_ptr<FaviconHandler> touch_icon_handler_; |
119 | 133 |
| 134 ObserverList<FaviconTabHelperObserver> observer_list_; |
| 135 |
120 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); | 136 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); |
121 }; | 137 }; |
122 | 138 |
123 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ | 139 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
OLD | NEW |