Skip to content

Commit

Permalink
Window remote fix (thrust:242) and Proxy API
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislas Polu committed Dec 2, 2014
1 parent faf195c commit 46d34a4
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/api.session.js
Expand Up @@ -28,6 +28,12 @@ var session = function(spec, my) {
//
// #### _public_
//
var visitedlink_add; /* visitedlink_add(url, cb_); */
var visitedlink_clear; /* visitedlink_clear(cb_); */
var proxy_set; /* proxy_set(rules, cb_); */
var proxy_clear; /* proxy_clear(cb_); */

var is_off_the_record; /* is_off_the_record(cb_); */

//
// #### _protected_
Expand Down Expand Up @@ -110,11 +116,62 @@ var session = function(spec, my) {
/****************************************************************************/
/* PUBLIC METHODS */
/****************************************************************************/
// ### visitedlink_add
//
// Adds a link to the list of visitedlinks
// ```
// @url {string}
// @cb_ {function(err)}
// ```
visitedlink_add = function(url, cb_) {
that.call('visitedlink_add', { url: url }, cb_);
};

// ### visitedlink_clear
//
// Clears the list of visitedlink
// ```
// @cb_ {function(err)}
// ```
visitedlink_clear = function(cb_) {
that.call('visitedlink_clear', {}, cb_);
};

// ### proxy_set
//
// Sets a proxy-rules string for this session to replace the default system
// settings.
//
// ```
// @rules {string}
// @cb_ {function(err)}
// ```
proxy_set = function(rules, cb_) {
that.call('proxy_set', { rules: rules }, cb_);
};

// ### proxy_clear
//
// Sets a proxy-rules string for this session to replace the default system
// settings.
//
// ```
// @cb_ {function(err)}
// ```
proxy_clear = function(cb_) {
that.call('proxy_clear', {}, cb_);
};


common.method(that, 'invoke_cookies_load', invoke_cookies_load, _super);
common.method(that, 'invoke_cookies_load_for_key', invoke_cookies_load_for_key, _super);
common.method(that, 'invoke_cookies_flush', invoke_cookies_flush, _super);

common.method(that, 'visitedlink_add', visitedlink_add, _super);
common.method(that, 'visitedlink_clear', visitedlink_clear, _super);
common.method(that, 'proxy_set', proxy_set, _super);
common.method(that, 'proxy_clear', proxy_clear, _super);

return that;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/api.window.js
Expand Up @@ -168,6 +168,9 @@ var window = function(spec, my) {
// @cb_ {function(err)}
// ```
remote = function(message, cb_) {
if(typeof message !== 'object') {
message = { payload: message };
}
that.call('remote', { message: message }, cb_);
};

Expand Down
72 changes: 72 additions & 0 deletions test/session_proxy.js
@@ -0,0 +1,72 @@
var async = require('async');
var common = require('../lib/common.js');
var http = require('http');

var _api = null;
var _window = null;
var _session = null;

async.series([
function(cb_) {
http.createServer(function(request, response) {
var proxy = http.createClient(80, request.headers['host'])
console.log('PROXIED REQUEST URL: ' + request.url);
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
});
proxy_response.addListener('end', function() {
response.end();
});
response.writeHead(proxy_response.statusCode, proxy_response.headers);
});
request.addListener('data', function(chunk) {
proxy_request.write(chunk, 'binary');
});
request.addListener('end', function() {
proxy_request.end();
});
}).listen(8080, cb_);
},
function(cb_) {
require('./base.js')(function(err, api) {
_api = api;
return cb_(err);
});
},
function(cb_) {
_session = _api.session({
off_the_record: true
});
return cb_();
},
function(cb_) {
_session.proxy_set('localhost:8080', cb_);
},
function(cb_) {
_window = _api.window({
size: {
width: 1024,
height: 768
},
session: _session,
root_url: 'http://breach.cc'
});
return cb_();
},
function(cb_) {
_window.show(cb_);
},
function(cb_) {
setTimeout(function() {
_session.proxy_clear(cb_);
}, 5000);
}
], function(err) {
if(err) {
common.log.out('FAILED');
common.log.error(err);
}
common.log.out('OK');
});
1 change: 1 addition & 0 deletions test/window_remote.html
Expand Up @@ -8,6 +8,7 @@
console.log(JSON.stringify(msg));
});
THRUST.remote.send({ foo: 'bar' });
THRUST.remote.send("foo");
});
</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions test/window_remote.js
Expand Up @@ -23,6 +23,7 @@ async.series([
console.log('REMOTE');
console.log(JSON.stringify(evt.message));
_window.remote({ foo: 'reply' });
_window.remote("reply");
});
return cb_();
},
Expand Down

0 comments on commit 46d34a4

Please sign in to comment.