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 05:00:35
Here we just invalidate weak pointers, but don't r
dominickn
2017/07/06 05:36:08
Good point, done.
| |
| 69 } | 68 } |
| 70 | 69 |
| 71 UpdateState(State::ACTIVE); | 70 UpdateState(State::ACTIVE); |
| 72 triggered_by_devtools_ = is_debug_mode; | 71 triggered_by_devtools_ = is_debug_mode; |
| 73 page_requested_prompt_ = false; | 72 page_requested_prompt_ = false; |
| 74 | 73 |
| 75 // We only need to call ReportStatus if we aren't in debug mode (this avoids | 74 // We only need to call ReportStatus if we aren't in debug mode (this avoids |
| 76 // skew from testing). | 75 // skew from testing). |
| 77 DCHECK(!need_to_log_status_); | 76 DCHECK(!need_to_log_status_); |
| 78 need_to_log_status_ = !IsDebugMode(); | 77 need_to_log_status_ = !IsDebugMode(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 108 } | 107 } |
| 109 | 108 |
| 110 void AppBannerManager::OnInstall() { | 109 void AppBannerManager::OnInstall() { |
| 111 blink::mojom::InstallationServicePtr installation_service; | 110 blink::mojom::InstallationServicePtr installation_service; |
| 112 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 111 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 113 mojo::MakeRequest(&installation_service)); | 112 mojo::MakeRequest(&installation_service)); |
| 114 DCHECK(installation_service); | 113 DCHECK(installation_service); |
| 115 installation_service->OnInstall(); | 114 installation_service->OnInstall(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void AppBannerManager::SendBannerAccepted(int request_id) { | 117 void AppBannerManager::SendBannerAccepted() { |
| 119 if (request_id != gCurrentRequestID) | 118 if (event_.is_bound()) |
| 120 return; | 119 event_->BannerAccepted(GetBannerType()); |
| 121 | |
| 122 DCHECK(event_.is_bound()); | |
| 123 event_->BannerAccepted(GetBannerType()); | |
| 124 } | 120 } |
| 125 | 121 |
| 126 void AppBannerManager::SendBannerDismissed(int request_id) { | 122 void AppBannerManager::SendBannerDismissed() { |
| 127 if (request_id != gCurrentRequestID) | 123 if (event_.is_bound()) |
| 128 return; | 124 event_->BannerDismissed(); |
| 129 | |
| 130 DCHECK(event_.is_bound()); | |
| 131 event_->BannerDismissed(); | |
| 132 } | 125 } |
| 133 | 126 |
| 134 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() { | 127 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() { |
| 135 return weak_factory_.GetWeakPtr(); | 128 return weak_factory_.GetWeakPtr(); |
| 136 } | 129 } |
| 137 | 130 |
| 138 AppBannerManager::AppBannerManager(content::WebContents* web_contents) | 131 AppBannerManager::AppBannerManager(content::WebContents* web_contents) |
| 139 : content::WebContentsObserver(web_contents), | 132 : content::WebContentsObserver(web_contents), |
| 140 SiteEngagementObserver(SiteEngagementService::Get( | 133 SiteEngagementObserver(SiteEngagementService::Get( |
| 141 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), | 134 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), |
| 142 state_(State::INACTIVE), | 135 state_(State::INACTIVE), |
| 143 manager_(InstallableManager::FromWebContents(web_contents)), | 136 manager_(InstallableManager::FromWebContents(web_contents)), |
| 144 event_request_id_(-1), | |
| 145 binding_(this), | 137 binding_(this), |
| 146 has_sufficient_engagement_(false), | 138 has_sufficient_engagement_(false), |
| 147 load_finished_(false), | 139 load_finished_(false), |
| 148 page_requested_prompt_(false), | 140 page_requested_prompt_(false), |
| 149 triggered_by_devtools_(false), | 141 triggered_by_devtools_(false), |
| 150 need_to_log_status_(false), | 142 need_to_log_status_(false), |
| 151 weak_factory_(this) { | 143 weak_factory_(this) { |
| 152 DCHECK(manager_); | 144 DCHECK(manager_); |
| 153 | 145 |
| 154 AppBannerSettingsHelper::UpdateFromFieldTrial(); | 146 AppBannerSettingsHelper::UpdateFromFieldTrial(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 controller_.reset(); | 337 controller_.reset(); |
| 346 event_.reset(); | 338 event_.reset(); |
| 347 | 339 |
| 348 UpdateState(State::COMPLETE); | 340 UpdateState(State::COMPLETE); |
| 349 need_to_log_status_ = false; | 341 need_to_log_status_ = false; |
| 350 has_sufficient_engagement_ = false; | 342 has_sufficient_engagement_ = false; |
| 351 } | 343 } |
| 352 | 344 |
| 353 void AppBannerManager::SendBannerPromptRequest() { | 345 void AppBannerManager::SendBannerPromptRequest() { |
| 354 RecordCouldShowBanner(); | 346 RecordCouldShowBanner(); |
| 355 | |
| 356 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 347 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 357 event_request_id_ = ++gCurrentRequestID; | |
| 358 | 348 |
| 359 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 349 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 360 mojo::MakeRequest(&controller_)); | 350 mojo::MakeRequest(&controller_)); |
| 361 | 351 |
| 362 blink::mojom::AppBannerServicePtr banner_proxy; | 352 blink::mojom::AppBannerServicePtr banner_proxy; |
| 363 binding_.Bind(mojo::MakeRequest(&banner_proxy)); | 353 binding_.Bind(mojo::MakeRequest(&banner_proxy)); |
| 364 controller_->BannerPromptRequest( | 354 controller_->BannerPromptRequest( |
| 365 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, | 355 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, |
| 366 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); | 356 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); |
| 367 } | 357 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 if (is_pending_event()) { | 561 if (is_pending_event()) { |
| 572 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 562 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 573 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 563 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 574 } else { | 564 } else { |
| 575 // Log that the prompt request was made for when we get the prompt reply. | 565 // Log that the prompt request was made for when we get the prompt reply. |
| 576 page_requested_prompt_ = true; | 566 page_requested_prompt_ = true; |
| 577 } | 567 } |
| 578 } | 568 } |
| 579 | 569 |
| 580 } // namespace banners | 570 } // namespace banners |
| OLD | NEW |