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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "chrome/browser/engagement/site_engagement_service.h" | 11 #include "chrome/browser/engagement/site_engagement_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_features.h" | 17 #include "chrome/common/chrome_features.h" |
| 18 #include "components/app_modal/javascript_dialog_manager.h" | 18 #include "components/app_modal/javascript_dialog_manager.h" |
| 19 #include "content/public/browser/render_frame_host.h" | |
| 19 | 20 |
| 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); | 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 bool IsEnabled() { | 25 bool IsEnabled() { |
| 25 return base::FeatureList::IsEnabled(features::kAutoDismissingDialogs); | 26 return base::FeatureList::IsEnabled(features::kAutoDismissingDialogs); |
| 26 } | 27 } |
| 27 | 28 |
| 28 app_modal::JavaScriptDialogManager* AppModalDialogManager() { | 29 app_modal::JavaScriptDialogManager* AppModalDialogManager() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 message_length); | 74 message_length); |
| 74 } else { | 75 } else { |
| 75 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementHigher", | 76 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.EngagementHigher", |
| 76 message_length); | 77 message_length); |
| 77 } | 78 } |
| 78 | 79 |
| 79 if (IsEnabled()) { | 80 if (IsEnabled()) { |
| 80 content::WebContents* parent_web_contents = | 81 content::WebContents* parent_web_contents = |
| 81 WebContentsObserver::web_contents(); | 82 WebContentsObserver::web_contents(); |
| 82 | 83 |
| 83 if (!IsWebContentsForemost(parent_web_contents) && | 84 if (!IsWebContentsForemost(parent_web_contents)) { |
| 84 message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { | 85 if (message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { |
| 85 // Don't allow "prompt" dialogs to steal the user's focus. TODO(avi): | 86 // Don't allow "prompt" dialogs to steal the user's focus. TODO(avi): |
| 86 // Eventually, for subsequent phases of http://bit.ly/project-oldspice, | 87 // Eventually, for subsequent phases of http://bit.ly/project-oldspice, |
| 87 // turn off focus stealing for other dialog types. | 88 // turn off focus stealing for other dialog types. |
| 88 *did_suppress_message = true; | 89 *did_suppress_message = true; |
| 89 return; | 90 alerting_web_contents->GetMainFrame()->AddMessageToConsole( |
| 91 content::CONSOLE_MESSAGE_LEVEL_WARNING, | |
| 92 "A window.prompt() dialog generated by this page was suppressed " | |
| 93 "because this page is not the active tab of the front window. " | |
| 94 "Please do not use dialogs to force browser windows to the front."); | |
|
Rick Byers
2016/11/10 04:18:39
Nit: add chromestatus.com feature link for now (we
Rick Byers
2016/11/10 04:18:39
Is there some way for developers to actually do wh
Avi (use Gerrit)
2016/11/10 21:04:30
What they should do is not use prompt() untriggere
Avi (use Gerrit)
2016/11/10 21:04:30
Done.
Rick Byers
2016/11/11 00:43:33
Sounds good - thanks!
| |
| 95 return; | |
| 96 } | |
| 97 // For now, let them off the hook with a warning. | |
| 98 alerting_web_contents->GetMainFrame()->AddMessageToConsole( | |
| 99 content::CONSOLE_MESSAGE_LEVEL_WARNING, | |
| 100 "A JavaScript dialog was generated by this page while this page was " | |
| 101 "not the active tab of the front window. Such dialogs will soon be " | |
| 102 "suppressed. Please do not use dialogs to force browser windows to " | |
| 103 "the front."); | |
|
Rick Byers
2016/11/10 04:18:39
Do you have UMA data on how often this occurs? We
Avi (use Gerrit)
2016/11/10 21:04:30
No, I don't, unfortunately.
Do you want to not wa
Rick Byers
2016/11/11 00:43:33
I guess I'd rather discuss this one separately - i
| |
| 90 } | 104 } |
| 91 | 105 |
| 92 if (dialog_) { | 106 if (dialog_) { |
| 93 // There's already a dialog up; clear it out. | 107 // There's already a dialog up; clear it out. |
| 94 CloseDialog(false, false, base::string16()); | 108 CloseDialog(false, false, base::string16()); |
| 95 } | 109 } |
| 96 | 110 |
| 97 base::string16 title = | 111 base::string16 title = |
| 98 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); | 112 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); |
| 99 dialog_callback_ = callback; | 113 dialog_callback_ = callback; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 DCHECK(dialog_); | 222 DCHECK(dialog_); |
| 209 | 223 |
| 210 dialog_->CloseDialogWithoutCallback(); | 224 dialog_->CloseDialogWithoutCallback(); |
| 211 if (!suppress_callback) | 225 if (!suppress_callback) |
| 212 dialog_callback_.Run(success, user_input); | 226 dialog_callback_.Run(success, user_input); |
| 213 | 227 |
| 214 dialog_.reset(); | 228 dialog_.reset(); |
| 215 dialog_callback_.Reset(); | 229 dialog_callback_.Reset(); |
| 216 BrowserList::RemoveObserver(this); | 230 BrowserList::RemoveObserver(this); |
| 217 } | 231 } |
| OLD | NEW |