Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / favicon / favicon_tab_helper.h
blobb0d04fabe866e14f57f38cd7924e74d8c6d2c1e1
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 "components/favicon/core/browser/favicon_client.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 namespace gfx {
19 class Image;
22 namespace content {
23 struct FaviconStatus;
26 class GURL;
27 class FaviconHandler;
28 class Profile;
29 class SkBitmap;
31 // FaviconTabHelper works with FaviconHandlers to fetch the favicons.
33 // 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 // downloaded and saved in the history backend.
37 class FaviconTabHelper : public content::WebContentsObserver,
38 public FaviconDriver,
39 public content::WebContentsUserData<FaviconTabHelper> {
40 public:
41 virtual ~FaviconTabHelper();
43 // Initiates loading the favicon for the specified url.
44 void FetchFavicon(const GURL& url);
46 // 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
48 // entry. This will return an empty bitmap if there are no navigation
49 // entries, which should rarely happen.
50 gfx::Image GetFavicon() const;
52 // Returns true if we have the favicon for the page.
53 bool FaviconIsValid() const;
55 // Returns whether the favicon should be displayed. If this returns false, no
56 // space is provided for the favicon, and the favicon is never displayed.
57 virtual bool ShouldDisplayFavicon();
59 // Returns the current tab's favicon urls. If this is empty,
60 // DidUpdateFaviconURL has not yet been called for the current navigation.
61 const std::vector<content::FaviconURL>& favicon_urls() const {
62 return favicon_urls_;
65 // content::WebContentsObserver override. Must be public, because also
66 // called from PrerenderContents.
67 virtual void DidUpdateFaviconURL(
68 const std::vector<content::FaviconURL>& candidates) override;
70 // Saves the favicon for the current page.
71 void SaveFavicon();
73 // FaviconDriver methods.
74 virtual int StartDownload(const GURL& url, int max_bitmap_size) override;
75 virtual void NotifyFaviconUpdated(bool icon_url_changed) override;
76 virtual bool IsOffTheRecord() override;
77 virtual const gfx::Image GetActiveFaviconImage() override;
78 virtual const GURL GetActiveFaviconURL() override;
79 virtual bool GetActiveFaviconValidity() override;
80 virtual const GURL GetActiveURL() override;
81 virtual void SetActiveFaviconImage(gfx::Image image) override;
82 virtual void SetActiveFaviconURL(GURL url) override;
83 virtual void SetActiveFaviconValidity(bool validity) override;
85 // Favicon download callback.
86 void DidDownloadFavicon(
87 int id,
88 int http_status_code,
89 const GURL& image_url,
90 const std::vector<SkBitmap>& bitmaps,
91 const std::vector<gfx::Size>& original_bitmap_sizes);
93 private:
94 explicit FaviconTabHelper(content::WebContents* web_contents);
95 friend class content::WebContentsUserData<FaviconTabHelper>;
97 // content::WebContentsObserver overrides.
98 virtual void DidStartNavigationToPendingEntry(
99 const GURL& url,
100 content::NavigationController::ReloadType reload_type) override;
101 virtual void DidNavigateMainFrame(
102 const content::LoadCommittedDetails& details,
103 const content::FrameNavigateParams& params) override;
105 // Helper method that returns the active navigation entry's favicon.
106 content::FaviconStatus& GetFaviconStatus();
108 Profile* profile_;
110 FaviconClient* client_;
112 std::vector<content::FaviconURL> favicon_urls_;
114 scoped_ptr<FaviconHandler> favicon_handler_;
116 // Handles downloading touchicons. It is NULL if
117 // browser_defaults::kEnableTouchIcon is false.
118 scoped_ptr<FaviconHandler> touch_icon_handler_;
120 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper);
123 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_