Commit b152a6ed authored by Kathleen Brade's avatar Kathleen Brade
Browse files

Bug 11199: Improve behavior if tor exits.

If Tor Launcher started the tor process and it exits, display
a prompt that allows the user to restart tor.
parent 6cf204d6
......@@ -29,7 +29,7 @@
<!-- Other: -->
<!ENTITY torsettings.startingTor "Waiting for Tor to start…">
<!ENTITY torsettings.restart "Restart">
<!ENTITY torsettings.restartTor "Restart Tor">
<!ENTITY torsettings.optional "Optional">
......
......@@ -4,7 +4,6 @@
torlauncher.error_title=Tor Launcher
torlauncher.tor_exited=Tor unexpectedly exited.
torlauncher.please_restart_app=Please restart this application.
torlauncher.tor_controlconn_failed=Could not connect to Tor control port.
torlauncher.tor_failed_to_start=Tor failed to start.
torlauncher.tor_control_failed=Failed to take control of Tor.
......
......@@ -4,7 +4,6 @@
# torlauncher.error_title=Tor Launcher
# torlauncher.tor_exited=Tor unexpectedly exited.
# torlauncher.please_restart_app=Please restart this application.
# torlauncher.tor_controlconn_failed=Could not connect to Tor control port.
# torlauncher.tor_failed_to_start=Tor failed to start.
# torlauncher.tor_bootstrap_failed=Tor failed to establish a Tor network connection.
......
......@@ -29,7 +29,7 @@
<!-- Other: -->
<!ENTITY torsettings.startingTor "等待 Tor 启动...">
<!ENTITY torsettings.restart "重新启动">
<!ENTITY torsettings.restartTor "Restart Tor">
<!ENTITY torsettings.optional "可选">
......
......@@ -4,7 +4,6 @@
torlauncher.error_title=Tor 启动器
torlauncher.tor_exited=Tor 意外退出。
torlauncher.please_restart_app=请重启该应用程序。
torlauncher.tor_controlconn_failed=无法连接 Tor 控制端口。
torlauncher.tor_failed_to_start=Tor 无法启动。
torlauncher.tor_control_failed=控制 Tor 失败。
......
......@@ -29,7 +29,7 @@
<!-- Other: -->
<!ENTITY torsettings.startingTor "Waiting for Tor to start…">
<!ENTITY torsettings.restart "Restart">
<!ENTITY torsettings.restartTor "Restart Tor">
<!ENTITY torsettings.optional "Optional">
......
......@@ -4,7 +4,6 @@
torlauncher.error_title=Tor啟動器
torlauncher.tor_exited=Tor unexpectedly exited.
torlauncher.please_restart_app=請重新啟動此程式。
torlauncher.tor_controlconn_failed=Could not connect to Tor control port.
torlauncher.tor_failed_to_start=Tor failed to start.
torlauncher.tor_control_failed=Failed to take control of Tor.
......
......@@ -29,7 +29,7 @@
<!-- Other: -->
<!ENTITY torsettings.startingTor "正在等待 Tor 啟動…">
<!ENTITY torsettings.restart "重新啟動">
<!ENTITY torsettings.restartTor "Restart Tor">
<!ENTITY torsettings.optional "選項">
......
......@@ -4,7 +4,6 @@
torlauncher.error_title=Tor 啟動程式
torlauncher.tor_exited=Tor 未預期的關閉。
torlauncher.please_restart_app=請重新啟動應用程式。
torlauncher.tor_controlconn_failed=無法連結至 Tor 控制連接埠。
torlauncher.tor_failed_to_start=Tor 啟動失敗
torlauncher.tor_control_failed=無法控制 Tor.
......
......@@ -4,7 +4,6 @@
# torlauncher.error_title=Tor Launcher
# torlauncher.tor_exited=Tor unexpectedly exited.
# torlauncher.please_restart_app=Please restart this application.
# torlauncher.tor_controlconn_failed=Could not connect to Tor control port.
# torlauncher.tor_failed_to_start=Tor failed to start.
# torlauncher.tor_bootstrap_failed=Tor failed to establish a Tor network connection.
......
......@@ -29,7 +29,7 @@
<!-- Other: -->
<!ENTITY torsettings.startingTor "Waiting for Tor to start…">
<!ENTITY torsettings.restart "Restart">
<!ENTITY torsettings.restartTor "Restart Tor">
<!ENTITY torsettings.optional "Optional">
......
......@@ -4,7 +4,6 @@
torlauncher.error_title=Tor Launcher
torlauncher.tor_exited=Tor unexpectedly exited.
torlauncher.please_restart_app=Please restart this application.
torlauncher.tor_controlconn_failed=Could not connect to Tor control port.
torlauncher.tor_failed_to_start=Tor failed to start.
torlauncher.tor_control_failed=Failed to take control of Tor.
......
......@@ -98,12 +98,9 @@ button.firstAnswer {
margin-left: 30px;
}
#startingTor {
min-height: 300px;
}
wizardpage[pageid="startingTor"] description,
wizardpage[pageid="errorPanel"] description,
#errorPanel description,
#startingTor description {
font-size: 120%;
font-weight: bold;
......
......@@ -140,14 +140,23 @@ TorProcessService.prototype =
this.mTorProcess = null;
this.mTorProcessStatus = this.kStatusExited;
this.mIsBootstrapDone = false;
this.mObsSvc.notifyObservers(null, "TorProcessExited", null);
if (!this.mIsQuitting)
{
this.mProtocolSvc.TorCleanupConnection();
var s = TorLauncherUtil.getLocalizedString("tor_exited");
TorLauncherUtil.showAlert(null, s);
TorLauncherLogger.log(4, s);
s += "\n" + TorLauncherUtil.getLocalizedString("tor_connection_lost");
var btnLabel = TorLauncherUtil.getLocalizedString("reconnect");
if (TorLauncherUtil.showConfirm(null, s, btnLabel) && !this.mIsQuitting)
{
this._startTor();
this._controlTor();
}
}
}
else if ("timer-callback" == aTopic)
......@@ -420,6 +429,12 @@ TorProcessService.prototype =
this._openNetworkSettings(true, panelID);
}
}
else if (this._networkSettingsWindow != null)
{
// If network settings is open, open progress dialog via notification.
if (this.mObsSvc)
this.mObsSvc.notifyObservers(null, "TorOpenProgressDialog", null);
}
else
{
this._openProgressDialog();
......@@ -547,9 +562,19 @@ TorProcessService.prototype =
TorLauncherUtil.showSaveSettingsAlert(null, errObj.details);
},
// Blocks until network settings dialog is closed.
// If this window is already open, put up "starting tor" panel, focus it and return.
// Otherwise, open the network settings dialog and block until it is closed.
_openNetworkSettings: function(aIsInitialBootstrap, aStartAtWizardPanel)
{
var win = this._networkSettingsWindow;
if (win)
{
// Return to "Starting tor" panel if being asked to open & dlog already exists.
win.showStartingTorPanel();
win.focus();
return;
}
const kSettingsURL = "chrome://torlauncher/content/network-settings.xul";
const kWizardURL = "chrome://torlauncher/content/network-settings-wizard.xul";
......@@ -562,6 +587,13 @@ TorProcessService.prototype =
wwSvc.openWindow(null, url, "_blank", winFeatures, argsArray);
},
get _networkSettingsWindow()
{
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
return wm.getMostRecentWindow("TorLauncher:NetworkSettings");
},
_openProgressDialog: function()
{
var chromeURL = "chrome://torlauncher/content/progress.xul";
......
......@@ -405,8 +405,7 @@ TorProtocolService.prototype =
TorCleanupConnection: function()
{
this._closeConnection();
this._closeConnection(this.mEventMonitorConnection);
this.mEventMonitorConnection = null;
this._shutDownEventMonitor();
},
TorStartEventMonitor: function()
......@@ -1163,6 +1162,17 @@ TorProtocolService.prototype =
return this.mRNGService;
},
_shutDownEventMonitor: function()
{
if (this.mEventMonitorConnection)
{
this._closeConnection(this.mEventMonitorConnection);
this.mEventMonitorConnection = null;
this.mEventMonitorBuffer = null;
this.mEventMonitorInProgressReply = null;
}
},
_waitForEventData: function()
{
if (!this.mEventMonitorConnection)
......@@ -1179,15 +1189,25 @@ TorProtocolService.prototype =
return;
}
var binStream = _this.mEventMonitorConnection.binInStream;
var bytes = binStream.readBytes(binStream.available());
if (!_this.mEventMonitorBuffer)
_this.mEventMonitorBuffer = bytes;
else
_this.mEventMonitorBuffer += bytes;
_this._processEventData();
try
{
var binStream = _this.mEventMonitorConnection.binInStream;
var bytes = binStream.readBytes(binStream.available());
if (!_this.mEventMonitorBuffer)
_this.mEventMonitorBuffer = bytes;
else
_this.mEventMonitorBuffer += bytes;
_this._processEventData();
_this._waitForEventData();
_this._waitForEventData();
}
catch (e)
{
// Probably we got here because tor exited. If tor is restarted by
// Tor Launcher, the event monitor will be restarted too.
TorLauncherLogger.safelog(4, "Event monitor read error", e);
_this._shutDownEventMonitor();
}
}
};
......
......@@ -61,6 +61,44 @@ let TorLauncherUtil = // Public
}
},
// Returns true if user confirms; false if not.
// Note that no prompt is shown (and false is returned) if the Network Settings
// window is open.
showConfirm: function(aParentWindow, aMsg, aOKButtonLabel)
{
try
{
if (!aParentWindow)
{
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
aParentWindow = wm.getMostRecentWindow("TorLauncher:NetworkSettings");
if (aParentWindow)
return false; // Don't show prompt if Network Settings window is open.
aParentWindow = wm.getMostRecentWindow("navigator:browser");
}
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var title = this.getLocalizedString("error_title");
var btnFlags = (ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_POS_0_DEFAULT
+ (ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL);
var notUsed = { value: false };
var btnIndex = ps.confirmEx(aParentWindow, title, aMsg, btnFlags,
aOKButtonLabel, null, null, null, notUsed);
return (0 == btnIndex);
}
catch (e)
{
return confirm(aMsg);
}
return false;
},
showSaveSettingsAlert: function(aParentWindow, aDetails)
{
if (!aDetails)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment