summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-20 12:50:36 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-20 12:50:36 +0000
commita6539cdfd95230b96139971a4248a5ce79603c93 (patch)
treecb8a4e1c3508a2a46b8f640f8e7fd30942f70057
parente13b0cb18276b22d83f9a059ddf81d4ebb074c3b (diff)
downloadchromium_src-a6539cdfd95230b96139971a4248a5ce79603c93.zip
chromium_src-a6539cdfd95230b96139971a4248a5ce79603c93.tar.gz
chromium_src-a6539cdfd95230b96139971a4248a5ce79603c93.tar.bz2
Refactor Windows MessageBox fallback code.
Inline the Windows-specific NativeShowMessageBox. Pass the parent HWND argument to the underlying call. Use MB_ICONQUESTION for MESSAGE_BOX_TYPE_QUESTION. BUG=NONE TEST=No Win MessageBox regressions; better icon for any fallback question MessageBox. R=sky@chromium.org Review URL: https://codereview.chromium.org/172633004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252197 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/hang_monitor/hung_plugin_action.cc7
-rw-r--r--chrome/browser/ui/simple_message_box.h3
-rw-r--r--chrome/browser/ui/views/simple_message_box_views.cc33
-rw-r--r--chrome/browser/ui/views/simple_message_box_win.cc30
-rw-r--r--chrome/browser/ui/views/simple_message_box_win.h19
-rw-r--r--chrome/chrome_browser_ui.gypi2
6 files changed, 30 insertions, 64 deletions
diff --git a/chrome/browser/hang_monitor/hung_plugin_action.cc b/chrome/browser/hang_monitor/hung_plugin_action.cc
index 4ce6f14..2aa2b4c 100644
--- a/chrome/browser/hang_monitor/hung_plugin_action.cc
+++ b/chrome/browser/hang_monitor/hung_plugin_action.cc
@@ -8,7 +8,7 @@
#include "base/metrics/histogram.h"
#include "base/version.h"
-#include "chrome/browser/ui/views/simple_message_box_win.h"
+#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/common/logging_chrome.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h"
@@ -113,10 +113,7 @@ bool HungPluginAction::OnHungWindowDetected(HWND hung_window,
HungWindowResponseCallback,
reinterpret_cast<ULONG_PTR>(this));
current_hung_plugin_window_ = hung_window;
- // We use chrome::NativeShowMessageBox instead of chrome::ShowMessageBox
- // because the latter depends on UI-thread classes on Win Aura. See
- // http://crbug.com/330424.
- if (chrome::NativeShowMessageBox(
+ if (chrome::ShowMessageBox(
NULL, title, message, chrome::MESSAGE_BOX_TYPE_QUESTION) ==
chrome::MESSAGE_BOX_RESULT_YES) {
*action = HungWindowNotification::HUNG_WINDOW_TERMINATE_PROCESS;
diff --git a/chrome/browser/ui/simple_message_box.h b/chrome/browser/ui/simple_message_box.h
index c289379..e4a155b 100644
--- a/chrome/browser/ui/simple_message_box.h
+++ b/chrome/browser/ui/simple_message_box.h
@@ -19,8 +19,7 @@ enum MessageBoxType {
MESSAGE_BOX_TYPE_INFORMATION, // Shows an OK button.
MESSAGE_BOX_TYPE_WARNING, // Shows an OK button.
MESSAGE_BOX_TYPE_QUESTION, // Shows YES and NO buttons.
- MESSAGE_BOX_TYPE_OK_CANCEL, // Shows OK and CANCEL buttons (Windows or aura
- // only).
+ MESSAGE_BOX_TYPE_OK_CANCEL, // Shows OK and CANCEL buttons (Aura only).
};
// Shows a dialog box with the given |title| and |message|. If |parent| is
diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc
index 3e85e68..146924b 100644
--- a/chrome/browser/ui/views/simple_message_box_views.cc
+++ b/chrome/browser/ui/views/simple_message_box_views.cc
@@ -23,7 +23,8 @@
#include "ui/views/window/dialog_delegate.h"
#if defined(OS_WIN)
-#include "chrome/browser/ui/views/simple_message_box_win.h"
+#include "ui/base/win/message_box_win.h"
+#include "ui/views/win/hwnd_util.h"
#endif
namespace chrome {
@@ -185,18 +186,38 @@ uint32_t SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) {
SimpleMessageBoxViews::~SimpleMessageBoxViews() {
}
+#if defined(OS_WIN)
+UINT GetMessageBoxFlagsFromType(MessageBoxType type) {
+ UINT flags = MB_SETFOREGROUND;
+ switch (type) {
+ case MESSAGE_BOX_TYPE_INFORMATION:
+ return flags | MB_OK | MB_ICONINFORMATION;
+ case MESSAGE_BOX_TYPE_WARNING:
+ return flags | MB_OK | MB_ICONWARNING;
+ case MESSAGE_BOX_TYPE_QUESTION:
+ return flags | MB_YESNO | MB_ICONQUESTION;
+ case MESSAGE_BOX_TYPE_OK_CANCEL:
+ return flags | MB_OKCANCEL | MB_ICONWARNING;
+ }
+ NOTREACHED();
+ return flags | MB_OK | MB_ICONWARNING;
+}
+#endif
+
MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
MessageBoxType type,
const base::string16& yes_text,
const base::string16& no_text) {
-
#if defined(OS_WIN)
- // If we're very early, we can't show a GPU-based dialog, so fallback to
- // plain Windows MessageBox.
- if (!ui::ContextFactory::GetInstance())
- return NativeShowMessageBox(NULL, title, message, type);
+ // GPU-based dialogs can't be used early on; fallback to a Windows MessageBox.
+ if (!ui::ContextFactory::GetInstance()) {
+ int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message,
+ title, GetMessageBoxFlagsFromType(type));
+ return (result == IDYES || result == IDOK) ?
+ MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO;
+ }
#endif
scoped_refptr<SimpleMessageBoxViews> dialog(
diff --git a/chrome/browser/ui/views/simple_message_box_win.cc b/chrome/browser/ui/views/simple_message_box_win.cc
deleted file mode 100644
index c769195..0000000
--- a/chrome/browser/ui/views/simple_message_box_win.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/simple_message_box.h"
-
-#include "ui/base/win/message_box_win.h"
-
-namespace chrome {
-
-MessageBoxResult NativeShowMessageBox(HWND parent,
- const base::string16& title,
- const base::string16& message,
- MessageBoxType type) {
- UINT flags = MB_SETFOREGROUND;
- if (type == MESSAGE_BOX_TYPE_QUESTION) {
- flags |= MB_YESNO;
- } else if (type == MESSAGE_BOX_TYPE_OK_CANCEL) {
- flags |= MB_OKCANCEL;
- } else {
- flags |= MB_OK;
- }
- flags |= ((type == MESSAGE_BOX_TYPE_INFORMATION) ?
- MB_ICONINFORMATION : MB_ICONWARNING);
- int result = ui::MessageBox(parent, message, title, flags);
- return (result == IDYES || result == IDOK) ?
- MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO;
-}
-
-} // namespace chrome
diff --git a/chrome/browser/ui/views/simple_message_box_win.h b/chrome/browser/ui/views/simple_message_box_win.h
deleted file mode 100644
index 9d9b54b..0000000
--- a/chrome/browser/ui/views/simple_message_box_win.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_WIN_H_
-#define CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_WIN_H_
-
-#include "chrome/browser/ui/simple_message_box.h"
-
-namespace chrome {
-
-MessageBoxResult NativeShowMessageBox(HWND parent,
- const base::string16& title,
- const base::string16& message,
- MessageBoxType type);
-
-} // namespace chrome
-
-#endif // CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_WIN_H_
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index a0de1d3..5ecc97d 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -2092,8 +2092,6 @@
'browser/ui/views/signed_certificate_timestamp_info_view.cc',
'browser/ui/views/signed_certificate_timestamp_info_view.h',
'browser/ui/views/simple_message_box_views.cc',
- 'browser/ui/views/simple_message_box_win.cc',
- 'browser/ui/views/simple_message_box_win.h',
'browser/ui/views/speech_recognition_bubble_views.cc',
'browser/ui/views/ssl_client_certificate_selector.cc',
'browser/ui/views/ssl_client_certificate_selector.h',