Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

introduce unloading. wip.

  • Loading branch information...
commit acfef4c3a72b96b188a25401fc2c758739300201 1 parent 0c54a72
@eeejay authored
View
11 bootstrap.js
@@ -12,6 +12,8 @@ var tts = null;
var externalMediaPath = null;
+var unloadFuncs = [];
+
/* From http://starkravingfinkle.org/blog/2011/01/bootstrap-jones-adventures-in-restartless-add-ons/ */
var windowListener = {
@@ -50,6 +52,7 @@ function loadIntoWindow (aWindow, data) {
aWindow.tts = tts;
let _globals = {window: aWindow};
loader.loadSubScript("resource://talktome/content/main.js", _globals);
+ unloadFuncs.push(_globals.unloadFunc);
try {
loadIntoContent (aWindow, data);
} catch (e) {
@@ -140,6 +143,14 @@ function shutdown (data, reason) {
let resource = Services.io.getProtocolHandler("resource").
QueryInterface(Ci.nsIResProtocolHandler);
resource.setSubstitution(data.id.substring(0, data.id.indexOf('@')), null);
+
+ // Unload all windows
+ for (let i in unloadFuncs) {
+ let unloadFunc = unloadFuncs[i];
+ console.log(unloadFunc);
+ if (unloadFunc)
+ unloadFunc();
+ }
}
function uninstall (reason, data) {
View
7 content/main.js
@@ -17,9 +17,16 @@ var TalkToMe = {
this.navigator = new Navigator (window, this.presenter);
this.inputManager = new InputManager(window, this.navigator);
this.inputManager.start();
+ },
+
+ unloadFunc: function () {
+ this.presenter.remove();
+ this.inputManager.stop();
}
}
+var unloadFunc = Callback(TalkToMe.unloadFunc, TalkToMe);
+
// Try to load into a window, if it is premature listen for events.
if (window.document.readyState == "complete")
TalkToMe.onUIReady(null);
View
28 content/presenter.js
@@ -58,6 +58,9 @@ Presenter.prototype = {
},
playThud: function playThud (phrase) {
this.tts.playEarcon("[thud]", TextToSpeech.QUEUE_ADD);
+ },
+ remove: function remove () {
+ this._highlighter.remove();
}
};
@@ -74,12 +77,12 @@ function _Highlighter(window) {
let document = window.document;
let stack = window.document.getElementById('stack');
- let highlightLayer = document.createElementNS(
+ this.highlightLayer = document.createElementNS(
"http://www.w3.org/1999/xhtml", "div");
- highlightLayer.style.pointerEvents = "none";
- highlightLayer.style.MozStackSizing = 'ignore';
- highlightLayer.style.position = "relative";
- stack.appendChild(highlightLayer);
+ this.highlightLayer.style.pointerEvents = "none";
+ this.highlightLayer.style.MozStackSizing = 'ignore';
+ this.highlightLayer.style.position = "relative";
+ stack.appendChild(this.highlightLayer);
this._highlightRect = document.createElementNS(
"http://www.w3.org/1999/xhtml", "div");
@@ -87,7 +90,7 @@ function _Highlighter(window) {
this._highlightRect.style.borderStyle = "solid";
this._highlightRect.style.pointerEvents = "none";
this._highlightRect.style.display = "none";
- highlightLayer.appendChild(this._highlightRect);
+ this.highlightLayer.appendChild(this._highlightRect);
// style it
this._highlightRect.style.borderColor = this.borderColor;
@@ -113,13 +116,13 @@ function _Highlighter(window) {
contentShowingObserver.addEventListener(
"broadcast",
Callback(function (e) {
- console.log(highlightLayer.getAttribute("disabled") == "true");
- if (highlightLayer.getAttribute("disabled") == "true")
+ console.log(this.highlightLayer.getAttribute("disabled") == "true");
+ if (this.highlightLayer.getAttribute("disabled") == "true")
this.hide ();
else
this.show ();
}, this));
- highlightLayer.appendChild(contentShowingObserver)
+ this.highlightLayer.appendChild(contentShowingObserver)
// Hook in to relevant events
window.Browser.controlsScrollbox.addEventListener(
@@ -203,4 +206,9 @@ _Highlighter.prototype.askForBounds = function () {
_Highlighter.prototype.showBoundsHandler = function (aMessage) {
this.highlight(aMessage.json.bounds);
-}
+};
+
+_Highlighter.prototype.remove = function () {
+ console.log("Removing highlighter");
+ this.highlightLayer.parentNode.removeChild(this.highlightLayer);
+};
View
4 content/speech.js
@@ -109,8 +109,10 @@ TextToSpeech.prototype.setPitch = function (f) {
TextToSpeech.prototype.shutdown = function () {
console.log("TextToSpeech.shutdown");
- if (this.android_tts)
+ if (this.android_tts) {
this.android_tts.shutdown();
+ this.android_tts = null;
+ }
}
TextToSpeech.QUEUE_FLUSH = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.