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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (validated_url_.is_empty()) | 106 if (validated_url_.is_empty()) |
| 107 validated_url_ = validated_url; | 107 validated_url_ = validated_url; |
| 108 | 108 |
| 109 // Any existing binding is invalid when we request a new banner. | 109 // Any existing binding is invalid when we request a new banner. |
| 110 if (binding_.is_bound()) | 110 if (binding_.is_bound()) |
| 111 binding_.Close(); | 111 binding_.Close(); |
| 112 | 112 |
| 113 UpdateState(State::PENDING_MANIFEST); | |
| 113 manager_->GetData( | 114 manager_->GetData( |
| 114 ParamsToGetManifest(), | 115 ParamsToGetManifest(), |
| 115 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); | 116 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void AppBannerManager::OnInstall() { | 119 void AppBannerManager::OnInstall() { |
| 119 blink::mojom::InstallationServicePtr installation_service; | 120 blink::mojom::InstallationServicePtr installation_service; |
| 120 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 121 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 121 mojo::MakeRequest(&installation_service)); | 122 mojo::MakeRequest(&installation_service)); |
| 122 DCHECK(installation_service); | 123 DCHECK(installation_service); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 187 |
| 187 int AppBannerManager::GetIdealPrimaryIconSizeInPx() { | 188 int AppBannerManager::GetIdealPrimaryIconSizeInPx() { |
| 188 return InstallableManager::GetMinimumIconSizeInPx(); | 189 return InstallableManager::GetMinimumIconSizeInPx(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 int AppBannerManager::GetMinimumPrimaryIconSizeInPx() { | 192 int AppBannerManager::GetMinimumPrimaryIconSizeInPx() { |
| 192 return InstallableManager::GetMinimumIconSizeInPx(); | 193 return InstallableManager::GetMinimumIconSizeInPx(); |
| 193 } | 194 } |
| 194 | 195 |
| 195 bool AppBannerManager::IsDebugMode() const { | 196 bool AppBannerManager::IsDebugMode() const { |
| 196 return is_debug_mode_ || | 197 return is_debug_mode_ || |
|
benwells
2017/06/14 11:39:06
Nit: This is a bit confusing - IsDebugMode and is_
dominickn
2017/06/15 04:16:07
Done.
| |
| 197 base::CommandLine::ForCurrentProcess()->HasSwitch( | 198 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 switches::kBypassAppBannerEngagementChecks); | 199 switches::kBypassAppBannerEngagementChecks); |
| 199 } | 200 } |
| 200 | 201 |
| 201 bool AppBannerManager::IsWebAppInstalled( | 202 bool AppBannerManager::IsWebAppInstalled( |
| 202 content::BrowserContext* browser_context, | 203 content::BrowserContext* browser_context, |
| 203 const GURL& start_url, | 204 const GURL& start_url, |
| 204 const GURL& manifest_url) { | 205 const GURL& manifest_url) { |
| 205 return false; | 206 return false; |
| 206 } | 207 } |
| 207 | 208 |
| 208 void AppBannerManager::OnDidGetManifest(const InstallableData& data) { | 209 void AppBannerManager::OnDidGetManifest(const InstallableData& data) { |
| 210 UpdateState(State::ACTIVE); | |
| 209 if (data.error_code != NO_ERROR_DETECTED) { | 211 if (data.error_code != NO_ERROR_DETECTED) { |
| 210 ReportStatus(web_contents(), data.error_code); | 212 ReportStatus(web_contents(), data.error_code); |
| 211 Stop(); | 213 Stop(); |
| 212 } | 214 } |
| 213 | 215 |
| 214 if (!is_active()) | 216 if (!is_active()) |
| 215 return; | 217 return; |
| 216 | 218 |
| 217 DCHECK(!data.manifest_url.is_empty()); | 219 DCHECK(!data.manifest_url.is_empty()); |
| 218 DCHECK(!data.manifest.IsEmpty()); | 220 DCHECK(!data.manifest.IsEmpty()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 230 PerformInstallableCheck(); | 232 PerformInstallableCheck(); |
| 231 } | 233 } |
| 232 | 234 |
| 233 InstallableParams AppBannerManager::ParamsToPerformInstallableCheck() { | 235 InstallableParams AppBannerManager::ParamsToPerformInstallableCheck() { |
| 234 InstallableParams params; | 236 InstallableParams params; |
| 235 params.ideal_primary_icon_size_in_px = GetIdealPrimaryIconSizeInPx(); | 237 params.ideal_primary_icon_size_in_px = GetIdealPrimaryIconSizeInPx(); |
| 236 params.minimum_primary_icon_size_in_px = GetMinimumPrimaryIconSizeInPx(); | 238 params.minimum_primary_icon_size_in_px = GetMinimumPrimaryIconSizeInPx(); |
| 237 params.check_installable = true; | 239 params.check_installable = true; |
| 238 params.fetch_valid_primary_icon = true; | 240 params.fetch_valid_primary_icon = true; |
| 239 | 241 |
| 242 // Don't wait for the worker if we're in debug mode. However, we want to | |
| 243 // ignore whether the bypass flag is on for this purpose (otherwise we won't | |
| 244 // wait for the worker in that instance). | |
|
benwells
2017/06/14 11:39:06
Maybe it's just late but this confuses me.
Edit:
dominickn
2017/06/15 04:16:07
Done.
| |
| 245 params.wait_for_worker = !is_debug_mode_; | |
| 246 | |
| 240 return params; | 247 return params; |
| 241 } | 248 } |
| 242 | 249 |
| 243 void AppBannerManager::PerformInstallableCheck() { | 250 void AppBannerManager::PerformInstallableCheck() { |
| 244 if (!CheckIfShouldShowBanner()) | 251 if (!CheckIfShouldShowBanner()) |
| 245 return; | 252 return; |
| 246 | 253 |
| 247 // Fetch and verify the other required information. | 254 // Fetch and verify the other required information. |
| 255 UpdateState(State::PENDING_INSTALLABLE_CHECK); | |
| 248 manager_->GetData(ParamsToPerformInstallableCheck(), | 256 manager_->GetData(ParamsToPerformInstallableCheck(), |
| 249 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, | 257 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, |
| 250 GetWeakPtr())); | 258 GetWeakPtr())); |
| 251 } | 259 } |
| 252 | 260 |
| 253 void AppBannerManager::OnDidPerformInstallableCheck( | 261 void AppBannerManager::OnDidPerformInstallableCheck( |
| 254 const InstallableData& data) { | 262 const InstallableData& data) { |
| 263 UpdateState(State::ACTIVE); | |
| 255 if (data.is_installable) | 264 if (data.is_installable) |
| 256 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED); | 265 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED); |
| 257 | 266 |
| 258 if (data.error_code != NO_ERROR_DETECTED) { | 267 if (data.error_code != NO_ERROR_DETECTED) { |
| 259 if (data.error_code == NO_MATCHING_SERVICE_WORKER) | 268 if (data.error_code == NO_MATCHING_SERVICE_WORKER) |
| 260 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); | 269 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); |
| 261 | 270 |
| 262 ReportStatus(web_contents(), data.error_code); | 271 ReportStatus(web_contents(), data.error_code); |
| 263 Stop(); | 272 Stop(); |
| 264 } | 273 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 329 |
| 321 void AppBannerManager::Stop() { | 330 void AppBannerManager::Stop() { |
| 322 if (state_ == State::PENDING_EVENT && !page_requested_prompt_) { | 331 if (state_ == State::PENDING_EVENT && !page_requested_prompt_) { |
| 323 TrackBeforeInstallEvent( | 332 TrackBeforeInstallEvent( |
| 324 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 333 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| 325 ReportStatus(web_contents(), RENDERER_CANCELLED); | 334 ReportStatus(web_contents(), RENDERER_CANCELLED); |
| 326 } else if (state_ == State::PENDING_ENGAGEMENT && | 335 } else if (state_ == State::PENDING_ENGAGEMENT && |
| 327 !has_sufficient_engagement_) { | 336 !has_sufficient_engagement_) { |
| 328 TrackDisplayEvent(DISPLAY_EVENT_NOT_VISITED_ENOUGH); | 337 TrackDisplayEvent(DISPLAY_EVENT_NOT_VISITED_ENOUGH); |
| 329 ReportStatus(web_contents(), INSUFFICIENT_ENGAGEMENT); | 338 ReportStatus(web_contents(), INSUFFICIENT_ENGAGEMENT); |
| 339 } else if (state_ == State::PENDING_MANIFEST) { | |
| 340 ReportStatus(web_contents(), WAITING_FOR_MANIFEST); | |
| 341 } else if (state_ == State::PENDING_INSTALLABLE_CHECK) { | |
| 342 ReportStatus(web_contents(), WAITING_FOR_INSTALLABLE_CHECK); | |
| 330 } | 343 } |
| 331 | 344 |
| 332 // 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 |
| 333 // ReportStatus() and set need_to_log_status_ to false. The only case where | 346 // ReportStatus() and set need_to_log_status_ to false. |
| 334 // we don't is if we're still active and waiting for a callback from the | 347 DCHECK(!need_to_log_status_); |
| 335 // InstallableManager (e.g. the renderer crashes or the browser is shutting | |
| 336 // down). These situations are explicitly not logged. | |
| 337 DCHECK(!need_to_log_status_ || is_active()); | |
| 338 | 348 |
| 339 weak_factory_.InvalidateWeakPtrs(); | 349 weak_factory_.InvalidateWeakPtrs(); |
| 340 binding_.Close(); | 350 binding_.Close(); |
| 341 controller_.reset(); | 351 controller_.reset(); |
| 342 event_.reset(); | 352 event_.reset(); |
| 343 | 353 |
| 344 UpdateState(State::COMPLETE); | 354 UpdateState(State::COMPLETE); |
| 345 need_to_log_status_ = false; | |
| 346 has_sufficient_engagement_ = false; | 355 has_sufficient_engagement_ = false; |
| 347 } | 356 } |
| 348 | 357 |
| 349 void AppBannerManager::SendBannerPromptRequest() { | 358 void AppBannerManager::SendBannerPromptRequest() { |
| 350 RecordCouldShowBanner(); | 359 RecordCouldShowBanner(); |
| 351 | 360 |
| 352 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 361 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 353 event_request_id_ = ++gCurrentRequestID; | 362 event_request_id_ = ++gCurrentRequestID; |
| 354 | 363 |
| 355 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 364 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 if (is_pending_event()) { | 569 if (is_pending_event()) { |
| 561 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 570 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 562 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 571 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 563 } else { | 572 } else { |
| 564 // Log that the prompt request was made for when we get the prompt reply. | 573 // Log that the prompt request was made for when we get the prompt reply. |
| 565 page_requested_prompt_ = true; | 574 page_requested_prompt_ = true; |
| 566 } | 575 } |
| 567 } | 576 } |
| 568 | 577 |
| 569 } // namespace banners | 578 } // namespace banners |
| OLD | NEW |