simple_message_box_mac.mm revision 5821806d5e7f356e8fa4b058a389a808ea183019
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
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/simple_message_box.h"
6
7#import <Cocoa/Cocoa.h>
8
9#include "base/sys_string_conversions.h"
10#include "chrome/common/startup_metric_utils.h"
11#include "grit/generated_resources.h"
12#include "ui/base/l10n/l10n_util_mac.h"
13
14namespace chrome {
15
16MessageBoxResult ShowMessageBox(gfx::NativeWindow parent,
17                                const string16& title,
18                                const string16& message,
19                                MessageBoxType type) {
20  startup_metric_utils::SetNonBrowserUIDisplayed();
21
22  // Ignore the title; it's the window title on other platforms and ignorable.
23  NSAlert* alert = [[[NSAlert alloc] init] autorelease];
24  [alert setMessageText:base::SysUTF16ToNSString(message)];
25  NSUInteger style = (type == MESSAGE_BOX_TYPE_INFORMATION) ?
26      NSInformationalAlertStyle : NSWarningAlertStyle;
27  [alert setAlertStyle:style];
28  if (type == MESSAGE_BOX_TYPE_QUESTION) {
29    [alert addButtonWithTitle:
30        l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)];
31    [alert addButtonWithTitle:
32        l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)];
33  } else {
34    [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)];
35  }
36  NSInteger result = [alert runModal];
37  return (result == NSAlertSecondButtonReturn) ?
38      MESSAGE_BOX_RESULT_NO : MESSAGE_BOX_RESULT_YES;
39}
40
41}  // namespace chrome
42