Chromium Code Reviews| 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 CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" | 13 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 14 #include "chrome/common/web_application_info.h" | 14 #include "chrome/common/web_application_info.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/common/manifest.h" | 17 #include "content/public/common/manifest.h" |
| 18 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" | 18 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" |
| 19 | 19 |
| 20 namespace chrome { | 20 namespace chrome { |
| 21 class BitmapFetcher; | 21 class BitmapFetcher; |
| 22 } // namespace chrome | 22 } // namespace chrome |
| 23 | 23 |
| 24 namespace infobars { | 24 namespace infobars { |
| 25 class InfoBar; | 25 class InfoBar; |
| 26 } // namespace infobars | 26 } // namespace infobars |
| 27 | 27 |
| 28 namespace banners { | 28 namespace banners { |
| 29 class AppBannerDataFetcher; | 29 class AppBannerDataFetcher; |
| 30 | 30 |
| 31 // Fetches data required to show a web app banner for the URL currently shown by | 31 // Fetches data required to show a web app banner for the URL currently shown by |
| 32 // the WebContents. | 32 // the WebContents. |
| 33 class AppBannerDataFetcher | 33 class AppBannerDataFetcher |
| 34 : public base::RefCounted<AppBannerDataFetcher>, | 34 : public base::RefCounted<AppBannerDataFetcher>, |
| 35 public chrome::BitmapFetcherDelegate, | |
| 36 public content::WebContentsObserver { | 35 public content::WebContentsObserver { |
| 37 public: | 36 public: |
| 38 class Observer { | 37 class Observer { |
| 39 public: | 38 public: |
| 40 virtual void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, | 39 virtual void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, |
| 41 bool will_show) = 0; | 40 bool will_show) = 0; |
| 42 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; | 41 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 class Delegate { | 44 class Delegate { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 // opportunity to cancel. | 112 // opportunity to cancel. |
| 114 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, | 113 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, |
| 115 int request_id, | 114 int request_id, |
| 116 blink::WebAppBannerPromptReply reply); | 115 blink::WebAppBannerPromptReply reply); |
| 117 | 116 |
| 118 // Called when the client has prevented a banner from being shown, and is | 117 // Called when the client has prevented a banner from being shown, and is |
| 119 // now requesting that it be shown later. | 118 // now requesting that it be shown later. |
| 120 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, | 119 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, |
| 121 int request_id); | 120 int request_id); |
| 122 | 121 |
| 122 // Called when it is determined that the webapp has fulfilled the intial | |
|
gone
2015/08/19 22:21:07
nit: initial
Lalit Maganti
2015/08/20 16:48:00
Done.
| |
| 123 // criteria of having a manifest and a service worker. | |
| 124 void OnHasServiceWorker(content::WebContents* web_contents); | |
| 125 | |
| 123 content::WebContents* GetWebContents(); | 126 content::WebContents* GetWebContents(); |
| 124 virtual std::string GetAppIdentifier(); | 127 virtual std::string GetAppIdentifier(); |
| 125 const content::Manifest& web_app_data() { return web_app_data_; } | 128 const content::Manifest& web_app_data() { return web_app_data_; } |
| 126 void set_app_title(const base::string16& title) { app_title_ = title; } | 129 void set_app_title(const base::string16& title) { app_title_ = title; } |
| 127 int event_request_id() { return event_request_id_; } | 130 int event_request_id() { return event_request_id_; } |
| 131 const scoped_ptr<ManifestIconDownloader>& icon_downloader() { | |
| 132 return icon_downloader_; | |
| 133 } | |
| 128 | 134 |
| 129 // Fetches the icon at the given URL asynchronously, returning |false| if a | 135 // Fetches the icon at the given URL asynchronously, returning |false| if a |
| 130 // load could not be started. | 136 // load could not be started. |
| 131 bool FetchIcon(const GURL& image_url); | 137 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); |
| 132 | 138 |
| 133 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 139 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
| 134 // metric being recorded. | 140 // metric being recorded. |
| 135 void RecordDidShowBanner(const std::string& event_name); | 141 void RecordDidShowBanner(const std::string& event_name); |
| 136 | 142 |
| 137 private: | 143 private: |
| 138 // Callbacks for data retrieval. | 144 // Callbacks for data retrieval. |
| 139 void OnDidGetManifest(const content::Manifest& manifest); | 145 void OnDidGetManifest(const content::Manifest& manifest); |
| 140 void OnDidCheckHasServiceWorker(bool has_service_worker); | 146 void OnDidCheckHasServiceWorker(bool has_service_worker); |
| 141 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; | 147 void OnAppIconFetched(const SkBitmap& bitmap); |
| 142 | 148 |
| 143 // Returns whether the given web app has already been installed. | 149 // Returns whether the given web app has already been installed. |
| 144 // Implemented on desktop platforms only. | 150 // Implemented on desktop platforms only. |
| 145 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 151 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
| 146 const GURL& start_url); | 152 const GURL& start_url); |
| 147 | 153 |
| 148 // Shows a banner for the app, if the given |icon| is valid. | |
| 149 virtual void RequestShowBanner(const SkBitmap* icon); | |
| 150 | |
| 151 // Record that the banner could be shown at this point, if the triggering | 154 // Record that the banner could be shown at this point, if the triggering |
| 152 // heuristic allowed. | 155 // heuristic allowed. |
| 153 void RecordCouldShowBanner(); | 156 void RecordCouldShowBanner(); |
| 154 | 157 |
| 155 // Creates a banner for the app using the given |icon|. | 158 // Creates a banner for the app using the given |icon|. |
| 156 virtual void ShowBanner(const SkBitmap* icon, | 159 virtual void ShowBanner(const SkBitmap* icon, |
| 157 const base::string16& title) = 0; | 160 const base::string16& title) = 0; |
| 158 | 161 |
| 159 // Returns whether the banner should be shown. | 162 // Returns whether the banner should be shown. |
| 160 bool CheckIfShouldShowBanner(); | 163 bool CheckIfShouldShowBanner(); |
| 161 | 164 |
| 162 // Returns whether the fetcher is active and web contents have not been | 165 // Returns whether the fetcher is active and web contents have not been |
| 163 // closed. | 166 // closed. |
| 164 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | 167 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
| 165 | 168 |
| 166 // Returns whether the given Manifest is following the requirements to show | 169 // Returns whether the given Manifest is following the requirements to show |
| 167 // a web app banner. | 170 // a web app banner. |
| 168 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 171 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
| 169 content::WebContents* web_contents); | 172 content::WebContents* web_contents); |
| 170 | 173 |
| 171 const int ideal_icon_size_; | 174 const int ideal_icon_size_; |
| 172 const base::WeakPtr<Delegate> weak_delegate_; | 175 const base::WeakPtr<Delegate> weak_delegate_; |
| 173 base::ObserverList<Observer> observer_list_; | 176 base::ObserverList<Observer> observer_list_; |
| 174 bool is_active_; | 177 bool is_active_; |
| 175 bool was_canceled_by_page_; | 178 bool was_canceled_by_page_; |
| 176 bool page_requested_prompt_; | 179 bool page_requested_prompt_; |
| 177 ui::PageTransition transition_type_; | 180 ui::PageTransition transition_type_; |
| 178 int event_request_id_; | 181 int event_request_id_; |
| 179 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; | 182 scoped_ptr<ManifestIconDownloader> icon_downloader_; |
| 180 scoped_ptr<SkBitmap> app_icon_; | 183 scoped_ptr<SkBitmap> app_icon_; |
| 181 | 184 |
| 182 GURL validated_url_; | 185 GURL validated_url_; |
| 183 base::string16 app_title_; | 186 base::string16 app_title_; |
| 184 content::Manifest web_app_data_; | 187 content::Manifest web_app_data_; |
| 185 | 188 |
| 186 friend class AppBannerDataFetcherUnitTest; | 189 friend class AppBannerDataFetcherUnitTest; |
| 187 friend class base::RefCounted<AppBannerDataFetcher>; | 190 friend class base::RefCounted<AppBannerDataFetcher>; |
| 188 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 191 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
| 189 }; | 192 }; |
| 190 | 193 |
| 191 } // namespace banners | 194 } // namespace banners |
| 192 | 195 |
| 193 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 196 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| OLD | NEW |