Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: remoting/host/me2me_preference_pane.mm

Issue 10408076: Merge 138322 - Implement Mac pref-pane UI mockups (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1132/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/me2me_preference_pane.h ('k') | remoting/host/me2me_preference_pane.xib » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <launch.h> 8 #include <launch.h>
9 #import <PreferencePanes/PreferencePanes.h> 9 #import <PreferencePanes/PreferencePanes.h>
10 #import <SecurityInterface/SFAuthorizationView.h> 10 #import <SecurityInterface/SFAuthorizationView.h>
11 11
12 #include "base/eintr_wrapper.h" 12 #include "base/eintr_wrapper.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/authorization_util.h" 16 #include "base/mac/authorization_util.h"
17 #include "base/mac/foundation_util.h" 17 #include "base/mac/foundation_util.h"
18 #include "base/mac/launchd.h" 18 #include "base/mac/launchd.h"
19 #include "base/mac/mac_logging.h" 19 #include "base/mac/mac_logging.h"
20 #include "base/mac/scoped_launch_data.h" 20 #include "base/mac/scoped_launch_data.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
23 #include "base/sys_string_conversions.h" 23 #include "base/sys_string_conversions.h"
24 #include "remoting/host/host_config.h" 24 #include "remoting/host/host_config.h"
25 #include "remoting/host/json_host_config.h" 25 #include "remoting/host/json_host_config.h"
26 #import "remoting/host/me2me_preference_pane_confirm_pin.h"
27 #import "remoting/host/me2me_preference_pane_disable.h"
26 #include "remoting/protocol/me2me_host_authenticator_factory.h" 28 #include "remoting/protocol/me2me_host_authenticator_factory.h"
27 29
28 namespace { 30 namespace {
29 // The name of the Remoting Host service that is registered with launchd. 31 // The name of the Remoting Host service that is registered with launchd.
30 #define kServiceName "org.chromium.chromoting" 32 #define kServiceName "org.chromium.chromoting"
31 33
32 // Use separate named notifications for success and failure because sandboxed 34 // Use separate named notifications for success and failure because sandboxed
33 // components can't include a dictionary when sending distributed notifications. 35 // 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. 36 // The preferences panel is not yet sandboxed, but err on the side of caution.
35 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded" 37 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 73
72 } // namespace 74 } // namespace
73 75
74 76
75 @implementation Me2MePreferencePane 77 @implementation Me2MePreferencePane
76 78
77 - (void)mainViewDidLoad { 79 - (void)mainViewDidLoad {
78 [authorization_view_ setDelegate:self]; 80 [authorization_view_ setDelegate:self];
79 [authorization_view_ setString:kAuthorizationRightExecute]; 81 [authorization_view_ setString:kAuthorizationRightExecute];
80 [authorization_view_ setAutoupdate:YES]; 82 [authorization_view_ setAutoupdate:YES];
83 confirm_pin_view_ = [[Me2MePreferencePaneConfirmPin alloc] init];
84 [confirm_pin_view_ setDelegate:self];
85 disable_view_ = [[Me2MePreferencePaneDisable alloc] init];
86 [disable_view_ setDelegate:self];
81 } 87 }
82 88
83 - (void)willSelect { 89 - (void)willSelect {
84 have_new_config_ = NO; 90 have_new_config_ = NO;
85 91
86 NSDistributedNotificationCenter* center = 92 NSDistributedNotificationCenter* center =
87 [NSDistributedNotificationCenter defaultCenter]; 93 [NSDistributedNotificationCenter defaultCenter];
88 [center addObserver:self 94 [center addObserver:self
89 selector:@selector(onNewConfigFile:) 95 selector:@selector(onNewConfigFile:)
90 name:@kServiceName 96 name:@kServiceName
(...skipping 17 matching lines...) Expand all
108 [center removeObserver:self]; 114 [center removeObserver:self];
109 115
110 [service_status_timer_ invalidate]; 116 [service_status_timer_ invalidate];
111 [service_status_timer_ release]; 117 [service_status_timer_ release];
112 service_status_timer_ = nil; 118 service_status_timer_ = nil;
113 if (have_new_config_) { 119 if (have_new_config_) {
114 [self notifyPlugin: kUpdateFailedNotificationName]; 120 [self notifyPlugin: kUpdateFailedNotificationName];
115 } 121 }
116 } 122 }
117 123
118 - (void)onApply:(id)sender { 124 - (void)applyConfiguration:(id)sender
125 pin:(NSString*)pin {
119 if (!have_new_config_) { 126 if (!have_new_config_) {
120 // It shouldn't be possible to hit the button if there is no config to 127 // It shouldn't be possible to hit the button if there is no config to
121 // apply, but check anyway just in case it happens somehow. 128 // apply, but check anyway just in case it happens somehow.
122 return; 129 return;
123 } 130 }
124 131
125 // Ensure the authorization token is up-to-date before using it. 132 // Ensure the authorization token is up-to-date before using it.
126 [self updateAuthorizationStatus]; 133 [self updateAuthorizationStatus];
127 [self updateUI]; 134 [self updateUI];
128 135
129 std::string pin = base::SysNSStringToUTF8([pin_ stringValue]); 136 std::string pin_utf8 = base::SysNSStringToUTF8(pin);
130 std::string host_id, host_secret_hash; 137 std::string host_id, host_secret_hash;
131 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && 138 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) &&
132 config_->GetString(remoting::kHostSecretHashConfigPath, 139 config_->GetString(remoting::kHostSecretHashConfigPath,
133 &host_secret_hash)); 140 &host_secret_hash));
134 DCHECK(result); 141 DCHECK(result);
135 if (!IsPinValid(pin, host_id, host_secret_hash)) { 142 if (!IsPinValid(pin_utf8, host_id, host_secret_hash)) {
136 [self showIncorrectPinMessage]; 143 [self showIncorrectPinMessage];
137 return; 144 return;
138 } 145 }
139 146
140 [self applyNewServiceConfig]; 147 [self applyNewServiceConfig];
141 [self updateUI]; 148 [self updateUI];
142 } 149 }
143 150
144 - (void)onDisable:(id)sender { 151 - (void)onDisable:(id)sender {
145 // Ensure the authorization token is up-to-date before using it. 152 // Ensure the authorization token is up-to-date before using it.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 222 }
216 file_util::Delete(file, false); 223 file_util::Delete(file, false);
217 if (!IsConfigValid(new_config_.get())) { 224 if (!IsConfigValid(new_config_.get())) {
218 LOG(ERROR) << "Invalid configuration data read."; 225 LOG(ERROR) << "Invalid configuration data read.";
219 [self showError]; 226 [self showError];
220 return; 227 return;
221 } 228 }
222 229
223 config_.swap(new_config_); 230 config_.swap(new_config_);
224 have_new_config_ = YES; 231 have_new_config_ = YES;
232
233 [confirm_pin_view_ resetPin];
225 } 234 }
226 235
227 - (void)updateUI { 236 - (void)updateUI {
228 // TODO(lambroslambrou): These strings should be localized. 237 if (have_new_config_) {
229 #ifdef OFFICIAL_BUILD 238 [box_ setContentView:[confirm_pin_view_ view]];
230 NSString* name = @"Chrome Remote Desktop"; 239 } else {
231 #else 240 [box_ setContentView:[disable_view_ view]];
232 NSString* name = @"Chromoting"; 241 }
233 #endif 242
243 // TODO(lambroslambrou): Show "enabled" and "disabled" in bold font.
234 NSString* message; 244 NSString* message;
235 if (is_service_running_) { 245 if (is_service_running_) {
236 message = [NSString stringWithFormat:@"%@ is enabled", name]; 246 if (have_new_config_) {
247 message = @"Please confirm your new PIN.";
248 } else {
249 message = @"Remote connections to this computer are enabled.";
250 }
237 } else { 251 } else {
238 message = [NSString stringWithFormat:@"%@ is disabled", name]; 252 if (have_new_config_) {
253 message = @"Remote connections to this computer are disabled. To enable "
254 "remote connections you must confirm your PIN.";
255 } else {
256 message = @"Remote connections to this computer are disabled.";
257 }
239 } 258 }
240 [status_message_ setStringValue:message]; 259 [status_message_ setStringValue:message];
241 260
242 std::string email; 261 std::string email;
243 if (config_.get()) { 262 if (config_.get()) {
244 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email); 263 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email);
245 264
246 // The config has already been checked by |IsConfigValid|. 265 // The config has already been checked by |IsConfigValid|.
247 DCHECK(result); 266 DCHECK(result);
248 } 267 }
249 [email_ setStringValue:base::SysUTF8ToNSString(email)];
250 268
251 [disable_button_ setEnabled:(is_pane_unlocked_ && is_service_running_)]; 269 [disable_view_ setEnabled:(is_pane_unlocked_ && is_service_running_)];
252 [pin_instruction_message_ setEnabled:have_new_config_]; 270 [confirm_pin_view_ setEnabled:is_pane_unlocked_];
253 [email_ setEnabled:have_new_config_]; 271 [confirm_pin_view_ setEmail:base::SysUTF8ToNSString(email)];
254 [pin_ setEnabled:have_new_config_]; 272 NSString* applyButtonText = is_service_running_ ? @"Confirm" : @"Enable";
255 [apply_button_ setEnabled:(is_pane_unlocked_ && have_new_config_)]; 273 [confirm_pin_view_ setButtonText:applyButtonText];
256 } 274 }
257 275
258 - (void)showError { 276 - (void)showError {
259 NSAlert* alert = [[NSAlert alloc] init]; 277 NSAlert* alert = [[NSAlert alloc] init];
260 [alert setMessageText:@"An unexpected error occurred."]; 278 [alert setMessageText:@"An unexpected error occurred."];
261 [alert setInformativeText:@"Check the system log for more information."]; 279 [alert setInformativeText:@"Check the system log for more information."];
262 [alert setAlertStyle:NSWarningAlertStyle]; 280 [alert setAlertStyle:NSWarningAlertStyle];
263 [alert beginSheetModalForWindow:[[self mainView] window] 281 [alert beginSheetModalForWindow:[[self mainView] window]
264 modalDelegate:nil 282 modalDelegate:nil
265 didEndSelector:nil 283 didEndSelector:nil
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 - (void)notifyPlugin:(const char*)message { 438 - (void)notifyPlugin:(const char*)message {
421 NSDistributedNotificationCenter* center = 439 NSDistributedNotificationCenter* center =
422 [NSDistributedNotificationCenter defaultCenter]; 440 [NSDistributedNotificationCenter defaultCenter];
423 NSString* name = [NSString stringWithUTF8String:message]; 441 NSString* name = [NSString stringWithUTF8String:message];
424 [center postNotificationName:name 442 [center postNotificationName:name
425 object:nil 443 object:nil
426 userInfo:nil]; 444 userInfo:nil];
427 } 445 }
428 446
429 @end 447 @end
OLDNEW
« no previous file with comments | « remoting/host/me2me_preference_pane.h ('k') | remoting/host/me2me_preference_pane.xib » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698