// 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" #import #include "base/strings/sys_string_conversions.h" #include "chrome/browser/ui/simple_message_box_internal.h" #include "chrome/grit/generated_resources.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "grit/components_strings.h" #include "ui/base/l10n/l10n_util_mac.h" namespace chrome { namespace { MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, const base::string16& title, const base::string16& message, MessageBoxType type) { startup_metric_utils::SetNonBrowserUIDisplayed(); if (internal::g_should_skip_message_box_for_test) return MESSAGE_BOX_RESULT_YES; // 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]; if (type == MESSAGE_BOX_TYPE_QUESTION) { [alert addButtonWithTitle: l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)]; [alert addButtonWithTitle: l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)]; } else { [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; } NSInteger result = [alert runModal]; return (result == NSAlertSecondButtonReturn) ? MESSAGE_BOX_RESULT_NO : MESSAGE_BOX_RESULT_YES; } } // namespace void ShowWarningMessageBox(gfx::NativeWindow parent, const base::string16& title, const base::string16& message) { ShowMessageBox(parent, title, message, MESSAGE_BOX_TYPE_WARNING); } MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent, const base::string16& title, const base::string16& message) { return ShowMessageBox(parent, title, message, MESSAGE_BOX_TYPE_QUESTION); } } // namespace chrome