Skip to content

Commit

Permalink
Bug 306471 part 1 - Some code style cleanup for nsExternalHelperAppSe…
Browse files Browse the repository at this point in the history
…rvice::GetTypeFromExtension. r=bz

MozReview-Commit-ID: 3N37Kd2fNjS

--HG--
extra : rebase_source : 825308563f4d1ebdb3e672d088975df30bf89392
  • Loading branch information
upsuper committed Aug 12, 2016
1 parent 611f544 commit f95f57c
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,9 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const nsACStri
return NS_OK;
}

NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt, nsACString& aContentType)
NS_IMETHODIMP
nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt,
nsACString& aContentType)
{
// OK. We want to try the following sources of mimetype information, in this order:
// 1. defaultMimeEntries array
Expand All @@ -2733,36 +2735,39 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString&
// 6. The "ext-to-type-mapping" category

// Early return if called with an empty extension parameter
if (aFileExt.IsEmpty())
if (aFileExt.IsEmpty()) {
return NS_ERROR_NOT_AVAILABLE;
}

nsresult rv = NS_OK;
// First of all, check our default entries
for (size_t i = 0; i < ArrayLength(defaultMimeEntries); i++)
{
if (aFileExt.LowerCaseEqualsASCII(defaultMimeEntries[i].mFileExtension)) {
aContentType = defaultMimeEntries[i].mMimeType;
return rv;
for (auto& entry : defaultMimeEntries) {
if (aFileExt.LowerCaseEqualsASCII(entry.mFileExtension)) {
aContentType = entry.mMimeType;
return NS_OK;
}
}

// Check user-set prefs
nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID);
if (handlerSvc)
rv = handlerSvc->GetTypeFromExtension(aFileExt, aContentType);
if (NS_SUCCEEDED(rv) && !aContentType.IsEmpty())
return NS_OK;
if (handlerSvc) {
nsresult rv = handlerSvc->GetTypeFromExtension(aFileExt, aContentType);
if (NS_SUCCEEDED(rv) && !aContentType.IsEmpty()) {
return NS_OK;
}
}

// Ask OS.
bool found = false;
nsCOMPtr<nsIMIMEInfo> mi = GetMIMEInfoFromOS(EmptyCString(), aFileExt, &found);
if (mi && found)
if (mi && found) {
return mi->GetMIMEType(aContentType);
}

// Check extras array.
found = GetTypeFromExtras(aFileExt, aContentType);
if (found)
if (found) {
return NS_OK;
}

// Try the plugins
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
Expand All @@ -2771,24 +2776,25 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString&
return NS_OK;
}

rv = NS_OK;
// Let's see if an extension added something
nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
nsCOMPtr<nsICategoryManager> catMan(
do_GetService("@mozilla.org/categorymanager;1"));
if (catMan) {
// The extension in the category entry is always stored as lowercase
nsAutoCString lowercaseFileExt(aFileExt);
ToLowerCase(lowercaseFileExt);
// Read the MIME type from the category entry, if available
nsXPIDLCString type;
rv = catMan->GetCategoryEntry("ext-to-type-mapping", lowercaseFileExt.get(),
getter_Copies(type));
aContentType = type;
}
else {
rv = NS_ERROR_NOT_AVAILABLE;
nsresult rv = catMan->GetCategoryEntry("ext-to-type-mapping",
lowercaseFileExt.get(),
getter_Copies(type));
if (NS_SUCCEEDED(rv)) {
aContentType = type;
return NS_OK;
}
}

return rv;
return NS_ERROR_NOT_AVAILABLE;
}

NS_IMETHODIMP nsExternalHelperAppService::GetPrimaryExtension(const nsACString& aMIMEType, const nsACString& aFileExt, nsACString& _retval)
Expand Down

0 comments on commit f95f57c

Please sign in to comment.