15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <PreferencePanes/PreferencePanes.h> 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <SecurityInterface/SFAuthorizationView.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/jsoncpp/source/include/json/value.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is an implementation of JsonHostConfig which does not use code from 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the "base" target, so it can be built for 64-bit on Mac OS X. 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(lambroslambrou): Once the "base" target has 64-bit support, remove this 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// implementation and use the one in remoting/host/json_host_config.h - see 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://crbug.com/128122. 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class JsonHostConfig { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JsonHostConfig(const std::string& filename); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~JsonHostConfig(); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Read(); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetString(const std::string& path, std::string* out_value) const; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string GetSerializedData() const; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Json::Value config_; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string filename_; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(JsonHostConfig); 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class Me2MePreferencePaneConfirmPin; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class Me2MePreferencePaneDisable; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface Me2MePreferencePane : NSPreferencePane { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Me2MePreferencePaneConfirmPin* confirm_pin_view_; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Me2MePreferencePaneDisable* disable_view_; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet NSTextField* status_message_; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet NSBox* box_; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet SFAuthorizationView* authorization_view_; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Holds the new proposed configuration if a temporary config file is 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // present. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<remoting::JsonHostConfig> config_; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSTimer* service_status_timer_; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These flags determine the UI state. These are computed in the 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // update...Status methods. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL is_service_running_; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL is_pane_unlocked_; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if a new proposed config file has been loaded into memory. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL have_new_config_; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if launchd has been instructed to stop the service and we are waiting 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the operation to complete. 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL awaiting_service_stop_; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if a version-mismatch has been detected. If true, this causes all 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // controls to be greyed out, and also prevents any config file from being 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // deleted, pending a restart of the preference pane. 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL restart_pending_or_canceled_; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)mainViewDidLoad; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)willSelect; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)didSelect; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)willUnselect; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)onDisable:(id)sender; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)applyConfiguration:(id)sender 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pin:(NSString*)pin; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)onNewConfigFile:(NSNotification*)notification; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)refreshServiceStatus:(NSTimer*)timer; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)authorizationViewDidAuthorize:(SFAuthorizationView*)view; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)authorizationViewDidDeauthorize:(SFAuthorizationView*)view; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)updateServiceStatus; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)updateAuthorizationStatus; 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Read any new config file if present. If a config file is successfully read, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this deletes the file and keeps the config data loaded in memory. If this 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// method is called a second time (when the file has been deleted), the current 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// config is remembered, so this method acts as a latch: it can change 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |have_new_config_| from NO to YES, but never from YES to NO. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This scheme means that this method can delete the file immediately (to avoid 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// leaving a stale file around in case of a crash), but this method can safely 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be called multiple times without forgetting the loaded config. To explicitly 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// forget the current config, set |have_new_config_| to NO. 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This method should not be called if |restart_pending_or_canceled_| is YES, 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// since this would delete any config file. 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)readNewConfig; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Update all UI controls according to any stored flags and loaded config. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This should be called after any sequence of operations that might change the 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// UI state. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)updateUI; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Alert the user to a generic error condition. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)showError; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Alert the user that the typed PIN is incorrect. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)showIncorrectPinMessage; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Save the new config to the system, and either start the service or inform 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the currently-running service of the new config. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)applyNewServiceConfig; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BOOL)runHelperAsRootWithCommand:(const char*)command 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) inputData:(const std::string&)input_data; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BOOL)sendJobControlMessage:(const char*)launch_key; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Compare the version of the running pref-pane against the installed version. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the versions are mismatched and the pref-pane is visible, disable the 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// pane to prevent interaction, and prompt the user to restart System 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Preferences. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This should be called on notification of a new config, and also in 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |didSelect| when the pane becomes visible. The pane needs to be visible so 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that the alert appears as a sheet over the pane (instead of a detached 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// window), which gives the user an appropriate context for the alert. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In the case of a version-mismatch, the new config file should be kept until 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// System Preferences is restarted, or thrown away when the user cancels the 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// alert. This method sets the |restart_pending_or_canceled_| flag on 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// detecting version-mismatch. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)checkInstalledVersion; 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)mismatchAlertDidEnd:(NSAlert*)alert 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) returnCode:(NSInteger)returnCode 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contextInfo:(void*)contextInfo; 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Called when the user chooses OK when prompted to restart System Preferences. 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)restartSystemPreferences; 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end 147