Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: chrome/browser/ui/cocoa/simple_message_box_mac.mm

Issue 2107493002: Offer user to send feedback from profile error dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet more compile errors Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/simple_message_box.h" 5 #include "chrome/browser/ui/simple_message_box.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/ui/simple_message_box_internal.h" 11 #include "chrome/browser/ui/simple_message_box_internal.h"
11 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
12 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 13 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
13 #include "grit/components_strings.h" 14 #include "grit/components_strings.h"
14 #include "ui/base/l10n/l10n_util_mac.h" 15 #include "ui/base/l10n/l10n_util_mac.h"
15 16
16 namespace chrome { 17 namespace chrome {
17 18
18 namespace { 19 namespace {
19 20
20 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, 21 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent,
21 const base::string16& title, 22 const base::string16& title,
22 const base::string16& message, 23 const base::string16& message,
24 const base::string16& checkbox_text,
23 MessageBoxType type) { 25 MessageBoxType type) {
24 startup_metric_utils::SetNonBrowserUIDisplayed(); 26 startup_metric_utils::SetNonBrowserUIDisplayed();
25 if (internal::g_should_skip_message_box_for_test) 27 if (internal::g_should_skip_message_box_for_test)
26 return MESSAGE_BOX_RESULT_YES; 28 return MESSAGE_BOX_RESULT_YES;
27 29
28 // Ignore the title; it's the window title on other platforms and ignorable. 30 // Ignore the title; it's the window title on other platforms and ignorable.
29 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; 31 NSAlert* alert = [[[NSAlert alloc] init] autorelease];
30 [alert setMessageText:base::SysUTF16ToNSString(message)]; 32 [alert setMessageText:base::SysUTF16ToNSString(message)];
31 [alert setAlertStyle:NSWarningAlertStyle]; 33 [alert setAlertStyle:NSWarningAlertStyle];
32 if (type == MESSAGE_BOX_TYPE_QUESTION) { 34 if (type == MESSAGE_BOX_TYPE_QUESTION) {
33 [alert addButtonWithTitle: 35 [alert addButtonWithTitle:
34 l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)]; 36 l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)];
35 [alert addButtonWithTitle: 37 [alert addButtonWithTitle:
36 l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)]; 38 l10n_util::GetNSString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)];
37 } else { 39 } else {
38 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; 40 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)];
39 } 41 }
42
43 base::scoped_nsobject<NSButton> checkbox;
44 if (!checkbox_text.empty()) {
45 checkbox.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
46 [checkbox setButtonType:NSSwitchButton];
47 [checkbox setTitle:base::SysUTF16ToNSString(checkbox_text)];
48 [checkbox sizeToFit];
49 [alert setAccessoryView:checkbox];
50 }
51
40 NSInteger result = [alert runModal]; 52 NSInteger result = [alert runModal];
41 return (result == NSAlertSecondButtonReturn) ? 53 if (result == NSAlertSecondButtonReturn)
42 MESSAGE_BOX_RESULT_NO : MESSAGE_BOX_RESULT_YES; 54 return MESSAGE_BOX_RESULT_NO;
55
56 if (checkbox) {
57 return ([checkbox state] == NSOnState) ? MESSAGE_BOX_RESULT_YES_CHECKED
58 : MESSAGE_BOX_RESULT_YES_NOT_CHECKED;
59 }
60
61 return MESSAGE_BOX_RESULT_YES;
43 } 62 }
44 63
45 } // namespace 64 } // namespace
46 65
47 void ShowWarningMessageBox(gfx::NativeWindow parent, 66 void ShowWarningMessageBox(gfx::NativeWindow parent,
48 const base::string16& title, 67 const base::string16& title,
49 const base::string16& message) { 68 const base::string16& message) {
50 ShowMessageBox(parent, title, message, MESSAGE_BOX_TYPE_WARNING); 69 ShowMessageBox(parent, title, message, base::string16(),
70 MESSAGE_BOX_TYPE_WARNING);
71 }
72
73 bool ShowWarningMessageBoxWithCheckbox(gfx::NativeWindow parent,
74 const base::string16& title,
75 const base::string16& message,
76 const base::string16& checkbox_text) {
77 ShowMessageBox(parent, title, message, checkbox_text,
78 MESSAGE_BOX_TYPE_WARNING);
79 return false;
51 } 80 }
52 81
53 MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent, 82 MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent,
54 const base::string16& title, 83 const base::string16& title,
55 const base::string16& message) { 84 const base::string16& message) {
56 return ShowMessageBox(parent, title, message, MESSAGE_BOX_TYPE_QUESTION); 85 return ShowMessageBox(parent, title, message, base::string16(),
86 MESSAGE_BOX_TYPE_QUESTION);
57 } 87 }
58 88
59 } // namespace chrome 89 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698