blob: c145a141467417efbff0344f699981c1464eddc6 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2009 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 "app/l10n_util.h"
#include "base/file_version_info.h"
#include "base/logging.h"
#include "base/mac_util.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#import "chrome/app/keystone_glue.h"
#import "chrome/browser/cocoa/about_window_controller.h"
#include "grit/generated_resources.h"
NSString* const kUserClosedAboutNotification =
@"kUserClosedAboutNotification";
@interface AboutWindowController (Private)
- (KeystoneGlue*)defaultKeystoneGlue;
@end
@implementation AboutWindowController
- (id)initWithWindowNibName:(NSString*)nibName {
NSString* nibpath = [mac_util::MainAppBundle() pathForResource:nibName
ofType:@"nib"];
self = [super initWithWindowNibPath:nibpath owner:self];
return self;
}
- (void)awakeFromNib {
// Set our current version.
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfoForCurrentModule());
NSString* version = base::SysWideToNSString(version_info->file_version());
[version_ setStringValue:version];
// Localize the update now button.
NSString* updateNow = base::SysWideToNSString(
l10n_util::GetString(IDS_ABOUT_CHROME_UPDATE_CHECK));
[updateNowButton_ setStringValue:updateNow];
// TODO(jrg): localize the rest of the elements:
// - "Google Chrome" string at top
// - copyright string at bottom
// Initiate an update check.
if ([[self defaultKeystoneGlue] checkForUpdate:self])
[spinner_ startAnimation:self];
}
- (KeystoneGlue*)defaultKeystoneGlue {
return [KeystoneGlue defaultKeystoneGlue];
}
// Callback from KeystoneGlue; implementation of KeystoneGlueCallbacks protocol.
// Warning: latest version may be nil if not set in server config.
- (void)upToDateCheckCompleted:(BOOL)updatesAvailable
latestVersion:(NSString*)latestVersion {
[spinner_ stopAnimation:self];
// If an update is available, be sure to enable the "update now" button.
NSString* display = @"No updates are available.";
if (updatesAvailable) {
[updateNowButton_ setEnabled:YES];
// TODO(jrg): IDS_UPGRADE_AVAILABLE seems close but there is no facility
// for specifying a verision in the update string. Do we care?
display = latestVersion ?
[NSString stringWithFormat:@"Version %@ is available for update.",
latestVersion] :
@"A new version is available.";
}
[upToDate_ setStringValue:display];
}
- (void)windowWillClose:(NSNotification*)notification {
// If an update has ever been triggered, we force reuse of the same About Box.
// This gives us 2 things:
// 1. If an update is ongoing and the window was closed we would have
// no way of getting status.
// 2. If we have a "Please restart" message we want it to stay there.
if (updateTriggered_)
return;
[[NSNotificationCenter defaultCenter]
postNotificationName:kUserClosedAboutNotification
object:self];
}
// Callback from KeystoneGlue; implementation of KeystoneGlueCallbacks protocol.
- (void)updateCompleted:(BOOL)successful installs:(int)installs {
[spinner_ stopAnimation:self];
// TODO(jrg): localize. No current string really says this.
NSString* display = ((successful && installs) ?
@"Update completed! Please restart Chrome." :
@"Self update failed.");
[updateCompleted_ setStringValue:display];
// Allow a second chance.
if (!(successful && installs))
[updateNowButton_ setEnabled:YES];
}
- (IBAction)updateNow:(id)sender {
updateTriggered_ = YES;
// Don't let someone click "Update Now" twice!
[updateNowButton_ setEnabled:NO];
[spinner_ startAnimation:self];
if ([[self defaultKeystoneGlue] startUpdate:self])
[spinner_ startAnimation:self];
else {
// TODO(jrg): localize.
// IDS_UPGRADE_ERROR doesn't work here; we don't have an error number, and
// "server not available" is too specific.
[updateCompleted_ setStringValue:@"Failed to start updates."];
}
}
- (NSButton*)updateButton {
return updateNowButton_;
}
- (NSTextField*)upToDateTextField {
return upToDate_;
}
- (NSTextField*)updateCompletedTextField {
return updateCompleted_;
}
@end
|