| 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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/engagement/site_engagement_observer.h" | 14 #include "chrome/browser/engagement/site_engagement_observer.h" |
| 15 #include "chrome/browser/installable/installable_logging.h" | 15 #include "chrome/browser/installable/installable_logging.h" |
| 16 #include "chrome/browser/installable/installable_manager.h" | 16 #include "chrome/browser/installable/installable_manager.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 19 #include "third_party/WebKit/public/platform/modules/app_banner/app_banner.mojom
.h" |
| 19 | 20 |
| 20 class SkBitmap; | 21 class SkBitmap; |
| 21 struct WebApplicationInfo; | 22 struct WebApplicationInfo; |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 class RenderFrameHost; | 25 class RenderFrameHost; |
| 25 class WebContents; | 26 class WebContents; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // This forward declaration exists solely for the DidFinishCreatingBookmarkApp | 29 // This forward declaration exists solely for the DidFinishCreatingBookmarkApp |
| 29 // callback, implemented and called on desktop platforms only. | 30 // callback, implemented and called on desktop platforms only. |
| 30 namespace extensions { | 31 namespace extensions { |
| 31 class Extension; | 32 class Extension; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace banners { | 35 namespace banners { |
| 35 | 36 |
| 36 // Coordinates the creation of an app banner, from detecting eligibility to | 37 // Coordinates the creation of an app banner, from detecting eligibility to |
| 37 // fetching data and creating the infobar. Sites declare that they want an app | 38 // fetching data and creating the infobar. Sites declare that they want an app |
| 38 // banner using the web app manifest. One web/native app may occupy the pipeline | 39 // banner using the web app manifest. One web/native app may occupy the pipeline |
| 39 // at a time; navigation resets the manager and discards any work in progress. | 40 // at a time; navigation resets the manager and discards any work in progress. |
| 40 // | 41 // |
| 41 // This class contains the generic functionality shared between all platforms, | 42 // This class contains the generic functionality shared between all platforms, |
| 42 // as well as no-op callbacks that the platform-specific implementations pass to | 43 // as well as no-op callbacks that the platform-specific implementations pass to |
| 43 // base::Bind. This allows a WeakPtrFactory to be housed in this class. | 44 // base::Bind. This allows a WeakPtrFactory to be housed in this class. |
| 44 // | 45 // |
| 45 // The InstallableManager fetches and validate a site's eligibility for banners. | 46 // The InstallableManager fetches and validates whether a site is eligible for |
| 46 // The manager is first called to fetch the manifest, so we can verify whether | 47 // banners. The manager is first called to fetch the manifest, so we can verify |
| 47 // the site is already installed (and on Android, divert the flow to a | 48 // whether the site is already installed (and on Android, divert the flow to a |
| 48 // native app banner if requested). The second call completes the checking for a | 49 // native app banner if requested). The second call completes the checking for a |
| 49 // web app banner (checking manifest validity, service worker, and icon). | 50 // web app banner (checking manifest validity, service worker, and icon). |
| 50 class AppBannerManager : public content::WebContentsObserver, | 51 class AppBannerManager : public content::WebContentsObserver, |
| 52 public blink::mojom::AppBannerService, |
| 51 public SiteEngagementObserver { | 53 public SiteEngagementObserver { |
| 52 public: | 54 public: |
| 53 static void DisableSecureSchemeCheckForTesting(); | 55 static void DisableSecureSchemeCheckForTesting(); |
| 54 | 56 |
| 55 // Returns the current time. | 57 // Returns the current time. |
| 56 static base::Time GetCurrentTime(); | 58 static base::Time GetCurrentTime(); |
| 57 | 59 |
| 58 // Fast-forwards the current time for testing. | 60 // Fast-forwards the current time for testing. |
| 59 static void SetTimeDeltaForTesting(int days); | 61 static void SetTimeDeltaForTesting(int days); |
| 60 | 62 |
| 61 // Sets the weights applied to direct and indirect navigations for triggering | 63 // Sets the weights applied to direct and indirect navigations for triggering |
| 62 // the banner. Deprecated and will be removed when app banners fully migrates | 64 // the banner. Deprecated and will be removed when app banners fully migrates |
| 63 // to using site engagement as a trigger. | 65 // to using site engagement as a trigger. |
| 64 static void SetEngagementWeights(double direct_engagement, | 66 static void SetEngagementWeights(double direct_engagement, |
| 65 double indirect_engagement); | 67 double indirect_engagement); |
| 66 | 68 |
| 67 // Returns whether or not the URLs match for everything except for the ref. | 69 // Returns whether or not the URLs match for everything except for the ref. |
| 68 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); | 70 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); |
| 69 | 71 |
| 70 // Requests an app banner. If |is_debug_mode| is true, any failure in the | 72 // Requests an app banner. If |is_debug_mode| is true, any failure in the |
| 71 // pipeline will be reported to the devtools console. | 73 // pipeline will be reported to the devtools console. |
| 72 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); | 74 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); |
| 73 | 75 |
| 76 // Sends a message to the renderer that the user accepted the banner. Does |
| 77 // nothing if |request_id| does not match the current request. |
| 78 void SendBannerAccepted(int request_id); |
| 79 |
| 80 // Sends a message to the renderer that the user dismissed the banner. Does |
| 81 // nothing if |request_id| does not match the current request. |
| 82 void SendBannerDismissed(int request_id); |
| 83 |
| 74 // Overridden and passed through base::Bind on desktop platforms. Called when | 84 // Overridden and passed through base::Bind on desktop platforms. Called when |
| 75 // the bookmark app install initiated by a banner has completed. Not used on | 85 // the bookmark app install initiated by a banner has completed. Not used on |
| 76 // Android. | 86 // Android. |
| 77 virtual void DidFinishCreatingBookmarkApp( | 87 virtual void DidFinishCreatingBookmarkApp( |
| 78 const extensions::Extension* extension, | 88 const extensions::Extension* extension, |
| 79 const WebApplicationInfo& web_app_info) { } | 89 const WebApplicationInfo& web_app_info) {} |
| 80 | 90 |
| 81 // Overridden and passed through base::Bind on Android. Called when the | 91 // Overridden and passed through base::Bind on Android. Called when the |
| 82 // download of a native app's icon is complete, as native banners use an icon | 92 // download of a native app's icon is complete, as native banners use an icon |
| 83 // provided from the Play Store rather than the web manifest. Not used on | 93 // provided from the Play Store rather than the web manifest. Not used on |
| 84 // desktop platforms. | 94 // desktop platforms. |
| 85 virtual void OnAppIconFetched(const SkBitmap& bitmap) { } | 95 virtual void OnAppIconFetched(const SkBitmap& bitmap) {} |
| 86 | 96 |
| 87 // Overridden and passed through base::Bind on Android. Called after a web app | 97 // Overridden and passed through base::Bind on Android. Called after a web app |
| 88 // banner was successfully used to add a web app to homescreen to kick off an | 98 // banner was successfully used to add a web app to homescreen to kick off an |
| 89 // asynchronous fetch of a splash screen icon. Not used on desktop platforms. | 99 // asynchronous fetch of a splash screen icon. Not used on desktop platforms. |
| 90 virtual base::Closure FetchWebappSplashScreenImageCallback( | 100 virtual base::Closure FetchWebappSplashScreenImageCallback( |
| 91 const std::string& webapp_id); | 101 const std::string& webapp_id); |
| 92 | 102 |
| 93 protected: | 103 protected: |
| 94 explicit AppBannerManager(content::WebContents* web_contents); | 104 explicit AppBannerManager(content::WebContents* web_contents); |
| 95 ~AppBannerManager() override; | 105 ~AppBannerManager() override; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // heuristic allowed. | 215 // heuristic allowed. |
| 206 void RecordCouldShowBanner(); | 216 void RecordCouldShowBanner(); |
| 207 | 217 |
| 208 // Creates a banner for the app. Overridden by subclasses as the infobar is | 218 // Creates a banner for the app. Overridden by subclasses as the infobar is |
| 209 // platform-specific. | 219 // platform-specific. |
| 210 virtual void ShowBanner() = 0; | 220 virtual void ShowBanner() = 0; |
| 211 | 221 |
| 212 // Returns true if the banner should be shown. | 222 // Returns true if the banner should be shown. |
| 213 bool CheckIfShouldShowBanner(); | 223 bool CheckIfShouldShowBanner(); |
| 214 | 224 |
| 215 bool OnMessageReceived(const IPC::Message& message, | |
| 216 content::RenderFrameHost* render_frame_host) override; | |
| 217 | |
| 218 // Called after the manager sends a message to the renderer regarding its | 225 // Called after the manager sends a message to the renderer regarding its |
| 219 // intention to show a prompt. The renderer will send a message back with the | 226 // intention to show a prompt. The renderer will send a message back with the |
| 220 // opportunity to cancel. | 227 // opportunity to cancel. |
| 221 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, | 228 void OnBannerPromptReply(blink::mojom::AppBannerPromptReply reply, |
| 222 int request_id, | 229 const std::string& referrer); |
| 223 blink::WebAppBannerPromptReply reply, | |
| 224 std::string referrer); | |
| 225 | 230 |
| 226 // Called when the client has prevented a banner from being shown, and is | 231 // blink::mojom::AppBannerService overrides. |
| 227 // now requesting that it be shown later. | 232 // Called when Blink has prevented a banner from being shown, and is now |
| 228 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, | 233 // requesting that it be shown later. |
| 229 int request_id); | 234 void DisplayAppBanner() override; |
| 230 | 235 |
| 231 // The type of navigation made to the page | 236 // The type of navigation made to the page |
| 232 ui::PageTransition last_transition_type_; | 237 ui::PageTransition last_transition_type_; |
| 233 | 238 |
| 234 // Fetches the data required to display a banner for the current page. | 239 // Fetches the data required to display a banner for the current page. |
| 235 InstallableManager* manager_; | 240 InstallableManager* manager_; |
| 236 | 241 |
| 237 // A monotonically increasing id to verify the response to the | 242 // A monotonically increasing id to verify the response to the |
| 238 // beforeinstallprompt event from the renderer. | 243 // beforeinstallprompt event from the renderer. |
| 239 int event_request_id_; | 244 int event_request_id_; |
| 240 | 245 |
| 241 // We do not want to trigger a banner when the manager is attached to | 246 // We do not want to trigger a banner when the manager is attached to |
| 242 // a WebContents that is playing video. Banners triggering on a site in the | 247 // a WebContents that is playing video. Banners triggering on a site in the |
| 243 // background will appear when the tab is reactivated. | 248 // background will appear when the tab is reactivated. |
| 244 std::vector<MediaPlayerId> active_media_players_; | 249 std::vector<MediaPlayerId> active_media_players_; |
| 245 | 250 |
| 251 // Mojo bindings and interface pointers. |
| 252 mojo::Binding<blink::mojom::AppBannerService> binding_; |
| 253 blink::mojom::AppBannerEventPtr event_; |
| 254 blink::mojom::AppBannerControllerPtr controller_; |
| 255 |
| 246 // Whether we are currently working on whether to show a banner. | 256 // Whether we are currently working on whether to show a banner. |
| 247 bool is_active_; | 257 bool is_active_; |
| 248 | 258 |
| 249 // If a banner is requested before the page has finished loading, defer | 259 // If a banner is requested before the page has finished loading, defer |
| 250 // triggering the pipeline until the load is complete. | 260 // triggering the pipeline until the load is complete. |
| 251 bool banner_request_queued_; | 261 bool banner_request_queued_; |
| 252 bool load_finished_; | 262 bool load_finished_; |
| 253 | 263 |
| 254 // Record whether the page decides to defer showing the banner, and if it | 264 // Record whether the page decides to defer showing the banner, and if it |
| 255 // requests for it to be shown later on. | 265 // requests for it to be shown later on. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 266 // scoped to the WebContents which they are observing. This allows us to use | 276 // scoped to the WebContents which they are observing. This allows us to use |
| 267 // weak pointers for callbacks. | 277 // weak pointers for callbacks. |
| 268 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 278 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 269 | 279 |
| 270 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 280 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 271 }; | 281 }; |
| 272 | 282 |
| 273 } // namespace banners | 283 } // namespace banners |
| 274 | 284 |
| 275 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 285 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |