Mozilla XPCOM is not registered

橙三吉。 提交于 2019-12-11 06:42:33

问题


I'm trying to build an extension for Firefox. This extension uses an XPCOM component (a C++ dll). I'm compiling the DLL, compilation is OK.

The next step would be to use the component in Javascript from my extension. I added the code to register my component from my c++ file :

static const mozilla::Module::CategoryEntry kSampleCategories[] = {
    { JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, "greenfox", NS_SAMPLE_CONTRACTID },
};

In my manifest, I declare the XPCOM :

component {03A6D0B4-22B9-11DF-B844-20D556D89593} components/GreenCodeLabFox.dll

The problem is, when I try to use the component in JS, it seems it is not registered :

    try {
        greenfox;
        return true;
    } catch( e ) {
        alert( e );
        return false;
    }   

This gives me the alert error:

ReferenceError: greenfox is not defined

In error console, I have no message.

How would I debug this if I have no error message ? By the way, my javascript.options.showInConsole is set to true.

Thanks !


回答1:


Per https://developer.mozilla.org/en/XPCOM/XPCOM_changes_in_Gecko_2.0 you must use a binary-component directive to register a binary component.

That page also links to an example; you only posted a part of the code required for registration.

If the component still doesn't work, I'd try to get it via Components.classes[contract id] from the Error Console - that will show if the problem is with the component registration or just with the global property part.

https://developer.mozilla.org/en/Troubleshooting_XPCOM_components_registration might be useful for troubleshooting, although it's a bit dated.




回答2:


Perhaps an Update, since Firefox 41 using binary-component for extensions is no longer supported in release builds, but may be available for custom builds using MOZ_BINARY_EXTENSIONS

https://blog.mozilla.org/addons/2015/05/04/dropping-support-for-binary-components/

https://github.com/mozilla/gecko-dev/blob/master/xpcom/components/ManifestParser.cpp

You may see errors like
[JavaScript Warning: "Only application manifests may use the 'binary-component' directive." {file: "..." line: ..}]



来源:https://stackoverflow.com/questions/9054143/mozilla-xpcom-is-not-registered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!