获取Firefox内置组件的接口实现

Getting Interface Implementation of built-in Mozilla Firefox Component

本文关键字:接口 实现 组件 Firefox 内置 获取      更新时间:2023-10-16

我目前正在尝试在c++中开发一个自定义密码管理器。

我已经开发了一个可部署的模块,实现了nsILoginManagerStorage接口,可以安装在firefox上,当出现密码字段时,firefox会正确调用它。

问题是,当我试图实例化要返回的nsILoginInfo对象时,do_CreateInstance函数总是返回null。我的方法实现是:

NS_IMETHODIMP FirefoxComponent::FindLogins(uint32_t *count, const nsAString & aHostname, const nsAString & aActionURL, const nsAString & aHttpRealm, nsILoginInfo * **logins)
{
    nsILoginInfo ** array = static_cast<nsILoginInfo**>(nsMemory::Alloc(sizeof(nsILoginInfo*)));
    nsresult result;
    nsCOMPtr<nsILoginInfo> loginInfo = do_CreateInstance("@mozilla.org/login-manager/loginInfo;1" , &result);
    //nsCOMPtr<nsILoginManager> loginInfo = do_CreateInstance("@mozilla.org/login-manager;1" , &result);

    if (NS_FAILED(result)){
        printf("shouldn't be here!!n");
        return result;
    }

}

我试过得到一个nsILoginManager实例(只是为了检查它是否工作),但它有相同的结果。nsILoginInfo可以通过java脚本在firefox上实例化:

    Components.classes["@mozilla.org/loginmanager/loginInfo;1"].createInstance(Components.interfaces.nsILoginInfo);

我在Ubuntu x64上使用firefox 20.0和xul-runner-sdk 20.0(与20.0.1的结果相同),并使用QtCreator(用于x64)构建。

我的代码灵感来自https://github.com/infinity0/mozilla-gnome-keyring

既然我现在nsILoginInfo被正确加载到firefox中,firefox是否需要任何字段/信息来允许我访问这些接口?

感谢您的支持。

编辑:试图通过直接访问组件管理器来加载模块,但无法加载组件管理器。

    nsIComponentManager * manager;
    result = NS_GetComponentManager(&manager);

    if (NS_FAILED(result)){
        printf("failed getting component manager!!n");
        return result;
    }

经过多次尝试和错误后,我发现这个错误是由于库的不良链接。我丢失了一个库(libxpcom.so)。

为了正确编译和运行它,我使用libxpcom库。libxpcomglue_s。A,都在gecko sdk/xul-runner lib文件夹中找到。

关于在每个平台中使用哪些库进行编译的更多信息:https://developer.mozilla.org/en-US/docs/XPCOM_Glue