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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 233 |
| 234 manifest_url_ = data.manifest_url; | 234 manifest_url_ = data.manifest_url; |
| 235 manifest_ = data.manifest; | 235 manifest_ = data.manifest; |
| 236 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() | 236 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() |
| 237 : manifest_.name.string(); | 237 : manifest_.name.string(); |
| 238 | 238 |
| 239 PerformInstallableCheck(); | 239 PerformInstallableCheck(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void AppBannerManager::PerformInstallableCheck() { | 242 void AppBannerManager::PerformInstallableCheck() { |
| 243 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), | 243 if (!CheckIfShouldShowBanner()) |
| 244 manifest_.start_url, manifest_url_) && | |
| 245 !IsDebugMode()) { | |
| 246 ReportStatus(web_contents(), ALREADY_INSTALLED); | |
| 247 Stop(); | |
| 248 } | |
| 249 | |
| 250 if (!is_active_) | |
| 251 return; | 244 return; |
| 252 | 245 |
| 253 // Fetch and verify the other required information. | 246 // Fetch and verify the other required information. |
| 254 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInPx(), | 247 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInPx(), |
| 255 GetMinimumIconSizeInPx()), | 248 GetMinimumIconSizeInPx()), |
| 256 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, | 249 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, |
| 257 GetWeakPtr())); | 250 GetWeakPtr())); |
| 258 } | 251 } |
| 259 | 252 |
| 260 void AppBannerManager::OnDidPerformInstallableCheck( | 253 void AppBannerManager::OnDidPerformInstallableCheck( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 was_canceled_by_page_ = false; | 324 was_canceled_by_page_ = false; |
| 332 page_requested_prompt_ = false; | 325 page_requested_prompt_ = false; |
| 333 need_to_log_status_ = false; | 326 need_to_log_status_ = false; |
| 334 validated_url_ = GURL(); | 327 validated_url_ = GURL(); |
| 335 referrer_.erase(); | 328 referrer_.erase(); |
| 336 } | 329 } |
| 337 | 330 |
| 338 void AppBannerManager::SendBannerPromptRequest() { | 331 void AppBannerManager::SendBannerPromptRequest() { |
| 339 RecordCouldShowBanner(); | 332 RecordCouldShowBanner(); |
| 340 | 333 |
| 341 // Given all of the other checks that have been made, the only possible reason | |
| 342 // for stopping now is that the app has been added to the homescreen. | |
| 343 if (!IsDebugMode() && !CheckIfShouldShowBanner()) { | |
| 344 Stop(); | |
| 345 return; | |
| 346 } | |
| 347 | |
| 348 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 334 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 349 event_request_id_ = ++gCurrentRequestID; | 335 event_request_id_ = ++gCurrentRequestID; |
| 350 | 336 |
| 351 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 337 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 352 mojo::MakeRequest(&controller_)); | 338 mojo::MakeRequest(&controller_)); |
| 353 | 339 |
| 354 controller_->BannerPromptRequest( | 340 controller_->BannerPromptRequest( |
| 355 binding_.CreateInterfacePtrAndBind(), mojo::MakeRequest(&event_), | 341 binding_.CreateInterfacePtrAndBind(), mojo::MakeRequest(&event_), |
| 356 {GetBannerType()}, | 342 {GetBannerType()}, |
| 357 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); | 343 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 void AppBannerManager::RecordCouldShowBanner() { | 429 void AppBannerManager::RecordCouldShowBanner() { |
| 444 content::WebContents* contents = web_contents(); | 430 content::WebContents* contents = web_contents(); |
| 445 DCHECK(contents); | 431 DCHECK(contents); |
| 446 | 432 |
| 447 AppBannerSettingsHelper::RecordBannerEvent( | 433 AppBannerSettingsHelper::RecordBannerEvent( |
| 448 contents, validated_url_, GetAppIdentifier(), | 434 contents, validated_url_, GetAppIdentifier(), |
| 449 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); | 435 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); |
| 450 } | 436 } |
| 451 | 437 |
| 452 bool AppBannerManager::CheckIfShouldShowBanner() { | 438 bool AppBannerManager::CheckIfShouldShowBanner() { |
| 439 if (IsDebugMode()) | |
| 440 return true; | |
| 441 | |
| 442 // Check whether we are permitted to show the banner. If we have already | |
| 443 // added this site to homescreen, or if the banner has been shown too | |
| 444 // recently, prevent the banner from being shown. | |
| 453 content::WebContents* contents = web_contents(); | 445 content::WebContents* contents = web_contents(); |
| 454 DCHECK(contents); | |
| 455 | |
| 456 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( | 446 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( |
| 457 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 447 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 458 if (code == NO_ERROR_DETECTED) | |
| 459 return true; | |
| 460 | 448 |
| 461 switch (code) { | 449 if (code == NO_ERROR_DETECTED && |
| 462 case ALREADY_INSTALLED: | 450 IsWebAppInstalled(contents->GetBrowserContext(), manifest_.start_url, |
| 463 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); | 451 manifest_url_)) { |
| 464 break; | 452 code = ALREADY_INSTALLED; |
| 465 case PREVIOUSLY_BLOCKED: | |
| 466 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | |
| 467 break; | |
| 468 case PREVIOUSLY_IGNORED: | |
| 469 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | |
| 470 break; | |
| 471 case INSUFFICIENT_ENGAGEMENT: | |
|
dominickn
2017/01/10 22:51:59
ShouldShowBanner() will never return INSUFFICIENT_
| |
| 472 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); | |
| 473 break; | |
| 474 default: | |
| 475 break; | |
| 476 } | 453 } |
| 477 | 454 |
| 478 // If we are in debug mode, AppBannerSettingsHelper::ShouldShowBanner must | 455 if (code != NO_ERROR_DETECTED) { |
| 479 // return NO_ERROR_DETECTED (bypass flag is set) or we must not have entered | 456 switch (code) { |
| 480 // this method. | 457 case ALREADY_INSTALLED: |
| 481 DCHECK(!IsDebugMode()); | 458 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); |
| 482 ReportStatus(web_contents(), code); | 459 break; |
| 483 return false; | 460 case PREVIOUSLY_BLOCKED: |
| 461 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | |
| 462 break; | |
| 463 case PREVIOUSLY_IGNORED: | |
| 464 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | |
| 465 break; | |
|
benwells
2017/01/13 06:04:27
Could this break be NOTREACHED()?
dominickn
2017/01/13 06:11:20
Done.
| |
| 466 default: | |
| 467 break; | |
| 468 } | |
| 469 ReportStatus(contents, code); | |
| 470 Stop(); | |
| 471 return false; | |
| 472 } | |
| 473 return true; | |
| 484 } | 474 } |
| 485 | 475 |
| 486 void AppBannerManager::OnBannerPromptReply( | 476 void AppBannerManager::OnBannerPromptReply( |
| 487 blink::mojom::AppBannerPromptReply reply, | 477 blink::mojom::AppBannerPromptReply reply, |
| 488 const std::string& referrer) { | 478 const std::string& referrer) { |
| 489 // We don't need the controller any more, so reset it so the Blink-side object | 479 // We don't need the controller any more, so reset it so the Blink-side object |
| 490 // is destroyed. | 480 // is destroyed. |
| 491 controller_.reset(); | 481 controller_.reset(); |
| 492 content::WebContents* contents = web_contents(); | 482 content::WebContents* contents = web_contents(); |
| 493 | 483 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 526 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 537 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 527 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 538 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 528 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 539 } else { | 529 } else { |
| 540 // Log that the prompt request was made for when we get the prompt reply. | 530 // Log that the prompt request was made for when we get the prompt reply. |
| 541 page_requested_prompt_ = true; | 531 page_requested_prompt_ = true; |
| 542 } | 532 } |
| 543 } | 533 } |
| 544 | 534 |
| 545 } // namespace banners | 535 } // namespace banners |
| OLD | NEW |