| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 blink::WebAppBannerPromptReply reply, | 125 blink::WebAppBannerPromptReply reply, |
| 126 std::string referrer); | 126 std::string referrer); |
| 127 | 127 |
| 128 // Called when the client has prevented a banner from being shown, and is | 128 // Called when the client has prevented a banner from being shown, and is |
| 129 // now requesting that it be shown later. | 129 // now requesting that it be shown later. |
| 130 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, | 130 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, |
| 131 int request_id); | 131 int request_id); |
| 132 | 132 |
| 133 content::WebContents* GetWebContents(); | 133 content::WebContents* GetWebContents(); |
| 134 virtual std::string GetAppIdentifier(); | 134 virtual std::string GetAppIdentifier(); |
| 135 const content::Manifest& web_app_data() { return web_app_data_; } | 135 const GURL& manifest_url() { return manifest_url_; } |
| 136 const content::Manifest& manifest() { return manifest_; } |
| 136 void set_app_title(const base::string16& title) { app_title_ = title; } | 137 void set_app_title(const base::string16& title) { app_title_ = title; } |
| 137 int event_request_id() { return event_request_id_; } | 138 int event_request_id() { return event_request_id_; } |
| 138 | 139 |
| 139 // Fetches the icon at the given URL asynchronously, returning |false| if a | 140 // Fetches the icon at the given URL asynchronously, returning |false| if a |
| 140 // load could not be started. | 141 // load could not be started. |
| 141 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); | 142 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); |
| 142 | 143 |
| 143 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 144 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
| 144 // metric being recorded. | 145 // metric being recorded. |
| 145 void RecordDidShowBanner(const std::string& event_name); | 146 void RecordDidShowBanner(const std::string& event_name); |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 // Callbacks for data retrieval. | 149 // Callbacks for data retrieval. |
| 149 void OnDidHasManifest(bool has_manifest); | 150 void OnDidHasManifest(bool has_manifest); |
| 150 void OnDidGetManifest(const content::Manifest& manifest); | 151 void OnDidGetManifest(const GURL& manifest_url, |
| 152 const content::Manifest& manifest); |
| 151 void OnDidCheckHasServiceWorker(bool has_service_worker); | 153 void OnDidCheckHasServiceWorker(bool has_service_worker); |
| 152 void OnAppIconFetched(const SkBitmap& bitmap); | 154 void OnAppIconFetched(const SkBitmap& bitmap); |
| 153 | 155 |
| 154 // Called when it is determined that the webapp has fulfilled the initial | 156 // Called when it is determined that the webapp has fulfilled the initial |
| 155 // criteria of having a manifest and a service worker. | 157 // criteria of having a manifest and a service worker. |
| 156 void OnHasServiceWorker(content::WebContents* web_contents); | 158 void OnHasServiceWorker(content::WebContents* web_contents); |
| 157 | 159 |
| 158 // Returns whether the given web app has already been installed. | 160 // Returns whether the given web app has already been installed. |
| 159 // Implemented on desktop platforms only. | 161 // Implemented on desktop platforms only. |
| 160 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 162 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
| 161 const GURL& start_url); | 163 const GURL& start_url); |
| 162 | 164 |
| 163 // Record that the banner could be shown at this point, if the triggering | 165 // Record that the banner could be shown at this point, if the triggering |
| 164 // heuristic allowed. | 166 // heuristic allowed. |
| 165 void RecordCouldShowBanner(); | 167 void RecordCouldShowBanner(); |
| 166 | 168 |
| 167 // Creates a banner for the app using the given |icon|. | 169 // Creates a banner for the app using the given icon. |
| 168 virtual void ShowBanner(const SkBitmap* icon, | 170 virtual void ShowBanner(const GURL& icon_url, |
| 171 const SkBitmap* icon, |
| 169 const base::string16& title, | 172 const base::string16& title, |
| 170 const std::string& referrer) = 0; | 173 const std::string& referrer) = 0; |
| 171 | 174 |
| 172 // Returns whether the banner should be shown. | 175 // Returns whether the banner should be shown. |
| 173 bool CheckIfShouldShowBanner(); | 176 bool CheckIfShouldShowBanner(); |
| 174 | 177 |
| 175 // Returns whether the fetcher is active and web contents have not been | 178 // Returns whether the fetcher is active and web contents have not been |
| 176 // closed. | 179 // closed. |
| 177 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | 180 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
| 178 | 181 |
| 179 // Returns whether the given Manifest is following the requirements to show | 182 // Returns whether the given Manifest is following the requirements to show |
| 180 // a web app banner. | 183 // a web app banner. |
| 181 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 184 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
| 182 content::WebContents* web_contents, | 185 content::WebContents* web_contents, |
| 183 bool is_debug_mode); | 186 bool is_debug_mode); |
| 184 | 187 |
| 185 const base::WeakPtr<Delegate> weak_delegate_; | 188 const base::WeakPtr<Delegate> weak_delegate_; |
| 186 const int ideal_icon_size_in_dp_; | 189 const int ideal_icon_size_in_dp_; |
| 187 const int minimum_icon_size_in_dp_; | 190 const int minimum_icon_size_in_dp_; |
| 188 base::ObserverList<Observer> observer_list_; | 191 base::ObserverList<Observer> observer_list_; |
| 189 bool is_active_; | 192 bool is_active_; |
| 190 bool was_canceled_by_page_; | 193 bool was_canceled_by_page_; |
| 191 bool page_requested_prompt_; | 194 bool page_requested_prompt_; |
| 192 const bool is_debug_mode_; | 195 const bool is_debug_mode_; |
| 193 ui::PageTransition transition_type_; | 196 ui::PageTransition transition_type_; |
| 194 int event_request_id_; | 197 int event_request_id_; |
| 198 GURL app_icon_url_; |
| 195 std::unique_ptr<SkBitmap> app_icon_; | 199 std::unique_ptr<SkBitmap> app_icon_; |
| 196 std::string referrer_; | 200 std::string referrer_; |
| 197 | 201 |
| 198 GURL validated_url_; | 202 GURL validated_url_; |
| 199 base::string16 app_title_; | 203 base::string16 app_title_; |
| 200 content::Manifest web_app_data_; | 204 |
| 205 // The URL of the Web app manifest. |
| 206 GURL manifest_url_; |
| 207 |
| 208 content::Manifest manifest_; |
| 201 | 209 |
| 202 friend struct content::BrowserThread::DeleteOnThread< | 210 friend struct content::BrowserThread::DeleteOnThread< |
| 203 content::BrowserThread::UI>; | 211 content::BrowserThread::UI>; |
| 204 friend class base::DeleteHelper<AppBannerDataFetcher>; | 212 friend class base::DeleteHelper<AppBannerDataFetcher>; |
| 205 friend class AppBannerDataFetcherUnitTest; | 213 friend class AppBannerDataFetcherUnitTest; |
| 206 friend class base::RefCounted<AppBannerDataFetcher>; | 214 friend class base::RefCounted<AppBannerDataFetcher>; |
| 207 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 215 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
| 208 }; | 216 }; |
| 209 | 217 |
| 210 } // namespace banners | 218 } // namespace banners |
| 211 | 219 |
| 212 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 220 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| OLD | NEW |