OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/app_modal/javascript_app_modal_dialog.h" | 5 #include "components/app_modal/javascript_app_modal_dialog.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "components/app_modal/javascript_dialog_manager.h" | 10 #include "components/app_modal/javascript_dialog_manager.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { | 85 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { |
86 return JavaScriptDialogManager::GetInstance() | 86 return JavaScriptDialogManager::GetInstance() |
87 ->native_dialog_factory() | 87 ->native_dialog_factory() |
88 ->CreateNativeJavaScriptDialog(this); | 88 ->CreateNativeJavaScriptDialog(this); |
89 } | 89 } |
90 | 90 |
91 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { | 91 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 void JavaScriptAppModalDialog::Invalidate() { | 95 void JavaScriptAppModalDialog::Invalidate(bool suppress_callbacks) { |
96 if (!IsValid()) | 96 if (!IsValid()) |
97 return; | 97 return; |
98 | 98 |
99 AppModalDialog::Invalidate(); | 99 AppModalDialog::Invalidate(suppress_callbacks); |
100 CallDialogClosedCallback(false, base::string16()); | 100 if (!suppress_callbacks) |
| 101 CallDialogClosedCallback(false, base::string16()); |
101 if (native_dialog()) | 102 if (native_dialog()) |
102 CloseModalDialog(); | 103 CloseModalDialog(); |
103 } | 104 } |
104 | 105 |
105 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { | 106 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { |
106 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame | 107 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame |
107 // will receive its activation messages before this dialog receives | 108 // will receive its activation messages before this dialog receives |
108 // WM_DESTROY. The parent frame would then try to activate any modal dialogs | 109 // WM_DESTROY. The parent frame would then try to activate any modal dialogs |
109 // that were still open in the ModalDialogQueue, which would send activation | 110 // that were still open in the ModalDialogQueue, which would send activation |
110 // back to this one. The framework should be improved to handle this, so this | 111 // back to this one. The framework should be improved to handle this, so this |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // data from the map owned by ::JavaScriptDialogManager. Make sure | 148 // data from the map owned by ::JavaScriptDialogManager. Make sure |
148 // to only use the data if still present. http://crbug.com/236476 | 149 // to only use the data if still present. http://crbug.com/236476 |
149 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); | 150 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); |
150 if (extra_data != extra_data_map_->end()) { | 151 if (extra_data != extra_data_map_->end()) { |
151 extra_data->second.has_already_shown_a_dialog_ = true; | 152 extra_data->second.has_already_shown_a_dialog_ = true; |
152 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; | 153 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; |
153 } | 154 } |
154 | 155 |
155 // On Views, we can end up coming through this code path twice :(. | 156 // On Views, we can end up coming through this code path twice :(. |
156 // See crbug.com/63732. | 157 // See crbug.com/63732. |
157 AppModalDialog::Invalidate(); | 158 AppModalDialog::Invalidate(false); |
158 } | 159 } |
159 | 160 |
160 void JavaScriptAppModalDialog::CallDialogClosedCallback(bool success, | 161 void JavaScriptAppModalDialog::CallDialogClosedCallback(bool success, |
161 const base::string16& user_input) { | 162 const base::string16& user_input) { |
162 // TODO(joenotcharles): Both the callers of this function also check IsValid | 163 // TODO(joenotcharles): Both the callers of this function also check IsValid |
163 // and call AppModalDialog::Invalidate, but in different orders. If the | 164 // and call AppModalDialog::Invalidate, but in different orders. If the |
164 // difference is not significant, more common code could be moved here. | 165 // difference is not significant, more common code could be moved here. |
165 UMA_HISTOGRAM_MEDIUM_TIMES( | 166 UMA_HISTOGRAM_MEDIUM_TIMES( |
166 "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndSameDialogClosed", | 167 "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndSameDialogClosed", |
167 base::TimeTicks::Now() - creation_time_); | 168 base::TimeTicks::Now() - creation_time_); |
168 if (!callback_.is_null()) { | 169 if (!callback_.is_null()) { |
169 callback_.Run(success, user_input); | 170 callback_.Run(success, user_input); |
170 callback_.Reset(); | 171 callback_.Reset(); |
171 } | 172 } |
172 } | 173 } |
173 | 174 |
174 } // namespace app_modal | 175 } // namespace app_modal |
OLD | NEW |