OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #import "chrome/browser/cocoa/restart_browser.h" |
| 6 |
5 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
6 #import "chrome/browser/cocoa/restart_browser.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/pref_service.h" |
| 11 #include "chrome/common/pref_names.h" |
7 #include "grit/chromium_strings.h" | 12 #include "grit/chromium_strings.h" |
8 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
9 #include "grit/app_strings.h" | 14 #include "grit/app_strings.h" |
10 | 15 |
11 // Helper to clean up after the notification that the alert was dismissed. | 16 // Helper to clean up after the notification that the alert was dismissed. |
12 @interface RestartHelper : NSObject { | 17 @interface RestartHelper : NSObject { |
13 @private | 18 @private |
14 NSAlert* alert_; | 19 NSAlert* alert_; |
15 } | 20 } |
16 - (NSAlert*)alert; | 21 - (NSAlert*)alert; |
(...skipping 10 matching lines...) Expand all Loading... |
27 } | 32 } |
28 | 33 |
29 - (void)dealloc { | 34 - (void)dealloc { |
30 [alert_ release]; | 35 [alert_ release]; |
31 [super dealloc]; | 36 [super dealloc]; |
32 } | 37 } |
33 | 38 |
34 - (void)alertDidEnd:(NSAlert*)alert | 39 - (void)alertDidEnd:(NSAlert*)alert |
35 returnCode:(int)returnCode | 40 returnCode:(int)returnCode |
36 contextInfo:(void*)contextInfo { | 41 contextInfo:(void*)contextInfo { |
37 // Nothing to do, just clean up | 42 if (returnCode == NSAlertFirstButtonReturn) { |
| 43 // Nothing to do. User will restart later. |
| 44 } else if (returnCode == NSAlertSecondButtonReturn) { |
| 45 // Set the flag to restore state after the restart. |
| 46 PrefService* pref_service = g_browser_process->local_state(); |
| 47 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
| 48 BrowserList::CloseAllBrowsersAndExit(); |
| 49 } else { |
| 50 NOTREACHED(); |
| 51 } |
38 [self autorelease]; | 52 [self autorelease]; |
39 } | 53 } |
40 | 54 |
41 @end | 55 @end |
42 | 56 |
43 namespace restart_browser { | 57 namespace restart_browser { |
44 | 58 |
45 void RequestRestart(NSWindow* parent) { | 59 void RequestRestart(NSWindow* parent) { |
46 NSString* title = | 60 NSString* title = |
47 l10n_util::GetNSStringFWithFixup(IDS_PLEASE_RESTART_BROWSER, | 61 l10n_util::GetNSStringFWithFixup(IDS_PLEASE_RESTART_BROWSER, |
48 l10n_util::GetStringUTF16(IDS_PRODUCT_NAM
E)); | 62 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
49 NSString* text = | 63 NSString* text = |
50 l10n_util::GetNSStringWithFixup(IDS_OPTIONS_RESTART_REQUIRED); | 64 l10n_util::GetNSStringFWithFixup(IDS_UPDATE_RECOMMENDED, |
51 NSString* okBtn = l10n_util::GetNSStringWithFixup(IDS_APP_OK); | 65 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 66 NSString* notNowButtin = l10n_util::GetNSStringWithFixup(IDS_NOT_NOW); |
| 67 NSString* restartButton = |
| 68 l10n_util::GetNSStringWithFixup(IDS_RESTART_AND_UPDATE); |
52 | 69 |
53 RestartHelper* helper = [[RestartHelper alloc] init]; | 70 RestartHelper* helper = [[RestartHelper alloc] init]; |
54 | 71 |
55 NSAlert* alert = [helper alert]; | 72 NSAlert* alert = [helper alert]; |
56 [alert setAlertStyle:NSInformationalAlertStyle]; | 73 [alert setAlertStyle:NSInformationalAlertStyle]; |
57 [alert setMessageText:title]; | 74 [alert setMessageText:title]; |
58 [alert setInformativeText:text]; | 75 [alert setInformativeText:text]; |
59 [alert addButtonWithTitle:okBtn]; | 76 [alert addButtonWithTitle:notNowButtin]; |
| 77 [alert addButtonWithTitle:restartButton]; |
60 | 78 |
61 [alert beginSheetModalForWindow:parent | 79 [alert beginSheetModalForWindow:parent |
62 modalDelegate:helper | 80 modalDelegate:helper |
63 didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) | 81 didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) |
64 contextInfo:nil]; | 82 contextInfo:nil]; |
65 } | 83 } |
66 | 84 |
67 } // namespace restart_browser | 85 } // namespace restart_browser |
OLD | NEW |