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