Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / favicon / favicon_tab_helper.h
blobb916d6df219210540bab9be82fa21528ebcad7c1
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_
6 #define CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/observer_list.h"
13 #include "components/favicon/core/favicon_client.h"
14 #include "components/favicon/core/favicon_driver.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h"
17 #include "content/public/common/favicon_url.h"
19 namespace gfx {
20 class Image;
23 namespace content {
24 struct FaviconStatus;
27 class GURL;
28 class FaviconHandler;
29 class FaviconTabHelperObserver;
30 class Profile;
31 class SkBitmap;
33 // FaviconTabHelper works with FaviconHandlers to fetch the favicons.
35 // FetchFavicon fetches the given page's icons. It requests the icons from the
36 // history backend. If the icon is not available or expired, the icon will be
37 // downloaded and saved in the history backend.
39 class FaviconTabHelper : public content::WebContentsObserver,
40 public FaviconDriver,
41 public content::WebContentsUserData<FaviconTabHelper> {
42 public:
43 ~FaviconTabHelper() override;
45 // Initiates loading the favicon for the specified url.
46 void FetchFavicon(const GURL& url);
48 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
49 // not have a favicon. The default implementation uses the current navigation
50 // entry. This will return an empty bitmap if there are no navigation
51 // entries, which should rarely happen.
52 gfx::Image GetFavicon() const;
54 // Returns true if we have the favicon for the page.
55 bool FaviconIsValid() const;
57 // Returns whether the favicon should be displayed. If this returns false, no
58 // space is provided for the favicon, and the favicon is never displayed.
59 virtual bool ShouldDisplayFavicon();
61 // Returns the current tab's favicon urls. If this is empty,
62 // DidUpdateFaviconURL has not yet been called for the current navigation.
63 const std::vector<content::FaviconURL>& favicon_urls() const {
64 return favicon_urls_;
67 // content::WebContentsObserver override. Must be public, because also
68 // called from PrerenderContents.
69 void DidUpdateFaviconURL(
70 const std::vector<content::FaviconURL>& candidates) override;
72 // Saves the favicon for the current page.
73 void SaveFavicon();
75 void AddObserver(FaviconTabHelperObserver* observer);
76 void RemoveObserver(FaviconTabHelperObserver* observer);
78 // FaviconDriver methods.
79 int StartDownload(const GURL& url, int max_bitmap_size) override;
80 bool IsOffTheRecord() override;
81 const gfx::Image GetActiveFaviconImage() override;
82 const GURL GetActiveFaviconURL() override;
83 bool GetActiveFaviconValidity() override;
84 const GURL GetActiveURL() override;
85 void OnFaviconAvailable(const gfx::Image& image,
86 const GURL& url,
87 bool is_active_favicon) override;
89 // Favicon download callback.
90 void DidDownloadFavicon(
91 int id,
92 int http_status_code,
93 const GURL& image_url,
94 const std::vector<SkBitmap>& bitmaps,
95 const std::vector<gfx::Size>& original_bitmap_sizes);
97 private:
98 friend class content::WebContentsUserData<FaviconTabHelper>;
99 friend class FaviconTabHelperTest;
101 explicit FaviconTabHelper(content::WebContents* web_contents);
103 // content::WebContentsObserver overrides.
104 void DidStartNavigationToPendingEntry(
105 const GURL& url,
106 content::NavigationController::ReloadType reload_type) override;
107 void DidNavigateMainFrame(
108 const content::LoadCommittedDetails& details,
109 const content::FrameNavigateParams& params) override;
111 // Sets whether the page's favicon is valid (if false, the default favicon is
112 // being used). Requires GetActiveURL() to be valid.
113 void SetActiveFaviconValidity(bool validity);
115 // Sets the URL of the favicon's bitmap.
116 void SetActiveFaviconURL(GURL url);
118 // Sets the bitmap of the current page's favicon.
119 void SetActiveFaviconImage(gfx::Image image);
121 // Helper method that returns the active navigation entry's favicon.
122 content::FaviconStatus& GetFaviconStatus();
124 Profile* profile_;
126 FaviconClient* client_;
128 std::vector<content::FaviconURL> favicon_urls_;
130 // Bypass cache when downloading favicons for this page URL.
131 GURL bypass_cache_page_url_;
133 scoped_ptr<FaviconHandler> favicon_handler_;
135 // Handles downloading touchicons. It is NULL if
136 // browser_defaults::kEnableTouchIcon is false.
137 scoped_ptr<FaviconHandler> touch_icon_handler_;
139 scoped_ptr<FaviconHandler> large_icon_handler_;
141 ObserverList<FaviconTabHelperObserver> observer_list_;
143 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper);
146 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_