| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // Requests an app banner. If |is_debug_mode| is true, any failure in the | 62 // Requests an app banner. If |is_debug_mode| is true, any failure in the |
| 63 // pipeline will be reported to the devtools console. | 63 // pipeline will be reported to the devtools console. |
| 64 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); | 64 virtual void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); |
| 65 | 65 |
| 66 // Informs the page that it has been installed via an app banner. | 66 // Informs the page that it has been installed via an app banner. |
| 67 // This is redundant for the beforeinstallprompt event's promise being | 67 // This is redundant for the beforeinstallprompt event's promise being |
| 68 // resolved, but is required by the install event spec. | 68 // resolved, but is required by the install event spec. |
| 69 void OnInstall(); | 69 void OnInstall(); |
| 70 | 70 |
| 71 // Sends a message to the renderer that the user accepted the banner. Does | 71 // Sends a message to the renderer that the user accepted the banner. |
| 72 // nothing if |request_id| does not match the current request. | 72 void SendBannerAccepted(); |
| 73 void SendBannerAccepted(int request_id); | |
| 74 | 73 |
| 75 // Sends a message to the renderer that the user dismissed the banner. Does | 74 // Sends a message to the renderer that the user dismissed the banner. |
| 76 // nothing if |request_id| does not match the current request. | 75 void SendBannerDismissed(); |
| 77 void SendBannerDismissed(int request_id); | |
| 78 | 76 |
| 79 // Returns a WeakPtr to this object. Exposed so subclasses/infobars may | 77 // Returns a WeakPtr to this object. Exposed so subclasses/infobars may |
| 80 // may bind callbacks without needing their own WeakPtrFactory. | 78 // may bind callbacks without needing their own WeakPtrFactory. |
| 81 base::WeakPtr<AppBannerManager> GetWeakPtr(); | 79 base::WeakPtr<AppBannerManager> GetWeakPtr(); |
| 82 | 80 |
| 83 // Overridden and passed through base::Bind on desktop platforms. Called when | 81 // Overridden and passed through base::Bind on desktop platforms. Called when |
| 84 // the bookmark app install initiated by a banner has completed. Not used on | 82 // the bookmark app install initiated by a banner has completed. Not used on |
| 85 // Android. | 83 // Android. |
| 86 virtual void DidFinishCreatingBookmarkApp( | 84 virtual void DidFinishCreatingBookmarkApp( |
| 87 const extensions::Extension* extension, | 85 const extensions::Extension* extension, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void WebContentsDestroyed() override; | 208 void WebContentsDestroyed() override; |
| 211 | 209 |
| 212 // SiteEngagementObserver overrides. | 210 // SiteEngagementObserver overrides. |
| 213 void OnEngagementIncreased(content::WebContents* web_contents, | 211 void OnEngagementIncreased(content::WebContents* web_contents, |
| 214 const GURL& url, | 212 const GURL& url, |
| 215 double score) override; | 213 double score) override; |
| 216 | 214 |
| 217 // Subclass accessors for private fields which should not be changed outside | 215 // Subclass accessors for private fields which should not be changed outside |
| 218 // this class. | 216 // this class. |
| 219 InstallableManager* manager() const { return manager_; } | 217 InstallableManager* manager() const { return manager_; } |
| 220 int event_request_id() const { return event_request_id_; } | |
| 221 bool is_active() const { return state_ == State::ACTIVE; } | 218 bool is_active() const { return state_ == State::ACTIVE; } |
| 222 bool is_active_or_pending() const { | 219 bool is_active_or_pending() const { |
| 223 switch (state_) { | 220 switch (state_) { |
| 224 case State::ACTIVE: | 221 case State::ACTIVE: |
| 225 case State::PENDING_MANIFEST: | 222 case State::PENDING_MANIFEST: |
| 226 case State::PENDING_INSTALLABLE_CHECK: | 223 case State::PENDING_INSTALLABLE_CHECK: |
| 227 case State::PENDING_ENGAGEMENT: | 224 case State::PENDING_ENGAGEMENT: |
| 228 case State::PENDING_EVENT: | 225 case State::PENDING_EVENT: |
| 229 return true; | 226 return true; |
| 230 case State::INACTIVE: | 227 case State::INACTIVE: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 259 // The referrer string (if any) specified in the app URL. Used only for native | 256 // The referrer string (if any) specified in the app URL. Used only for native |
| 260 // app banners. | 257 // app banners. |
| 261 std::string referrer_; | 258 std::string referrer_; |
| 262 | 259 |
| 263 // The current banner pipeline state for this page load. | 260 // The current banner pipeline state for this page load. |
| 264 State state_; | 261 State state_; |
| 265 | 262 |
| 266 private: | 263 private: |
| 267 friend class AppBannerManagerTest; | 264 friend class AppBannerManagerTest; |
| 268 | 265 |
| 266 // Voids all outstanding weak pointers and service pointers. |
| 267 void ResetBindings(); |
| 268 |
| 269 // Record that the banner could be shown at this point, if the triggering | 269 // Record that the banner could be shown at this point, if the triggering |
| 270 // heuristic allowed. | 270 // heuristic allowed. |
| 271 void RecordCouldShowBanner(); | 271 void RecordCouldShowBanner(); |
| 272 | 272 |
| 273 // Creates a banner for the app. Overridden by subclasses as the infobar is | 273 // Creates a banner for the app. Overridden by subclasses as the infobar is |
| 274 // platform-specific. | 274 // platform-specific. |
| 275 virtual void ShowBanner() = 0; | 275 virtual void ShowBanner() = 0; |
| 276 | 276 |
| 277 // Called after the manager sends a message to the renderer regarding its | 277 // Called after the manager sends a message to the renderer regarding its |
| 278 // intention to show a prompt. The renderer will send a message back with the | 278 // intention to show a prompt. The renderer will send a message back with the |
| 279 // opportunity to cancel. | 279 // opportunity to cancel. |
| 280 void OnBannerPromptReply(blink::mojom::AppBannerPromptReply reply, | 280 void OnBannerPromptReply(blink::mojom::AppBannerPromptReply reply, |
| 281 const std::string& referrer); | 281 const std::string& referrer); |
| 282 | 282 |
| 283 // blink::mojom::AppBannerService overrides. | 283 // blink::mojom::AppBannerService overrides. |
| 284 // Called when Blink has prevented a banner from being shown, and is now | 284 // Called when Blink has prevented a banner from being shown, and is now |
| 285 // requesting that it be shown later. | 285 // requesting that it be shown later. |
| 286 void DisplayAppBanner(bool user_gesture) override; | 286 void DisplayAppBanner(bool user_gesture) override; |
| 287 | 287 |
| 288 // Fetches the data required to display a banner for the current page. | 288 // Fetches the data required to display a banner for the current page. |
| 289 InstallableManager* manager_; | 289 InstallableManager* manager_; |
| 290 | 290 |
| 291 // A monotonically increasing id to verify the response to the | |
| 292 // beforeinstallprompt event from the renderer. | |
| 293 int event_request_id_; | |
| 294 | |
| 295 // We do not want to trigger a banner when the manager is attached to | 291 // We do not want to trigger a banner when the manager is attached to |
| 296 // a WebContents that is playing video. Banners triggering on a site in the | 292 // a WebContents that is playing video. Banners triggering on a site in the |
| 297 // background will appear when the tab is reactivated. | 293 // background will appear when the tab is reactivated. |
| 298 std::vector<MediaPlayerId> active_media_players_; | 294 std::vector<MediaPlayerId> active_media_players_; |
| 299 | 295 |
| 300 // Mojo bindings and interface pointers. | 296 // Mojo bindings and interface pointers. |
| 301 mojo::Binding<blink::mojom::AppBannerService> binding_; | 297 mojo::Binding<blink::mojom::AppBannerService> binding_; |
| 302 blink::mojom::AppBannerEventPtr event_; | 298 blink::mojom::AppBannerEventPtr event_; |
| 303 blink::mojom::AppBannerControllerPtr controller_; | 299 blink::mojom::AppBannerControllerPtr controller_; |
| 304 | 300 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 320 // scoped to the WebContents which they are observing. This allows us to use | 316 // scoped to the WebContents which they are observing. This allows us to use |
| 321 // weak pointers for callbacks. | 317 // weak pointers for callbacks. |
| 322 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 318 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 323 | 319 |
| 324 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 320 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 325 }; | 321 }; |
| 326 | 322 |
| 327 } // namespace banners | 323 } // namespace banners |
| 328 | 324 |
| 329 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 325 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |