summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc33
-rw-r--r--chrome/browser/hang_monitor/hung_plugin_action.cc4
-rw-r--r--chrome/browser/platform_util.h9
-rw-r--r--chrome/browser/platform_util_common_linux.cc48
-rw-r--r--chrome/browser/platform_util_mac.mm21
-rw-r--r--chrome/browser/platform_util_win.cc7
-rw-r--r--chrome/browser/process_singleton_win.cc4
7 files changed, 77 insertions, 49 deletions
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 1221ae8..331d46c 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -23,6 +23,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/history/query_parser.h"
+#include "chrome/browser/platform_util.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/page_navigator.h"
@@ -164,37 +165,11 @@ bool ShouldOpenAll(gfx::NativeWindow parent,
if (descendant_count < bookmark_utils::num_urls_before_prompting)
return true;
- // Bug 40011: we should refactor this into a cross-platform "prompt before
- // continuing" function.
-#if defined(OS_WIN)
- std::wstring message =
- l10n_util::GetStringF(IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL,
- IntToWString(descendant_count));
- return MessageBox(parent, message.c_str(),
- l10n_util::GetString(IDS_PRODUCT_NAME).c_str(),
- MB_YESNO | MB_ICONWARNING | MB_TOPMOST) == IDYES;
-#elif defined(TOOLKIT_GTK)
- std::string message = l10n_util::GetStringFUTF8(
+ string16 message = l10n_util::GetStringFUTF16(
IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL,
IntToString16(descendant_count));
- GtkWidget* dialog = gtk_message_dialog_new(parent,
- static_cast<GtkDialogFlags>(
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- "%s", message.c_str());
- gtk_util::ApplyMessageDialogQuirks(dialog);
- gtk_window_set_title(GTK_WINDOW(dialog),
- l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
- gint result = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- return (result == GTK_RESPONSE_YES);
-#else
- // TODO(port): Display a dialog prompt.
- // http://crbug.com/34481
- NOTIMPLEMENTED();
- return true;
-#endif
+ string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
+ return platform_util::SimpleYesNoBox(parent, title, message);
}
// Comparison function that compares based on date modified of the two nodes.
diff --git a/chrome/browser/hang_monitor/hung_plugin_action.cc b/chrome/browser/hang_monitor/hung_plugin_action.cc
index 5bed393..5fdcfd1 100644
--- a/chrome/browser/hang_monitor/hung_plugin_action.cc
+++ b/chrome/browser/hang_monitor/hung_plugin_action.cc
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "app/win_util.h"
#include "base/win_util.h"
+#include "chrome/browser/platform_util.h"
#include "chrome/common/logging_chrome.h"
#include "grit/generated_resources.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
@@ -62,8 +63,7 @@ bool HungPluginAction::OnHungWindowDetected(HWND hung_window,
HungWindowResponseCallback,
reinterpret_cast<ULONG_PTR>(this));
current_hung_plugin_window_ = hung_window;
- const UINT mb_flags = MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND;
- if (IDYES == win_util::MessageBox(NULL, msg, title, mb_flags)) {
+ if (platform_util::SimpleYesNoBox(NULL, title, msg)) {
*action = HungWindowNotification::HUNG_WINDOW_TERMINATE_PROCESS;
} else {
// If the user choses to ignore the hung window warning, the
diff --git a/chrome/browser/platform_util.h b/chrome/browser/platform_util.h
index 1f148f4..3278696 100644
--- a/chrome/browser/platform_util.h
+++ b/chrome/browser/platform_util.h
@@ -36,11 +36,18 @@ bool IsVisible(gfx::NativeView view);
// Pops up an error box with an OK button. If |parent| is non-null, the box
// will be modal on it. (On Mac, it is always app-modal.) Generally speaking,
-// this class should not be used for much. Infobars are preferred.
+// this function should not be used for much. Infobars are preferred.
void SimpleErrorBox(gfx::NativeWindow parent,
const string16& title,
const string16& message);
+// Pops up a dialog box with two buttons (Yes/No), with the default button of
+// Yes. If |parent| is non-null, the box will be modal on it. (On Mac, it is
+// always app-modal.) Returns true if the Yes button was chosen.
+bool SimpleYesNoBox(gfx::NativeWindow parent,
+ const string16& title,
+ const string16& message);
+
// Return a human readable modifier for the version string. For a
// branded Chrome (not Chromium), this modifier is the channel (dev,
// beta, stable).
diff --git a/chrome/browser/platform_util_common_linux.cc b/chrome/browser/platform_util_common_linux.cc
index 328d260..80fc66c 100644
--- a/chrome/browser/platform_util_common_linux.cc
+++ b/chrome/browser/platform_util_common_linux.cc
@@ -14,6 +14,28 @@
#include "gfx/native_widget_types.h"
#include "googleurl/src/gurl.h"
+namespace {
+
+void SetDialogTitle(GtkWidget* dialog, const string16& title) {
+ gtk_window_set_title(GTK_WINDOW(dialog), UTF16ToUTF8(title).c_str());
+
+ // Make sure it's big enough to show the title.
+ GtkRequisition req;
+ gtk_widget_size_request(dialog, &req);
+ int width;
+ gtk_util::GetWidgetSizeFromCharacters(dialog, title.length(), 0,
+ &width, NULL);
+ // The fudge factor accounts for extra space needed by the frame
+ // decorations as well as width differences between average text and the
+ // actual title text.
+ width = width * 1.2 + 50;
+
+ if (width > req.width)
+ gtk_widget_set_size_request(dialog, width, -1);
+}
+
+} // namespace
+
namespace platform_util {
gfx::NativeWindow GetTopLevel(gfx::NativeView view) {
@@ -37,24 +59,24 @@ void SimpleErrorBox(gfx::NativeWindow parent,
GtkWidget* dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", UTF16ToUTF8(message).c_str());
gtk_util::ApplyMessageDialogQuirks(dialog);
- gtk_window_set_title(GTK_WINDOW(dialog), UTF16ToUTF8(title).c_str());
+ SetDialogTitle(dialog, title);
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_widget_show_all(dialog);
+}
- // Make sure it's big enough to show the title.
- GtkRequisition req;
- gtk_widget_size_request(dialog, &req);
- int width;
- gtk_util::GetWidgetSizeFromCharacters(dialog, title.length(), 0,
- &width, NULL);
- // The fudge factor accounts for extra space needed by the frame
- // decorations as well as width differences between average text and the
- // actual title text.
- width = width * 1.2 + 50;
+bool SimpleYesNoBox(gfx::NativeWindow parent,
+ const string16& title,
+ const string16& message) {
+ GtkWidget* dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s",
+ UTF16ToUTF8(message).c_str());
+ gtk_util::ApplyMessageDialogQuirks(dialog);
+ SetDialogTitle(dialog, title);
- if (width > req.width)
- gtk_widget_set_size_request(dialog, width, -1);
+ gint result = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ return (result == GTK_RESPONSE_YES);
}
/* Warning: this may be either Linux or ChromeOS */
diff --git a/chrome/browser/platform_util_mac.mm b/chrome/browser/platform_util_mac.mm
index 43d9582..789059a 100644
--- a/chrome/browser/platform_util_mac.mm
+++ b/chrome/browser/platform_util_mac.mm
@@ -59,14 +59,31 @@ bool IsVisible(gfx::NativeView view) {
void SimpleErrorBox(gfx::NativeWindow parent,
const string16& title,
const string16& message) {
+ // Ignore the title; it's the window title on other platforms and ignorable.
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)];
- [alert setMessageText:base::SysUTF16ToNSString(title)];
- [alert setInformativeText:base::SysUTF16ToNSString(message)];
+ [alert setMessageText:base::SysUTF16ToNSString(message)];
[alert setAlertStyle:NSWarningAlertStyle];
[alert runModal];
}
+bool SimpleYesNoBox(gfx::NativeWindow parent,
+ const string16& title,
+ const string16& message) {
+ // Ignore the title; it's the window title on other platforms and ignorable.
+ NSAlert* alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:base::SysUTF16ToNSString(message)];
+ [alert setAlertStyle:NSWarningAlertStyle];
+
+ [alert addButtonWithTitle:
+ l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)];
+ [alert addButtonWithTitle:
+ l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)];
+
+ NSInteger result = [alert runModal];
+ return result == NSAlertFirstButtonReturn;
+}
+
string16 GetVersionStringModifier() {
#if defined(GOOGLE_CHROME_BUILD)
NSBundle* bundle = mac_util::MainAppBundle();
diff --git a/chrome/browser/platform_util_win.cc b/chrome/browser/platform_util_win.cc
index 7738fe3..e612f64 100644
--- a/chrome/browser/platform_util_win.cc
+++ b/chrome/browser/platform_util_win.cc
@@ -154,6 +154,13 @@ void SimpleErrorBox(gfx::NativeWindow parent,
win_util::MessageBox(parent, message, title, MB_OK | MB_SETFOREGROUND);
}
+bool SimpleYesNoBox(gfx::NativeWindow parent,
+ const string16& title,
+ const string16& message) {
+ return win_util::MessageBox(parent, message.c_str(), title.c_str(),
+ MB_YESNO | MB_ICONWARNING | MB_SETFOREGROUND) == IDYES;
+}
+
string16 GetVersionStringModifier() {
#if defined(GOOGLE_CHROME_BUILD)
FilePath module;
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
index 09dec13..6ae556a 100644
--- a/chrome/browser/process_singleton_win.cc
+++ b/chrome/browser/process_singleton_win.cc
@@ -14,6 +14,7 @@
#include "base/win_util.h"
#include "chrome/browser/browser_init.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/platform_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/common/chrome_constants.h"
@@ -143,8 +144,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
if (visible_window) {
std::wstring text = l10n_util::GetString(IDS_BROWSER_HUNGBROWSER_MESSAGE);
std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
- if (IDYES != win_util::MessageBox(NULL, text, caption,
- MB_YESNO | MB_ICONSTOP | MB_TOPMOST)) {
+ if (!platform_util::SimpleYesNoBox(NULL, caption, text)) {
// The user denied. Quit silently.
return PROCESS_NOTIFIED;
}