| 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 "chrome/browser/ui/simple_message_box.h" | 5 #include "chrome/browser/ui/simple_message_box.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
| 15 #include "ui/views/controls/message_box_view.h" | 16 #include "ui/views/controls/message_box_view.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/window/dialog_delegate.h" | 18 #include "ui/views/window/dialog_delegate.h" |
| 18 #include "ui/wm/public/dispatcher_client.h" | 19 #include "ui/wm/public/dispatcher_client.h" |
| 19 | 20 |
| 20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 21 #include "ui/base/win/message_box_win.h" | 22 #include "ui/base/win/message_box_win.h" |
| 22 #include "ui/views/win/hwnd_util.h" | 23 #include "ui/views/win/hwnd_util.h" |
| 23 #endif | 24 #endif |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return flags | MB_OK | MB_ICONWARNING; | 189 return flags | MB_OK | MB_ICONWARNING; |
| 189 } | 190 } |
| 190 #endif | 191 #endif |
| 191 | 192 |
| 192 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, | 193 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
| 193 const base::string16& title, | 194 const base::string16& title, |
| 194 const base::string16& message, | 195 const base::string16& message, |
| 195 MessageBoxType type, | 196 MessageBoxType type, |
| 196 const base::string16& yes_text, | 197 const base::string16& yes_text, |
| 197 const base::string16& no_text) { | 198 const base::string16& no_text) { |
| 198 // Views dialogs cannot be shown outside the UI thread message loop. | 199 // Views dialogs cannot be shown outside the UI thread message loop or if the |
| 200 // ResourceBundle is not initialized yet. |
| 199 // Fallback to logging with a default response or a Windows MessageBox. | 201 // Fallback to logging with a default response or a Windows MessageBox. |
| 202 #if defined(OS_WIN) |
| 200 if (!base::MessageLoopForUI::IsCurrent() || | 203 if (!base::MessageLoopForUI::IsCurrent() || |
| 201 !base::MessageLoopForUI::current()->is_running()) { | 204 !base::MessageLoopForUI::current()->is_running() || |
| 202 #if defined(OS_WIN) | 205 !ResourceBundle::HasSharedInstance()) { |
| 203 int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message, | 206 int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message, |
| 204 title, GetMessageBoxFlagsFromType(type)); | 207 title, GetMessageBoxFlagsFromType(type)); |
| 205 return (result == IDYES || result == IDOK) ? | 208 return (result == IDYES || result == IDOK) ? |
| 206 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO; | 209 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO; |
| 210 } |
| 207 #else | 211 #else |
| 212 if (!base::MessageLoopForUI::IsCurrent() || |
| 213 !ResourceBundle::HasSharedInstance()) { |
| 208 LOG(ERROR) << "Unable to show a dialog outside the UI thread message loop: " | 214 LOG(ERROR) << "Unable to show a dialog outside the UI thread message loop: " |
| 209 << title << " - " << message; | 215 << title << " - " << message; |
| 210 return MESSAGE_BOX_RESULT_NO; | 216 return MESSAGE_BOX_RESULT_NO; |
| 217 } |
| 211 #endif | 218 #endif |
| 212 } | |
| 213 | 219 |
| 214 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; | 220 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; |
| 215 SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews( | 221 SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews( |
| 216 title, | 222 title, |
| 217 message, | 223 message, |
| 218 type, | 224 type, |
| 219 yes_text, | 225 yes_text, |
| 220 no_text, | 226 no_text, |
| 221 parent == NULL, // is_system_modal | 227 parent == NULL, // is_system_modal |
| 222 &result); | 228 &result); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 246 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, | 252 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
| 247 const base::string16& title, | 253 const base::string16& title, |
| 248 const base::string16& message, | 254 const base::string16& message, |
| 249 const base::string16& yes_text, | 255 const base::string16& yes_text, |
| 250 const base::string16& no_text) { | 256 const base::string16& no_text) { |
| 251 return ShowMessageBoxImpl( | 257 return ShowMessageBoxImpl( |
| 252 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); | 258 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); |
| 253 } | 259 } |
| 254 | 260 |
| 255 } // namespace chrome | 261 } // namespace chrome |
| OLD | NEW |