content_favicon_driver.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_
  5. #define COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_
  6. #include <vector>
  7. #include "components/favicon/core/favicon_driver_impl.h"
  8. #include "content/public/browser/document_user_data.h"
  9. #include "content/public/browser/navigation_handle_user_data.h"
  10. #include "content/public/browser/reload_type.h"
  11. #include "content/public/browser/web_contents_observer.h"
  12. #include "content/public/browser/web_contents_user_data.h"
  13. #include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
  14. #include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h"
  15. #include "url/gurl.h"
  16. namespace favicon {
  17. class CoreFaviconService;
  18. // ContentFaviconDriver is an implementation of FaviconDriver that listens to
  19. // WebContents events to start download of favicons and to get informed when the
  20. // favicon download has completed.
  21. class ContentFaviconDriver
  22. : public content::WebContentsObserver,
  23. public content::WebContentsUserData<ContentFaviconDriver>,
  24. public FaviconDriverImpl {
  25. public:
  26. ContentFaviconDriver(const ContentFaviconDriver&) = delete;
  27. ContentFaviconDriver& operator=(const ContentFaviconDriver&) = delete;
  28. ~ContentFaviconDriver() override;
  29. // FaviconDriver implementation.
  30. gfx::Image GetFavicon() const override;
  31. bool FaviconIsValid() const override;
  32. GURL GetActiveURL() override;
  33. GURL GetManifestURL(content::RenderFrameHost* rfh);
  34. protected:
  35. ContentFaviconDriver(content::WebContents* web_contents,
  36. CoreFaviconService* favicon_service);
  37. private:
  38. friend class content::WebContentsUserData<ContentFaviconDriver>;
  39. // TODO(crbug.com/1205018): these two classes are current used to ensure that
  40. // we disregard manifest URL updates that arrive prior to onload firing.
  41. struct DocumentManifestData
  42. : public content::DocumentUserData<DocumentManifestData> {
  43. explicit DocumentManifestData(content::RenderFrameHost* rfh);
  44. ~DocumentManifestData() override;
  45. DOCUMENT_USER_DATA_KEY_DECL();
  46. bool has_manifest_url = false;
  47. };
  48. struct NavigationManifestData
  49. : public content::NavigationHandleUserData<NavigationManifestData> {
  50. explicit NavigationManifestData(
  51. content::NavigationHandle& navigation_handle);
  52. ~NavigationManifestData() override;
  53. NAVIGATION_HANDLE_USER_DATA_KEY_DECL();
  54. bool has_manifest_url = false;
  55. };
  56. // Callback when a manifest is downloaded.
  57. void OnDidDownloadManifest(ManifestDownloadCallback callback,
  58. const GURL& manifest_url,
  59. blink::mojom::ManifestPtr manifest);
  60. // FaviconHandler::Delegate implementation.
  61. int DownloadImage(const GURL& url,
  62. int max_image_size,
  63. ImageDownloadCallback callback) override;
  64. void DownloadManifest(const GURL& url,
  65. ManifestDownloadCallback callback) override;
  66. bool IsOffTheRecord() override;
  67. void OnFaviconUpdated(const GURL& page_url,
  68. FaviconDriverObserver::NotificationIconType icon_type,
  69. const GURL& icon_url,
  70. bool icon_url_changed,
  71. const gfx::Image& image) override;
  72. void OnFaviconDeleted(const GURL& page_url,
  73. FaviconDriverObserver::NotificationIconType
  74. notification_icon_type) override;
  75. // content::WebContentsObserver implementation.
  76. void DidUpdateFaviconURL(
  77. content::RenderFrameHost* rfh,
  78. const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
  79. void DidUpdateWebManifestURL(content::RenderFrameHost* rfh,
  80. const GURL& manifest_url) override;
  81. void DidStartNavigation(
  82. content::NavigationHandle* navigation_handle) override;
  83. void DidFinishNavigation(
  84. content::NavigationHandle* navigation_handle) override;
  85. GURL bypass_cache_page_url_;
  86. WEB_CONTENTS_USER_DATA_KEY_DECL();
  87. };
  88. } // namespace favicon
  89. #endif // COMPONENTS_FAVICON_CONTENT_CONTENT_FAVICON_DRIVER_H_