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/feature_list.h" | 8 #include "base/feature_list.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "build/build_config.h" | |
10 #include "chrome/browser/engagement/site_engagement_service.h" | 11 #include "chrome/browser/engagement/site_engagement_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_views.h" | 15 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_views.h" |
15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 16 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "components/app_modal/javascript_dialog_manager.h" | 18 #include "components/app_modal/javascript_dialog_manager.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
19 | 20 |
21 #if defined(OS_MACOSX) | |
22 #include "chrome/browser/ui/browser_dialogs.h" | |
23 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_cocoa.h" | |
24 #endif | |
25 | |
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); | 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
21 | 27 |
22 namespace { | 28 namespace { |
23 | 29 |
24 const base::Feature kAutoDismissingDialogsFeature{ | 30 const base::Feature kAutoDismissingDialogsFeature{ |
25 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; | 31 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; |
26 | 32 |
27 bool IsEnabled() { | 33 bool IsEnabled() { |
28 return base::FeatureList::IsEnabled(kAutoDismissingDialogsFeature); | 34 return base::FeatureList::IsEnabled(kAutoDismissingDialogsFeature); |
29 } | 35 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // There's already a dialog up; clear it out. | 98 // There's already a dialog up; clear it out. |
93 CloseDialog(false, false, base::string16()); | 99 CloseDialog(false, false, base::string16()); |
94 } | 100 } |
95 | 101 |
96 parent_web_contents->GetDelegate()->ActivateContents(parent_web_contents); | 102 parent_web_contents->GetDelegate()->ActivateContents(parent_web_contents); |
97 | 103 |
98 base::string16 title = | 104 base::string16 title = |
99 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); | 105 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); |
100 dialog_callback_ = callback; | 106 dialog_callback_ = callback; |
101 BrowserList::AddObserver(this); | 107 BrowserList::AddObserver(this); |
102 // TODO(avi): abstract out so that we have a Mac version too... | 108 #if defined(OS_MACOSX) |
Robert Sesek
2016/10/27 15:17:24
Alternatively, this block could be in JavaScriptDi
Avi (use Gerrit)
2016/10/27 18:41:22
Yes, that would be cleaner. Done.
| |
103 dialog_ = JavaScriptDialogViews::Create( | 109 if (!chrome::ToolkitViewsWebUIDialogsEnabled()) { |
104 parent_web_contents, alerting_web_contents, title, message_type, | 110 dialog_ = JavaScriptDialogCocoa::Create( |
105 message_text, default_prompt_text, callback); | 111 parent_web_contents, alerting_web_contents, title, message_type, |
112 message_text, default_prompt_text, callback); | |
113 } else { | |
114 #endif | |
115 dialog_ = JavaScriptDialogViews::Create( | |
116 parent_web_contents, alerting_web_contents, title, message_type, | |
117 message_text, default_prompt_text, callback); | |
118 #if defined(OS_MACOSX) | |
119 } | |
120 #endif | |
106 | 121 |
107 // Message suppression is something that we don't give the user a checkbox | 122 // Message suppression is something that we don't give the user a checkbox |
108 // for any more. It was useful back in the day when dialogs were app-modal | 123 // for any more. It was useful back in the day when dialogs were app-modal |
109 // and clicking the checkbox was the only way to escape a loop that the page | 124 // and clicking the checkbox was the only way to escape a loop that the page |
110 // was doing, but now the user can just close the page. | 125 // was doing, but now the user can just close the page. |
111 *did_suppress_message = false; | 126 *did_suppress_message = false; |
112 } else { | 127 } else { |
113 AppModalDialogManager()->RunJavaScriptDialog( | 128 AppModalDialogManager()->RunJavaScriptDialog( |
114 alerting_web_contents, origin_url, message_type, message_text, | 129 alerting_web_contents, origin_url, message_type, message_text, |
115 default_prompt_text, callback, did_suppress_message); | 130 default_prompt_text, callback, did_suppress_message); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 DCHECK(dialog_); | 219 DCHECK(dialog_); |
205 | 220 |
206 dialog_->CloseDialogWithoutCallback(); | 221 dialog_->CloseDialogWithoutCallback(); |
207 if (!suppress_callback) | 222 if (!suppress_callback) |
208 dialog_callback_.Run(success, user_input); | 223 dialog_callback_.Run(success, user_input); |
209 | 224 |
210 dialog_.reset(); | 225 dialog_.reset(); |
211 dialog_callback_.Reset(); | 226 dialog_callback_.Reset(); |
212 BrowserList::RemoveObserver(this); | 227 BrowserList::RemoveObserver(this); |
213 } | 228 } |
OLD | NEW |