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 "chrome/grit/chromium_strings.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
14 // Helper to clean up after the notification that the alert was dismissed.
15 @interface RestartHelper : NSObject {
20 - (void)alertDidEnd:(NSAlert*)alert
21 returnCode:(int)returnCode
22 contextInfo:(void*)contextInfo;
25 @implementation RestartHelper
28 alert_ = [[NSAlert alloc] init];
37 - (void)alertDidEnd:(NSAlert*)alert
38 returnCode:(int)returnCode
39 contextInfo:(void*)contextInfo {
40 if (returnCode == NSAlertFirstButtonReturn) {
41 chrome::AttemptRestart();
42 } else if (returnCode == NSAlertSecondButtonReturn) {
43 // Nothing to do. User will restart later.
52 namespace restart_browser {
54 void RequestRestart(NSWindow* parent) {
56 l10n_util::GetNSStringFWithFixup(IDS_PLEASE_RELAUNCH_BROWSER,
57 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
59 l10n_util::GetNSStringFWithFixup(IDS_UPDATE_RECOMMENDED,
60 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
61 NSString* notNowButton = l10n_util::GetNSStringWithFixup(IDS_NOT_NOW);
62 NSString* restartButton =
63 l10n_util::GetNSStringWithFixup(IDS_RELAUNCH_AND_UPDATE);
65 RestartHelper* helper = [[RestartHelper alloc] init];
67 NSAlert* alert = [helper alert];
68 [alert setAlertStyle:NSInformationalAlertStyle];
69 [alert setMessageText:title];
70 [alert setInformativeText:text];
71 [alert addButtonWithTitle:restartButton];
72 [alert addButtonWithTitle:notNowButton];
75 [alert beginSheetModalForWindow:parent
77 didEndSelector:@selector(alertDidEnd:
82 NSInteger returnCode = [alert runModal];
83 [helper alertDidEnd:alert
89 } // namespace restart_browser