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