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" | |
| 9 #include "chrome/browser/engagement/site_engagement_service.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "components/app_modal/javascript_dialog_manager.h" | 11 #include "components/app_modal/javascript_dialog_manager.h" |
| 9 | 12 |
| 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 const base::Feature kAutoDismissingDialogsFeature{ | 17 const base::Feature kAutoDismissingDialogsFeature{ |
| 15 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; | 18 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 16 | 19 |
| 17 bool IsEnabled() { | 20 bool IsEnabled() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 36 } | 39 } |
| 37 | 40 |
| 38 void JavaScriptDialogTabHelper::RunJavaScriptDialog( | 41 void JavaScriptDialogTabHelper::RunJavaScriptDialog( |
| 39 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
| 40 const GURL& origin_url, | 43 const GURL& origin_url, |
| 41 content::JavaScriptMessageType message_type, | 44 content::JavaScriptMessageType message_type, |
| 42 const base::string16& message_text, | 45 const base::string16& message_text, |
| 43 const base::string16& default_prompt_text, | 46 const base::string16& default_prompt_text, |
| 44 const DialogClosedCallback& callback, | 47 const DialogClosedCallback& callback, |
| 45 bool* did_suppress_message) { | 48 bool* did_suppress_message) { |
| 46 if (!IsEnabled()) { | 49 Profile* profile = |
|
dominickn
2016/09/06 23:50:29
Minor nit - you could inline the Profile::FromBrow
Avi (use Gerrit)
2016/09/07 16:41:55
Done.
| |
| 47 return AppModalDialogManager()->RunJavaScriptDialog( | 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 51 SiteEngagementService* site_engagement_service = | |
| 52 SiteEngagementService::Get(profile); | |
| 53 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteKarmaOfDialogs", | |
| 54 site_engagement_service->GetScore(origin_url)); | |
| 55 int32_t message_length = static_cast<int32_t>(message_text.length()); | |
| 56 switch (site_engagement_service->GetEngagementLevel(origin_url)) { | |
| 57 case SiteEngagementService::ENGAGEMENT_LEVEL_NONE: { | |
|
dominickn
2016/09/06 23:50:29
I think it might be better to base these histogram
Avi (use Gerrit)
2016/09/07 16:41:55
Done.
Also, is it OK to use "karma" as a term in
| |
| 58 UMA_HISTOGRAM_COUNTS( | |
| 59 "JSDialogs.CountOfJSDialogMessageCharactersKarmaNone", | |
| 60 message_length); | |
| 61 break; | |
| 62 } | |
| 63 | |
| 64 case SiteEngagementService::ENGAGEMENT_LEVEL_LOW: { | |
| 65 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfJSDialogMessageCharactersKarmaLow", | |
| 66 message_length); | |
| 67 break; | |
| 68 } | |
| 69 | |
| 70 default: { | |
| 71 UMA_HISTOGRAM_COUNTS( | |
| 72 "JSDialogs.CountOfJSDialogMessageCharactersKarmaHigher", | |
| 73 message_length); | |
| 74 break; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 if (IsEnabled()) { | |
| 79 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; | |
| 80 } else { | |
| 81 AppModalDialogManager()->RunJavaScriptDialog( | |
| 48 web_contents, origin_url, message_type, message_text, | 82 web_contents, origin_url, message_type, message_text, |
| 49 default_prompt_text, callback, did_suppress_message); | 83 default_prompt_text, callback, did_suppress_message); |
| 50 } | 84 } |
| 51 | 85 |
| 52 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; | 86 if (did_suppress_message) { |
| 87 UMA_HISTOGRAM_COUNTS( | |
| 88 "JSDialogs.CountOfJSDialogMessageCharactersUserSuppressed", | |
| 89 message_length); | |
| 90 } | |
| 53 } | 91 } |
| 54 | 92 |
| 55 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( | 93 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( |
| 56 content::WebContents* web_contents, | 94 content::WebContents* web_contents, |
| 57 bool is_reload, | 95 bool is_reload, |
| 58 const DialogClosedCallback& callback) { | 96 const DialogClosedCallback& callback) { |
| 97 Profile* profile = | |
| 98 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 99 SiteEngagementService* site_engagement_service = | |
| 100 SiteEngagementService::Get(profile); | |
| 101 UMA_HISTOGRAM_PERCENTAGE( | |
| 102 "JSDialogs.SiteKarmaOfBeforeUnload", | |
| 103 site_engagement_service->GetScore(web_contents->GetLastCommittedURL())); | |
| 104 | |
| 59 // onbeforeunload dialogs are always handled with an app-modal dialog, because | 105 // onbeforeunload dialogs are always handled with an app-modal dialog, because |
| 60 // - they are critical to the user not losing data | 106 // - they are critical to the user not losing data |
| 61 // - they can be requested for tabs that are not foremost | 107 // - they can be requested for tabs that are not foremost |
| 62 // - they can be requested for many tabs at the same time | 108 // - they can be requested for many tabs at the same time |
| 63 // and therefore auto-dismissal is inappropriate for them. | 109 // and therefore auto-dismissal is inappropriate for them. |
| 64 | 110 |
| 65 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, | 111 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, |
| 66 callback); | 112 callback); |
| 67 } | 113 } |
| 68 | 114 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 88 } | 134 } |
| 89 | 135 |
| 90 void JavaScriptDialogTabHelper::ResetDialogState( | 136 void JavaScriptDialogTabHelper::ResetDialogState( |
| 91 content::WebContents* web_contents) { | 137 content::WebContents* web_contents) { |
| 92 // Reset any app-modal dialog state that may exist. | 138 // Reset any app-modal dialog state that may exist. |
| 93 if (!IsEnabled()) | 139 if (!IsEnabled()) |
| 94 return AppModalDialogManager()->ResetDialogState(web_contents); | 140 return AppModalDialogManager()->ResetDialogState(web_contents); |
| 95 | 141 |
| 96 // More work here for the auto-dismissing dialogs. | 142 // More work here for the auto-dismissing dialogs. |
| 97 } | 143 } |
| OLD | NEW |