| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 content::WebContents* web_contents = GetWebContents(); | 100 content::WebContents* web_contents = GetWebContents(); |
| 101 DCHECK(web_contents); | 101 DCHECK(web_contents); |
| 102 | 102 |
| 103 is_active_ = true; | 103 is_active_ = true; |
| 104 was_canceled_by_page_ = false; | 104 was_canceled_by_page_ = false; |
| 105 page_requested_prompt_ = false; | 105 page_requested_prompt_ = false; |
| 106 transition_type_ = transition_type; | 106 transition_type_ = transition_type; |
| 107 validated_url_ = validated_url; | 107 validated_url_ = validated_url; |
| 108 referrer_.erase(); | 108 referrer_.erase(); |
| 109 web_contents->HasManifest( | 109 web_contents->GetManifest( |
| 110 base::Bind(&AppBannerDataFetcher::OnDidHasManifest, this)); | 110 base::Bind(&AppBannerDataFetcher::OnDidGetManifest, 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_) { | 118 if (was_canceled_by_page_ && !page_requested_prompt_) { |
| 119 TrackBeforeInstallEvent( | 119 TrackBeforeInstallEvent( |
| 120 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 120 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 AppBannerSettingsHelper::RecordBannerEvent( | 264 AppBannerSettingsHelper::RecordBannerEvent( |
| 265 web_contents, validated_url_, GetAppIdentifier(), | 265 web_contents, validated_url_, GetAppIdentifier(), |
| 266 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | 266 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
| 267 GetCurrentTime()); | 267 GetCurrentTime()); |
| 268 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 268 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 269 event_name, | 269 event_name, |
| 270 web_contents->GetURL()); | 270 web_contents->GetURL()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void AppBannerDataFetcher::OnDidHasManifest(bool has_manifest) { | |
| 274 content::WebContents* web_contents = GetWebContents(); | |
| 275 | |
| 276 if (!CheckFetcherIsStillAlive(web_contents) || !has_manifest) { | |
| 277 if (!has_manifest) | |
| 278 OutputDeveloperNotShownMessage(web_contents, kNoManifest, is_debug_mode_); | |
| 279 | |
| 280 Cancel(); | |
| 281 return; | |
| 282 } | |
| 283 | |
| 284 web_contents->GetManifest( | |
| 285 base::Bind(&AppBannerDataFetcher::OnDidGetManifest, this)); | |
| 286 } | |
| 287 | |
| 288 void AppBannerDataFetcher::OnDidGetManifest( | 273 void AppBannerDataFetcher::OnDidGetManifest( |
| 289 const GURL& manifest_url, | 274 const GURL& manifest_url, |
| 290 const content::Manifest& manifest) { | 275 const content::Manifest& manifest) { |
| 291 content::WebContents* web_contents = GetWebContents(); | 276 content::WebContents* web_contents = GetWebContents(); |
| 292 if (!CheckFetcherIsStillAlive(web_contents)) { | 277 if (!CheckFetcherIsStillAlive(web_contents)) { |
| 293 Cancel(); | 278 Cancel(); |
| 294 return; | 279 return; |
| 295 } | 280 } |
| 281 if (manifest_url.is_empty()) { |
| 282 OutputDeveloperNotShownMessage(web_contents, kNoManifest, is_debug_mode_); |
| 283 Cancel(); |
| 284 return; |
| 285 } |
| 296 if (manifest.IsEmpty()) { | 286 if (manifest.IsEmpty()) { |
| 297 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty, | 287 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty, |
| 298 is_debug_mode_); | 288 is_debug_mode_); |
| 299 Cancel(); | 289 Cancel(); |
| 300 return; | 290 return; |
| 301 } | 291 } |
| 302 | 292 |
| 303 if (manifest.prefer_related_applications && | 293 if (manifest.prefer_related_applications && |
| 304 manifest.related_applications.size()) { | 294 manifest.related_applications.size()) { |
| 305 for (const auto& application : manifest.related_applications) { | 295 for (const auto& application : manifest.related_applications) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 487 |
| 498 if (!DoesManifestContainRequiredIcon(manifest)) { | 488 if (!DoesManifestContainRequiredIcon(manifest)) { |
| 499 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, | 489 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, |
| 500 is_debug_mode); | 490 is_debug_mode); |
| 501 return false; | 491 return false; |
| 502 } | 492 } |
| 503 return true; | 493 return true; |
| 504 } | 494 } |
| 505 | 495 |
| 506 } // namespace banners | 496 } // namespace banners |
| OLD | NEW |