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 <errno.h> | 9 #include <errno.h> |
10 #include <launch.h> | 10 #include <launch.h> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 namespace { | 28 namespace { |
29 // The name of the Remoting Host service that is registered with launchd. | 29 // The name of the Remoting Host service that is registered with launchd. |
30 #define kServiceName "org.chromium.chromoting" | 30 #define kServiceName "org.chromium.chromoting" |
31 | 31 |
32 // Use separate named notifications for success and failure because sandboxed | 32 // Use separate named notifications for success and failure because sandboxed |
33 // components can't include a dictionary when sending distributed notifications. | 33 // components can't include a dictionary when sending distributed notifications. |
34 // The preferences panel is not yet sandboxed, but err on the side of caution. | 34 // The preferences panel is not yet sandboxed, but err on the side of caution. |
35 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded" | 35 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded" |
36 #define kUpdateFailedNotificationName kServiceName ".update_failed" | 36 #define kUpdateFailedNotificationName kServiceName ".update_failed" |
37 | 37 |
38 // This notification (or the UpdateFailed notification) is sent whenever the | |
39 // pref-pane is deselected. This is analogous to the user canceling the | |
40 // confirm-PIN dialog (or UAC prompt) on Windows. | |
41 // If the plugin is expecting an action to occur (such as the user disabling | |
42 // the Host service), it should treat this as a signal to stop waiting, and | |
43 // assume the action has been canceled by the user. | |
44 // Otherwise, the plugin should ignore this notification. The pref-pane does | |
45 // not know whether it was launched by the plugin or by the user (in the case | |
46 // of disabling remote connections), so it has to send this notification | |
47 // regardless. | |
48 #define kUserCanceledNotificationName kServiceName ".user_canceled" | |
Jamie
2012/06/15 22:34:56
Can we call this update_canceled for consistency w
| |
49 | |
38 #define kConfigDir "/Library/PrivilegedHelperTools/" | 50 #define kConfigDir "/Library/PrivilegedHelperTools/" |
39 | 51 |
40 // This helper script is executed as root. It is passed a command-line option | 52 // This helper script is executed as root. It is passed a command-line option |
41 // (--enable or --disable), which causes it to create or remove a file that | 53 // (--enable or --disable), which causes it to create or remove a file that |
42 // informs the host's launch script of whether the host is enabled or disabled. | 54 // informs the host's launch script of whether the host is enabled or disabled. |
43 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; | 55 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; |
44 | 56 |
45 bool GetTemporaryConfigFilePath(std::string* path) { | 57 bool GetTemporaryConfigFilePath(std::string* path) { |
46 NSString* filename = NSTemporaryDirectory(); | 58 NSString* filename = NSTemporaryDirectory(); |
47 if (filename == nil) | 59 if (filename == nil) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 - (void)willUnselect { | 334 - (void)willUnselect { |
323 NSDistributedNotificationCenter* center = | 335 NSDistributedNotificationCenter* center = |
324 [NSDistributedNotificationCenter defaultCenter]; | 336 [NSDistributedNotificationCenter defaultCenter]; |
325 [center removeObserver:self]; | 337 [center removeObserver:self]; |
326 | 338 |
327 [service_status_timer_ invalidate]; | 339 [service_status_timer_ invalidate]; |
328 [service_status_timer_ release]; | 340 [service_status_timer_ release]; |
329 service_status_timer_ = nil; | 341 service_status_timer_ = nil; |
330 if (have_new_config_) | 342 if (have_new_config_) |
331 [self notifyPlugin:kUpdateFailedNotificationName]; | 343 [self notifyPlugin:kUpdateFailedNotificationName]; |
344 else | |
345 [self notifyPlugin:kUserCanceledNotificationName]; | |
Jamie
2012/06/15 22:34:56
This feels inconsistent. Why send a failed notific
| |
332 } | 346 } |
333 | 347 |
334 - (void)applyConfiguration:(id)sender | 348 - (void)applyConfiguration:(id)sender |
335 pin:(NSString*)pin { | 349 pin:(NSString*)pin { |
336 if (!have_new_config_) { | 350 if (!have_new_config_) { |
337 // It shouldn't be possible to hit the button if there is no config to | 351 // It shouldn't be possible to hit the button if there is no config to |
338 // apply, but check anyway just in case it happens somehow. | 352 // apply, but check anyway just in case it happens somehow. |
339 return; | 353 return; |
340 } | 354 } |
341 | 355 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 // spinning state until System Preferences eventually gets restarted and | 760 // spinning state until System Preferences eventually gets restarted and |
747 // the user visits this pane again. | 761 // the user visits this pane again. |
748 std::string file; | 762 std::string file; |
749 if (!GetTemporaryConfigFilePath(&file)) { | 763 if (!GetTemporaryConfigFilePath(&file)) { |
750 // There's no point in alerting the user here. The same error would | 764 // There's no point in alerting the user here. The same error would |
751 // happen when the pane is eventually restarted, so the user would be | 765 // happen when the pane is eventually restarted, so the user would be |
752 // alerted at that time. | 766 // alerted at that time. |
753 NSLog(@"Failed to get path of configuration data."); | 767 NSLog(@"Failed to get path of configuration data."); |
754 return; | 768 return; |
755 } | 769 } |
756 if (access(file.c_str(), F_OK) != 0) | 770 if (access(file.c_str(), F_OK) != 0) { |
757 return; | 771 [self notifyPlugin:kUserCanceledNotificationName]; |
Jamie
2012/06/15 22:34:56
Under what circumstances can this happen? Would it
| |
758 | 772 } else { |
759 remove(file.c_str()); | 773 remove(file.c_str()); |
760 [self notifyPlugin:kUpdateFailedNotificationName]; | 774 [self notifyPlugin:kUpdateFailedNotificationName]; |
775 } | |
761 } | 776 } |
762 } | 777 } |
763 | 778 |
764 - (void)restartSystemPreferences { | 779 - (void)restartSystemPreferences { |
765 NSTask* task = [[NSTask alloc] init]; | 780 NSTask* task = [[NSTask alloc] init]; |
766 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; | 781 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; |
767 [task setLaunchPath:[NSString stringWithUTF8String:kHelperTool]]; | 782 [task setLaunchPath:[NSString stringWithUTF8String:kHelperTool]]; |
768 [task setArguments:arguments]; | 783 [task setArguments:arguments]; |
769 [task setStandardInput:[NSPipe pipe]]; | 784 [task setStandardInput:[NSPipe pipe]]; |
770 [task launch]; | 785 [task launch]; |
771 [task release]; | 786 [task release]; |
772 [NSApp terminate:nil]; | 787 [NSApp terminate:nil]; |
773 } | 788 } |
774 | 789 |
775 @end | 790 @end |
OLD | NEW |