Hi,
 
I am trying to access Mozilla Password Manager XPCOM component from outside browser space.
My aim is to read / write passwords from / to the Password Manager from outside the browser so that when I launch mozilla browser I should be able to see the passwords that I wrote from outside.
 
I downloaded the mozilla 1.7.5 source and compiled it to get the xpcom test programs.
I used the mozilla/xpcom/tests/nsIFileTest as reference and tried to access the nsIPasswordManager component in a similar way as nsILocalFile was accessed.
 
The C++ code flow is like below. When I run this code, it fails in nsComponentManager::CreateInstance() call and returns.
 
void InitTest()
{
 nsIPasswordManager* pm = nsnull;
 nsresult rv = nsComponentManager::CreateInstance("@mozilla.org/passwordmanager;1",nsnull,NS_GET_IID(nsIPasswordManager),(void**)&pm);
                                                                                                                             
    if (NS_FAILED(rv) || (!pm))
     {
        printf("create nsIPasswordManager failed\n");
        return;
     }
}
 
int main(void)
{
    nsCOMPtr<nsIServiceManager> servMan;
    NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
    registrar->AutoRegister(nsnull);
 
    InitTest();
 
}
 
But the nsComponentManager::CreateInstance() works fine when I try to access nsILocalFile component.
 
I also tried to get the PasswordManager service using the below code instead of CreateInstance().
 
    nsCOMPtr<nsIServiceManager> servMan;
    nsresult rv = NS_GetServiceManager(getter_AddRefs(servMan));
    if (NS_FAILED(rv))
        printf("Failed in getting service manager\n");
                                                                                                                             
    nsCOMPtr<nsIPasswordManager> pManager;
   rv = servMan->GetServiceByContractID("@mozilla.org/passwordmanager;1", NS_GET_IID(nsIPasswordManager), getter_AddRefs(pManager));
                                                                                                                             
    if (NS_FAILED(rv))
        printf("Failed in getting the service\n");
 
This failed in the second step - getting the service through GetServiceByContractID().
 
Could anybody help me by letting me know how we can properly access the nsIPasswordManager component to read / write passwords ?
Also please let me know whether we can do this from outside mozilla browser space ? i.e is it possible to write / read passwords to the Password Manager from an external application without launching the browser ?
 
 
Thanks,
Rajaram.
 
 
 
 
 
 

Reply via email to