This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Bug 686320 - Allow Mozmill to probe the OS for a free port instead of hardcoded value in JSBridge. r=jhammel #45
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* 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/. */ | ||
|
||
const Cc = Components.classes; | ||
const Ci = Components.interfaces; | ||
const Cu = Components.utils; | ||
|
||
// Import global modules | ||
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||
Cu.import("resource://gre/modules/Services.jsm"); | ||
|
||
// Include local modules | ||
Cu.import("resource://jsbridge/modules/Log.jsm"); | ||
|
||
|
||
// Constants for preferences names | ||
const PREF_JSBRIDGE_PORT = "extensions.jsbridge.port"; | ||
|
||
|
||
/** | ||
* XPCOM component to observe different application states and to | ||
* handle the JSBridge server. | ||
*/ | ||
function JSBridge() { | ||
this._server = null; | ||
} | ||
|
||
JSBridge.prototype = { | ||
classDescription: "JSBridge", | ||
classID: Components.ID("{2872d428-14f6-11de-ac86-001f5bd9235c}"), | ||
contractID: "@mozilla.org/jsbridge;1", | ||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), | ||
|
||
_xpcom_categories: [{category: "profile-after-change"}], | ||
|
||
/** | ||
* Handler for registered observer notifications. | ||
* | ||
* @param {String} aSubject | ||
* Subject of the observer message (not used) | ||
* @param {String} aTopic | ||
* Topic of the observer message | ||
* @param {Object} aData | ||
* Data of the observer message (not used) | ||
*/ | ||
observe: function JSB_observe(aSubject, aTopic, aData) { | ||
Log.dump("Observer topic", aTopic); | ||
|
||
switch (aTopic) { | ||
// The server cannot be started before the ui is shown. That means | ||
// we also have to register for the final-ui-startup notification. | ||
case "profile-after-change": | ||
Services.obs.addObserver(this, "final-ui-startup", false); | ||
Services.obs.addObserver(this, "quit-application", false); | ||
break; | ||
|
||
case "final-ui-startup": | ||
Services.obs.removeObserver(this, "final-ui-startup", false); | ||
|
||
// The port the server has to be started on is set via a preference | ||
let port = Services.prefs.getIntPref(PREF_JSBRIDGE_PORT); | ||
|
||
// Start the server | ||
Cu.import('resource://jsbridge/modules/Server.jsm'); | ||
this._server = new Server.Server(port); | ||
this._server.start(); | ||
|
||
break; | ||
|
||
case "quit-application": | ||
Services.obs.removeObserver(this, "quit-application", false); | ||
|
||
// Stop the server | ||
this._server.stop(); | ||
this._server = null; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([JSBridge]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the behaviour is if the preference is not set. What happens in that case? IMHO, we should just not start the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getIntPref will throw an exception if the preference cannot be found. Given that all the code below will not be executed and we bail out. As you said, we do NOT start the server in such a case.