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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() | 210 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() |
211 : manifest_.name.string(); | 211 : manifest_.name.string(); |
212 | 212 |
213 PerformInstallableCheck(); | 213 PerformInstallableCheck(); |
214 } | 214 } |
215 | 215 |
216 void AppBannerManager::PerformInstallableCheck() { | 216 void AppBannerManager::PerformInstallableCheck() { |
217 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), | 217 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), |
218 manifest_.start_url) && | 218 manifest_.start_url) && |
219 !IsDebugMode()) { | 219 !IsDebugMode()) { |
220 TrackInstallableErrorCode(ALREADY_INSTALLED); | |
220 Stop(); | 221 Stop(); |
221 } | 222 } |
222 | 223 |
223 if (!is_active_) | 224 if (!is_active_) |
224 return; | 225 return; |
225 | 226 |
226 // Fetch and verify the other required information. | 227 // Fetch and verify the other required information. |
227 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInDp(), | 228 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInDp(), |
228 GetMinimumIconSizeInDp()), | 229 GetMinimumIconSizeInDp()), |
229 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, | 230 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 GetCurrentTime()); | 267 GetCurrentTime()); |
267 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 268 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
268 event_name, | 269 event_name, |
269 contents->GetLastCommittedURL()); | 270 contents->GetLastCommittedURL()); |
270 } | 271 } |
271 | 272 |
272 void AppBannerManager::ReportError(content::WebContents* web_contents, | 273 void AppBannerManager::ReportError(content::WebContents* web_contents, |
273 InstallableErrorCode code) { | 274 InstallableErrorCode code) { |
274 if (IsDebugMode()) | 275 if (IsDebugMode()) |
275 LogErrorToConsole(web_contents, code, GetErrorParam(code)); | 276 LogErrorToConsole(web_contents, code, GetErrorParam(code)); |
277 else | |
278 TrackInstallableErrorCode(code); | |
276 } | 279 } |
277 | 280 |
278 void AppBannerManager::Stop() { | 281 void AppBannerManager::Stop() { |
279 if (was_canceled_by_page_ && !page_requested_prompt_) { | 282 if (was_canceled_by_page_ && !page_requested_prompt_) { |
280 TrackBeforeInstallEvent( | 283 TrackBeforeInstallEvent( |
281 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 284 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
285 ReportError(web_contents(), RENDERER_CANCELLED); | |
282 } | 286 } |
283 | 287 |
284 is_active_ = false; | 288 is_active_ = false; |
285 was_canceled_by_page_ = false; | 289 was_canceled_by_page_ = false; |
286 page_requested_prompt_ = false; | 290 page_requested_prompt_ = false; |
287 referrer_.erase(); | 291 referrer_.erase(); |
288 } | 292 } |
289 | 293 |
290 void AppBannerManager::SendBannerPromptRequest() { | 294 void AppBannerManager::SendBannerPromptRequest() { |
291 RecordCouldShowBanner(); | 295 RecordCouldShowBanner(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 Stop(); | 364 Stop(); |
361 } | 365 } |
362 | 366 |
363 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, | 367 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, |
364 const GURL& url, | 368 const GURL& url, |
365 double score) { | 369 double score) { |
366 // Only trigger a banner using site engagement if: | 370 // Only trigger a banner using site engagement if: |
367 // 1. engagement increased for the web contents which we are attached to; and | 371 // 1. engagement increased for the web contents which we are attached to; and |
368 // 2. there are no currently active media players; and | 372 // 2. there are no currently active media players; and |
369 // 3. we have accumulated sufficient engagement. | 373 // 3. we have accumulated sufficient engagement. |
370 if (web_contents() == contents && active_media_players_.empty() && | 374 if (web_contents() == contents && active_media_players_.empty()) { |
371 AppBannerSettingsHelper::HasSufficientEngagement(score)) { | 375 if (AppBannerSettingsHelper::HasSufficientEngagement(score)) { |
372 // Stop observing so we don't double-trigger the banner. | 376 // Stop observing so we don't double-trigger the banner. |
373 SiteEngagementObserver::Observe(nullptr); | 377 SiteEngagementObserver::Observe(nullptr); |
374 | 378 |
375 if (!load_finished_) { | 379 if (!load_finished_) { |
376 // Wait until the main frame finishes loading before requesting a banner. | 380 // Queue the banner request until the main frame finishes loading. |
377 banner_request_queued_ = true; | 381 banner_request_queued_ = true; |
382 } else { | |
383 // A banner request performs some simple tests, creates a data fetcher, | |
384 // and starts some asynchronous checks to test installability. It should | |
385 // be safe to start this in response to user input. | |
386 RequestAppBanner(url, false /* is_debug_mode */); | |
387 } | |
378 } else { | 388 } else { |
379 // Requesting a banner performs some simple tests, creates a data fetcher, | 389 // If IsDebugMode() returns true, we must have taken the other branch, so |
380 // and starts some asynchronous checks to test installability. It should | 390 // there is no need to recheck it here to avoid skew. |
gone
2016/08/10 21:02:51
Seems like something that should be DCHECKED, as w
dominickn
2016/08/11 07:00:19
Done.
| |
381 // be safe to start this in response to user input. | 391 TrackInstallableErrorCode(INSUFFICIENT_ENGAGEMENT); |
382 RequestAppBanner(url, false /* is_debug_mode */); | |
383 } | 392 } |
384 } | 393 } |
385 } | 394 } |
386 | 395 |
387 void AppBannerManager::RecordCouldShowBanner() { | 396 void AppBannerManager::RecordCouldShowBanner() { |
388 content::WebContents* contents = web_contents(); | 397 content::WebContents* contents = web_contents(); |
389 DCHECK(contents); | 398 DCHECK(contents); |
390 | 399 |
391 AppBannerSettingsHelper::RecordBannerCouldShowEvent( | 400 AppBannerSettingsHelper::RecordBannerCouldShowEvent( |
392 contents, validated_url_, GetAppIdentifier(), | 401 contents, validated_url_, GetAppIdentifier(), |
393 GetCurrentTime(), last_transition_type_); | 402 GetCurrentTime(), last_transition_type_); |
394 } | 403 } |
395 | 404 |
396 bool AppBannerManager::CheckIfShouldShowBanner() { | 405 bool AppBannerManager::CheckIfShouldShowBanner() { |
397 content::WebContents* contents = web_contents(); | 406 content::WebContents* contents = web_contents(); |
398 DCHECK(contents); | 407 DCHECK(contents); |
399 | 408 |
409 // ShouldShowBanner will call TrackInstallableErrorCode as appropriate. | |
400 return AppBannerSettingsHelper::ShouldShowBanner( | 410 return AppBannerSettingsHelper::ShouldShowBanner( |
401 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 411 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
402 } | 412 } |
403 | 413 |
404 bool AppBannerManager::OnMessageReceived( | 414 bool AppBannerManager::OnMessageReceived( |
405 const IPC::Message& message, | 415 const IPC::Message& message, |
406 content::RenderFrameHost* render_frame_host) { | 416 content::RenderFrameHost* render_frame_host) { |
407 bool handled = true; | 417 bool handled = true; |
408 | 418 |
409 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerManager, message, render_frame_host) | 419 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerManager, message, render_frame_host) |
(...skipping 22 matching lines...) Expand all Loading... | |
432 // called if a redisplay isn't asked for. | 442 // called if a redisplay isn't asked for. |
433 // | 443 // |
434 // We use the additional page_requested_prompt_ variable because the redisplay | 444 // We use the additional page_requested_prompt_ variable because the redisplay |
435 // request may be received *before* the Cancel prompt reply (e.g. if redisplay | 445 // request may be received *before* the Cancel prompt reply (e.g. if redisplay |
436 // is requested in the beforeinstallprompt event handler). | 446 // is requested in the beforeinstallprompt event handler). |
437 referrer_ = referrer; | 447 referrer_ = referrer; |
438 if (reply == blink::WebAppBannerPromptReply::Cancel && | 448 if (reply == blink::WebAppBannerPromptReply::Cancel && |
439 !page_requested_prompt_) { | 449 !page_requested_prompt_) { |
440 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); | 450 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); |
441 was_canceled_by_page_ = true; | 451 was_canceled_by_page_ = true; |
442 ReportError(contents, RENDERER_CANCELLED); | |
443 return; | 452 return; |
444 } | 453 } |
445 | 454 |
446 // If we haven't yet returned, but either of |was_canceled_by_page_| or | 455 // If we haven't yet returned, but either of |was_canceled_by_page_| or |
447 // |page_requested_prompt_| is true, the page has requested a delayed showing | 456 // |page_requested_prompt_| is true, the page has requested a delayed showing |
448 // of the prompt. Otherwise, the prompt was never canceled by the page. | 457 // of the prompt. Otherwise, the prompt was never canceled by the page. |
449 if (was_canceled_by_page_ || page_requested_prompt_) { | 458 if (was_canceled_by_page_ || page_requested_prompt_) { |
450 TrackBeforeInstallEvent( | 459 TrackBeforeInstallEvent( |
451 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); | 460 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); |
452 was_canceled_by_page_ = false; | 461 was_canceled_by_page_ = false; |
453 } else { | 462 } else { |
454 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); | 463 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); |
455 } | 464 } |
456 | 465 |
457 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( | 466 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( |
458 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 467 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
459 | 468 |
460 DCHECK(!manifest_url_.is_empty()); | 469 DCHECK(!manifest_url_.is_empty()); |
461 DCHECK(!manifest_.IsEmpty()); | 470 DCHECK(!manifest_.IsEmpty()); |
462 DCHECK(!icon_url_.is_empty()); | 471 DCHECK(!icon_url_.is_empty()); |
463 DCHECK(icon_.get()); | 472 DCHECK(icon_.get()); |
473 | |
464 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); | 474 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); |
465 ShowBanner(); | 475 ShowBanner(); |
466 is_active_ = false; | 476 is_active_ = false; |
467 } | 477 } |
468 | 478 |
469 void AppBannerManager::OnRequestShowAppBanner( | 479 void AppBannerManager::OnRequestShowAppBanner( |
470 content::RenderFrameHost* render_frame_host, | 480 content::RenderFrameHost* render_frame_host, |
471 int request_id) { | 481 int request_id) { |
472 if (was_canceled_by_page_) { | 482 if (was_canceled_by_page_) { |
473 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 483 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
474 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 484 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
475 OnBannerPromptReply(render_frame_host, request_id, | 485 OnBannerPromptReply(render_frame_host, request_id, |
476 blink::WebAppBannerPromptReply::None, referrer_); | 486 blink::WebAppBannerPromptReply::None, referrer_); |
477 } else { | 487 } else { |
478 // Log that the prompt request was made for when we get the prompt reply. | 488 // Log that the prompt request was made for when we get the prompt reply. |
479 page_requested_prompt_ = true; | 489 page_requested_prompt_ = true; |
480 } | 490 } |
481 } | 491 } |
482 | 492 |
483 } // namespace banners | 493 } // namespace banners |
OLD | NEW |