| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/js_modal_dialog.h" | 5 #include "chrome/browser/js_modal_dialog.h" | 
| 6 | 6 | 
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" | 
| 8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" | 
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" | 
| 10 #include "chrome/browser/native_app_modal_dialog.h" | 10 #include "chrome/browser/native_app_modal_dialog.h" | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102   if (is_before_unload_dialog_) | 102   if (is_before_unload_dialog_) | 
| 103     browser_shutdown::SetTryingToQuit(false); | 103     browser_shutdown::SetTryingToQuit(false); | 
| 104 | 104 | 
| 105   // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame | 105   // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame | 
| 106   // will receive its activation messages before this dialog receives | 106   // will receive its activation messages before this dialog receives | 
| 107   // WM_DESTROY. The parent frame would then try to activate any modal dialogs | 107   // WM_DESTROY. The parent frame would then try to activate any modal dialogs | 
| 108   // that were still open in the ModalDialogQueue, which would send activation | 108   // that were still open in the ModalDialogQueue, which would send activation | 
| 109   // back to this one. The framework should be improved to handle this, so this | 109   // back to this one. The framework should be improved to handle this, so this | 
| 110   // is a temporary workaround. | 110   // is a temporary workaround. | 
| 111   CompleteDialog(); | 111   CompleteDialog(); | 
| 112 | 112   UpdateDelegate(false, L"", suppress_js_messages); | 
| 113   if (!skip_this_dialog_) { |  | 
| 114     delegate_->OnMessageBoxClosed(reply_msg_, false, std::wstring()); |  | 
| 115     if (suppress_js_messages) |  | 
| 116       delegate_->SetSuppressMessageBoxes(true); |  | 
| 117   } |  | 
| 118 |  | 
| 119   Cleanup(); |  | 
| 120 } | 113 } | 
| 121 | 114 | 
| 122 void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text, | 115 void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text, | 
| 123                                         bool suppress_js_messages) { | 116                                         bool suppress_js_messages) { | 
| 124   CompleteDialog(); | 117   CompleteDialog(); | 
| 125 | 118   UpdateDelegate(true, prompt_text, suppress_js_messages); | 
| 126   if (!skip_this_dialog_) { |  | 
| 127     delegate_->OnMessageBoxClosed(reply_msg_, true, prompt_text); |  | 
| 128     if (suppress_js_messages) |  | 
| 129       delegate_->SetSuppressMessageBoxes(true); |  | 
| 130   } |  | 
| 131 |  | 
| 132   Cleanup(); |  | 
| 133 } | 119 } | 
| 134 | 120 | 
| 135 void JavaScriptAppModalDialog::OnClose() { | 121 void JavaScriptAppModalDialog::OnClose() { | 
| 136   Cleanup(); | 122   // Should we be handling suppress here too? See crbug.com/65008. | 
|  | 123   UpdateDelegate(false, L"", false); | 
| 137 } | 124 } | 
| 138 | 125 | 
| 139 void JavaScriptAppModalDialog::Cleanup() { | 126 void JavaScriptAppModalDialog::UpdateDelegate(bool success, | 
| 140   if (skip_this_dialog_) { | 127                                               const std::wstring& prompt_text, | 
| 141     // We can't use the |delegate_|, because we might be in the process of | 128                                               bool suppress_js_messages) { | 
| 142     // destroying it. | 129   if (skip_this_dialog_) | 
| 143     if (tab_contents_) | 130     return; | 
| 144       tab_contents_->OnMessageBoxClosed(reply_msg_, false, L""); | 131 | 
| 145 // The extension_host_ will always be a dirty pointer on OS X because the alert | 132   delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text); | 
| 146 // window will cause the extension popup to close since it is resigning its key | 133   if (suppress_js_messages) | 
| 147 // state, destroying the host. http://crbug.com/29355 | 134     delegate_->SetSuppressMessageBoxes(true); | 
| 148 #if !defined(OS_MACOSX) |  | 
| 149     else if (extension_host_) |  | 
| 150       extension_host_->OnMessageBoxClosed(reply_msg_, false, L""); |  | 
| 151     else |  | 
| 152       NOTREACHED(); |  | 
| 153 #endif |  | 
| 154   } |  | 
| 155 } | 135 } | 
| OLD | NEW | 
|---|