Registering components under XULRunner 24

95 views
Skip to first unread message

Christian Sell

unread,
Feb 13, 2014, 12:31:59 PM2/13/14
to
Hello,

me again ;). We are embedding XULRunner in our Java application, using a thin integration layer written in C++ that provides extended functionality. We also have a XPCOM component written in Javascript, which we previously called though JavaXPCOM, and now need to call from C++. However, no matter what I do, I keep getting a NS_ERROR_FACTORY_NOT_REGISTERED when issuing the following call:

nsCOMPtr<nsIRegionCapture> regionPrinter;
retval = servMan->GetServiceByContractID("@mozilla.org/regioncapture;1", NS_GET_IID(nsIRegionCapture), getter_AddRefs(regionPrinter));

I have tried adding the .js and .xpt files to the xulrunner components subdirectory (which I had to create), added chrome.manifest files pointing to the component, and even tried programmatic registration through

nsIComponentRegistrar> registrar;
retval = NS_GetComponentRegistrar(getter_AddRefs(registrar));
retval = registrar->AutoRegister(file);

all to no avail. Can someone point out the missing link?

TIA alot!
Christian

Benjamin Smedberg

unread,
Feb 13, 2014, 12:39:52 PM2/13/14
to Christian Sell, dev-em...@lists.mozilla.org
If `file` points to the .manifest file you created, then AutoRegister
should work. Are you seeing any errors from nsIConsoleService? When we
adopted manifests I tried to make sure that any parsing errors would
show up in the Firefox console.

--BDS

Christian Sell

unread,
Feb 13, 2014, 12:46:47 PM2/13/14
to
no, "file" points to the directory where the component resides. I dont know where the output from nsIConsoleService goes, as that is maintained by the Eclipse/SWT integration. I'll try pointing to the manifest file. Thanks

Christian Sell

unread,
Feb 13, 2014, 1:12:22 PM2/13/14
to
doesnt work. I am creating the file like this:

retval = directory->Get(NS_GRE_DIR, NS_GET_IID(nsILocalFile), (void **)&greDir);
file->InitWithFile(greDir);
file->AppendRelativePath(NS_LITERAL_STRING("components/components.manifest"));

the contents of the components.manifest file are just one line:

interfaces RegionCapture.xpt

I still get NS_ERROR_FACTORY_NOT_REGISTERED when trying to access the component.

Chris

Christian Sell

unread,
Feb 13, 2014, 1:28:36 PM2/13/14
to
added component and contract entries to the manifest file, still no hope. BTW, file->Exists() returns true.

I am out till next week. This was a fruitless day..

Benjamin Smedberg

unread,
Feb 14, 2014, 12:16:14 PM2/14/14
to Christian Sell, dev-em...@lists.mozilla.org
That's because the "interfaces" line only registers the interfaces, not
the component. To register the component you use something like

http://mxr.mozilla.org/mozilla-central/source/toolkit/components/downloads/nsDownloadManagerUI.manifest

to register the "component" and "contract" entries

--BDS

Christian Sell

unread,
Feb 14, 2014, 1:06:36 PM2/14/14
to
I tried that, too, but it didn't do the job either. However, today I found this article: https://developer.mozilla.org/en-US/docs/Mozilla/XPCOM/XPCOM_changes_in_Gecko_2.0, which seems to indicate that I also have to update the javascript component code. I'll do that on monday.

thanks for your help so far,
Chris

Christian Sell

unread,
Feb 17, 2014, 4:49:28 AM2/17/14
to
so I've tried to follow the guide under the URL in my previous mail, but still no success.

However, looking at the source code of my component, and the sample code under the mentioned URL, I found an import reference to an external file:

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

so I decided to check whether that file existed. It turns out that it DOES exist in XULRunner 10, but IT DOESN'T EXIST in the XULRunner 24 distro I downloaded from the Mozilla site.

I am a little wary about just copying the file over from V10 to V24. Can you tell me how to proceed?

thanks,
Chris

Christian Sell

unread,
Feb 17, 2014, 7:03:28 AM2/17/14
to
I have copied the XPCOMUtils.jsm from a recent firefox install. Still doesn't work. I have then registered a console listener. The error message I see is:

Could not read chrome manifest 'file:///G:/mozilla24/xulrunner'.

as already mentioned above, I am creating the file like this

nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1", &retval));
nsILocalFile *greDir;
retval = directory->Get(NS_GRE_DIR, NS_GET_IID(nsILocalFile), (void **)&greDir);
file->InitWithFile(greDir);
file->AppendRelativePath(NS_LITERAL_STRING("components/components.manifest"));

//later: registrar->AutoRegister(file);

It seems the file I pass to the AutoRegister method is not valid. In particular, the part I add via AppendRelativePath seems to get lost, but why?? I've tried all permutations I can come up with, still the same...

Christian Sell

unread,
Feb 17, 2014, 8:30:48 AM2/17/14
to
the AppendRelativePath actually returns an NS_ERROR_UNRECOGNIZED_PATH (never checked the return code before)! The file does exist on the filesystem! How in the world am I to create the nsIFile object? What is going wrong??

Christian Sell

unread,
Feb 17, 2014, 9:37:20 AM2/17/14
to
replaced the
file->AppendRelativePath(NS_LITERAL_STRING("components/components.manifest"));

with 2 calls:
retval = file->Append(NS_LITERAL_STRING("components"));
retval = file->Append(NS_LITERAL_STRING("components.manifest"));

now the manifest file is detected and parsed, resulting in a Javascript warning

[JavaScript Warning: "Trying to re-register CID '{e96f8106-a919-4a31-8b44-74bf3e5283ed}' already registered by ...

No additional error messages. When trying to load the component later on, still NS_ERROR_FACTORY_NOT_REGISTERED.

Christian Sell

unread,
Feb 17, 2014, 9:39:44 AM2/17/14
to
heres the code that fails to load the component:

Christian Sell

unread,
Feb 17, 2014, 10:13:39 AM2/17/14
to
added another line to components.manifest, as mentioned in the referenced document:

category profile-after-change RegionCapture @mozilla.org/regioncapture;1

still getting NS_ERROR_FACTORY_NOT_REGISTERED. There are no error messages in nsIConsoleService (at least none my listener gets). This is easily the worst ordeal I have encountered in a decade. Is there ANYBODY out there who can help??

Christian Sell

unread,
Feb 17, 2014, 11:07:38 AM2/17/14
to
ok, I finally got it registered, there was one change that I had applied to the wrong copy of one file. So, in summary, heres the steps I had to go through:

1. create a manifest file with the described entries
2. change the component javascript file and add the generateNSGetFactory thingy
3. steal a copy of the missing XPCOMUtils.jsm file and put it into the xulrunner/modules directory
3. when building the path for the ComponentRegistrar, dont use AppendRelativePath but rather use one Append call for each path segment

3 days of headbanging are over..

Benjamin Smedberg

unread,
Feb 17, 2014, 1:41:44 PM2/17/14
to Christian Sell, dev-em...@lists.mozilla.org
On 2/17/2014 11:07 AM, Christian Sell wrote:
> 3. steal a copy of the missing XPCOMUtils.jsm file and put it into the xulrunner/modules directory
This should not be necessary. The correct location for this file is
within omni.ja, and it seems to be present in the XR27 release.

> 3. when building the path for the ComponentRegistrar, dont use AppendRelativePath but rather use one Append call for each path segment
AppendRelativePath is supposed to work, but it's possible you ran into
issues with Windows path separators: you must use backslashes on Windows
and forward slashes on unixy OSes. Lesson learned, though, always check
result codes ;-)

--BDS

mrmag...@yahoo.com

unread,
Feb 18, 2014, 4:59:32 AM2/18/14
to
!!!!! wow all the for ONE little bit of of detail huh? pretty special I can't wait to get better at this myself.
Reply all
Reply to author
Forward
0 new messages