summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/simple_message_box_win.cc
blob: 1cea29357c5dfd28224bca897d291c24d5a6c359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 "components/startup_metric_utils/startup_metric_utils.h"
#include "ui/base/win/message_box_win.h"
#include "ui/gfx/win/hwnd_util.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;
}

#if !defined(USE_AURA)
MessageBoxResult ShowMessageBox(gfx::NativeWindow parent,
                                const base::string16& title,
                                const base::string16& message,
                                MessageBoxType type) {
  startup_metric_utils::SetNonBrowserUIDisplayed();

  if (!parent)
    parent = gfx::GetWindowToParentTo(true);

  return NativeShowMessageBox(parent, title, message, type);
}
#endif

}  // namespace chrome