OLD | NEW |
---|---|
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 #import "remoting/host/me2me_preference_pane.h" | 5 #import "remoting/host/me2me_preference_pane.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <CommonCrypto/CommonHMAC.h> | 8 #include <CommonCrypto/CommonHMAC.h> |
9 #include <launch.h> | 9 #include <launch.h> |
10 #import <PreferencePanes/PreferencePanes.h> | 10 #import <PreferencePanes/PreferencePanes.h> |
11 #import <SecurityInterface/SFAuthorizationView.h> | 11 #import <SecurityInterface/SFAuthorizationView.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include <fstream> | 14 #include <fstream> |
15 | 15 |
16 #include "base/eintr_wrapper.h" | 16 #include "base/eintr_wrapper.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/mac/authorization_util.h" | 18 #include "base/mac/authorization_util.h" |
19 #include "base/mac/foundation_util.h" | 19 #include "base/mac/foundation_util.h" |
20 #include "base/mac/launchd.h" | 20 #include "base/mac/launchd.h" |
21 #include "base/mac/mac_logging.h" | 21 #include "base/mac/mac_logging.h" |
22 #include "base/mac/scoped_launch_data.h" | 22 #include "base/mac/scoped_launch_data.h" |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
25 #include "base/sys_string_conversions.h" | 25 #include "base/sys_string_conversions.h" |
26 #include "remoting/host/host_config.h" | 26 #include "remoting/host/host_config.h" |
27 #import "remoting/host/me2me_preference_pane_confirm_pin.h" | |
28 #import "remoting/host/me2me_preference_pane_disable.h" | |
27 #include "third_party/jsoncpp/source/include/json/reader.h" | 29 #include "third_party/jsoncpp/source/include/json/reader.h" |
28 #include "third_party/jsoncpp/source/include/json/writer.h" | 30 #include "third_party/jsoncpp/source/include/json/writer.h" |
29 #include "third_party/modp_b64/modp_b64.h" | 31 #include "third_party/modp_b64/modp_b64.h" |
30 | 32 |
31 namespace { | 33 namespace { |
32 // The name of the Remoting Host service that is registered with launchd. | 34 // The name of the Remoting Host service that is registered with launchd. |
33 #define kServiceName "org.chromium.chromoting" | 35 #define kServiceName "org.chromium.chromoting" |
34 | 36 |
35 // Use separate named notifications for success and failure because sandboxed | 37 // Use separate named notifications for success and failure because sandboxed |
36 // components can't include a dictionary when sending distributed notifications. | 38 // components can't include a dictionary when sending distributed notifications. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 } | 147 } |
146 | 148 |
147 } // namespace remoting | 149 } // namespace remoting |
148 | 150 |
149 @implementation Me2MePreferencePane | 151 @implementation Me2MePreferencePane |
150 | 152 |
151 - (void)mainViewDidLoad { | 153 - (void)mainViewDidLoad { |
152 [authorization_view_ setDelegate:self]; | 154 [authorization_view_ setDelegate:self]; |
153 [authorization_view_ setString:kAuthorizationRightExecute]; | 155 [authorization_view_ setString:kAuthorizationRightExecute]; |
154 [authorization_view_ setAutoupdate:YES]; | 156 [authorization_view_ setAutoupdate:YES]; |
157 confirm_pin_view_ = [[Me2MePreferencePaneConfirmPin alloc] init]; | |
dcaiafa
2012/05/21 15:45:31
Leak in non-GC environment. I'd move the alloc/ini
| |
158 [confirm_pin_view_ setDelegate:self]; | |
159 disable_view_ = [[Me2MePreferencePaneDisable alloc] init]; | |
160 [disable_view_ setDelegate:self]; | |
155 } | 161 } |
156 | 162 |
157 - (void)willSelect { | 163 - (void)willSelect { |
158 have_new_config_ = NO; | 164 have_new_config_ = NO; |
159 | 165 |
160 NSDistributedNotificationCenter* center = | 166 NSDistributedNotificationCenter* center = |
161 [NSDistributedNotificationCenter defaultCenter]; | 167 [NSDistributedNotificationCenter defaultCenter]; |
162 [center addObserver:self | 168 [center addObserver:self |
163 selector:@selector(onNewConfigFile:) | 169 selector:@selector(onNewConfigFile:) |
164 name:@kServiceName | 170 name:@kServiceName |
(...skipping 17 matching lines...) Expand all Loading... | |
182 [center removeObserver:self]; | 188 [center removeObserver:self]; |
183 | 189 |
184 [service_status_timer_ invalidate]; | 190 [service_status_timer_ invalidate]; |
185 [service_status_timer_ release]; | 191 [service_status_timer_ release]; |
186 service_status_timer_ = nil; | 192 service_status_timer_ = nil; |
187 if (have_new_config_) { | 193 if (have_new_config_) { |
188 [self notifyPlugin: kUpdateFailedNotificationName]; | 194 [self notifyPlugin: kUpdateFailedNotificationName]; |
189 } | 195 } |
190 } | 196 } |
191 | 197 |
192 - (void)onApply:(id)sender { | 198 - (void)applyConfiguration:(id)sender |
199 pin:(NSString*)pin { | |
193 if (!have_new_config_) { | 200 if (!have_new_config_) { |
194 // It shouldn't be possible to hit the button if there is no config to | 201 // It shouldn't be possible to hit the button if there is no config to |
195 // apply, but check anyway just in case it happens somehow. | 202 // apply, but check anyway just in case it happens somehow. |
196 return; | 203 return; |
197 } | 204 } |
198 | 205 |
199 // Ensure the authorization token is up-to-date before using it. | 206 // Ensure the authorization token is up-to-date before using it. |
200 [self updateAuthorizationStatus]; | 207 [self updateAuthorizationStatus]; |
201 [self updateUI]; | 208 [self updateUI]; |
202 | 209 |
203 std::string pin = base::SysNSStringToUTF8([pin_ stringValue]); | 210 std::string pin_utf8 = base::SysNSStringToUTF8(pin); |
204 std::string host_id, host_secret_hash; | 211 std::string host_id, host_secret_hash; |
205 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && | 212 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && |
206 config_->GetString(remoting::kHostSecretHashConfigPath, | 213 config_->GetString(remoting::kHostSecretHashConfigPath, |
207 &host_secret_hash)); | 214 &host_secret_hash)); |
208 DCHECK(result); | 215 DCHECK(result); |
209 if (!IsPinValid(pin, host_id, host_secret_hash)) { | 216 if (!IsPinValid(pin_utf8, host_id, host_secret_hash)) { |
210 [self showIncorrectPinMessage]; | 217 [self showIncorrectPinMessage]; |
211 return; | 218 return; |
212 } | 219 } |
213 | 220 |
214 [self applyNewServiceConfig]; | 221 [self applyNewServiceConfig]; |
215 [self updateUI]; | 222 [self updateUI]; |
216 } | 223 } |
217 | 224 |
218 - (void)onDisable:(id)sender { | 225 - (void)onDisable:(id)sender { |
219 // Ensure the authorization token is up-to-date before using it. | 226 // Ensure the authorization token is up-to-date before using it. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 } | 293 } |
287 remove(file.c_str()); | 294 remove(file.c_str()); |
288 if (!IsConfigValid(new_config_.get())) { | 295 if (!IsConfigValid(new_config_.get())) { |
289 LOG(ERROR) << "Invalid configuration data read."; | 296 LOG(ERROR) << "Invalid configuration data read."; |
290 [self showError]; | 297 [self showError]; |
291 return; | 298 return; |
292 } | 299 } |
293 | 300 |
294 config_.swap(new_config_); | 301 config_.swap(new_config_); |
295 have_new_config_ = YES; | 302 have_new_config_ = YES; |
303 | |
304 [confirm_pin_view_ resetPin]; | |
296 } | 305 } |
297 | 306 |
298 - (void)updateUI { | 307 - (void)updateUI { |
299 // TODO(lambroslambrou): These strings should be localized. | 308 if (have_new_config_) { |
300 #ifdef OFFICIAL_BUILD | 309 [box_ setContentView:[confirm_pin_view_ view]]; |
301 NSString* name = @"Chrome Remote Desktop"; | 310 } else { |
302 #else | 311 [box_ setContentView:[disable_view_ view]]; |
303 NSString* name = @"Chromoting"; | 312 } |
304 #endif | 313 |
314 // TODO(lambroslambrou): Show "enabled" and "disabled" in bold font. | |
305 NSString* message; | 315 NSString* message; |
306 if (is_service_running_) { | 316 if (is_service_running_) { |
307 message = [NSString stringWithFormat:@"%@ is enabled", name]; | 317 if (have_new_config_) { |
318 message = @"Please confirm your new PIN."; | |
319 } else { | |
320 message = @"Remote connections to this computer are enabled."; | |
321 } | |
308 } else { | 322 } else { |
309 message = [NSString stringWithFormat:@"%@ is disabled", name]; | 323 if (have_new_config_) { |
324 message = @"Remote connections to this computer are disabled. To enable " | |
325 "remote connections you must confirm your PIN."; | |
326 } else { | |
327 message = @"Remote connections to this computer are disabled."; | |
328 } | |
310 } | 329 } |
311 [status_message_ setStringValue:message]; | 330 [status_message_ setStringValue:message]; |
312 | 331 |
313 std::string email; | 332 std::string email; |
314 if (config_.get()) { | 333 if (config_.get()) { |
315 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email); | 334 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email); |
316 | 335 |
317 // The config has already been checked by |IsConfigValid|. | 336 // The config has already been checked by |IsConfigValid|. |
318 DCHECK(result); | 337 DCHECK(result); |
319 } | 338 } |
320 [email_ setStringValue:base::SysUTF8ToNSString(email)]; | |
321 | 339 |
322 [disable_button_ setEnabled:(is_pane_unlocked_ && is_service_running_)]; | 340 [disable_view_ setEnabled:(is_pane_unlocked_ && is_service_running_)]; |
323 [pin_instruction_message_ setEnabled:have_new_config_]; | 341 [confirm_pin_view_ setEnabled:is_pane_unlocked_]; |
324 [email_ setEnabled:have_new_config_]; | 342 [confirm_pin_view_ setEmail:base::SysUTF8ToNSString(email)]; |
325 [pin_ setEnabled:have_new_config_]; | 343 NSString* applyButtonText = is_service_running_ ? @"Confirm" : @"Enable"; |
326 [apply_button_ setEnabled:(is_pane_unlocked_ && have_new_config_)]; | 344 [confirm_pin_view_ setButtonText:applyButtonText]; |
327 } | 345 } |
328 | 346 |
329 - (void)showError { | 347 - (void)showError { |
330 NSAlert* alert = [[NSAlert alloc] init]; | 348 NSAlert* alert = [[NSAlert alloc] init]; |
331 [alert setMessageText:@"An unexpected error occurred."]; | 349 [alert setMessageText:@"An unexpected error occurred."]; |
332 [alert setInformativeText:@"Check the system log for more information."]; | 350 [alert setInformativeText:@"Check the system log for more information."]; |
333 [alert setAlertStyle:NSWarningAlertStyle]; | 351 [alert setAlertStyle:NSWarningAlertStyle]; |
334 [alert beginSheetModalForWindow:[[self mainView] window] | 352 [alert beginSheetModalForWindow:[[self mainView] window] |
335 modalDelegate:nil | 353 modalDelegate:nil |
336 didEndSelector:nil | 354 didEndSelector:nil |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 - (void)notifyPlugin:(const char*)message { | 509 - (void)notifyPlugin:(const char*)message { |
492 NSDistributedNotificationCenter* center = | 510 NSDistributedNotificationCenter* center = |
493 [NSDistributedNotificationCenter defaultCenter]; | 511 [NSDistributedNotificationCenter defaultCenter]; |
494 NSString* name = [NSString stringWithUTF8String:message]; | 512 NSString* name = [NSString stringWithUTF8String:message]; |
495 [center postNotificationName:name | 513 [center postNotificationName:name |
496 object:nil | 514 object:nil |
497 userInfo:nil]; | 515 userInfo:nil]; |
498 } | 516 } |
499 | 517 |
500 @end | 518 @end |
OLD | NEW |