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; |
28 class Profile; | 29 class Profile; |
29 class SkBitmap; | 30 class SkBitmap; |
30 | 31 |
31 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. | 32 // FaviconTabHelper works with FaviconHandlers to fetch the favicons. |
32 // | 33 // |
33 // FetchFavicon fetches the given page's icons. It requests the icons from the | 34 // 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 | 35 // history backend. If the icon is not available or expired, the icon will be |
35 // downloaded and saved in the history backend. | 36 // downloaded and saved in the history backend. |
36 // | 37 // |
37 class FaviconTabHelper : public content::WebContentsObserver, | 38 class FaviconTabHelper : public content::WebContentsObserver, |
38 public FaviconDriver, | 39 public FaviconDriver, |
39 public content::WebContentsUserData<FaviconTabHelper> { | 40 public content::WebContentsUserData<FaviconTabHelper> { |
40 public: | 41 public: |
42 class Observer { | |
sky
2014/11/04 18:11:43
Move to it's own file and add protected virtual de
michaelbai
2014/11/04 19:26:57
Done.
| |
43 public: | |
44 // Called when favicon |image| is retrieved from either web site or history | |
45 // backend. | |
46 virtual void OnFaviconAvailable(const gfx::Image& image) = 0; | |
47 }; | |
48 | |
41 ~FaviconTabHelper() override; | 49 ~FaviconTabHelper() override; |
42 | 50 |
43 // Initiates loading the favicon for the specified url. | 51 // Initiates loading the favicon for the specified url. |
44 void FetchFavicon(const GURL& url); | 52 void FetchFavicon(const GURL& url); |
45 | 53 |
46 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does | 54 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does |
47 // not have a favicon. The default implementation uses the current navigation | 55 // not have a favicon. The default implementation uses the current navigation |
48 // entry. This will return an empty bitmap if there are no navigation | 56 // entry. This will return an empty bitmap if there are no navigation |
49 // entries, which should rarely happen. | 57 // entries, which should rarely happen. |
50 gfx::Image GetFavicon() const; | 58 gfx::Image GetFavicon() const; |
(...skipping 12 matching lines...) Expand all Loading... | |
63 } | 71 } |
64 | 72 |
65 // content::WebContentsObserver override. Must be public, because also | 73 // content::WebContentsObserver override. Must be public, because also |
66 // called from PrerenderContents. | 74 // called from PrerenderContents. |
67 void DidUpdateFaviconURL( | 75 void DidUpdateFaviconURL( |
68 const std::vector<content::FaviconURL>& candidates) override; | 76 const std::vector<content::FaviconURL>& candidates) override; |
69 | 77 |
70 // Saves the favicon for the current page. | 78 // Saves the favicon for the current page. |
71 void SaveFavicon(); | 79 void SaveFavicon(); |
72 | 80 |
81 void AddObserver(Observer* observer); | |
82 void RemoveObserver(Observer* observer); | |
83 | |
73 // FaviconDriver methods. | 84 // FaviconDriver methods. |
74 int StartDownload(const GURL& url, int max_bitmap_size) override; | 85 int StartDownload(const GURL& url, int max_bitmap_size) override; |
75 void NotifyFaviconUpdated(bool icon_url_changed) override; | |
76 bool IsOffTheRecord() override; | 86 bool IsOffTheRecord() override; |
77 const gfx::Image GetActiveFaviconImage() override; | 87 const gfx::Image GetActiveFaviconImage() override; |
78 const GURL GetActiveFaviconURL() override; | 88 const GURL GetActiveFaviconURL() override; |
79 bool GetActiveFaviconValidity() override; | 89 bool GetActiveFaviconValidity() override; |
80 const GURL GetActiveURL() override; | 90 const GURL GetActiveURL() override; |
81 void SetActiveFaviconImage(gfx::Image image) override; | 91 void OnFaviconAvailable(const gfx::Image& image, |
82 void SetActiveFaviconURL(GURL url) override; | 92 const GURL& url, |
83 void SetActiveFaviconValidity(bool validity) override; | 93 bool update_active_favicon) override; |
84 | 94 |
85 // Favicon download callback. | 95 // Favicon download callback. |
86 void DidDownloadFavicon( | 96 void DidDownloadFavicon( |
87 int id, | 97 int id, |
88 int http_status_code, | 98 int http_status_code, |
89 const GURL& image_url, | 99 const GURL& image_url, |
90 const std::vector<SkBitmap>& bitmaps, | 100 const std::vector<SkBitmap>& bitmaps, |
91 const std::vector<gfx::Size>& original_bitmap_sizes); | 101 const std::vector<gfx::Size>& original_bitmap_sizes); |
92 | 102 |
93 private: | 103 private: |
94 explicit FaviconTabHelper(content::WebContents* web_contents); | 104 explicit FaviconTabHelper(content::WebContents* web_contents); |
95 friend class content::WebContentsUserData<FaviconTabHelper>; | 105 friend class content::WebContentsUserData<FaviconTabHelper>; |
96 | 106 |
97 // content::WebContentsObserver overrides. | 107 // content::WebContentsObserver overrides. |
98 void DidStartNavigationToPendingEntry( | 108 void DidStartNavigationToPendingEntry( |
99 const GURL& url, | 109 const GURL& url, |
100 content::NavigationController::ReloadType reload_type) override; | 110 content::NavigationController::ReloadType reload_type) override; |
101 void DidNavigateMainFrame( | 111 void DidNavigateMainFrame( |
102 const content::LoadCommittedDetails& details, | 112 const content::LoadCommittedDetails& details, |
103 const content::FrameNavigateParams& params) override; | 113 const content::FrameNavigateParams& params) override; |
104 | 114 |
115 // Sets whether the page's favicon is valid (if false, the default favicon is | |
116 // being used). Requires GetActiveURL() to be valid. | |
117 void SetActiveFaviconValidity(bool validity); | |
118 | |
119 // Sets the URL of the favicon's bitmap. | |
120 void SetActiveFaviconURL(GURL url); | |
121 | |
122 // Sets the bitmap of the current page's favicon. | |
123 void SetActiveFaviconImage(gfx::Image image); | |
124 | |
105 // Helper method that returns the active navigation entry's favicon. | 125 // Helper method that returns the active navigation entry's favicon. |
106 content::FaviconStatus& GetFaviconStatus(); | 126 content::FaviconStatus& GetFaviconStatus(); |
107 | 127 |
108 Profile* profile_; | 128 Profile* profile_; |
109 | 129 |
110 FaviconClient* client_; | 130 FaviconClient* client_; |
111 | 131 |
112 std::vector<content::FaviconURL> favicon_urls_; | 132 std::vector<content::FaviconURL> favicon_urls_; |
113 | 133 |
114 scoped_ptr<FaviconHandler> favicon_handler_; | 134 scoped_ptr<FaviconHandler> favicon_handler_; |
115 | 135 |
116 // Handles downloading touchicons. It is NULL if | 136 // Handles downloading touchicons. It is NULL if |
117 // browser_defaults::kEnableTouchIcon is false. | 137 // browser_defaults::kEnableTouchIcon is false. |
118 scoped_ptr<FaviconHandler> touch_icon_handler_; | 138 scoped_ptr<FaviconHandler> touch_icon_handler_; |
119 | 139 |
140 ObserverList<Observer> observer_list_; | |
141 | |
120 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); | 142 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper); |
121 }; | 143 }; |
122 | 144 |
123 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ | 145 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_ |
OLD | NEW |