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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, | 88 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, |
| 89 const GURL& second) { | 89 const GURL& second) { |
| 90 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 90 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
| 91 first.path() == second.path() && first.query() == second.query(); | 91 first.path() == second.path() && first.query() == second.query(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AppBannerManager::RequestAppBanner(const GURL& validated_url, | 94 void AppBannerManager::RequestAppBanner(const GURL& validated_url, |
| 95 bool is_debug_mode) { | 95 bool is_debug_mode) { |
| 96 // Don't start a redundant banner request. Otherwise, if one is running, | |
| 97 // invalidate our weak pointers so it terminates. | |
| 96 content::WebContents* contents = web_contents(); | 98 content::WebContents* contents = web_contents(); |
| 99 if (is_active_) { | |
| 100 if (URLsAreForTheSamePage(validated_url, contents->GetLastCommittedURL())) | |
| 101 return; | |
| 102 else | |
| 103 weak_factory_.InvalidateWeakPtrs(); | |
| 104 } | |
| 105 | |
| 106 is_active_ = true; | |
| 107 is_debug_mode_ = is_debug_mode; | |
| 108 | |
| 109 DCHECK(!need_to_log_status_); | |
| 110 need_to_log_status_ = !IsDebugMode(); | |
| 111 | |
| 97 if (contents->GetMainFrame()->GetParent()) { | 112 if (contents->GetMainFrame()->GetParent()) { |
| 98 ReportError(contents, NOT_IN_MAIN_FRAME); | 113 ReportStatus(contents, NOT_IN_MAIN_FRAME); |
| 114 Stop(); | |
| 99 return; | 115 return; |
| 100 } | 116 } |
| 101 | 117 |
| 102 // Don't start a redundant banner request. | |
| 103 if (is_active_ && | |
| 104 URLsAreForTheSamePage(validated_url, contents->GetLastCommittedURL())) { | |
| 105 return; | |
| 106 } | |
| 107 | |
| 108 // A secure origin is required to show banners, so exit early if we see the | 118 // A secure origin is required to show banners, so exit early if we see the |
| 109 // URL is invalid. | 119 // URL is invalid. |
| 110 if (!content::IsOriginSecure(validated_url) && | 120 if (!content::IsOriginSecure(validated_url) && |
| 111 !gDisableSecureCheckForTesting) { | 121 !gDisableSecureCheckForTesting) { |
| 112 ReportError(contents, NOT_FROM_SECURE_ORIGIN); | 122 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); |
| 123 Stop(); | |
| 113 return; | 124 return; |
| 114 } | 125 } |
| 115 | 126 |
| 116 is_debug_mode_ = is_debug_mode; | |
| 117 is_active_ = true; | |
| 118 | |
| 119 // We start by requesting the manifest from the InstallableManager. The | |
| 120 // default-constructed params will have all other fields as false. | |
| 121 manager_->GetData( | 127 manager_->GetData( |
| 122 ParamsToGetManifest(), | 128 ParamsToGetManifest(), |
| 123 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); | 129 base::Bind(&AppBannerManager::OnDidGetManifest, GetWeakPtr())); |
| 124 } | 130 } |
| 125 | 131 |
| 126 base::Closure AppBannerManager::FetchWebappSplashScreenImageCallback( | 132 base::Closure AppBannerManager::FetchWebappSplashScreenImageCallback( |
| 127 const std::string& webapp_id) { | 133 const std::string& webapp_id) { |
| 128 return base::Closure(); | 134 return base::Closure(); |
| 129 } | 135 } |
| 130 | 136 |
| 131 AppBannerManager::AppBannerManager(content::WebContents* web_contents) | 137 AppBannerManager::AppBannerManager(content::WebContents* web_contents) |
| 132 : content::WebContentsObserver(web_contents), | 138 : content::WebContentsObserver(web_contents), |
| 133 SiteEngagementObserver(nullptr), | 139 SiteEngagementObserver(nullptr), |
| 134 manager_(nullptr), | 140 manager_(nullptr), |
| 135 event_request_id_(-1), | 141 event_request_id_(-1), |
| 136 is_active_(false), | 142 is_active_(false), |
| 137 banner_request_queued_(false), | 143 banner_request_queued_(false), |
| 138 load_finished_(false), | 144 load_finished_(false), |
| 139 was_canceled_by_page_(false), | 145 was_canceled_by_page_(false), |
| 140 page_requested_prompt_(false), | 146 page_requested_prompt_(false), |
| 141 is_debug_mode_(false), | 147 is_debug_mode_(false), |
| 148 need_to_log_status_(false), | |
| 142 weak_factory_(this) { | 149 weak_factory_(this) { |
| 143 // Ensure the InstallableManager exists since we have a hard dependency on it. | 150 // Ensure the InstallableManager exists since we have a hard dependency on it. |
| 144 InstallableManager::CreateForWebContents(web_contents); | 151 InstallableManager::CreateForWebContents(web_contents); |
| 145 manager_ = InstallableManager::FromWebContents(web_contents); | 152 manager_ = InstallableManager::FromWebContents(web_contents); |
| 146 DCHECK(manager_); | 153 DCHECK(manager_); |
| 147 | 154 |
| 148 AppBannerSettingsHelper::UpdateFromFieldTrial(); | 155 AppBannerSettingsHelper::UpdateFromFieldTrial(); |
| 149 } | 156 } |
| 150 | 157 |
| 151 AppBannerManager::~AppBannerManager() { } | 158 AppBannerManager::~AppBannerManager() { } |
| 152 | 159 |
| 153 std::string AppBannerManager::GetAppIdentifier() { | 160 std::string AppBannerManager::GetAppIdentifier() { |
| 154 DCHECK(!manifest_.IsEmpty()); | 161 DCHECK(!manifest_.IsEmpty()); |
| 155 return manifest_.start_url.spec(); | 162 return manifest_.start_url.spec(); |
| 156 } | 163 } |
| 157 | 164 |
| 158 std::string AppBannerManager::GetBannerType() { | 165 std::string AppBannerManager::GetBannerType() { |
| 159 return "web"; | 166 return "web"; |
| 160 } | 167 } |
| 161 | 168 |
| 162 std::string AppBannerManager::GetErrorParam(InstallableErrorCode code) { | 169 std::string AppBannerManager::GetStatusParam(InstallableStatusCode code) { |
| 163 if (code == NO_ACCEPTABLE_ICON || code == MANIFEST_MISSING_SUITABLE_ICON) { | 170 if (code == NO_ACCEPTABLE_ICON || code == MANIFEST_MISSING_SUITABLE_ICON) { |
| 164 return base::IntToString(InstallableManager::GetMinimumIconSizeInPx()); | 171 return base::IntToString(InstallableManager::GetMinimumIconSizeInPx()); |
| 165 } | 172 } |
| 166 | 173 |
| 167 return std::string(); | 174 return std::string(); |
| 168 } | 175 } |
| 169 | 176 |
| 170 int AppBannerManager::GetIdealIconSizeInDp() { | 177 int AppBannerManager::GetIdealIconSizeInDp() { |
| 171 return ConvertIconSizeFromPxToDp( | 178 return ConvertIconSizeFromPxToDp( |
| 172 InstallableManager::GetMinimumIconSizeInPx()); | 179 InstallableManager::GetMinimumIconSizeInPx()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 188 } | 195 } |
| 189 | 196 |
| 190 bool AppBannerManager::IsWebAppInstalled( | 197 bool AppBannerManager::IsWebAppInstalled( |
| 191 content::BrowserContext* browser_context, | 198 content::BrowserContext* browser_context, |
| 192 const GURL& start_url) { | 199 const GURL& start_url) { |
| 193 return false; | 200 return false; |
| 194 } | 201 } |
| 195 | 202 |
| 196 void AppBannerManager::OnDidGetManifest(const InstallableData& data) { | 203 void AppBannerManager::OnDidGetManifest(const InstallableData& data) { |
| 197 if (data.error_code != NO_ERROR_DETECTED) { | 204 if (data.error_code != NO_ERROR_DETECTED) { |
| 198 ReportError(web_contents(), data.error_code); | 205 ReportStatus(web_contents(), data.error_code); |
| 199 Stop(); | 206 Stop(); |
| 200 } | 207 } |
| 201 | 208 |
| 202 if (!is_active_) | 209 if (!is_active_) |
| 203 return; | 210 return; |
| 204 | 211 |
| 205 DCHECK(!data.manifest_url.is_empty()); | 212 DCHECK(!data.manifest_url.is_empty()); |
| 206 DCHECK(!data.manifest.IsEmpty()); | 213 DCHECK(!data.manifest.IsEmpty()); |
| 207 | 214 |
| 208 manifest_url_ = data.manifest_url; | 215 manifest_url_ = data.manifest_url; |
| 209 manifest_ = data.manifest; | 216 manifest_ = data.manifest; |
| 210 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() | 217 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() |
| 211 : manifest_.name.string(); | 218 : manifest_.name.string(); |
| 212 | 219 |
| 213 PerformInstallableCheck(); | 220 PerformInstallableCheck(); |
| 214 } | 221 } |
| 215 | 222 |
| 216 void AppBannerManager::PerformInstallableCheck() { | 223 void AppBannerManager::PerformInstallableCheck() { |
| 217 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), | 224 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), |
| 218 manifest_.start_url) && | 225 manifest_.start_url) && |
| 219 !IsDebugMode()) { | 226 !IsDebugMode()) { |
| 227 ReportStatus(web_contents(), ALREADY_INSTALLED); | |
| 220 Stop(); | 228 Stop(); |
| 221 } | 229 } |
| 222 | 230 |
| 223 if (!is_active_) | 231 if (!is_active_) |
| 224 return; | 232 return; |
| 225 | 233 |
| 226 // Fetch and verify the other required information. | 234 // Fetch and verify the other required information. |
| 227 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInDp(), | 235 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInDp(), |
| 228 GetMinimumIconSizeInDp()), | 236 GetMinimumIconSizeInDp()), |
| 229 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, | 237 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, |
| 230 GetWeakPtr())); | 238 GetWeakPtr())); |
| 231 } | 239 } |
| 232 | 240 |
| 233 void AppBannerManager::OnDidPerformInstallableCheck( | 241 void AppBannerManager::OnDidPerformInstallableCheck( |
| 234 const InstallableData& data) { | 242 const InstallableData& data) { |
| 235 if (data.is_installable) | 243 if (data.is_installable) |
| 236 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED); | 244 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED); |
| 237 | 245 |
| 238 if (data.error_code != NO_ERROR_DETECTED) { | 246 if (data.error_code != NO_ERROR_DETECTED) { |
| 239 if (data.error_code == NO_MATCHING_SERVICE_WORKER) | 247 if (data.error_code == NO_MATCHING_SERVICE_WORKER) |
| 240 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); | 248 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); |
| 241 | 249 |
| 242 ReportError(web_contents(), data.error_code); | 250 ReportStatus(web_contents(), data.error_code); |
| 243 Stop(); | 251 Stop(); |
| 244 } | 252 } |
| 245 | 253 |
| 246 if (!is_active_) | 254 if (!is_active_) |
| 247 return; | 255 return; |
| 248 | 256 |
| 249 DCHECK(data.is_installable); | 257 DCHECK(data.is_installable); |
| 250 DCHECK(!data.icon_url.is_empty()); | 258 DCHECK(!data.icon_url.is_empty()); |
| 251 DCHECK(data.icon); | 259 DCHECK(data.icon); |
| 252 | 260 |
| 253 icon_url_ = data.icon_url; | 261 icon_url_ = data.icon_url; |
| 254 icon_.reset(new SkBitmap(*data.icon)); | 262 icon_.reset(new SkBitmap(*data.icon)); |
| 255 | 263 |
| 256 SendBannerPromptRequest(); | 264 SendBannerPromptRequest(); |
| 257 } | 265 } |
| 258 | 266 |
| 259 void AppBannerManager::RecordDidShowBanner(const std::string& event_name) { | 267 void AppBannerManager::RecordDidShowBanner(const std::string& event_name) { |
| 260 content::WebContents* contents = web_contents(); | 268 content::WebContents* contents = web_contents(); |
| 261 DCHECK(contents); | 269 DCHECK(contents); |
| 262 | 270 |
| 263 AppBannerSettingsHelper::RecordBannerEvent( | 271 AppBannerSettingsHelper::RecordBannerEvent( |
| 264 contents, validated_url_, GetAppIdentifier(), | 272 contents, validated_url_, GetAppIdentifier(), |
| 265 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | 273 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
| 266 GetCurrentTime()); | 274 GetCurrentTime()); |
| 267 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 275 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 268 event_name, | 276 event_name, |
| 269 contents->GetLastCommittedURL()); | 277 contents->GetLastCommittedURL()); |
| 270 } | 278 } |
| 271 | 279 |
| 272 void AppBannerManager::ReportError(content::WebContents* web_contents, | 280 void AppBannerManager::ReportStatus(content::WebContents* web_contents, |
| 273 InstallableErrorCode code) { | 281 InstallableStatusCode code) { |
| 274 if (IsDebugMode()) | 282 if (IsDebugMode()) { |
| 275 LogErrorToConsole(web_contents, code, GetErrorParam(code)); | 283 LogErrorToConsole(web_contents, code, GetStatusParam(code)); |
| 284 } else { | |
| 285 // Ensure that we haven't yet logged a status code for this page. Only | |
| 286 // log status for pages where we are not in debug mode to avoid skew. | |
| 287 DCHECK(need_to_log_status_); | |
| 288 TrackInstallableStatusCode(code); | |
| 289 need_to_log_status_ = false; | |
| 290 } | |
| 276 } | 291 } |
| 277 | 292 |
| 278 void AppBannerManager::Stop() { | 293 void AppBannerManager::Stop() { |
| 279 if (was_canceled_by_page_ && !page_requested_prompt_) { | 294 if (was_canceled_by_page_ && !page_requested_prompt_) { |
| 280 TrackBeforeInstallEvent( | 295 TrackBeforeInstallEvent( |
| 281 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 296 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| 297 ReportStatus(web_contents(), RENDERER_CANCELLED); | |
| 282 } | 298 } |
| 283 | 299 |
| 300 // Ensure that we've either logged an InstallableStatusCode, or that we're | |
| 301 // still active and waiting for a callback, or that we're in debug mode. The | |
| 302 // final time a status is logged is within the platform-specific ShowBanner() | |
| 303 // implementations, and is_active_ is not reset until those have run and | |
| 304 // logged a status. | |
| 305 DCHECK(!need_to_log_status_ || is_active_ || IsDebugMode()); | |
| 306 | |
| 284 is_active_ = false; | 307 is_active_ = false; |
| 285 was_canceled_by_page_ = false; | 308 was_canceled_by_page_ = false; |
| 286 page_requested_prompt_ = false; | 309 page_requested_prompt_ = false; |
| 310 need_to_log_status_ = false; | |
|
benwells
2016/08/11 07:14:23
I don't understand how this works - won't the DCHE
dominickn
2016/08/11 08:13:38
need_to_log_status_ is set to true in RequestAppBa
benwells
2016/08/12 01:34:23
OK, as discussed offline there might be some subtl
| |
| 287 referrer_.erase(); | 311 referrer_.erase(); |
| 288 } | 312 } |
| 289 | 313 |
| 290 void AppBannerManager::SendBannerPromptRequest() { | 314 void AppBannerManager::SendBannerPromptRequest() { |
| 291 RecordCouldShowBanner(); | 315 RecordCouldShowBanner(); |
| 292 | 316 |
| 293 // Given all of the other checks that have been made, the only possible reason | 317 // Given all of the other checks that have been made, the only possible reason |
| 294 // for stopping now is that the app has been added to the homescreen. | 318 // for stopping now is that the app has been added to the homescreen. |
| 295 if (!IsDebugMode() && !CheckIfShouldShowBanner()) | 319 if (!IsDebugMode() && !CheckIfShouldShowBanner()) { |
|
benwells
2016/08/11 07:14:23
Why is this changing?
dominickn
2016/08/11 08:13:38
The only way is_active_ will be false here is if S
| |
| 296 Stop(); | 320 Stop(); |
| 297 | |
| 298 if (!is_active_) | |
| 299 return; | 321 return; |
| 322 } | |
| 300 | 323 |
| 301 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 324 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 302 event_request_id_ = ++gCurrentRequestID; | 325 event_request_id_ = ++gCurrentRequestID; |
| 303 content::RenderFrameHost* frame = web_contents()->GetMainFrame(); | 326 content::RenderFrameHost* frame = web_contents()->GetMainFrame(); |
| 304 frame->Send(new ChromeViewMsg_AppBannerPromptRequest( | 327 frame->Send(new ChromeViewMsg_AppBannerPromptRequest( |
| 305 frame->GetRoutingID(), event_request_id_, GetBannerType())); | 328 frame->GetRoutingID(), event_request_id_, GetBannerType())); |
| 306 } | 329 } |
| 307 | 330 |
| 308 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { | 331 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { |
| 309 if (!handle->IsInMainFrame()) | 332 if (!handle->IsInMainFrame()) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 Stop(); | 383 Stop(); |
| 361 } | 384 } |
| 362 | 385 |
| 363 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, | 386 void AppBannerManager::OnEngagementIncreased(content::WebContents* contents, |
| 364 const GURL& url, | 387 const GURL& url, |
| 365 double score) { | 388 double score) { |
| 366 // Only trigger a banner using site engagement if: | 389 // Only trigger a banner using site engagement if: |
| 367 // 1. engagement increased for the web contents which we are attached to; and | 390 // 1. engagement increased for the web contents which we are attached to; and |
| 368 // 2. there are no currently active media players; and | 391 // 2. there are no currently active media players; and |
| 369 // 3. we have accumulated sufficient engagement. | 392 // 3. we have accumulated sufficient engagement. |
| 370 if (web_contents() == contents && active_media_players_.empty() && | 393 if (web_contents() == contents && active_media_players_.empty()) { |
| 371 AppBannerSettingsHelper::HasSufficientEngagement(score)) { | 394 if (AppBannerSettingsHelper::HasSufficientEngagement(score)) { |
|
benwells
2016/08/11 07:14:23
Why is this changing?
dominickn
2016/08/11 08:13:38
Ah, I had a ReportStatus branch here that was remo
| |
| 372 // Stop observing so we don't double-trigger the banner. | 395 // Stop observing so we don't double-trigger the banner. |
| 373 SiteEngagementObserver::Observe(nullptr); | 396 SiteEngagementObserver::Observe(nullptr); |
| 374 | 397 |
| 375 if (!load_finished_) { | 398 if (!load_finished_) { |
| 376 // Wait until the main frame finishes loading before requesting a banner. | 399 // Queue the banner request until the main frame finishes loading. |
| 377 banner_request_queued_ = true; | 400 banner_request_queued_ = true; |
| 378 } else { | 401 } else { |
| 379 // Requesting a banner performs some simple tests, creates a data fetcher, | 402 // A banner request performs some simple tests, creates a data fetcher, |
| 380 // and starts some asynchronous checks to test installability. It should | 403 // and starts some asynchronous checks to test installability. It should |
| 381 // be safe to start this in response to user input. | 404 // be safe to start this in response to user input. |
| 382 RequestAppBanner(url, false /* is_debug_mode */); | 405 RequestAppBanner(url, false /* is_debug_mode */); |
| 406 } | |
| 383 } | 407 } |
| 384 } | 408 } |
| 385 } | 409 } |
| 386 | 410 |
| 387 void AppBannerManager::RecordCouldShowBanner() { | 411 void AppBannerManager::RecordCouldShowBanner() { |
| 388 content::WebContents* contents = web_contents(); | 412 content::WebContents* contents = web_contents(); |
| 389 DCHECK(contents); | 413 DCHECK(contents); |
| 390 | 414 |
| 391 AppBannerSettingsHelper::RecordBannerCouldShowEvent( | 415 AppBannerSettingsHelper::RecordBannerCouldShowEvent( |
| 392 contents, validated_url_, GetAppIdentifier(), | 416 contents, validated_url_, GetAppIdentifier(), |
| 393 GetCurrentTime(), last_transition_type_); | 417 GetCurrentTime(), last_transition_type_); |
| 394 } | 418 } |
| 395 | 419 |
| 396 bool AppBannerManager::CheckIfShouldShowBanner() { | 420 bool AppBannerManager::CheckIfShouldShowBanner() { |
| 397 content::WebContents* contents = web_contents(); | 421 content::WebContents* contents = web_contents(); |
| 398 DCHECK(contents); | 422 DCHECK(contents); |
| 399 | 423 |
| 400 return AppBannerSettingsHelper::ShouldShowBanner( | 424 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( |
| 401 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 425 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 426 if (code == NO_ERROR_DETECTED) | |
| 427 return true; | |
| 428 | |
| 429 DCHECK(!IsDebugMode()); | |
|
benwells
2016/08/11 07:14:23
Could you have a comment explaining why this DCHEC
dominickn
2016/08/11 08:13:38
Done.
| |
| 430 ReportStatus(web_contents(), code); | |
| 431 return false; | |
| 402 } | 432 } |
| 403 | 433 |
| 404 bool AppBannerManager::OnMessageReceived( | 434 bool AppBannerManager::OnMessageReceived( |
| 405 const IPC::Message& message, | 435 const IPC::Message& message, |
| 406 content::RenderFrameHost* render_frame_host) { | 436 content::RenderFrameHost* render_frame_host) { |
| 407 bool handled = true; | 437 bool handled = true; |
| 408 | 438 |
| 409 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerManager, message, render_frame_host) | 439 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerManager, message, render_frame_host) |
| 410 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AppBannerPromptReply, | 440 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AppBannerPromptReply, |
| 411 OnBannerPromptReply) | 441 OnBannerPromptReply) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 432 // called if a redisplay isn't asked for. | 462 // called if a redisplay isn't asked for. |
| 433 // | 463 // |
| 434 // We use the additional page_requested_prompt_ variable because the redisplay | 464 // We use the additional page_requested_prompt_ variable because the redisplay |
| 435 // request may be received *before* the Cancel prompt reply (e.g. if redisplay | 465 // request may be received *before* the Cancel prompt reply (e.g. if redisplay |
| 436 // is requested in the beforeinstallprompt event handler). | 466 // is requested in the beforeinstallprompt event handler). |
| 437 referrer_ = referrer; | 467 referrer_ = referrer; |
| 438 if (reply == blink::WebAppBannerPromptReply::Cancel && | 468 if (reply == blink::WebAppBannerPromptReply::Cancel && |
| 439 !page_requested_prompt_) { | 469 !page_requested_prompt_) { |
| 440 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); | 470 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); |
| 441 was_canceled_by_page_ = true; | 471 was_canceled_by_page_ = true; |
| 442 ReportError(contents, RENDERER_CANCELLED); | |
| 443 return; | 472 return; |
| 444 } | 473 } |
| 445 | 474 |
| 446 // If we haven't yet returned, but either of |was_canceled_by_page_| or | 475 // If we haven't yet returned, but either of |was_canceled_by_page_| or |
| 447 // |page_requested_prompt_| is true, the page has requested a delayed showing | 476 // |page_requested_prompt_| is true, the page has requested a delayed showing |
| 448 // of the prompt. Otherwise, the prompt was never canceled by the page. | 477 // of the prompt. Otherwise, the prompt was never canceled by the page. |
| 449 if (was_canceled_by_page_ || page_requested_prompt_) { | 478 if (was_canceled_by_page_ || page_requested_prompt_) { |
| 450 TrackBeforeInstallEvent( | 479 TrackBeforeInstallEvent( |
| 451 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); | 480 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); |
| 452 was_canceled_by_page_ = false; | 481 was_canceled_by_page_ = false; |
| 453 } else { | 482 } else { |
| 454 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); | 483 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); |
| 455 } | 484 } |
| 456 | 485 |
| 457 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( | 486 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( |
| 458 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 487 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 459 | 488 |
| 460 DCHECK(!manifest_url_.is_empty()); | 489 DCHECK(!manifest_url_.is_empty()); |
| 461 DCHECK(!manifest_.IsEmpty()); | 490 DCHECK(!manifest_.IsEmpty()); |
| 462 DCHECK(!icon_url_.is_empty()); | 491 DCHECK(!icon_url_.is_empty()); |
| 463 DCHECK(icon_.get()); | 492 DCHECK(icon_.get()); |
| 493 | |
| 464 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); | 494 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); |
| 465 ShowBanner(); | 495 ShowBanner(); |
| 466 is_active_ = false; | 496 is_active_ = false; |
| 467 } | 497 } |
| 468 | 498 |
| 469 void AppBannerManager::OnRequestShowAppBanner( | 499 void AppBannerManager::OnRequestShowAppBanner( |
| 470 content::RenderFrameHost* render_frame_host, | 500 content::RenderFrameHost* render_frame_host, |
| 471 int request_id) { | 501 int request_id) { |
| 472 if (was_canceled_by_page_) { | 502 if (was_canceled_by_page_) { |
| 473 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 503 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 474 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 504 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 475 OnBannerPromptReply(render_frame_host, request_id, | 505 OnBannerPromptReply(render_frame_host, request_id, |
| 476 blink::WebAppBannerPromptReply::None, referrer_); | 506 blink::WebAppBannerPromptReply::None, referrer_); |
| 477 } else { | 507 } else { |
| 478 // Log that the prompt request was made for when we get the prompt reply. | 508 // Log that the prompt request was made for when we get the prompt reply. |
| 479 page_requested_prompt_ = true; | 509 page_requested_prompt_ = true; |
| 480 } | 510 } |
| 481 } | 511 } |
| 482 | 512 |
| 483 } // namespace banners | 513 } // namespace banners |
| OLD | NEW |