views:

22

answers:

2

We are using the following code to read preference value browser.search.defaultenginename from external exe (Without loading it into firefox) to retrieve default search engine of searchbox in firefox. We have tried all possible ways but still are unable to read this value. It is returning empty string. When we tried to get the preference type using GetPrefType() method we found that the preference type is invalid instead of string.

Please help.

Method:

CString ClassName::GetDefaultSearchBox() {

CString strRetVal = L"unknown";

nsCOMPtr<nsIServiceManager> sp_ServMgr;

nsresult rv = NS_GetServiceManager((nsIServiceManager**)&sp_ServMgr);
if(!(NS_FAILED(rv)))
{
    nsCOMPtr<nsIPrefService> sp_PrefMon;
    rv = sp_ServMgr->GetServiceByContractID("@mozilla.org/preferences-service;1", 
        NS_GET_IID(nsIPrefService),
        getter_AddRefs(sp_PrefMon));
    if(!(NS_FAILED(rv)) && (NULL != sp_PrefMon))
    {
        nsCOMPtr<nsIPrefBranch> sp_PrefSelect;
        rv = sp_PrefMon->GetBranch("browser.search.", getter_AddRefs(sp_PrefSelect));
        if(!(NS_FAILED(rv)))
        {
            if(NULL != sp_PrefSelect)
            {
                nsCString nsstrSBX;
                sp_PrefSelect->GetCharPref("defaultenginename", getter_Copies(nsstrSBX));                   
                strRetVal = CString(nsstrSBX.get());
            }
        }
    }
}
return strRetVal;

}

A: 

Looking at http://mxr.mozilla.org/mozilla-central/source/toolkit/components/search/nsSearchService.js#1627 I see that the code calls "GetComplexValue" for this pref. There is some discussion of this type at https://developer.mozilla.org/en/Code_snippets/Preferences .

Matthew Wilson
thanks for quick reply Mathew.I have tried with GetComplexValue() method as well but still its returning empty value.
A: 

Ok, I'll work on it. It's a challenge for me.

Ranbeer