Skip to content

Commit

Permalink
Merge branch 'master' into paul-udp
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-E committed Jun 6, 2014
2 parents 7f70bb7 + 3c31aea commit dc591ca
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
freedom-for-firefox.jsm
freedom.map
node_modules
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ module.exports = function(grunt) {
'freedom-for-firefox.jsm':
FILES.lib
.concat(promise_lib)
.concat(FILES.src)
.concat(FILES.srcCore)
.concat('providers/*.js')
}
}
},
clean: ["freedom-for-firefox.jsm"]
clean: ["freedom-for-firefox.jsm", "freedom.map"]
});

grunt.loadNpmTasks('grunt-contrib-uglify');
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Or in classic firefox extensions use:
Components.utils.import(PATH TO .jsm);


This will define the function `setupFreedom` in the current scope. `setupFreedom` takes two arguments. The first argument is an "options" object. The second argument is the path to the freedom manifest file. `setupFreedom` returns a freedom object.
This will define the function `setupFreedom` in the current scope. `setupFreedom` takes three arguments:
- manifest: the path to the freedom manifest file.
- debug: true for debugging output.
- freedomcfg: the freedomcfg function for defining new freedom apis.

`setupFreedom` returns a freedom object.

NOTE: The behavior of calling `setupFreedom` more than once is undefined.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "freedom-for-firefox",
"description": "Embracing a distributed web",
"version": "0.0.1",
"version": "0.1.4",
"homepage": "http://freedomjs.org",
"bugs": {
"url": "http://github.com/freedomjs/freedom-for-firefox/issues",
Expand Down
11 changes: 11 additions & 0 deletions providers/client_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ nsIInputStreamCallback.prototype.onInputStreamReady = function(stream) {
.getService(Components.interfaces.nsISocketTransportService);
if (typeof this.socket.onData === 'function') {
this.socket.onData(typedBuffer);
} else {
// Save data until we have a handler.
this.socket._waitingData.push(typedBuffer);
}
this.socket.rawInputStream.asyncWait(this, 0, 0, mainThread);
};
Expand All @@ -54,6 +57,7 @@ function ClientSocket(incomingTransport) {
if (typeof incomingTransport !== 'undefined') {
this._setupTransport(incomingTransport);
}
this._waitingData = [];
}

ClientSocket.prototype._setupTransport = function(transport) {
Expand Down Expand Up @@ -120,6 +124,13 @@ ClientSocket.prototype.getInfo = function() {

};

ClientSocket.prototype.setOnDataListener = function(listener) {
while (this._waitingData.length > 0) {
listener(this._waitingData.shift());
}
this.onData = listener;
};

ClientSocket.prototype.arrayBufferToString = function(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
};
4 changes: 2 additions & 2 deletions providers/tcp_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Socket_firefox(channel, dispatchEvent, socketId) {
if (socketId in incommingConnections) {
this.clientSocket = incommingConnections[socketId];
delete incommingConnections[socketId];
this.clientSocket.onData = this._onData.bind(this);
this.clientSocket.setOnDataListener(this._onData.bind(this));
}
}

Expand All @@ -27,7 +27,7 @@ Socket_firefox.prototype.close = function(continuation) {

Socket_firefox.prototype.connect = function(hostname, port, continuation) {
this.clientSocket = new ClientSocket();
this.clientSocket.onData = this.onData.bind(this);
this.clientSocket.setOnDataListener(this._onData.bind(this));
this.clientSocket.connect(hostname, port);
continuation();
};
Expand Down
15 changes: 13 additions & 2 deletions src/firefox-preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ var mozRTCPeerConnection = hiddenWindow.mozRTCPeerConnection;
var mozRTCSessionDescription = hiddenWindow.mozRTCSessionDescription;
var mozRTCIceCandidate = hiddenWindow.mozRTCIceCandidate;

// Replace Blob with blob that has prototype defined.
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1007318
var Blob = hiddenWindow.Blob;

var freedom;

function setupFreedom(manifest, debug) {
// Fake the location object so that freedom detects that it is in a
// privileged environment.
var location = {
protocol: "resource:"
};

function setupFreedom(manifest, debug, freedomcfg) {
if (this.freedom) {
return this.freedom;
}
Expand All @@ -27,6 +37,7 @@ function setupFreedom(manifest, debug) {
portType: 'Worker',
stayLocal: true,
location: manifestLocation,
debug: debug || false
debug: debug || false,
isModule: false
};

0 comments on commit dc591ca

Please sign in to comment.