1 // Copyright (c) 2011 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.
5 #import "chrome/browser/ui/cocoa/restart_browser.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/lifetime/application_lifetime.h"
9 #include "grit/chromium_strings.h"
10 #include "grit/generated_resources.h"
11 #include "grit/ui_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/l10n/l10n_util_mac.h"
15 // Helper to clean up after the notification that the alert was dismissed.
16 @interface RestartHelper : NSObject {
21 - (void)alertDidEnd:(NSAlert*)alert
22 returnCode:(int)returnCode
23 contextInfo:(void*)contextInfo;
26 @implementation RestartHelper
29 alert_ = [[NSAlert alloc] init];
38 - (void)alertDidEnd:(NSAlert*)alert
39 returnCode:(int)returnCode
40 contextInfo:(void*)contextInfo {
41 if (returnCode == NSAlertFirstButtonReturn) {
42 chrome::AttemptRestart();
43 } else if (returnCode == NSAlertSecondButtonReturn) {
44 // Nothing to do. User will restart later.
53 namespace restart_browser {
55 void RequestRestart(NSWindow* parent) {
57 l10n_util::GetNSStringFWithFixup(IDS_PLEASE_RELAUNCH_BROWSER,
58 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
60 l10n_util::GetNSStringFWithFixup(IDS_UPDATE_RECOMMENDED,
61 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
62 NSString* notNowButton = l10n_util::GetNSStringWithFixup(IDS_NOT_NOW);
63 NSString* restartButton =
64 l10n_util::GetNSStringWithFixup(IDS_RELAUNCH_AND_UPDATE);
66 RestartHelper* helper = [[RestartHelper alloc] init];
68 NSAlert* alert = [helper alert];
69 [alert setAlertStyle:NSInformationalAlertStyle];
70 [alert setMessageText:title];
71 [alert setInformativeText:text];
72 [alert addButtonWithTitle:restartButton];
73 [alert addButtonWithTitle:notNowButton];
76 [alert beginSheetModalForWindow:parent
78 didEndSelector:@selector(alertDidEnd:
83 NSInteger returnCode = [alert runModal];
84 [helper alertDidEnd:alert
90 } // namespace restart_browser