| 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 "base/optional.h" |
| 9 #include "components/favicon/core/favicon_driver_impl.h" | 10 #include "components/favicon/core/favicon_driver_impl.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" |
| 14 #include "content/public/common/favicon_url.h" |
| 13 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 14 | 16 |
| 15 namespace content { | 17 namespace content { |
| 16 struct FaviconURL; | 18 struct FaviconURL; |
| 17 class WebContents; | 19 class WebContents; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace favicon { | 22 namespace favicon { |
| 21 | 23 |
| 22 // ContentFaviconDriver is an implementation of FaviconDriver that listens to | 24 // ContentFaviconDriver is an implementation of FaviconDriver that listens to |
| 23 // WebContents events to start download of favicons and to get informed when the | 25 // WebContents events to start download of favicons and to get informed when the |
| 24 // favicon download has completed. | 26 // favicon download has completed. |
| 25 class ContentFaviconDriver | 27 class ContentFaviconDriver |
| 26 : public content::WebContentsObserver, | 28 : public content::WebContentsObserver, |
| 27 public content::WebContentsUserData<ContentFaviconDriver>, | 29 public content::WebContentsUserData<ContentFaviconDriver>, |
| 28 public FaviconDriverImpl { | 30 public FaviconDriverImpl { |
| 29 public: | 31 public: |
| 30 ~ContentFaviconDriver() override; | 32 ~ContentFaviconDriver() override; |
| 31 | 33 |
| 32 static void CreateForWebContents(content::WebContents* web_contents, | 34 static void CreateForWebContents(content::WebContents* web_contents, |
| 33 FaviconService* favicon_service, | 35 FaviconService* favicon_service, |
| 34 history::HistoryService* history_service, | 36 history::HistoryService* history_service, |
| 35 bookmarks::BookmarkModel* bookmark_model); | 37 bookmarks::BookmarkModel* bookmark_model); |
| 36 | 38 |
| 37 // Returns the current tab's favicon URLs. If this is empty, | 39 // Returns the current tab's favicon URLs. If this is empty, |
| 38 // DidUpdateFaviconURL has not yet been called for the current navigation. | 40 // DidUpdateFaviconURL has not yet been called for the current navigation. |
| 39 const std::vector<content::FaviconURL>& favicon_urls() const { | 41 std::vector<content::FaviconURL> favicon_urls() const { |
| 40 return favicon_urls_; | 42 return favicon_urls_.value_or(std::vector<content::FaviconURL>()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 // Saves the favicon for the last committed navigation entry to the thumbnail | 45 // Saves the favicon for the last committed navigation entry to the thumbnail |
| 44 // database. | 46 // database. |
| 45 void SaveFavicon(); | 47 void SaveFavicon(); |
| 46 | 48 |
| 47 // FaviconDriver implementation. | 49 // FaviconDriver implementation. |
| 48 gfx::Image GetFavicon() const override; | 50 gfx::Image GetFavicon() const override; |
| 49 bool FaviconIsValid() const override; | 51 bool FaviconIsValid() const override; |
| 50 GURL GetActiveURL() override; | 52 GURL GetActiveURL() override; |
| 51 | 53 |
| 52 protected: | 54 protected: |
| 53 ContentFaviconDriver(content::WebContents* web_contents, | 55 ContentFaviconDriver(content::WebContents* web_contents, |
| 54 FaviconService* favicon_service, | 56 FaviconService* favicon_service, |
| 55 history::HistoryService* history_service, | 57 history::HistoryService* history_service, |
| 56 bookmarks::BookmarkModel* bookmark_model); | 58 bookmarks::BookmarkModel* bookmark_model); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 friend class content::WebContentsUserData<ContentFaviconDriver>; | 61 friend class content::WebContentsUserData<ContentFaviconDriver>; |
| 60 | 62 |
| 61 // FaviconHandler::Delegate implementation. | 63 // FaviconHandler::Delegate implementation. |
| 62 int DownloadImage(const GURL& url, | 64 int DownloadImage(const GURL& url, |
| 63 int max_image_size, | 65 int max_image_size, |
| 64 ImageDownloadCallback callback) override; | 66 ImageDownloadCallback callback) override; |
| 67 void DownloadManifest(const GURL& url, |
| 68 ManifestDownloadCallback callback) override; |
| 65 bool IsOffTheRecord() override; | 69 bool IsOffTheRecord() override; |
| 66 void OnFaviconUpdated(const GURL& page_url, | 70 void OnFaviconUpdated(const GURL& page_url, |
| 67 FaviconDriverObserver::NotificationIconType icon_type, | 71 FaviconDriverObserver::NotificationIconType icon_type, |
| 68 const GURL& icon_url, | 72 const GURL& icon_url, |
| 69 bool icon_url_changed, | 73 bool icon_url_changed, |
| 70 const gfx::Image& image) override; | 74 const gfx::Image& image) override; |
| 71 | 75 |
| 72 // content::WebContentsObserver implementation. | 76 // content::WebContentsObserver implementation. |
| 73 void DidUpdateFaviconURL( | 77 void DidUpdateFaviconURL( |
| 74 const std::vector<content::FaviconURL>& candidates) override; | 78 const std::vector<content::FaviconURL>& candidates) override; |
| 79 void DidUpdateWebManifestURL( |
| 80 const base::Optional<GURL>& manifest_url) override; |
| 75 void DidStartNavigation( | 81 void DidStartNavigation( |
| 76 content::NavigationHandle* navigation_handle) override; | 82 content::NavigationHandle* navigation_handle) override; |
| 77 void DidFinishNavigation( | 83 void DidFinishNavigation( |
| 78 content::NavigationHandle* navigation_handle) override; | 84 content::NavigationHandle* navigation_handle) override; |
| 79 | 85 |
| 80 GURL bypass_cache_page_url_; | 86 GURL bypass_cache_page_url_; |
| 81 std::vector<content::FaviconURL> favicon_urls_; | 87 // nullopt until the actual list is reported via DidUpdateFaviconURL(). |
| 88 base::Optional<std::vector<content::FaviconURL>> favicon_urls_; |
| 89 // Web Manifest URL or empty URL if none. |
| 90 GURL manifest_url_; |
| 82 | 91 |
| 83 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriver); | 92 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriver); |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 } // namespace favicon | 95 } // namespace favicon |
| 87 | 96 |
| 88 #endif // COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ | 97 #endif // COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_ |
| OLD | NEW |