Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/javascript_dialogs/javascript_dialog_tab_helper.h" | 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/engagement/site_engagement_service.h" | 9 #include "chrome/browser/engagement/site_engagement_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
| 43 const GURL& origin_url, | 43 const GURL& origin_url, |
| 44 content::JavaScriptMessageType message_type, | 44 content::JavaScriptMessageType message_type, |
| 45 const base::string16& message_text, | 45 const base::string16& message_text, |
| 46 const base::string16& default_prompt_text, | 46 const base::string16& default_prompt_text, |
| 47 const DialogClosedCallback& callback, | 47 const DialogClosedCallback& callback, |
| 48 bool* did_suppress_message) { | 48 bool* did_suppress_message) { |
| 49 SiteEngagementService* site_engagement_service = SiteEngagementService::Get( | 49 SiteEngagementService* site_engagement_service = SiteEngagementService::Get( |
| 50 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 50 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| 51 double engagement_score = site_engagement_service->GetScore(origin_url); | 51 double engagement_score = site_engagement_service->GetScore(origin_url); |
| 52 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfDialogs", | 52 switch (message_type) { |
| 53 engagement_score); | 53 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: |
| 54 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfDialogs.Alert", | |
| 55 engagement_score); | |
| 56 break; | |
| 57 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: | |
| 58 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfDialogs.Confirm", | |
| 59 engagement_score); | |
| 60 break; | |
| 61 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: | |
| 62 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfDialogs.Prompt", | |
| 63 engagement_score); | |
| 64 break; | |
| 65 } | |
| 54 int32_t message_length = static_cast<int32_t>(message_text.length()); | 66 int32_t message_length = static_cast<int32_t>(message_text.length()); |
| 55 if (engagement_score == 0) { | 67 if (engagement_score == 0) { |
| 56 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementNone", | 68 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementNone", |
| 57 message_length); | 69 message_length); |
| 58 } else if (engagement_score < 1) { | 70 } else if (engagement_score < 1) { |
| 59 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementLessThanOne", | 71 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementLessThanOne", |
| 60 message_length); | 72 message_length); |
| 61 } else if (engagement_score < 5) { | 73 } else if (engagement_score < 5) { |
| 62 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementOneToFive", | 74 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementOneToFive", |
| 63 message_length); | 75 message_length); |
| 64 } else { | 76 } else { |
| 65 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementHigher", | 77 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementHigher", |
| 66 message_length); | 78 message_length); |
| 67 } | 79 } |
| 68 | 80 |
| 69 if (IsEnabled()) { | 81 if (IsEnabled()) { |
| 70 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; | 82 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; |
| 71 } else { | 83 } else { |
| 72 AppModalDialogManager()->RunJavaScriptDialog( | 84 AppModalDialogManager()->RunJavaScriptDialog( |
| 73 web_contents, origin_url, message_type, message_text, | 85 web_contents, origin_url, message_type, message_text, |
| 74 default_prompt_text, callback, did_suppress_message); | 86 default_prompt_text, callback, did_suppress_message); |
| 75 } | 87 } |
| 76 | 88 |
| 77 if (did_suppress_message) { | 89 if (did_suppress_message) { |
| 78 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCountUserSuppressed", | 90 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCountUserSuppressed", |
| 79 message_length); | 91 message_length); |
| 80 } | 92 } |
| 81 } | 93 } |
| 82 | 94 |
| 95 namespace { | |
| 96 | |
| 97 void SaveUnloadUmaStats( | |
| 98 double engagement_score, | |
| 99 content::JavaScriptDialogManager::DialogClosedCallback callback, | |
| 100 bool success, | |
| 101 const base::string16& user_input) { | |
| 102 if (success) { | |
| 103 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfBeforeUnload.Leave", | |
| 104 engagement_score); | |
| 105 } else { | |
| 106 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteEngagementOfBeforeUnload.Stay", | |
| 107 engagement_score); | |
| 108 } | |
| 109 | |
| 110 callback.Run(success, user_input); | |
| 111 } | |
| 112 | |
| 113 } // namespace | |
| 114 | |
| 83 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( | 115 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( |
| 84 content::WebContents* web_contents, | 116 content::WebContents* web_contents, |
| 85 bool is_reload, | 117 bool is_reload, |
| 86 const DialogClosedCallback& callback) { | 118 const DialogClosedCallback& callback) { |
| 87 Profile* profile = | |
| 88 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 89 SiteEngagementService* site_engagement_service = | |
| 90 SiteEngagementService::Get(profile); | |
| 91 UMA_HISTOGRAM_PERCENTAGE( | |
| 92 "JSDialogs.SiteEngagementOfBeforeUnload", | |
| 93 site_engagement_service->GetScore(web_contents->GetLastCommittedURL())); | |
| 94 | |
| 95 // onbeforeunload dialogs are always handled with an app-modal dialog, because | 119 // onbeforeunload dialogs are always handled with an app-modal dialog, because |
| 96 // - they are critical to the user not losing data | 120 // - they are critical to the user not losing data |
| 97 // - they can be requested for tabs that are not foremost | 121 // - they can be requested for tabs that are not foremost |
| 98 // - they can be requested for many tabs at the same time | 122 // - they can be requested for many tabs at the same time |
| 99 // and therefore auto-dismissal is inappropriate for them. | 123 // and therefore auto-dismissal is inappropriate for them. |
| 100 | 124 |
| 125 Profile* profile = | |
| 126 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 127 SiteEngagementService* site_engagement_service = | |
| 128 SiteEngagementService::Get(profile); | |
| 129 double engagement_score = | |
| 130 site_engagement_service->GetScore(web_contents->GetLastCommittedURL()); | |
| 131 | |
| 132 base::Bind(&SaveUnloadUmaStats, engagement_score, callback); | |
|
Alexei Svitkine (slow)
2016/09/19 19:54:59
Er, shouldn't you be doing something with the retu
Avi (use Gerrit)
2016/09/19 20:46:21
Ugh.
I forgot to save, I did git cl format, and t
| |
| 133 | |
| 101 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, | 134 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, |
| 102 callback); | 135 callback); |
| 103 } | 136 } |
| 104 | 137 |
| 105 bool JavaScriptDialogTabHelper::HandleJavaScriptDialog( | 138 bool JavaScriptDialogTabHelper::HandleJavaScriptDialog( |
| 106 content::WebContents* web_contents, | 139 content::WebContents* web_contents, |
| 107 bool accept, | 140 bool accept, |
| 108 const base::string16* prompt_override) { | 141 const base::string16* prompt_override) { |
| 109 if (!IsEnabled()) { | 142 if (!IsEnabled()) { |
| 110 return AppModalDialogManager()->HandleJavaScriptDialog(web_contents, accept, | 143 return AppModalDialogManager()->HandleJavaScriptDialog(web_contents, accept, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 124 } | 157 } |
| 125 | 158 |
| 126 void JavaScriptDialogTabHelper::ResetDialogState( | 159 void JavaScriptDialogTabHelper::ResetDialogState( |
| 127 content::WebContents* web_contents) { | 160 content::WebContents* web_contents) { |
| 128 // Reset any app-modal dialog state that may exist. | 161 // Reset any app-modal dialog state that may exist. |
| 129 if (!IsEnabled()) | 162 if (!IsEnabled()) |
| 130 return AppModalDialogManager()->ResetDialogState(web_contents); | 163 return AppModalDialogManager()->ResetDialogState(web_contents); |
| 131 | 164 |
| 132 // More work here for the auto-dismissing dialogs. | 165 // More work here for the auto-dismissing dialogs. |
| 133 } | 166 } |
| OLD | NEW |