| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ | 5 #ifndef COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ |
| 6 #define COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ | 6 #define COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "components/favicon/core/favicon_driver_impl.h" | 9 #include "components/favicon/core/favicon_driver_impl.h" |
| 10 #include "components/favicon/core/favicon_handler.h" |
| 10 #include "content/public/browser/reload_type.h" | 11 #include "content/public/browser/reload_type.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 struct FaviconURL; | 17 struct FaviconURL; |
| 17 class WebContents; | 18 class WebContents; |
| 18 } | 19 } |
| 19 | 20 |
| 21 namespace bookmarks { |
| 22 class BookmarkModel; |
| 23 } |
| 24 |
| 20 namespace favicon { | 25 namespace favicon { |
| 21 | 26 |
| 22 // ContentFaviconDriver is an implementation of FaviconDriver that listens to | 27 // ContentFaviconDriver is an implementation of FaviconDriver that listens to |
| 23 // WebContents events to start download of favicons and to get informed when the | 28 // WebContents events to start download of favicons and to get informed when the |
| 24 // favicon download has completed. | 29 // favicon download has completed. |
| 25 class ContentFaviconDriver | 30 class ContentFaviconDriver |
| 26 : public content::WebContentsObserver, | 31 : public content::WebContentsObserver, |
| 27 public content::WebContentsUserData<ContentFaviconDriver>, | 32 public content::WebContentsUserData<ContentFaviconDriver>, |
| 33 public FaviconHandler::Delegate, |
| 28 public FaviconDriverImpl { | 34 public FaviconDriverImpl { |
| 29 public: | 35 public: |
| 30 static void CreateForWebContents(content::WebContents* web_contents, | 36 static void CreateForWebContents(content::WebContents* web_contents, |
| 31 FaviconService* favicon_service, | 37 FaviconService* favicon_service, |
| 32 history::HistoryService* history_service, | 38 history::HistoryService* history_service, |
| 33 bookmarks::BookmarkModel* bookmark_model); | 39 bookmarks::BookmarkModel* bookmark_model); |
| 34 | 40 |
| 35 // Returns the current tab's favicon URLs. If this is empty, | 41 // Returns the current tab's favicon URLs. If this is empty, |
| 36 // DidUpdateFaviconURL has not yet been called for the current navigation. | 42 // DidUpdateFaviconURL has not yet been called for the current navigation. |
| 37 const std::vector<content::FaviconURL>& favicon_urls() const { | 43 const std::vector<content::FaviconURL>& favicon_urls() const { |
| 38 return favicon_urls_; | 44 return favicon_urls_; |
| 39 } | 45 } |
| 40 | 46 |
| 41 // Saves the favicon for the last committed navigation entry to the thumbnail | 47 // Saves the favicon for the last committed navigation entry to the thumbnail |
| 42 // database. | 48 // database. |
| 43 void SaveFavicon(); | 49 void SaveFavicon(); |
| 44 | 50 |
| 45 // FaviconDriver implementation. | 51 // FaviconDriver implementation. |
| 46 gfx::Image GetFavicon() const override; | 52 gfx::Image GetFavicon() const override; |
| 47 bool FaviconIsValid() const override; | 53 bool FaviconIsValid() const override; |
| 48 int StartDownload(const GURL& url, int max_bitmap_size) override; | 54 GURL GetActiveURL() override; |
| 55 |
| 56 // FaviconHandler::Delegate implementation. |
| 57 int DownloadImage(const GURL& url, |
| 58 int max_image_size, |
| 59 ImageDownloadCallback callback) override; |
| 49 bool IsOffTheRecord() override; | 60 bool IsOffTheRecord() override; |
| 50 GURL GetActiveURL() override; | 61 void OnFaviconUpdated(const GURL& page_url, |
| 62 FaviconDriverObserver::NotificationIconType icon_type, |
| 63 const GURL& icon_url, |
| 64 bool icon_url_changed, |
| 65 const gfx::Image& image) override; |
| 51 | 66 |
| 52 protected: | 67 protected: |
| 53 ContentFaviconDriver(content::WebContents* web_contents, | 68 ContentFaviconDriver(content::WebContents* web_contents, |
| 54 FaviconService* favicon_service, | 69 FaviconService* favicon_service, |
| 55 history::HistoryService* history_service, | 70 history::HistoryService* history_service); |
| 56 bookmarks::BookmarkModel* bookmark_model); | |
| 57 ~ContentFaviconDriver() override; | 71 ~ContentFaviconDriver() override; |
| 58 | 72 |
| 59 private: | 73 private: |
| 60 friend class content::WebContentsUserData<ContentFaviconDriver>; | 74 friend class content::WebContentsUserData<ContentFaviconDriver>; |
| 61 | 75 |
| 62 // FaviconDriver implementation. | |
| 63 void OnFaviconUpdated( | |
| 64 const GURL& page_url, | |
| 65 FaviconDriverObserver::NotificationIconType icon_type, | |
| 66 const GURL& icon_url, | |
| 67 bool icon_url_changed, | |
| 68 const gfx::Image& image) override; | |
| 69 | |
| 70 // content::WebContentsObserver implementation. | 76 // content::WebContentsObserver implementation. |
| 71 void DidUpdateFaviconURL( | 77 void DidUpdateFaviconURL( |
| 72 const std::vector<content::FaviconURL>& candidates) override; | 78 const std::vector<content::FaviconURL>& candidates) override; |
| 73 void DidStartNavigation( | 79 void DidStartNavigation( |
| 74 content::NavigationHandle* navigation_handle) override; | 80 content::NavigationHandle* navigation_handle) override; |
| 75 void DidFinishNavigation( | 81 void DidFinishNavigation( |
| 76 content::NavigationHandle* navigation_handle) override; | 82 content::NavigationHandle* navigation_handle) override; |
| 77 | 83 |
| 78 GURL bypass_cache_page_url_; | 84 GURL bypass_cache_page_url_; |
| 79 std::vector<content::FaviconURL> favicon_urls_; | 85 std::vector<content::FaviconURL> favicon_urls_; |
| 80 | 86 |
| 81 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriver); | 87 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriver); |
| 82 }; | 88 }; |
| 83 | 89 |
| 84 } // namespace favicon | 90 } // namespace favicon |
| 85 | 91 |
| 86 #endif // COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ | 92 #endif // COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ |
| OLD | NEW |