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 #include "chrome/browser/banners/app_banner_manager.h" | 5 #include "chrome/browser/banners/app_banner_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 void AppBannerManager::SetTotalEngagementToTrigger(double engagement) { | 56 void AppBannerManager::SetTotalEngagementToTrigger(double engagement) { |
| 57 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); | 57 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void AppBannerManager::RequestAppBanner(const GURL& validated_url, | 60 void AppBannerManager::RequestAppBanner(const GURL& validated_url, |
| 61 bool is_debug_mode) { | 61 bool is_debug_mode) { |
| 62 content::WebContents* contents = web_contents(); | 62 content::WebContents* contents = web_contents(); |
| 63 | 63 |
| 64 // The only time we should start the pipeline while it is already running is | 64 // The only time we should start the pipeline while it is already running is |
| 65 // if it's been triggered from devtools. | 65 // if it's been triggered from devtools. |
| 66 if (is_active_or_pending()) { | 66 if (state_ != State::INACTIVE) { |
| 67 DCHECK(is_debug_mode); | 67 DCHECK(is_debug_mode); |
| 68 weak_factory_.InvalidateWeakPtrs(); | 68 weak_factory_.InvalidateWeakPtrs(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 UpdateState(State::ACTIVE); | 71 UpdateState(State::ACTIVE); |
| 72 triggered_by_devtools_ = is_debug_mode; | 72 triggered_by_devtools_ = is_debug_mode; |
| 73 page_requested_prompt_ = false; | |
| 74 | 73 |
| 75 // We only need to call ReportStatus if we aren't in debug mode (this avoids | 74 // We only need to call ReportStatus if we aren't in debug mode (this avoids |
| 76 // skew from testing). | 75 // skew from testing). |
| 77 DCHECK(!need_to_log_status_); | 76 DCHECK(!need_to_log_status_); |
| 78 need_to_log_status_ = !IsDebugMode(); | 77 need_to_log_status_ = !IsDebugMode(); |
| 79 | 78 |
| 80 // Exit if this is an incognito window, non-main frame, or insecure context. | 79 // Exit if this is an incognito window, non-main frame, or insecure context. |
| 81 InstallableStatusCode code = NO_ERROR_DETECTED; | 80 InstallableStatusCode code = NO_ERROR_DETECTED; |
| 82 if (Profile::FromBrowserContext(contents->GetBrowserContext()) | 81 if (Profile::FromBrowserContext(contents->GetBrowserContext()) |
| 83 ->IsOffTheRecord()) { | 82 ->IsOffTheRecord()) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 94 return; | 93 return; |
| 95 } | 94 } |
| 96 | 95 |
| 97 if (validated_url_.is_empty()) | 96 if (validated_url_.is_empty()) |
| 98 validated_url_ = validated_url; | 97 validated_url_ = validated_url; |
| 99 | 98 |
| 100 // Any existing binding is invalid when we request a new banner. | 99 // Any existing binding is invalid when we request a new banner. |
| 101 if (binding_.is_bound()) | 100 if (binding_.is_bound()) |
| 102 binding_.Close(); | 101 binding_.Close(); |
| 103 | 102 |
| 104 UpdateState(State::PENDING_MANIFEST); | 103 UpdateState(State::FETCHING_MANIFEST); |
| 105 manager_->GetData( | 104 manager_->GetData( |
| 106 ParamsToGetManifest(), | 105 ParamsToGetManifest(), |
| 107 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); | 106 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void AppBannerManager::OnInstall() { | 109 void AppBannerManager::OnInstall() { |
| 111 blink::mojom::InstallationServicePtr installation_service; | 110 blink::mojom::InstallationServicePtr installation_service; |
| 112 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 111 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 113 mojo::MakeRequest(&installation_service)); | 112 mojo::MakeRequest(&installation_service)); |
| 114 DCHECK(installation_service); | 113 DCHECK(installation_service); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 138 AppBannerManager::AppBannerManager(content::WebContents* web_contents) | 137 AppBannerManager::AppBannerManager(content::WebContents* web_contents) |
| 139 : content::WebContentsObserver(web_contents), | 138 : content::WebContentsObserver(web_contents), |
| 140 SiteEngagementObserver(SiteEngagementService::Get( | 139 SiteEngagementObserver(SiteEngagementService::Get( |
| 141 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), | 140 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), |
| 142 state_(State::INACTIVE), | 141 state_(State::INACTIVE), |
| 143 manager_(nullptr), | 142 manager_(nullptr), |
| 144 event_request_id_(-1), | 143 event_request_id_(-1), |
| 145 binding_(this), | 144 binding_(this), |
| 146 has_sufficient_engagement_(false), | 145 has_sufficient_engagement_(false), |
| 147 load_finished_(false), | 146 load_finished_(false), |
| 148 page_requested_prompt_(false), | |
| 149 triggered_by_devtools_(false), | 147 triggered_by_devtools_(false), |
| 150 need_to_log_status_(false), | 148 need_to_log_status_(false), |
| 151 weak_factory_(this) { | 149 weak_factory_(this) { |
| 152 // Ensure the InstallableManager exists since we have a hard dependency on it. | 150 // Ensure the InstallableManager exists since we have a hard dependency on it. |
| 153 InstallableManager::CreateForWebContents(web_contents); | 151 InstallableManager::CreateForWebContents(web_contents); |
| 154 manager_ = InstallableManager::FromWebContents(web_contents); | 152 manager_ = InstallableManager::FromWebContents(web_contents); |
| 155 DCHECK(manager_); | 153 DCHECK(manager_); |
| 156 | 154 |
| 157 AppBannerSettingsHelper::UpdateFromFieldTrial(); | 155 AppBannerSettingsHelper::UpdateFromFieldTrial(); |
| 158 } | 156 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 manifest_ = content::Manifest(); | 307 manifest_ = content::Manifest(); |
| 310 manifest_url_ = GURL(); | 308 manifest_url_ = GURL(); |
| 311 validated_url_ = GURL(); | 309 validated_url_ = GURL(); |
| 312 referrer_.erase(); | 310 referrer_.erase(); |
| 313 } | 311 } |
| 314 | 312 |
| 315 void AppBannerManager::Stop() { | 313 void AppBannerManager::Stop() { |
| 316 // Record the status if we are currently waiting for data. | 314 // Record the status if we are currently waiting for data. |
| 317 InstallableStatusCode code = NO_ERROR_DETECTED; | 315 InstallableStatusCode code = NO_ERROR_DETECTED; |
| 318 switch (state_) { | 316 switch (state_) { |
| 319 case State::PENDING_EVENT: | 317 case State::PENDING_PROMPT: |
| 320 if (!page_requested_prompt_) { | 318 TrackBeforeInstallEvent( |
| 321 TrackBeforeInstallEvent( | 319 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| 322 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 320 code = RENDERER_CANCELLED; |
| 323 code = RENDERER_CANCELLED; | |
| 324 } | |
| 325 break; | 321 break; |
| 326 case State::PENDING_ENGAGEMENT: | 322 case State::PENDING_ENGAGEMENT: |
| 327 if (!has_sufficient_engagement_) { | 323 if (!has_sufficient_engagement_) { |
| 328 TrackDisplayEvent(DISPLAY_EVENT_NOT_VISITED_ENOUGH); | 324 TrackDisplayEvent(DISPLAY_EVENT_NOT_VISITED_ENOUGH); |
| 329 code = INSUFFICIENT_ENGAGEMENT; | 325 code = INSUFFICIENT_ENGAGEMENT; |
| 330 } | 326 } |
| 331 break; | 327 break; |
| 332 case State::PENDING_MANIFEST: | 328 case State::FETCHING_MANIFEST: |
| 333 code = WAITING_FOR_MANIFEST; | 329 code = WAITING_FOR_MANIFEST; |
| 334 break; | 330 break; |
| 335 case State::PENDING_INSTALLABLE_CHECK: | 331 case State::PENDING_INSTALLABLE_CHECK: |
| 336 code = WAITING_FOR_INSTALLABLE_CHECK; | 332 code = WAITING_FOR_INSTALLABLE_CHECK; |
| 337 break; | 333 break; |
| 338 case State::ACTIVE: | 334 case State::ACTIVE: |
| 335 case State::SENDING_EVENT: | |
| 336 case State::SENDING_EVENT_GOT_EARLY_PROMPT: | |
| 339 case State::INACTIVE: | 337 case State::INACTIVE: |
| 340 case State::COMPLETE: | 338 case State::COMPLETE: |
| 341 break; | 339 break; |
| 342 } | 340 } |
| 343 | 341 |
| 344 if (code != NO_ERROR_DETECTED) | 342 if (code != NO_ERROR_DETECTED) |
| 345 ReportStatus(web_contents(), code); | 343 ReportStatus(web_contents(), code); |
| 346 | 344 |
| 347 // In every non-debug run through the banner pipeline, we should have called | 345 // In every non-debug run through the banner pipeline, we should have called |
| 348 // ReportStatus() and set need_to_log_status_ to false. The only case where | 346 // ReportStatus() and set need_to_log_status_ to false. The only case where |
| 349 // we don't is if we're still active and waiting for native app data, which is | 347 // we don't is if we're still active and waiting for native app data, which is |
| 350 // explicitly not logged. | 348 // explicitly not logged. |
| 351 DCHECK(!need_to_log_status_ || is_active()); | 349 DCHECK(!need_to_log_status_ || is_active()); |
| 352 | 350 |
| 353 weak_factory_.InvalidateWeakPtrs(); | 351 weak_factory_.InvalidateWeakPtrs(); |
| 354 binding_.Close(); | 352 binding_.Close(); |
| 355 controller_.reset(); | 353 controller_.reset(); |
| 356 event_.reset(); | 354 event_.reset(); |
| 357 | 355 |
| 358 UpdateState(State::COMPLETE); | 356 UpdateState(State::COMPLETE); |
| 359 need_to_log_status_ = false; | 357 need_to_log_status_ = false; |
| 360 has_sufficient_engagement_ = false; | 358 has_sufficient_engagement_ = false; |
| 361 } | 359 } |
| 362 | 360 |
| 363 void AppBannerManager::SendBannerPromptRequest() { | 361 void AppBannerManager::SendBannerPromptRequest() { |
| 364 RecordCouldShowBanner(); | 362 RecordCouldShowBanner(); |
| 365 | 363 |
| 364 UpdateState(State::SENDING_EVENT); | |
| 366 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 365 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 367 event_request_id_ = ++gCurrentRequestID; | 366 event_request_id_ = ++gCurrentRequestID; |
| 368 | 367 |
| 369 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 368 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 370 mojo::MakeRequest(&controller_)); | 369 mojo::MakeRequest(&controller_)); |
| 371 | 370 |
| 372 blink::mojom::AppBannerServicePtr banner_proxy; | 371 blink::mojom::AppBannerServicePtr banner_proxy; |
| 373 binding_.Bind(mojo::MakeRequest(&banner_proxy)); | 372 binding_.Bind(mojo::MakeRequest(&banner_proxy)); |
| 374 controller_->BannerPromptRequest( | 373 controller_->BannerPromptRequest( |
| 375 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, | 374 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, |
| 376 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); | 375 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); |
| 377 } | 376 } |
| 378 | 377 |
| 379 void AppBannerManager::UpdateState(State state) { | 378 void AppBannerManager::UpdateState(State state) { |
| 380 state_ = state; | 379 state_ = state; |
| 381 | |
| 382 // If we are PENDING_EVENT, we must have sufficient engagement. | |
| 383 DCHECK(!is_pending_event() || has_sufficient_engagement_); | |
|
benwells
2017/06/27 22:55:58
We could put this back in, but it seems like there
| |
| 384 } | 380 } |
| 385 | 381 |
| 386 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { | 382 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { |
| 387 if (!handle->IsInMainFrame() || handle->IsSameDocument()) | 383 if (!handle->IsInMainFrame() || handle->IsSameDocument()) |
| 388 return; | 384 return; |
| 389 | 385 |
| 390 if (is_active_or_pending()) | 386 if (state_ != State::COMPLETE && state_ != State::INACTIVE) |
| 391 Stop(); | 387 Stop(); |
| 392 UpdateState(State::INACTIVE); | 388 UpdateState(State::INACTIVE); |
| 393 load_finished_ = false; | 389 load_finished_ = false; |
| 394 has_sufficient_engagement_ = false; | 390 has_sufficient_engagement_ = false; |
| 395 page_requested_prompt_ = false; | |
| 396 } | 391 } |
| 397 | 392 |
| 398 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { | 393 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { |
| 399 if (handle->IsInMainFrame() && handle->HasCommitted() && | 394 if (handle->IsInMainFrame() && handle->HasCommitted() && |
| 400 !handle->IsSameDocument()) { | 395 !handle->IsSameDocument()) { |
| 401 ResetCurrentPageData(); | 396 ResetCurrentPageData(); |
| 402 } | 397 } |
| 403 } | 398 } |
| 404 | 399 |
| 405 void AppBannerManager::DidFinishLoad( | 400 void AppBannerManager::DidFinishLoad( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 418 // Additionally, if the page already has enough engagement, trigger the | 413 // Additionally, if the page already has enough engagement, trigger the |
| 419 // pipeline immediately. | 414 // pipeline immediately. |
| 420 if (AppBannerSettingsHelper::HasSufficientEngagement(0) || | 415 if (AppBannerSettingsHelper::HasSufficientEngagement(0) || |
| 421 AppBannerSettingsHelper::HasSufficientEngagement( | 416 AppBannerSettingsHelper::HasSufficientEngagement( |
| 422 GetSiteEngagementService()->GetScore(validated_url))) { | 417 GetSiteEngagementService()->GetScore(validated_url))) { |
| 423 has_sufficient_engagement_ = true; | 418 has_sufficient_engagement_ = true; |
| 424 } | 419 } |
| 425 | 420 |
| 426 // Start the pipeline immediately if we pass (or bypass) the engagement check, | 421 // Start the pipeline immediately if we pass (or bypass) the engagement check, |
| 427 // or if the feature to run the installability check on page load is enabled. | 422 // or if the feature to run the installability check on page load is enabled. |
| 428 if (!is_active_or_pending() && | 423 if (state_ == State::INACTIVE && |
| 429 (has_sufficient_engagement_ || | 424 (has_sufficient_engagement_ || |
| 430 base::FeatureList::IsEnabled( | 425 base::FeatureList::IsEnabled( |
| 431 features::kCheckInstallabilityForBannerOnLoad))) { | 426 features::kCheckInstallabilityForBannerOnLoad))) { |
| 432 RequestAppBanner(validated_url, false /* is_debug_mode */); | 427 RequestAppBanner(validated_url, false /* is_debug_mode */); |
| 433 } | 428 } |
| 434 } | 429 } |
| 435 | 430 |
| 436 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info, | 431 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info, |
| 437 const MediaPlayerId& id) { | 432 const MediaPlayerId& id) { |
| 438 active_media_players_.push_back(id); | 433 active_media_players_.push_back(id); |
| 439 } | 434 } |
| 440 | 435 |
| 441 void AppBannerManager::MediaStoppedPlaying(const MediaPlayerInfo& media_info, | 436 void AppBannerManager::MediaStoppedPlaying(const MediaPlayerInfo& media_info, |
| 442 const MediaPlayerId& id) { | 437 const MediaPlayerId& id) { |
| 443 active_media_players_.erase(std::remove(active_media_players_.begin(), | 438 active_media_players_.erase(std::remove(active_media_players_.begin(), |
| 444 active_media_players_.end(), id), | 439 active_media_players_.end(), id), |
| 445 active_media_players_.end()); | 440 active_media_players_.end()); |
| 446 } | 441 } |
| 447 | 442 |
| 448 void AppBannerManager::WebContentsDestroyed() { | 443 void AppBannerManager::WebContentsDestroyed() { |
| 449 Stop(); | 444 Stop(); |
| 450 } | 445 } |
| 451 | 446 |
| 452 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, | 447 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, |
| 453 const GURL& url, | 448 const GURL& url, |
| 454 double score) { | 449 double score) { |
| 455 // In the ACTIVE state, we may have triggered the installability check, but | |
| 456 // not checked engagement yet. In the INACTIVE or PENDING_ENGAGEMENT states, | |
| 457 // we are waiting for an engagement signal to trigger the pipeline. | |
| 458 if (is_complete() || is_pending_event()) | |
| 459 return; | |
| 460 | |
|
benwells
2017/06/27 22:55:58
I think this is unnecessary due to the logic in th
| |
| 461 // Only trigger a banner using site engagement if: | 450 // Only trigger a banner using site engagement if: |
| 462 // 1. engagement increased for the web contents which we are attached to; and | 451 // 1. engagement increased for the web contents which we are attached to; and |
| 463 // 2. there are no currently active media players; and | 452 // 2. there are no currently active media players; and |
| 464 // 3. we have accumulated sufficient engagement. | 453 // 3. we have accumulated sufficient engagement. |
| 465 if (web_contents() == contents && active_media_players_.empty() && | 454 if (web_contents() == contents && active_media_players_.empty() && |
| 466 AppBannerSettingsHelper::HasSufficientEngagement(score)) { | 455 AppBannerSettingsHelper::HasSufficientEngagement(score)) { |
| 467 has_sufficient_engagement_ = true; | 456 has_sufficient_engagement_ = true; |
| 468 | 457 |
| 469 if (is_pending_engagement()) { | 458 if (is_pending_engagement()) { |
| 470 // We have already finished the installability eligibility checks. Proceed | 459 // We have already finished the installability eligibility checks. Proceed |
| 471 // directly to sending the banner prompt request. | 460 // directly to sending the banner prompt request. |
| 472 UpdateState(State::ACTIVE); | 461 UpdateState(State::ACTIVE); |
| 473 SendBannerPromptRequest(); | 462 SendBannerPromptRequest(); |
| 474 } else if (load_finished_ && !is_active_or_pending()) { | 463 } else if (load_finished_ && state_ == State::INACTIVE) { |
| 475 // This performs some simple tests and starts async checks to test | 464 // This performs some simple tests and starts async checks to test |
| 476 // installability. It should be safe to start in response to user input. | 465 // installability. It should be safe to start in response to user input. |
| 477 // Don't call if we're already working on processing a banner request. | 466 // Don't call if we're already working on processing a banner request. |
| 478 RequestAppBanner(url, false /* is_debug_mode */); | 467 RequestAppBanner(url, false /* is_debug_mode */); |
| 479 } | 468 } |
| 480 } | 469 } |
| 481 } | 470 } |
| 482 | 471 |
| 483 void AppBannerManager::RecordCouldShowBanner() { | 472 void AppBannerManager::RecordCouldShowBanner() { |
| 484 content::WebContents* contents = web_contents(); | 473 content::WebContents* contents = web_contents(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 // We don't need the controller any more, so reset it so the Blink-side object | 524 // We don't need the controller any more, so reset it so the Blink-side object |
| 536 // is destroyed. | 525 // is destroyed. |
| 537 controller_.reset(); | 526 controller_.reset(); |
| 538 content::WebContents* contents = web_contents(); | 527 content::WebContents* contents = web_contents(); |
| 539 | 528 |
| 540 // The renderer might have requested the prompt to be canceled. They may | 529 // The renderer might have requested the prompt to be canceled. They may |
| 541 // request that it is redisplayed later, so don't Stop() here. However, log | 530 // request that it is redisplayed later, so don't Stop() here. However, log |
| 542 // that the cancelation was requested, so Stop() can be called if a redisplay | 531 // that the cancelation was requested, so Stop() can be called if a redisplay |
| 543 // isn't asked for. | 532 // isn't asked for. |
| 544 // | 533 // |
| 545 // We use the additional page_requested_prompt_ variable because the redisplay | 534 // If the redisplay request has not been received already, we stop here and |
| 546 // request may be received *before* the Cancel prompt reply (e.g. if redisplay | 535 // wait for the prompt function to be called. If the redisplay request has |
| 547 // is requested in the beforeinstallprompt event handler). | 536 // already been received before cancel was sent (e.g. if redisplay was |
| 537 // requested in the beforeinstallprompt event handle), we keep going and show | |
| 538 // the banner immediately. | |
| 548 referrer_ = referrer; | 539 referrer_ = referrer; |
| 549 if (reply == blink::mojom::AppBannerPromptReply::CANCEL) { | 540 if (reply == blink::mojom::AppBannerPromptReply::CANCEL) { |
| 550 UpdateState(State::PENDING_EVENT); | |
| 551 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); | 541 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); |
| 552 if (!page_requested_prompt_) | 542 if (state_ == State::SENDING_EVENT) { |
| 543 UpdateState(State::PENDING_PROMPT); | |
| 553 return; | 544 return; |
| 545 } | |
| 546 DCHECK(state_ == State::SENDING_EVENT_GOT_EARLY_PROMPT); | |
| 554 } | 547 } |
| 555 | 548 |
| 556 // If we haven't yet returned, but we're in the PENDING_EVENT state or | 549 // If we are still in the SENDING_EVENT state, the prompt was never canceled |
| 557 // |page_requested_prompt_| is true, the page has requested a delayed showing | 550 // by the page. Otherwise the page requested a delayed showing of the prompt. |
| 558 // of the prompt. Otherwise, the prompt was never canceled by the page. | 551 if (state_ == State::SENDING_EVENT) { |
| 559 if (is_pending_event()) { | 552 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); |
| 553 } else { | |
| 560 TrackBeforeInstallEvent( | 554 TrackBeforeInstallEvent( |
| 561 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); | 555 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); |
| 562 UpdateState(State::ACTIVE); | |
|
benwells
2017/06/27 22:55:58
I think going to ACTIVE here isn't needed, as we g
| |
| 563 } else { | |
| 564 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); | |
| 565 } | 556 } |
| 566 | 557 |
| 567 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( | 558 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( |
| 568 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 559 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 569 | 560 |
| 570 DCHECK(!manifest_url_.is_empty()); | 561 DCHECK(!manifest_url_.is_empty()); |
| 571 DCHECK(!manifest_.IsEmpty()); | 562 DCHECK(!manifest_.IsEmpty()); |
| 572 DCHECK(!primary_icon_url_.is_empty()); | 563 DCHECK(!primary_icon_url_.is_empty()); |
| 573 DCHECK(!primary_icon_.drawsNothing()); | 564 DCHECK(!primary_icon_.drawsNothing()); |
| 574 | 565 |
| 575 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); | 566 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); |
| 576 ShowBanner(); | 567 ShowBanner(); |
| 577 UpdateState(State::COMPLETE); | 568 UpdateState(State::COMPLETE); |
| 578 } | 569 } |
| 579 | 570 |
| 580 void AppBannerManager::DisplayAppBanner(bool user_gesture) { | 571 void AppBannerManager::DisplayAppBanner(bool user_gesture) { |
| 581 if (is_pending_event()) { | 572 if (state_ == State::PENDING_PROMPT) { |
| 582 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 573 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 583 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 574 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 584 } else { | 575 } else if (state_ == State::SENDING_EVENT) { |
| 585 // Log that the prompt request was made for when we get the prompt reply. | 576 UpdateState(State::SENDING_EVENT_GOT_EARLY_PROMPT); |
| 586 page_requested_prompt_ = true; | |
| 587 } | 577 } |
| 588 } | 578 } |
| 589 | 579 |
| 590 } // namespace banners | 580 } // namespace banners |
| OLD | NEW |