Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: chrome/browser/banners/app_banner_manager.h

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Fix Win clang compile Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:
55 static void Create(content::WebContents* web_contents);
56 static AppBannerManager* Get(content::WebContents* web_contents);
57
58 static void BindToMojoRequest(content::RenderFrameHost* render_frame_host,
59 blink::mojom::AppBannerServiceRequest request);
60
53 static void DisableSecureSchemeCheckForTesting(); 61 static void DisableSecureSchemeCheckForTesting();
54 62
55 // Returns the current time. 63 // Returns the current time.
56 static base::Time GetCurrentTime(); 64 static base::Time GetCurrentTime();
57 65
58 // Fast-forwards the current time for testing. 66 // Fast-forwards the current time for testing.
59 static void SetTimeDeltaForTesting(int days); 67 static void SetTimeDeltaForTesting(int days);
60 68
61 // Sets the weights applied to direct and indirect navigations for triggering 69 // Sets the weights applied to direct and indirect navigations for triggering
62 // the banner. Deprecated and will be removed when app banners fully migrates 70 // the banner. Deprecated and will be removed when app banners fully migrates
63 // to using site engagement as a trigger. 71 // to using site engagement as a trigger.
64 static void SetEngagementWeights(double direct_engagement, 72 static void SetEngagementWeights(double direct_engagement,
65 double indirect_engagement); 73 double indirect_engagement);
66 74
67 // Returns whether or not the URLs match for everything except for the ref. 75 // Returns whether or not the URLs match for everything except for the ref.
68 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); 76 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second);
69 77
70 // Requests an app banner. If |is_debug_mode| is true, any failure in the 78 // Requests an app banner. If |is_debug_mode| is true, any failure in the
71 // pipeline will be reported to the devtools console. 79 // pipeline will be reported to the devtools console.
72 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); 80 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode);
73 81
74 // Overridden and passed through base::Bind on desktop platforms. Called when 82 // Sends a message to the renderer that the user accepted the banner. Does
83 // nothing if |request_id| does not match the current request.
84 void SendBannerAccepted(int request_id);
85
86 // Sends a message to the renderer that the user dismissed the banner. Does
87 // nothing if |request_id| does not match the current request.
88 void SendBannerDismissed(int request_id);
89
90 // Overridden and passed through base::Bind on desktop platforms. Called
91 // when
Sam McNally 2016/10/06 07:17:43 Reflow.
dominickn 2016/10/06 22:58:12 Done.
75 // the bookmark app install initiated by a banner has completed. Not used on 92 // the bookmark app install initiated by a banner has completed. Not used on
76 // Android. 93 // Android.
77 virtual void DidFinishCreatingBookmarkApp( 94 virtual void DidFinishCreatingBookmarkApp(
78 const extensions::Extension* extension, 95 const extensions::Extension* extension,
79 const WebApplicationInfo& web_app_info) { } 96 const WebApplicationInfo& web_app_info) {}
80 97
81 // Overridden and passed through base::Bind on Android. Called when the 98 // 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 99 // 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 100 // provided from the Play Store rather than the web manifest. Not used on
84 // desktop platforms. 101 // desktop platforms.
85 virtual void OnAppIconFetched(const SkBitmap& bitmap) { } 102 virtual void OnAppIconFetched(const SkBitmap& bitmap) {}
86 103
87 // Overridden and passed through base::Bind on Android. Called after a web app 104 // 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 105 // 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. 106 // asynchronous fetch of a splash screen icon. Not used on desktop platforms.
90 virtual base::Closure FetchWebappSplashScreenImageCallback( 107 virtual base::Closure FetchWebappSplashScreenImageCallback(
91 const std::string& webapp_id); 108 const std::string& webapp_id);
92 109
93 protected: 110 protected:
94 explicit AppBannerManager(content::WebContents* web_contents); 111 explicit AppBannerManager(content::WebContents* web_contents);
95 ~AppBannerManager() override; 112 ~AppBannerManager() override;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // The URL of the icon. 208 // The URL of the icon.
192 GURL icon_url_; 209 GURL icon_url_;
193 210
194 // The icon object. 211 // The icon object.
195 std::unique_ptr<SkBitmap> icon_; 212 std::unique_ptr<SkBitmap> icon_;
196 213
197 // The referrer string (if any) specified in the app URL. Used only for native 214 // The referrer string (if any) specified in the app URL. Used only for native
198 // app banners. 215 // app banners.
199 std::string referrer_; 216 std::string referrer_;
200 217
218 // The app banner client which we are communicating with.
219 blink::mojom::AppBannerClientPtr banner_client_;
220
201 private: 221 private:
202 friend class AppBannerManagerTest; 222 friend class AppBannerManagerTest;
203 223
204 // Record that the banner could be shown at this point, if the triggering 224 // Record that the banner could be shown at this point, if the triggering
205 // heuristic allowed. 225 // heuristic allowed.
206 void RecordCouldShowBanner(); 226 void RecordCouldShowBanner();
207 227
208 // Creates a banner for the app. Overridden by subclasses as the infobar is 228 // Creates a banner for the app. Overridden by subclasses as the infobar is
209 // platform-specific. 229 // platform-specific.
210 virtual void ShowBanner() = 0; 230 virtual void ShowBanner() = 0;
211 231
212 // Returns true if the banner should be shown. 232 // Returns true if the banner should be shown.
213 bool CheckIfShouldShowBanner(); 233 bool CheckIfShouldShowBanner();
214 234
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 235 // 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 236 // intention to show a prompt. The renderer will send a message back with the
220 // opportunity to cancel. 237 // opportunity to cancel.
221 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, 238 void OnBannerPromptReply(int request_id,
222 int request_id, 239 blink::mojom::AppBannerPromptReply reply,
223 blink::WebAppBannerPromptReply reply, 240 mojo::String referrer);
224 std::string referrer);
225 241
226 // Called when the client has prevented a banner from being shown, and is 242 // blink::mojom::AppBannerService overrides.
227 // now requesting that it be shown later. 243 // Called when the client has prevented a banner from being shown, and is now
228 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, 244 // requesting that it be shown later.
229 int request_id); 245 void DisplayAppBanner(int request_id) override;
246
247 // Sets the current beforeinstallprompt event.
248 void SetEvent(blink::mojom::AppBannerEventPtr event) override;
230 249
231 // The type of navigation made to the page 250 // The type of navigation made to the page
232 ui::PageTransition last_transition_type_; 251 ui::PageTransition last_transition_type_;
233 252
234 // Fetches the data required to display a banner for the current page. 253 // Fetches the data required to display a banner for the current page.
235 InstallableManager* manager_; 254 InstallableManager* manager_;
236 255
237 // A monotonically increasing id to verify the response to the 256 // A monotonically increasing id to verify the response to the
238 // beforeinstallprompt event from the renderer. 257 // beforeinstallprompt event from the renderer.
239 int event_request_id_; 258 int event_request_id_;
240 259
241 // We do not want to trigger a banner when the manager is attached to 260 // 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 261 // a WebContents that is playing video. Banners triggering on a site in the
243 // background will appear when the tab is reactivated. 262 // background will appear when the tab is reactivated.
244 std::vector<MediaPlayerId> active_media_players_; 263 std::vector<MediaPlayerId> active_media_players_;
245 264
265 std::unique_ptr<mojo::Binding<blink::mojom::AppBannerService>> binding_;
266
267 // A pointer to the current beforeinstallprompt event (if it exists).
268 std::unique_ptr<blink::mojom::AppBannerEventPtr> event_;
269
246 // Whether we are currently working on whether to show a banner. 270 // Whether we are currently working on whether to show a banner.
247 bool is_active_; 271 bool is_active_;
248 272
249 // If a banner is requested before the page has finished loading, defer 273 // If a banner is requested before the page has finished loading, defer
250 // triggering the pipeline until the load is complete. 274 // triggering the pipeline until the load is complete.
251 bool banner_request_queued_; 275 bool banner_request_queued_;
252 bool load_finished_; 276 bool load_finished_;
253 277
254 // Record whether the page decides to defer showing the banner, and if it 278 // Record whether the page decides to defer showing the banner, and if it
255 // requests for it to be shown later on. 279 // requests for it to be shown later on.
(...skipping 10 matching lines...) Expand all
266 // scoped to the WebContents which they are observing. This allows us to use 290 // scoped to the WebContents which they are observing. This allows us to use
267 // weak pointers for callbacks. 291 // weak pointers for callbacks.
268 base::WeakPtrFactory<AppBannerManager> weak_factory_; 292 base::WeakPtrFactory<AppBannerManager> weak_factory_;
269 293
270 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); 294 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
271 }; 295 };
272 296
273 } // namespace banners 297 } // namespace banners
274 298
275 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ 299 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698