Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / favicon / favicon_tab_helper.h
blob7758121ab6adb04ad7d7d8c740778d46a0e15155
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 "chrome/browser/favicon/favicon_handler_delegate.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
15 #include "content/public/common/favicon_url.h"
17 namespace gfx {
18 class Image;
21 class GURL;
22 class FaviconHandler;
23 class Profile;
24 class SkBitmap;
26 // FaviconTabHelper works with FaviconHandlers to fetch the favicons.
28 // FetchFavicon fetches the given page's icons. It requests the icons from the
29 // history backend. If the icon is not available or expired, the icon will be
30 // downloaded and saved in the history backend.
32 class FaviconTabHelper : public content::WebContentsObserver,
33 public FaviconHandlerDelegate,
34 public content::WebContentsUserData<FaviconTabHelper> {
35 public:
36 virtual ~FaviconTabHelper();
38 // Initiates loading the favicon for the specified url.
39 void FetchFavicon(const GURL& url);
41 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
42 // not have a favicon. The default implementation uses the current navigation
43 // entry. This will return an empty bitmap if there are no navigation
44 // entries, which should rarely happen.
45 gfx::Image GetFavicon() const;
47 // Returns true if we have the favicon for the page.
48 bool FaviconIsValid() const;
50 // Returns whether the favicon should be displayed. If this returns false, no
51 // space is provided for the favicon, and the favicon is never displayed.
52 virtual bool ShouldDisplayFavicon();
54 // Returns the current tab's favicon urls. If this is empty,
55 // DidUpdateFaviconURL has not yet been called for the current navigation.
56 const std::vector<content::FaviconURL>& favicon_urls() const {
57 return favicon_urls_;
60 // Allows the client to determine if they want to fetch the Favicons as
61 // they are discovered.
62 void set_should_fetch_icons(bool fetch) {
63 should_fetch_icons_ = fetch;
66 // content::WebContentsObserver override. Must be public, because also
67 // called from PrerenderContents.
68 virtual void DidUpdateFaviconURL(
69 int32 page_id,
70 const std::vector<content::FaviconURL>& candidates) OVERRIDE;
72 // Saves the favicon for the current page.
73 void SaveFavicon();
75 // FaviconHandlerDelegate methods.
76 virtual content::NavigationEntry* GetActiveEntry() OVERRIDE;
77 virtual int StartDownload(const GURL& url, int max_bitmap_size) OVERRIDE;
78 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE;
80 // Favicon download callback.
81 void DidDownloadFavicon(
82 int id,
83 int http_status_code,
84 const GURL& image_url,
85 const std::vector<SkBitmap>& bitmaps,
86 const std::vector<gfx::Size>& original_bitmap_sizes);
88 private:
89 explicit FaviconTabHelper(content::WebContents* web_contents);
90 friend class content::WebContentsUserData<FaviconTabHelper>;
92 // content::WebContentsObserver overrides.
93 virtual void DidStartNavigationToPendingEntry(
94 const GURL& url,
95 content::NavigationController::ReloadType reload_type) OVERRIDE;
96 virtual void DidNavigateMainFrame(
97 const content::LoadCommittedDetails& details,
98 const content::FrameNavigateParams& params) OVERRIDE;
100 Profile* profile_;
101 bool should_fetch_icons_;
103 std::vector<content::FaviconURL> favicon_urls_;
105 scoped_ptr<FaviconHandler> favicon_handler_;
107 // Handles downloading touchicons. It is NULL if
108 // browser_defaults::kEnableTouchIcon is false.
109 scoped_ptr<FaviconHandler> touch_icon_handler_;
111 DISALLOW_COPY_AND_ASSIGN(FaviconTabHelper);
114 #endif // CHROME_BROWSER_FAVICON_FAVICON_TAB_HELPER_H_