Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc

Issue 2491163002: Log to the console when a dialog is suppressed or would be. (Closed)
Patch Set: drop the second one Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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;
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 make sure your dialogs are triggered by user interactions "
95 "to avoid this situation. "
96 "https://www.chromestatus.com/feature/5637107137642496");
89 return; 97 return;
90 } 98 }
91 99
92 if (dialog_) { 100 if (dialog_) {
93 // There's already a dialog up; clear it out. 101 // There's already a dialog up; clear it out.
94 CloseDialog(false, false, base::string16()); 102 CloseDialog(false, false, base::string16());
95 } 103 }
96 104
97 base::string16 title = 105 base::string16 title =
98 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); 106 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 DCHECK(dialog_); 216 DCHECK(dialog_);
209 217
210 dialog_->CloseDialogWithoutCallback(); 218 dialog_->CloseDialogWithoutCallback();
211 if (!suppress_callback) 219 if (!suppress_callback)
212 dialog_callback_.Run(success, user_input); 220 dialog_callback_.Run(success, user_input);
213 221
214 dialog_.reset(); 222 dialog_.reset();
215 dialog_callback_.Reset(); 223 dialog_callback_.Reset();
216 BrowserList::RemoveObserver(this); 224 BrowserList::RemoveObserver(this);
217 } 225 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698