summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/app_modal_dialog_mac.mm106
-rw-r--r--chrome/browser/jsmessage_box_handler.cc9
-rw-r--r--chrome/chrome.gyp1
3 files changed, 107 insertions, 9 deletions
diff --git a/chrome/browser/app_modal_dialog_mac.mm b/chrome/browser/app_modal_dialog_mac.mm
new file mode 100644
index 0000000..81143cc
--- /dev/null
+++ b/chrome/browser/app_modal_dialog_mac.mm
@@ -0,0 +1,106 @@
+// Copyright (c) 2009 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/app_modal_dialog.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/sys_string_conversions.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/message_box_flags.h"
+#include "grit/generated_resources.h"
+
+// Helper object that receives the notification that the dialog/sheet is
+// going away. Is responsible for cleaning itself up.
+@interface AppModalDialogHelper : NSObject
+@end
+
+@implementation AppModalDialogHelper
+// |contextInfo| is the bridge back to the C++ AppModalDialog. When complete,
+// autorelease to clean ourselves up.
+- (void)sheetDidEnd:(NSWindow *)sheet
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo {
+ AppModalDialog* bridge = reinterpret_cast<AppModalDialog*>(contextInfo);
+ switch (returnCode) {
+ case NSAlertDefaultReturn: // OK
+ bridge->OnAccept(std::wstring(), false);
+ break;
+ case NSAlertOtherReturn: // Cancel
+ bridge->OnCancel();
+ break;
+ default:
+ NOTREACHED();
+ }
+ [self autorelease];
+}
+@end
+
+AppModalDialog::~AppModalDialog() {
+}
+
+void AppModalDialog::CreateAndShowDialog() {
+ // Determine the names of the dialog buttons based on the flags. "Default"
+ // is the OK button. "Other" is the cancel button. We don't use the
+ // "Alternate" button in NSRunAlertPanel.
+ // TODO(pinkerton): Need to find the right localized strings for these.
+ NSString* default_button = NSLocalizedString(@"OK", nil);
+ NSString* other_button = NSLocalizedString(@"Cancel", nil);
+ switch (dialog_flags_) {
+ case MessageBox::kIsJavascriptAlert:
+ // OK & Cancel are fine for these types of alerts.
+ break;
+ case MessageBox::kIsJavascriptConfirm:
+ if (is_before_unload_dialog_) {
+ std::string button_text = l10n_util::GetStringUTF8(
+ IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
+ default_button = base::SysUTF8ToNSString(button_text);
+ button_text = l10n_util::GetStringUTF8(
+ IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
+ other_button = base::SysUTF8ToNSString(button_text);
+ }
+ break;
+ case MessageBox::kIsJavascriptPrompt:
+ // We need to make a custom message box for javascript prompts. Not
+ // sure how to handle this...
+ NOTIMPLEMENTED();
+ break;
+
+ default:
+ NOTREACHED();
+ }
+
+ // Create a helper which will receive the sheet ended selector. It will
+ // delete itself when done. It doesn't need anything passed to its init
+ // as it will get a contextInfo parameter.
+ AppModalDialogHelper* helper = [[AppModalDialogHelper alloc] init];
+
+ // Show the modal dialog.
+ NSString* title_str = base::SysWideToNSString(title_);
+ NSString* message_str = base::SysWideToNSString(message_text_);
+ NSBeginAlertSheet(title_str, default_button, nil, other_button, nil,
+ helper, @selector(sheetDidEnd:returnCode:contextInfo:),
+ nil, this, message_str);
+}
+
+void AppModalDialog::ActivateModalDialog() {
+ NOTIMPLEMENTED();
+}
+
+void AppModalDialog::CloseModalDialog() {
+ NOTIMPLEMENTED();
+}
+
+int AppModalDialog::GetDialogButtons() {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+void AppModalDialog::AcceptWindow() {
+ NOTIMPLEMENTED();
+}
+
+void AppModalDialog::CancelWindow() {
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc
index 551cf4b..6c43fbf 100644
--- a/chrome/browser/jsmessage_box_handler.cc
+++ b/chrome/browser/jsmessage_box_handler.cc
@@ -68,14 +68,9 @@ void RunJavascriptMessageBox(WebContents* web_contents,
bool display_suppress_checkbox,
IPC::Message* reply_msg) {
std::wstring title = GetWindowTitle(web_contents, frame_url, dialog_flags);
-
-#if defined(OS_WIN) || defined(OS_LINUX)
AppModalDialogQueue::AddDialog(new AppModalDialog(web_contents, title,
dialog_flags, MakeTextSafe(message_text), default_prompt_text,
display_suppress_checkbox, false, reply_msg));
-#else
- NOTIMPLEMENTED();
-#endif
}
void RunBeforeUnloadDialog(WebContents* web_contents,
@@ -84,12 +79,8 @@ void RunBeforeUnloadDialog(WebContents* web_contents,
std::wstring full_message =
message_text + L"\n\n" +
l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER);
-#if defined(OS_WIN) || defined(OS_LINUX)
AppModalDialogQueue::AddDialog(new AppModalDialog(
web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE),
MessageBox::kIsJavascriptConfirm, MakeTextSafe(message_text),
std::wstring(), false, true, reply_msg));
-#else
- NOTIMPLEMENTED();
-#endif
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 8b869f9..5c6a186 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -385,6 +385,7 @@
'browser/app_modal_dialog.cc',
'browser/app_modal_dialog.h',
'browser/app_modal_dialog_gtk.cc',
+ 'browser/app_modal_dialog_mac.mm',
'browser/app_modal_dialog_win.cc',
'browser/app_modal_dialog_queue.cc',
'browser/app_modal_dialog_queue.h',