commit 1794bb4d3ba23410a302639fbe7672fe103a5b95 Author: David Fifield david@bamsoftware.com Date: Wed Mar 12 21:09:18 2014 -0700
Look more like a real extension.
The code is now in a component, not a browser overlay. I followed some instructions from https://developer.mozilla.org/en-US/docs/How_to_Build_an_XPCOM_Component_in_... https://developer.mozilla.org/en-US/docs/Mozilla/XPCOM/Receiving_startup_not... https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPC... It now runs just once at startup. (Previously it ran for each new browser window.) --- firefox/chrome.manifest | 7 +++-- firefox/chrome/content/main.js | 47 ----------------------------- firefox/chrome/content/main.xul | 5 ---- firefox/components/main.js | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 54 deletions(-)
diff --git a/firefox/chrome.manifest b/firefox/chrome.manifest index 5403d2b..ef6596c 100644 --- a/firefox/chrome.manifest +++ b/firefox/chrome.manifest @@ -1,2 +1,5 @@ -content meek-http-helper chrome/content/ -overlay chrome://browser/content/browser.xul chrome://meek-http-helper/content/main.xul +# https://developer.mozilla.org/en-US/docs/How_to_Build_an_XPCOM_Component_in_... +# https://developer.mozilla.org/en-US/docs/Mozilla/XPCOM/Receiving_startup_not... +component {e7bc2b9c-f454-49f3-a19f-14848a4d871d} components/main.js +contract @bamsoftware.com/meek-http-helper;1 {e7bc2b9c-f454-49f3-a19f-14848a4d871d} +category profile-after-change MeekHTTPHelper @bamsoftware.com/meek-http-helper;1 diff --git a/firefox/chrome/content/main.js b/firefox/chrome/content/main.js deleted file mode 100644 index 1430a57..0000000 --- a/firefox/chrome/content/main.js +++ /dev/null @@ -1,47 +0,0 @@ -var FRONT_URL = "https://www.google.com/"; -var HOST = "meek-reflect.appspot.com"; - -// Create a "direct" nsIProxyInfo that bypasses the default proxy. -// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProtoc... -var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"] - .getService(Components.interfaces.nsIProtocolProxyService); -// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProxyI... -var proxy = pps.newProxyInfo("direct", "", 0, 0, 0xffffffff, null); - -// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIIOServ... -var ioService = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); -var httpProtocolHandler = ioService.getProtocolHandler("http") - .QueryInterface(Components.interfaces.nsIHttpProtocolHandler); -var uri = ioService.newURI(FRONT_URL, null, null); -// Construct an HTTP channel with the proxy bypass. -// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpCh... -var channel = httpProtocolHandler.newProxiedChannel(uri, proxy, 0, null) - .QueryInterface(Components.interfaces.nsIHttpChannel); -// Set the host we really want. -channel.setRequestHeader("Host", HOST, false); -channel.redirectionLimit = 0; -// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIUpload... -// channel.requestMethod = "POST"; - -var listener = new StreamListener(); -channel.asyncOpen(listener, null); - -// https://developer.mozilla.org/en-US/docs/Creating_Sandboxed_HTTP_Connections -function StreamListener() { - this.onStartRequest = function(aRequest, aContext) { - dump("onStartRequest\n"); - }; - this.onStopRequest = function(aRequest, aContext, aStatus) { - dump("onStopRequest\n"); - }; - this.onDataAvailable = function(aRequest, aContext, aStream, aSourceOffset, aLength) { - dump("onDataAvailable\n"); - var a = new Uint8Array(aLength); - var input = Components.classes["@mozilla.org/binaryinputstream;1"] - .createInstance(Components.interfaces.nsIBinaryInputStream); - input.setInputStream(aStream); - input.readByteArray(aLength, a); - dump(aLength + ":" + a + "\n"); - }; -} diff --git a/firefox/chrome/content/main.xul b/firefox/chrome/content/main.xul deleted file mode 100644 index c93a89e..0000000 --- a/firefox/chrome/content/main.xul +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0"?> - -<overlay id="main" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - <script src="chrome://meek-http-helper/content/main.js"></script> -</overlay> diff --git a/firefox/components/main.js b/firefox/components/main.js new file mode 100644 index 0000000..0588b4a --- /dev/null +++ b/firefox/components/main.js @@ -0,0 +1,63 @@ +const FRONT_URL = "https://www.google.com/"; +const HOST = "meek-reflect.appspot.com"; + +// https://developer.mozilla.org/en-US/docs/How_to_Build_an_XPCOM_Component_in_... +// https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPC... +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +function MeekHTTPHelper() { + this.wrappedJSObject = this; + + // Create a "direct" nsIProxyInfo that bypasses the default proxy. + // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProtoc... + var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"] + .getService(Components.interfaces.nsIProtocolProxyService); + // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProxyI... + var proxy = pps.newProxyInfo("direct", "", 0, 0, 0xffffffff, null); + + // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIIOServ... + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var httpProtocolHandler = ioService.getProtocolHandler("http") + .QueryInterface(Components.interfaces.nsIHttpProtocolHandler); + var uri = ioService.newURI(FRONT_URL, null, null); + // Construct an HTTP channel with the proxy bypass. + // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpCh... + var channel = httpProtocolHandler.newProxiedChannel(uri, proxy, 0, null) + .QueryInterface(Components.interfaces.nsIHttpChannel); + // Set the host we really want. + channel.setRequestHeader("Host", HOST, false); + channel.redirectionLimit = 0; + // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIUpload... + // channel.requestMethod = "POST"; + + // https://developer.mozilla.org/en-US/docs/Creating_Sandboxed_HTTP_Connections + function StreamListener() { + this.onStartRequest = function(aRequest, aContext) { + dump("onStartRequest\n"); + }; + this.onStopRequest = function(aRequest, aContext, aStatus) { + dump("onStopRequest\n"); + }; + this.onDataAvailable = function(aRequest, aContext, aStream, aSourceOffset, aLength) { + dump("onDataAvailable\n"); + var a = new Uint8Array(aLength); + var input = Components.classes["@mozilla.org/binaryinputstream;1"] + .createInstance(Components.interfaces.nsIBinaryInputStream); + input.setInputStream(aStream); + input.readByteArray(aLength, a); + dump(aLength + ":" + a + "\n"); + }; + } + + var listener = new StreamListener(); + channel.asyncOpen(listener, null); +} + +MeekHTTPHelper.prototype = { + classDescription: "meek HTTP helper component", + classID: Components.ID("{e7bc2b9c-f454-49f3-a19f-14848a4d871d}"), + contractID: "@bamsoftware.com/meek-http-helper;1", +}; + +var NSGetFactory = XPCOMUtils.generateNSGetFactory([MeekHTTPHelper]);
tor-commits@lists.torproject.org