Thread Closed

#1
I found a problem with commandline component. It has global scoped code that instantiates other components. This should not be done and fails in my case when the component is placed in components/ directory of the along with Spicebird.exe. The problem is that when components are being registered, each component is loaded into memory and registerSelf is called. This may happen in any order. When we have global code doing getService and createInstance, it is not guaranteed that those components have been registered before our component and hence that fails.

If a component truly depends on another component even for registration, the components ought to check for the dependency components and return an error code saying that registration should be tried again. But since this is not the case for us, I just re-factored the code to fix the problem.

Also, the name of the file "commandLine.js" might easily clash with something else when it is put in components/ directory along with main installer. So, I renamed it to trayCommandLine.js. Here is the patch:

changeset: 5173:0727abdaf82a
branch: minimizetotray
tag: tip
parent: 5169:168de0c8f9b5
user: Sunil Mohan Adapa <sunil@synovel.com>
date: Thu Feb 25 16:09:24 2010 +0530
summary: component should not run code in global scope in tray

diff --git a/collab/extensions/minimizetotray/components/trayCommandLine.js b/collab/extensions/minimizetotray/components/trayCommandLine.js
--- a/collab/extensions/minimizetotray/components/trayCommandLine.js
+++ b/collab/extensions/minimizetotray/components/trayCommandLine.js
@@ -14,25 +14,6 @@

const cc = Components.classes;
const ci = Components.interfaces;
-
-const PromptService = cc
- .getService(ci.nsIPromptService);
-const WindowMediator = cc
- .getService(ci.nsIWindowMediator);
-const PrefBranch = cc
- .getService(ci.nsIPrefBranch);
-const WindowWatcherService = cc
- .getService(ci.nsIWindowWatcher);
-const SupportsString = cc
- .createInstance(ci.nsISupportsString);
-const ExtensionManager = cc
- .getService(ci.nsIExtensionManager);
-const RDFService = cc
- .getService(ci.nsIRDFService);
-const AppStartup = cc
- .getService(ci.nsIAppStartup);
-const XULRuntime = cc
- .getService(ci.nsIXULRuntime);

const PREF_PREFIX = 'extensions.minimizetotray.';

@@ -69,6 +50,8 @@
}

function openTurboWindow(url) {
+ var WindowWatcherService = cc.getService(ci.nsIWindowWatcher);
+ var SupportsString = cc.createInstance(ci.nsISupportsString);
WindowWatcherService.openWindow(
null, // parent
url, // url
@@ -80,8 +63,10 @@

function checkExtensionEnabled(id) {
var enabled = false;
+ var RDFService = cc.getService(ci.nsIRDFService);
var itemResource = RDFService.GetResource(PREFIX_ITEM_URI + id);
if (itemResource) {
+ var ExtensionManager = cc.getService(ci.nsIExtensionManager);
var ds = ExtensionManager.datasource;
var target = ds.GetTarget(itemResource, RDFService
.GetResource(PREFIX_NS_EM + "isDisabled"), true);
@@ -114,8 +99,9 @@
/* nsICommandLineHandler */

handle : function clh_handle(aCommandLine) {
- //PromptService.alert(null, '', XULRuntime.OS + '-'
- // + ((XULRuntime.XPCOMABI.substring(0, 6) == 'x86_64') ? '64' : '32'));
+ //var PromptService = cc.getService(ci.nsIPromptService);
+ //PromptService.alert(null, '', XULRuntime.OS + '-'
+ // + ((XULRuntime.XPCOMABI.substring(0, 6) == 'x86_64') ? '64' : '32'));

/* if there are other extensions installed, disable them */
if(nsICommandLine.STATE_INITIAL_LAUNCH == aCommandLine.state) {
@@ -123,6 +109,7 @@
for( var i = 0; i < INCOMPATIBLE.length; i++) {
var extensionId = INCOMPATIBLE;
try {
+ var ExtensionManager = cc.getService(ci.nsIExtensionManager);
if (ExtensionManager.getItemForID(extensionId)
&& checkExtensionEnabled(extensionId)) {
ExtensionManager.disableItem(extensionId);
@@ -131,11 +118,13 @@
} catch (e) {}
}
if(changed){
+ var AppStartup = cc.getService(ci.nsIAppStartup);
AppStartup.quit(AppStartup.eRestart | AppStartup.eAttemptQuit);
}
}
/* do the turbo processing */
var productID = getProductID();
+ var PrefBranch = cc.getService(ci.nsIPrefBranch);
if (nsICommandLine.STATE_INITIAL_LAUNCH != aCommandLine.state) {
aCommandLine.handleFlag("turbo", false); // remove if there are
// windows open
@@ -144,6 +133,7 @@
* restore
*/
if(PrefBranch.getBoolPref(PREF_PREFIX + 'restore-on-open')){
+ var WindowMediator = cc.getService(ci.nsIWindowMediator);
var e = WindowMediator.getEnumerator(null);
while (e.hasMoreElements()) {
var w = e.getNext();

changeset: 5158:58851d812fbd
branch: minimizetotray
user: Sunil Mohan Adapa <sunil@synovel.com>
date: Fri Feb 19 12:05:22 2010 +0530
summary: Make tray command line handler work

diff --git a/collab/extensions/minimizetotray/components/commandLine.js b/collab/extensions/minimizetotray/components/trayCommandLine.js
copy from collab/extensions/minimizetotray/components/commandLine.js
copy to collab/extensions/minimizetotray/components/trayCommandLine.js
ReportQuote
#2
Also, I made the following change to the main makefile for automatically install the component during compilation.

changeset: 5158:58851d812fbd
branch: minimizetotray
user: Sunil Mohan Adapa <sunil@synovel.com>
date: Fri Feb 19 12:05:22 2010 +0530
summary: Make tray command line handler work

diff --git a/collab/extensions/minimizetotray/Makefile.in b/collab/extensions/minimizetotray/Makefile.in
--- a/collab/extensions/minimizetotray/Makefile.in
+++ b/collab/extensions/minimizetotray/Makefile.in
@@ -19,5 +19,9 @@
$(srcdir)/defaults/preferences/minimizetotray.js \
$(NULL)

+EXTRA_PP_COMPONENTS = \
+ components/trayCommandLine.js \
+ $(NULL)
+
include $(topsrcdir)/config/rules.mk
ReportQuote

Thread Closed