| 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_data_fetcher.h" | 5 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 referrer_.erase(); | 108 referrer_.erase(); |
| 109 web_contents->HasManifest( | 109 web_contents->HasManifest( |
| 110 base::Bind(&AppBannerDataFetcher::OnDidHasManifest, this)); | 110 base::Bind(&AppBannerDataFetcher::OnDidHasManifest, this)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void AppBannerDataFetcher::Cancel() { | 113 void AppBannerDataFetcher::Cancel() { |
| 114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 115 if (is_active_) { | 115 if (is_active_) { |
| 116 FOR_EACH_OBSERVER(Observer, observer_list_, | 116 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 117 OnDecidedWhetherToShow(this, false)); | 117 OnDecidedWhetherToShow(this, false)); |
| 118 if (was_canceled_by_page_ && !page_requested_prompt_) { |
| 119 TrackBeforeInstallEvent( |
| 120 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| 121 } |
| 122 |
| 118 is_active_ = false; | 123 is_active_ = false; |
| 119 was_canceled_by_page_ = false; | 124 was_canceled_by_page_ = false; |
| 120 page_requested_prompt_ = false; | 125 page_requested_prompt_ = false; |
| 121 referrer_.erase(); | 126 referrer_.erase(); |
| 122 } | 127 } |
| 123 } | 128 } |
| 124 | 129 |
| 125 void AppBannerDataFetcher::ReplaceWebContents( | 130 void AppBannerDataFetcher::ReplaceWebContents( |
| 126 content::WebContents* web_contents) { | 131 content::WebContents* web_contents) { |
| 127 Observe(web_contents); | 132 Observe(web_contents); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // called if a redisplay isn't asked for. | 186 // called if a redisplay isn't asked for. |
| 182 // | 187 // |
| 183 // The redisplay request may be received before the Cancel prompt reply | 188 // The redisplay request may be received before the Cancel prompt reply |
| 184 // *after* if it is made before the beforeinstallprompt event handler | 189 // *after* if it is made before the beforeinstallprompt event handler |
| 185 // concludes (e.g. in the event handler itself), so allow the pipeline | 190 // concludes (e.g. in the event handler itself), so allow the pipeline |
| 186 // to continue in this case. | 191 // to continue in this case. |
| 187 // | 192 // |
| 188 // Stash the referrer for the case where the banner is redisplayed. | 193 // Stash the referrer for the case where the banner is redisplayed. |
| 189 if (reply == blink::WebAppBannerPromptReply::Cancel && | 194 if (reply == blink::WebAppBannerPromptReply::Cancel && |
| 190 !page_requested_prompt_) { | 195 !page_requested_prompt_) { |
| 196 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); |
| 191 was_canceled_by_page_ = true; | 197 was_canceled_by_page_ = true; |
| 192 referrer_ = referrer; | 198 referrer_ = referrer; |
| 193 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel, | 199 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel, |
| 194 is_debug_mode_); | 200 is_debug_mode_); |
| 195 return; | 201 return; |
| 196 } | 202 } |
| 197 | 203 |
| 204 // If we haven't yet returned, but either of |was_canceled_by_page_| or |
| 205 // |page_requested_prompt_| is true, the page has requested a delayed showing |
| 206 // of the prompt. Otherwise, the prompt was never canceled by the page. |
| 207 if (was_canceled_by_page_ || page_requested_prompt_) { |
| 208 TrackBeforeInstallEvent( |
| 209 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); |
| 210 was_canceled_by_page_ = false; |
| 211 } else { |
| 212 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); |
| 213 } |
| 214 |
| 198 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( | 215 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( |
| 199 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 216 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 200 | 217 |
| 201 // Definitely going to show the banner now. | 218 // Definitely going to show the banner now. |
| 202 FOR_EACH_OBSERVER(Observer, observer_list_, | 219 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 203 OnDecidedWhetherToShow(this, true)); | 220 OnDecidedWhetherToShow(this, true)); |
| 204 | 221 |
| 222 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); |
| 205 ShowBanner(app_icon_url_, app_icon_.get(), app_title_, referrer); | 223 ShowBanner(app_icon_url_, app_icon_.get(), app_title_, referrer); |
| 206 is_active_ = false; | 224 is_active_ = false; |
| 207 } | 225 } |
| 208 | 226 |
| 209 void AppBannerDataFetcher::OnRequestShowAppBanner( | 227 void AppBannerDataFetcher::OnRequestShowAppBanner( |
| 210 content::RenderFrameHost* render_frame_host, | 228 content::RenderFrameHost* render_frame_host, |
| 211 int request_id) { | 229 int request_id) { |
| 212 if (was_canceled_by_page_) { | 230 if (was_canceled_by_page_) { |
| 213 // Simulate an "OK" from the website to restart the banner display pipeline. | 231 // Simulate an "OK" from the website to restart the banner display pipeline. |
| 214 was_canceled_by_page_ = false; | 232 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 215 OnBannerPromptReply(render_frame_host, request_id, | 233 OnBannerPromptReply(render_frame_host, request_id, |
| 216 blink::WebAppBannerPromptReply::None, referrer_); | 234 blink::WebAppBannerPromptReply::None, referrer_); |
| 217 } else { | 235 } else { |
| 218 // Log that the prompt request was made for when we get the prompt reply. | 236 // Log that the prompt request was made for when we get the prompt reply. |
| 219 page_requested_prompt_ = true; | 237 page_requested_prompt_ = true; |
| 220 } | 238 } |
| 221 } | 239 } |
| 222 | 240 |
| 223 AppBannerDataFetcher::~AppBannerDataFetcher() { | 241 AppBannerDataFetcher::~AppBannerDataFetcher() { |
| 224 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); | 242 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 RecordCouldShowBanner(); | 412 RecordCouldShowBanner(); |
| 395 if (!is_debug_mode_ && !CheckIfShouldShowBanner()) { | 413 if (!is_debug_mode_ && !CheckIfShouldShowBanner()) { |
| 396 // At this point, the only possible case is that the banner has been added | 414 // At this point, the only possible case is that the banner has been added |
| 397 // to the homescreen, given all of the other checks that have been made. | 415 // to the homescreen, given all of the other checks that have been made. |
| 398 Cancel(); | 416 Cancel(); |
| 399 return; | 417 return; |
| 400 } | 418 } |
| 401 | 419 |
| 402 app_icon_.reset(new SkBitmap(bitmap)); | 420 app_icon_.reset(new SkBitmap(bitmap)); |
| 403 event_request_id_ = ++gCurrentRequestID; | 421 event_request_id_ = ++gCurrentRequestID; |
| 422 |
| 423 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 404 web_contents->GetMainFrame()->Send( | 424 web_contents->GetMainFrame()->Send( |
| 405 new ChromeViewMsg_AppBannerPromptRequest( | 425 new ChromeViewMsg_AppBannerPromptRequest( |
| 406 web_contents->GetMainFrame()->GetRoutingID(), | 426 web_contents->GetMainFrame()->GetRoutingID(), |
| 407 event_request_id_, | 427 event_request_id_, |
| 408 GetBannerType())); | 428 GetBannerType())); |
| 409 } | 429 } |
| 410 | 430 |
| 411 bool AppBannerDataFetcher::IsWebAppInstalled( | 431 bool AppBannerDataFetcher::IsWebAppInstalled( |
| 412 content::BrowserContext* browser_context, | 432 content::BrowserContext* browser_context, |
| 413 const GURL& start_url) { | 433 const GURL& start_url) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 497 |
| 478 if (!DoesManifestContainRequiredIcon(manifest)) { | 498 if (!DoesManifestContainRequiredIcon(manifest)) { |
| 479 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, | 499 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, |
| 480 is_debug_mode); | 500 is_debug_mode); |
| 481 return false; | 501 return false; |
| 482 } | 502 } |
| 483 return true; | 503 return true; |
| 484 } | 504 } |
| 485 | 505 |
| 486 } // namespace banners | 506 } // namespace banners |
| OLD | NEW |