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 12 matching lines...) Expand all Loading... | |
| 23 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "mojo/public/cpp/bindings/interface_request.h" | 26 #include "mojo/public/cpp/bindings/interface_request.h" |
| 27 #include "services/service_manager/public/cpp/interface_provider.h" | 27 #include "services/service_manager/public/cpp/interface_provider.h" |
| 28 #include "third_party/WebKit/public/platform/modules/installation/installation.m ojom.h" | 28 #include "third_party/WebKit/public/platform/modules/installation/installation.m ojom.h" |
| 29 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 int gCurrentRequestID = -1; | |
| 34 int gTimeDeltaInDaysForTesting = 0; | 33 int gTimeDeltaInDaysForTesting = 0; |
| 35 | 34 |
| 36 InstallableParams ParamsToGetManifest() { | 35 InstallableParams ParamsToGetManifest() { |
| 37 return InstallableParams(); | 36 return InstallableParams(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 } // anonymous namespace | 39 } // anonymous namespace |
| 41 | 40 |
| 42 namespace banners { | 41 namespace banners { |
| 43 | 42 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 58 } | 57 } |
| 59 | 58 |
| 60 void AppBannerManager::RequestAppBanner(const GURL& validated_url, | 59 void AppBannerManager::RequestAppBanner(const GURL& validated_url, |
| 61 bool is_debug_mode) { | 60 bool is_debug_mode) { |
| 62 content::WebContents* contents = web_contents(); | 61 content::WebContents* contents = web_contents(); |
| 63 | 62 |
| 64 // The only time we should start the pipeline while it is already running is | 63 // The only time we should start the pipeline while it is already running is |
| 65 // if it's been triggered from devtools. | 64 // if it's been triggered from devtools. |
| 66 if (is_active_or_pending()) { | 65 if (is_active_or_pending()) { |
| 67 DCHECK(is_debug_mode); | 66 DCHECK(is_debug_mode); |
| 68 weak_factory_.InvalidateWeakPtrs(); | 67 weak_factory_.InvalidateWeakPtrs(); |
|
benwells
2017/07/06 07:22:39
Nit: can you factor this out into a separate funct
dominickn
2017/07/07 00:35:40
Done.
| |
| 68 binding_.Close(); | |
| 69 controller_.reset(); | |
| 70 event_.reset(); | |
| 69 } | 71 } |
| 70 | 72 |
| 71 UpdateState(State::ACTIVE); | 73 UpdateState(State::ACTIVE); |
| 72 triggered_by_devtools_ = is_debug_mode; | 74 triggered_by_devtools_ = is_debug_mode; |
| 73 page_requested_prompt_ = false; | 75 page_requested_prompt_ = false; |
| 74 | 76 |
| 75 // We only need to call ReportStatus if we aren't in debug mode (this avoids | 77 // We only need to call ReportStatus if we aren't in debug mode (this avoids |
| 76 // skew from testing). | 78 // skew from testing). |
| 77 DCHECK(!need_to_log_status_); | 79 DCHECK(!need_to_log_status_); |
| 78 need_to_log_status_ = !IsDebugMode(); | 80 need_to_log_status_ = !IsDebugMode(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 108 } | 110 } |
| 109 | 111 |
| 110 void AppBannerManager::OnInstall() { | 112 void AppBannerManager::OnInstall() { |
| 111 blink::mojom::InstallationServicePtr installation_service; | 113 blink::mojom::InstallationServicePtr installation_service; |
| 112 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 114 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 113 mojo::MakeRequest(&installation_service)); | 115 mojo::MakeRequest(&installation_service)); |
| 114 DCHECK(installation_service); | 116 DCHECK(installation_service); |
| 115 installation_service->OnInstall(); | 117 installation_service->OnInstall(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void AppBannerManager::SendBannerAccepted(int request_id) { | 120 void AppBannerManager::SendBannerAccepted() { |
| 119 if (request_id != gCurrentRequestID) | 121 if (event_.is_bound()) |
| 120 return; | 122 event_->BannerAccepted(GetBannerType()); |
| 121 | |
| 122 DCHECK(event_.is_bound()); | |
| 123 event_->BannerAccepted(GetBannerType()); | |
| 124 } | 123 } |
| 125 | 124 |
| 126 void AppBannerManager::SendBannerDismissed(int request_id) { | 125 void AppBannerManager::SendBannerDismissed() { |
| 127 if (request_id != gCurrentRequestID) | 126 if (event_.is_bound()) |
| 128 return; | 127 event_->BannerDismissed(); |
| 129 | |
| 130 DCHECK(event_.is_bound()); | |
| 131 event_->BannerDismissed(); | |
| 132 } | 128 } |
| 133 | 129 |
| 134 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() { | 130 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() { |
| 135 return weak_factory_.GetWeakPtr(); | 131 return weak_factory_.GetWeakPtr(); |
| 136 } | 132 } |
| 137 | 133 |
| 138 AppBannerManager::AppBannerManager(content::WebContents* web_contents) | 134 AppBannerManager::AppBannerManager(content::WebContents* web_contents) |
| 139 : content::WebContentsObserver(web_contents), | 135 : content::WebContentsObserver(web_contents), |
| 140 SiteEngagementObserver(SiteEngagementService::Get( | 136 SiteEngagementObserver(SiteEngagementService::Get( |
| 141 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), | 137 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), |
| 142 state_(State::INACTIVE), | 138 state_(State::INACTIVE), |
| 143 manager_(InstallableManager::FromWebContents(web_contents)), | 139 manager_(InstallableManager::FromWebContents(web_contents)), |
| 144 event_request_id_(-1), | |
| 145 binding_(this), | 140 binding_(this), |
| 146 has_sufficient_engagement_(false), | 141 has_sufficient_engagement_(false), |
| 147 load_finished_(false), | 142 load_finished_(false), |
| 148 page_requested_prompt_(false), | 143 page_requested_prompt_(false), |
| 149 triggered_by_devtools_(false), | 144 triggered_by_devtools_(false), |
| 150 need_to_log_status_(false), | 145 need_to_log_status_(false), |
| 151 weak_factory_(this) { | 146 weak_factory_(this) { |
| 152 DCHECK(manager_); | 147 DCHECK(manager_); |
| 153 | 148 |
| 154 AppBannerSettingsHelper::UpdateFromFieldTrial(); | 149 AppBannerSettingsHelper::UpdateFromFieldTrial(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 controller_.reset(); | 340 controller_.reset(); |
| 346 event_.reset(); | 341 event_.reset(); |
| 347 | 342 |
| 348 UpdateState(State::COMPLETE); | 343 UpdateState(State::COMPLETE); |
| 349 need_to_log_status_ = false; | 344 need_to_log_status_ = false; |
| 350 has_sufficient_engagement_ = false; | 345 has_sufficient_engagement_ = false; |
| 351 } | 346 } |
| 352 | 347 |
| 353 void AppBannerManager::SendBannerPromptRequest() { | 348 void AppBannerManager::SendBannerPromptRequest() { |
| 354 RecordCouldShowBanner(); | 349 RecordCouldShowBanner(); |
| 355 | |
| 356 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 350 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 357 event_request_id_ = ++gCurrentRequestID; | |
| 358 | 351 |
| 359 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 352 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 360 mojo::MakeRequest(&controller_)); | 353 mojo::MakeRequest(&controller_)); |
| 361 | 354 |
| 362 blink::mojom::AppBannerServicePtr banner_proxy; | 355 blink::mojom::AppBannerServicePtr banner_proxy; |
| 363 binding_.Bind(mojo::MakeRequest(&banner_proxy)); | 356 binding_.Bind(mojo::MakeRequest(&banner_proxy)); |
| 364 controller_->BannerPromptRequest( | 357 controller_->BannerPromptRequest( |
| 365 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, | 358 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, |
| 366 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); | 359 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); |
| 367 } | 360 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 if (is_pending_event()) { | 564 if (is_pending_event()) { |
| 572 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 565 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 573 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 566 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 574 } else { | 567 } else { |
| 575 // Log that the prompt request was made for when we get the prompt reply. | 568 // Log that the prompt request was made for when we get the prompt reply. |
| 576 page_requested_prompt_ = true; | 569 page_requested_prompt_ = true; |
| 577 } | 570 } |
| 578 } | 571 } |
| 579 | 572 |
| 580 } // namespace banners | 573 } // namespace banners |
| OLD | NEW |