Question

I'm currently trying to develop a custom password manager in c++.

I've already developed a deployable module implementing the nsILoginManagerStorage interface, can install it on firefox and it is being called properly by firefox when a password field appears.

The problem is that when I try to instantiate the nsILoginInfo objects to be returned, the do_CreateInstance function is always returning null. My method implementation is:

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;
    }

}

I've tried getting an nsILoginManager instance (just to check if it worked) but it had the same result. The nsILoginInfo can be instantited by java script on firefox using:

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

I'm using firefox 20.0 and xul-runner-sdk 20.0 (same results with 20.0.1), on Ubuntu x64, and building with QtCreator (for x64).

My code has been inspired from https://github.com/infinity0/mozilla-gnome-keyring

Since I now that nsILoginInfo is properly loaded into firefox, is there any required field/information for firefox to allow me to access these interfaces?

Thanks for the support.

edit: Tried to load the module by accessing the component manager directly, but I cannot load the component manager.

    nsIComponentManager * manager;

    result = NS_GetComponentManager(&manager);


    if (NS_FAILED(result)){
        printf("failed getting component manager!!\n");
        return result;
    }
Was it helpful?

Solution

After lots of trial and error I discovered that this error was due to bad linking of the libraries. I was missing one library (libxpcom.so).

To compile and run it right i use the libraries libxpcom.so and libxpcomglue_s.a, both found at the gecko sdk/xul-runner lib folder.

More information about which libraries to compile with in each platform: https://developer.mozilla.org/en-US/docs/XPCOM_Glue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top