|
Lines 1199-1295
nsOSHelperAppService::GetHandlerAndDescr
Link Here
|
| 1199 |
rv = mailcap->ReadLine(cBuffer, &more); |
1199 |
rv = mailcap->ReadLine(cBuffer, &more); |
| 1200 |
} while (NS_SUCCEEDED(rv)); |
1200 |
} while (NS_SUCCEEDED(rv)); |
| 1201 |
mailcapFile->Close(); |
1201 |
mailcapFile->Close(); |
| 1202 |
return rv; |
1202 |
return rv; |
| 1203 |
} |
1203 |
} |
| 1204 |
|
1204 |
|
| 1205 |
/* Looks up the handler for a specific scheme from prefs and returns the |
|
|
| 1206 |
* file representing it in aApp. Note: This function doesn't guarantee the |
| 1207 |
* existance of *aApp. |
| 1208 |
*/ |
| 1209 |
nsresult |
| 1210 |
nsOSHelperAppService::GetHandlerAppFromPrefs(const char* aScheme, /*out*/ nsIFile** aApp) |
| 1211 |
{ |
| 1212 |
nsresult rv; |
| 1213 |
nsCOMPtr<nsIPrefService> srv(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
| 1214 |
if (NS_FAILED(rv)) // we have no pref service... that's bad |
| 1215 |
return rv; |
| 1216 |
|
| 1217 |
nsCOMPtr<nsIPrefBranch> branch; |
| 1218 |
srv->GetBranch("network.protocol-handler.app.", getter_AddRefs(branch)); |
| 1219 |
if (!branch) // No protocol handlers set up -> can't load url |
| 1220 |
return NS_ERROR_NOT_AVAILABLE; |
| 1221 |
|
| 1222 |
nsXPIDLCString appPath; |
| 1223 |
rv = branch->GetCharPref(aScheme, getter_Copies(appPath)); |
| 1224 |
if (NS_FAILED(rv)) |
| 1225 |
return rv; |
| 1226 |
|
| 1227 |
LOG((" found app %s\n", appPath.get())); |
| 1228 |
|
| 1229 |
// First, try to treat |appPath| as absolute path, if it starts with '/' |
| 1230 |
NS_ConvertUTF8toUTF16 utf16AppPath(appPath); |
| 1231 |
if (appPath.First() == '/') { |
| 1232 |
nsILocalFile* file; |
| 1233 |
rv = NS_NewLocalFile(utf16AppPath, PR_TRUE, &file); |
| 1234 |
*aApp = file; |
| 1235 |
// If this worked, we are finished |
| 1236 |
if (NS_SUCCEEDED(rv)) |
| 1237 |
return NS_OK; |
| 1238 |
} |
| 1239 |
|
| 1240 |
// Second, check for a file in the mozilla app directory |
| 1241 |
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR, aApp); |
| 1242 |
if (NS_SUCCEEDED(rv)) { |
| 1243 |
rv = (*aApp)->Append(utf16AppPath); |
| 1244 |
if (NS_SUCCEEDED(rv)) { |
| 1245 |
PRBool exists = PR_FALSE; |
| 1246 |
rv = (*aApp)->Exists(&exists); |
| 1247 |
if (NS_SUCCEEDED(rv) && exists) |
| 1248 |
return NS_OK; |
| 1249 |
} |
| 1250 |
NS_RELEASE(*aApp); |
| 1251 |
} |
| 1252 |
|
| 1253 |
// Thirdly, search the path |
| 1254 |
return GetFileTokenForPath(utf16AppPath.get(), aApp); |
| 1255 |
} |
| 1256 |
|
| 1257 |
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists) |
1205 |
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists) |
| 1258 |
{ |
1206 |
{ |
| 1259 |
LOG(("-- nsOSHelperAppService::OSProtocolHandlerExists for '%s'\n", |
1207 |
LOG(("-- nsOSHelperAppService::OSProtocolHandlerExists for '%s'\n", |
| 1260 |
aProtocolScheme)); |
1208 |
aProtocolScheme)); |
| 1261 |
*aHandlerExists = PR_FALSE; |
1209 |
*aHandlerExists = PR_FALSE; |
| 1262 |
|
1210 |
|
| 1263 |
nsCOMPtr<nsIFile> app; |
|
|
| 1264 |
nsresult rv = GetHandlerAppFromPrefs(aProtocolScheme, getter_AddRefs(app)); |
| 1265 |
if (NS_SUCCEEDED(rv)) { |
| 1266 |
PRBool isExecutable = PR_FALSE, exists = PR_FALSE; |
| 1267 |
nsresult rv1 = app->Exists(&exists); |
| 1268 |
nsresult rv2 = app->IsExecutable(&isExecutable); |
| 1269 |
*aHandlerExists = (NS_SUCCEEDED(rv1) && exists && NS_SUCCEEDED(rv2) && isExecutable); |
| 1270 |
LOG((" handler exists: %s\n", *aHandlerExists ? "yes" : "no")); |
| 1271 |
} |
| 1272 |
|
| 1273 |
#ifdef MOZ_WIDGET_GTK2 |
1211 |
#ifdef MOZ_WIDGET_GTK2 |
| 1274 |
// Check the GConf registry for a protocol handler |
1212 |
// Check the GConf registry for a protocol handler |
| 1275 |
if (!*aHandlerExists) |
1213 |
*aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme); |
| 1276 |
*aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme); |
|
|
| 1277 |
#endif |
1214 |
#endif |
| 1278 |
|
1215 |
|
| 1279 |
return NS_OK; |
1216 |
return NS_OK; |
| 1280 |
} |
1217 |
} |
| 1281 |
|
1218 |
|
| 1282 |
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) |
1219 |
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) |
| 1283 |
{ |
1220 |
{ |
| 1284 |
nsCOMPtr<nsIFile> appFile; |
|
|
| 1285 |
nsresult rv = GetHandlerAppFromPrefs(PromiseFlatCString(aScheme).get(), |
| 1286 |
getter_AddRefs(appFile)); |
| 1287 |
if (NS_SUCCEEDED(rv)) |
| 1288 |
return appFile->GetLeafName(_retval); |
| 1289 |
|
| 1290 |
#ifdef MOZ_WIDGET_GTK2 |
1221 |
#ifdef MOZ_WIDGET_GTK2 |
| 1291 |
nsGNOMERegistry::GetAppDescForScheme(aScheme, _retval); |
1222 |
nsGNOMERegistry::GetAppDescForScheme(aScheme, _retval); |
| 1292 |
return _retval.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK; |
1223 |
return _retval.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK; |
| 1293 |
#else |
1224 |
#else |
| 1294 |
return NS_ERROR_NOT_AVAILABLE; |
1225 |
return NS_ERROR_NOT_AVAILABLE; |
| 1295 |
#endif |
1226 |
#endif |