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
3// found in the LICENSE file.
4
5#import <Cocoa/Cocoa.h>
6#import <PreferencePanes/PreferencePanes.h>
7#import <SecurityInterface/SFAuthorizationView.h>
8
9#include <string>
10
11#include "base/memory/scoped_ptr.h"
12#include "third_party/jsoncpp/source/include/json/value.h"
13
14namespace remoting {
15
16// This is an implementation of JsonHostConfig which does not use code from
17// the "base" target, so it can be built for 64-bit on Mac OS X.
18
19// TODO(lambroslambrou): Once the "base" target has 64-bit support, remove this
20// implementation and use the one in remoting/host/json_host_config.h - see
21// http://crbug.com/128122.
22class JsonHostConfig {
23 public:
24  JsonHostConfig(const std::string& filename);
25  ~JsonHostConfig();
26
27  bool Read();
28  bool GetString(const std::string& path, std::string* out_value) const;
29  std::string GetSerializedData() const;
30
31 private:
32  Json::Value config_;
33  std::string filename_;
34
35  DISALLOW_COPY_AND_ASSIGN(JsonHostConfig);
36};
37
38}
39
40@class Me2MePreferencePaneConfirmPin;
41@class Me2MePreferencePaneDisable;
42
43@interface Me2MePreferencePane : NSPreferencePane {
44  Me2MePreferencePaneConfirmPin* confirm_pin_view_;
45  Me2MePreferencePaneDisable* disable_view_;
46
47  IBOutlet NSTextField* status_message_;
48  IBOutlet NSBox* box_;
49  IBOutlet SFAuthorizationView* authorization_view_;
50
51  // Holds the new proposed configuration if a temporary config file is
52  // present.
53  scoped_ptr<remoting::JsonHostConfig> config_;
54
55  NSTimer* service_status_timer_;
56
57  // These flags determine the UI state.  These are computed in the
58  // update...Status methods.
59  BOOL is_service_running_;
60  BOOL is_pane_unlocked_;
61
62  // True if a new proposed config file has been loaded into memory.
63  BOOL have_new_config_;
64
65  // True if launchd has been instructed to stop the service and we are waiting
66  // for the operation to complete.
67  BOOL awaiting_service_stop_;
68
69  // True if a version-mismatch has been detected.  If true, this causes all
70  // controls to be greyed out, and also prevents any config file from being
71  // deleted, pending a restart of the preference pane.
72  BOOL restart_pending_or_canceled_;
73}
74
75- (void)mainViewDidLoad;
76- (void)willSelect;
77- (void)didSelect;
78- (void)willUnselect;
79- (void)onDisable:(id)sender;
80- (void)applyConfiguration:(id)sender
81                       pin:(NSString*)pin;
82- (void)onNewConfigFile:(NSNotification*)notification;
83- (void)refreshServiceStatus:(NSTimer*)timer;
84- (void)authorizationViewDidAuthorize:(SFAuthorizationView*)view;
85- (void)authorizationViewDidDeauthorize:(SFAuthorizationView*)view;
86- (void)updateServiceStatus;
87- (void)updateAuthorizationStatus;
88
89// Read any new config file if present.  If a config file is successfully read,
90// this deletes the file and keeps the config data loaded in memory.  If this
91// method is called a second time (when the file has been deleted), the current
92// config is remembered, so this method acts as a latch: it can change
93// |have_new_config_| from NO to YES, but never from YES to NO.
94//
95// This scheme means that this method can delete the file immediately (to avoid
96// leaving a stale file around in case of a crash), but this method can safely
97// be called multiple times without forgetting the loaded config.  To explicitly
98// forget the current config, set |have_new_config_| to NO.
99//
100// This method should not be called if |restart_pending_or_canceled_| is YES,
101// since this would delete any config file.
102- (void)readNewConfig;
103
104// Update all UI controls according to any stored flags and loaded config.
105// This should be called after any sequence of operations that might change the
106// UI state.
107- (void)updateUI;
108
109// Alert the user to a generic error condition.
110- (void)showError;
111
112// Alert the user that the typed PIN is incorrect.
113- (void)showIncorrectPinMessage;
114
115// Save the new config to the system, and either start the service or inform
116// the currently-running service of the new config.
117- (void)applyNewServiceConfig;
118
119- (BOOL)runHelperAsRootWithCommand:(const char*)command
120                         inputData:(const std::string&)input_data;
121- (BOOL)sendJobControlMessage:(const char*)launch_key;
122
123// Compare the version of the running pref-pane against the installed version.
124// If the versions are mismatched and the pref-pane is visible, disable the
125// pane to prevent interaction, and prompt the user to restart System
126// Preferences.
127//
128// This should be called on notification of a new config, and also in
129// |didSelect| when the pane becomes visible.  The pane needs to be visible so
130// that the alert appears as a sheet over the pane (instead of a detached
131// window), which gives the user an appropriate context for the alert.
132//
133// In the case of a version-mismatch, the new config file should be kept until
134// System Preferences is restarted, or thrown away when the user cancels the
135// alert.  This method sets the |restart_pending_or_canceled_| flag on
136// detecting version-mismatch.
137- (void)checkInstalledVersion;
138
139- (void)mismatchAlertDidEnd:(NSAlert*)alert
140                 returnCode:(NSInteger)returnCode
141                contextInfo:(void*)contextInfo;
142
143// Called when the user chooses OK when prompted to restart System Preferences.
144- (void)restartSystemPreferences;
145
146@end
147