From 26c45bcba0587b5145b974d8e7688d3a5a58a4ae Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Tue, 12 Jun 2012 00:25:50 +0200 Subject: [PATCH] Bug 686320 - Allow Mozmill to probe the OS for a free port instead of hardcoded value in JSBridge. r=jhammel --- jsbridge/jsbridge/__init__.py | 18 +- jsbridge/jsbridge/extension/chrome.manifest | 15 +- .../extension/chrome/content/overlay.js | 7 - .../extension/chrome/content/overlay.xul | 9 - .../jsbridge/extension/components/cmdarg.js | 145 ------------ .../jsbridge/extension/components/jsbridge.js | 82 +++++++ .../modules/{bridge.js => Bridge.jsm} | 26 ++- .../extension/resource/modules/Events.jsm | 34 +++ .../extension/resource/modules/Log.jsm | 37 +++ .../extension/resource/modules/NSPR.jsm | 123 ++++++++++ .../modules/{nspr-server.js => Server.jsm} | 84 ++++--- .../extension/resource/modules/Sockets.jsm | 124 ++++++++++ .../extension/resource/modules/events.js | 18 -- .../extension/resource/modules/init.js | 9 - .../resource/modules/jsbridgefilelogger.js | 45 ---- .../extension/resource/modules/nspr-socket.js | 118 ---------- .../extension/resource/modules/nspr.js | 105 --------- .../extension/resource/modules/server.js | 214 ------------------ jsbridge/jsbridge/network.py | 9 +- mozmill/mozmill/__init__.py | 54 +++-- .../extension/resource/modules/frame.js | 14 +- .../test_pre.js | 2 +- mutt/mutt/tests/python/usemozmill.py | 3 - 23 files changed, 528 insertions(+), 767 deletions(-) delete mode 100644 jsbridge/jsbridge/extension/chrome/content/overlay.js delete mode 100644 jsbridge/jsbridge/extension/chrome/content/overlay.xul delete mode 100644 jsbridge/jsbridge/extension/components/cmdarg.js create mode 100644 jsbridge/jsbridge/extension/components/jsbridge.js rename jsbridge/jsbridge/extension/resource/modules/{bridge.js => Bridge.jsm} (88%) create mode 100644 jsbridge/jsbridge/extension/resource/modules/Events.jsm create mode 100644 jsbridge/jsbridge/extension/resource/modules/Log.jsm create mode 100644 jsbridge/jsbridge/extension/resource/modules/NSPR.jsm rename jsbridge/jsbridge/extension/resource/modules/{nspr-server.js => Server.jsm} (55%) create mode 100644 jsbridge/jsbridge/extension/resource/modules/Sockets.jsm delete mode 100644 jsbridge/jsbridge/extension/resource/modules/events.js delete mode 100644 jsbridge/jsbridge/extension/resource/modules/init.js delete mode 100644 jsbridge/jsbridge/extension/resource/modules/jsbridgefilelogger.js delete mode 100644 jsbridge/jsbridge/extension/resource/modules/nspr-socket.js delete mode 100644 jsbridge/jsbridge/extension/resource/modules/nspr.js delete mode 100644 jsbridge/jsbridge/extension/resource/modules/server.js diff --git a/jsbridge/jsbridge/__init__.py b/jsbridge/jsbridge/__init__.py index 90021b23..d33d6d72 100644 --- a/jsbridge/jsbridge/__init__.py +++ b/jsbridge/jsbridge/__init__.py @@ -15,6 +15,16 @@ extension_path = os.path.join(parent, 'extension') wait_to_create_timeout = 60 + +def find_port(): + free_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + free_socket.bind(('127.0.0.1', 0)) + port = free_socket.getsockname()[1] + free_socket.close() + + return port + + def wait_and_create_network(host, port, timeout=wait_to_create_timeout): ttl = 0 while ttl < timeout: @@ -28,16 +38,16 @@ def wait_and_create_network(host, port, timeout=wait_to_create_timeout): sleep(.25) ttl += .25 if ttl == timeout: - raise Exception("Sorry, cannot connect to jsbridge extension, port %s" % port) - + raise Exception("Cannot connect to jsbridge extension, port %s" % port) + back_channel, bridge = create_network(host, port) sleep(.5) - + while back_channel.registered is False: back_channel.close() bridge.close() asyncore.socket_map = {} sleep(1) back_channel, bridge = create_network(host, port) - + return back_channel, bridge diff --git a/jsbridge/jsbridge/extension/chrome.manifest b/jsbridge/jsbridge/extension/chrome.manifest index 6d548889..f9aa69f7 100644 --- a/jsbridge/jsbridge/extension/chrome.manifest +++ b/jsbridge/jsbridge/extension/chrome.manifest @@ -1,15 +1,6 @@ resource jsbridge resource/ -content jsbridge chrome/content/ +component {2872d428-14f6-11de-ac86-001f5bd9235c} components/jsbridge.js +contract @mozilla.org/jsbridge;1 {2872d428-14f6-11de-ac86-001f5bd9235c} +category profile-after-change JSBridge @mozilla.org/jsbridge;1 -overlay chrome://browser/content/browser.xul chrome://jsbridge/content/overlay.xul -overlay chrome://messenger/content/mailWindowOverlay.xul chrome://jsbridge/content/overlay.xul - -overlay chrome://calendar/content/calendar.xul chrome://jsbridge/content/overlay.xul - -overlay windowtype:Songbird:Main chrome://jsbridge/content/overlay.xul - -component {2872d428-14f6-11de-ac86-001f5bd9235c} components/cmdarg.js -contract @mozilla.org/commandlinehandler/general-startup;1?type=jsbridge {2872d428-14f6-11de-ac86-001f5bd9235c} -category profile-after-change jsbridge @mozilla.org/commandlinehandler/general-startup;1?type=jsbridge -category command-line-handler jsbridge @mozilla.org/commandlinehandler/general-startup;1?type=jsbridge diff --git a/jsbridge/jsbridge/extension/chrome/content/overlay.js b/jsbridge/jsbridge/extension/chrome/content/overlay.js deleted file mode 100644 index 549c96b2..00000000 --- a/jsbridge/jsbridge/extension/chrome/content/overlay.js +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var jsbridgeInit = {}; Cu.import('resource://jsbridge/modules/init.js',jsbridgeInit); - - diff --git a/jsbridge/jsbridge/extension/chrome/content/overlay.xul b/jsbridge/jsbridge/extension/chrome/content/overlay.xul deleted file mode 100644 index 879cd919..00000000 --- a/jsbridge/jsbridge/extension/chrome/content/overlay.xul +++ /dev/null @@ -1,9 +0,0 @@ - - - - -