Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ | |
| 6 #define CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | |
| 15 | |
| 16 class SkBitmap; | |
| 17 | |
| 18 namespace content { | |
| 19 struct FaviconURL; | |
| 20 } | |
| 21 | |
| 22 namespace gfx { | |
| 23 class Size; | |
| 24 } | |
| 25 | |
| 26 // Class to help download all favicons for a tab. | |
|
pkotwicz
2013/12/03 19:06:49
You are sure that you want to get the favicons for
calamity
2013/12/04 05:31:48
In this case, the large icon is used as the app ic
| |
| 27 class FaviconDownloader : public content::WebContentsObserver { | |
| 28 public: | |
| 29 typedef std::map<GURL, std::vector<SkBitmap> > FaviconMap; | |
| 30 typedef base::Callback<void( | |
| 31 bool, /* success */ | |
| 32 /* A map of icon urls to the bitmaps provided by that url. */ | |
| 33 const FaviconMap&)> | |
| 34 FaviconDownloaderCallback; | |
| 35 | |
| 36 FaviconDownloader(content::WebContents* web_contents, | |
|
pkotwicz
2013/12/03 19:06:49
Can you add a comment as to why |extra_favicon_url
calamity
2013/12/04 05:31:48
Done.
| |
| 37 std::vector<GURL> extra_favicon_urls, | |
| 38 FaviconDownloaderCallback callback); | |
| 39 virtual ~FaviconDownloader(); | |
| 40 | |
| 41 void Start(); | |
| 42 | |
| 43 private: | |
| 44 friend class TestFaviconDownloader; | |
| 45 | |
| 46 // Initiates a download of the image at |url| and returns the download id. | |
| 47 // This is overridden in testing. | |
| 48 virtual int DownloadImage(const GURL& url); | |
| 49 | |
| 50 // Queries FaviconTabHelper for the page's current favicon URLs. | |
| 51 // This is overridden in testing. | |
| 52 virtual void PopulateFaviconURLsFromWebContents(); | |
| 53 | |
| 54 // Fetches icons for |favicon_url_candidates_| and |extra_favicon_urls_|. | |
| 55 // |callback| is run when all downloads complete. | |
| 56 void FetchIcons(); | |
| 57 | |
| 58 // Icon download callback. | |
| 59 void DidDownloadFavicon(int id, | |
| 60 int http_status_code, | |
| 61 const GURL& image_url, | |
| 62 const std::vector<SkBitmap>& bitmaps, | |
| 63 const std::vector<gfx::Size>& original_bitmap_sizes); | |
| 64 | |
| 65 // content::WebContentsObserver overrides: | |
| 66 virtual void DidNavigateMainFrame( | |
| 67 const content::LoadCommittedDetails& details, | |
| 68 const content::FrameNavigateParams& params) OVERRIDE; | |
| 69 virtual void DidUpdateFaviconURL( | |
| 70 int32 page_id, | |
| 71 const std::vector<content::FaviconURL>& candidates) OVERRIDE; | |
| 72 | |
| 73 // FaviconURLs for the current web contents. | |
| 74 // This is populated when PopulateFaviconURLsFromWebContents() is called if | |
|
pkotwicz
2013/12/03 19:06:49
Can this be a bool instead? |got_favicon_urls_| or
calamity
2013/12/04 05:31:48
Done.
| |
| 75 // available. Otherwise it is populated when | |
| 76 // WebContentsObserver::DidUpdateFaviconURL() is called. | |
| 77 const std::vector<content::FaviconURL>* favicon_url_candidates_; | |
| 78 | |
| 79 // URLs that aren't given by WebContentsObserver::DidUpdateFaviconURL() that | |
| 80 // should be used for this favicon. This is necessary in order to get touch | |
| 81 // icons on non-android environments. | |
| 82 std::vector<GURL> extra_favicon_urls_; | |
| 83 | |
| 84 // The current page's icons. Populated by FetchIcons(). | |
|
pkotwicz
2013/12/03 19:06:49
How about: "The icons which were downloaded."
calamity
2013/12/04 05:31:48
Done.
| |
| 85 FaviconMap favicon_map_; | |
| 86 | |
| 87 // Request ids of in-progress requests. | |
| 88 std::set<int> in_progress_requests_; | |
| 89 | |
| 90 // Callback to run on favicon download completion. | |
| 91 FaviconDownloaderCallback callback_; | |
| 92 | |
| 93 base::WeakPtrFactory<FaviconDownloader> weak_ptr_factory_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(FaviconDownloader); | |
| 96 }; | |
| 97 | |
| 98 #endif // CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ | |
| OLD | NEW |