Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / favicon / favicon_tab_helper.h
blob812dd1c10df8b18a4a9b673e2ad99bdb8792a745
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_driver.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
16 #include "content/public/common/favicon_url.h"
18 class GURL;
19 class Profile;
20 class SkBitmap;
22 namespace gfx {
23 class Image;
26 namespace content {
27 struct FaviconStatus;
30 namespace favicon {
31 class FaviconDriverObserver;
32 class FaviconHandler;
35 // FaviconTabHelper works with favicon::FaviconHandlers to fetch the favicons.
37 // FetchFavicon fetches the given page's icons. It requests the icons from the
38 // history backend. If the icon is not available or expired, the icon will be
39 // downloaded and saved in the history backend.
41 class FaviconTabHelper : public content::WebContentsObserver,
42 public favicon::FaviconDriver,
43 public content::WebContentsUserData<FaviconTabHelper> {
44 public:
45 ~FaviconTabHelper() override;
47 // Initiates loading the favicon for the specified url.
48 void FetchFavicon(const GURL& url);
50 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
51 // not have a favicon. The default implementation uses the current navigation
52 // entry. This will return an empty bitmap if there are no navigation
53 // entries, which should rarely happen.
54 gfx::Image GetFavicon() const;
56 // Returns true if we have the favicon for the page.
57 bool FaviconIsValid() const;
59 // Returns whether the favicon should be displayed. If this returns false, no
60 // space is provided for the favicon, and the favicon is never displayed.
61 virtual bool ShouldDisplayFavicon();
63 // Returns the current tab's favicon urls. If this is empty,
64 // DidUpdateFaviconURL has not yet been called for the current navigation.
65 const std::vector<content::FaviconURL>& favicon_urls() const {
66 return favicon_urls_;
69 // content::WebContentsObserver override. Must be public, because also
70 // called from PrerenderContents.
71 void DidUpdateFaviconURL(
72 const std::vector<content::FaviconURL>& candidates) override;
74 // Saves the favicon for the current page.
75 void SaveFavicon();
77 void AddObserver(favicon::FaviconDriverObserver* observer);
78 void RemoveObserver(favicon::FaviconDriverObserver* observer);
80 // favicon::FaviconDriver methods.
81 int StartDownload(const GURL& url, int max_bitmap_size) override;
82 bool IsOffTheRecord() override;
83 bool IsBookmarked(const GURL& url) override;
84 const gfx::Image GetActiveFaviconImage() override;
85 const GURL GetActiveFaviconURL() override;
86 bool GetActiveFaviconValidity() override;
87 const GURL GetActiveURL() override;
88 void OnFaviconAvailable(const gfx::Image& image,
89 const GURL& url,
90 bool is_active_favicon) override;
92 // Favicon download callback.
93 void DidDownloadFavicon(
94 int id,
95 int http_status_code,
96 const GURL& image_url,
97 const std::vector<SkBitmap>& bitmaps,
98 const std::vector<gfx::Size>& original_bitmap_sizes);
100 private:
101 friend class content::WebContentsUserData<FaviconTabHelper>;
102 friend class FaviconTabHelperTest;
104 explicit FaviconTabHelper(content::WebContents* web_contents);
106 // content::WebContentsObserver overrides.
107 void DidStartNavigationToPendingEntry(
108 const GURL& url,
109 content::NavigationController::ReloadType reload_type) override;
110 void DidNavigateMainFrame(
111 const content::LoadCommittedDetails& details,
112 const content::FrameNavigateParams& params) override;
114 // Sets whether the page's favicon is valid (if false, the default favicon is
115 // being used). Requires GetActiveURL() to be valid.
116 void SetActiveFaviconValidity(bool validity);
118 // Sets the URL of the favicon's bitmap.
119 void SetActiveFaviconURL(GURL url);
121 // Sets the bitmap of the current page's favicon.
122 void SetActiveFaviconImage(gfx::Image image);
124 // Helper method that returns the active navigation entry's favicon.
125 content::FaviconStatus& GetFaviconStatus();
127 Profile* profile_;
129 std::vector<content::FaviconURL> favicon_urls_;
131 // Bypass cache when downloading favicons for this page URL.
132 GURL bypass_cache_page_url_;
134 // FaviconHandlers used to download the different kind of favicons. Both
135 // |touch_icon_handler_| and |large_icon_handler_| may be null depending
136 // on the platform or variations.
137 scoped_ptr<favicon::FaviconHandler> favicon_handler_;
138 scoped_ptr<favicon::FaviconHandler> touch_icon_handler_;
139 scoped_ptr<favicon::FaviconHandler> large_icon_handler_;
141 ObserverList<favicon::FaviconDriverObserver> observer_list_;
143 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper);
146 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_