From ff75b2488746233f9fd66bffd33755fa793b7547 Mon Sep 17 00:00:00 2001 From: John Schoenick Date: Tue, 7 Aug 2012 17:39:38 -0700 Subject: [PATCH] Bug 334288 - Use early returns in nsObjectLoadingContent::IsSupportedDocument. r=bz --- content/base/src/nsObjectLoadingContent.cpp | 52 +++++++++++---------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 9a9400bcc0c1..2f485b1f663c 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -566,39 +566,41 @@ nsObjectLoadingContent::IsSupportedDocument(const nsCString& aMimeType) do_QueryInterface(static_cast(this)); NS_ASSERTION(thisContent, "must be a content"); - nsresult rv; nsCOMPtr info( - do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv)); - PRUint32 supported; - if (info) { - nsCOMPtr webNav; - nsIDocument* currentDoc = thisContent->GetCurrentDoc(); - if (currentDoc) { - webNav = do_GetInterface(currentDoc->GetScriptGlobalObject()); - } - rv = info->IsTypeSupported(aMimeType, webNav, &supported); + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID)); + if (!info) { + return false; } - if (NS_SUCCEEDED(rv)) { - if (supported == nsIWebNavigationInfo::UNSUPPORTED) { - // Try a stream converter - // NOTE: We treat any type we can convert from as a supported type. If a - // type is not actually supported, the URI loader will detect that and - // return an error, and we'll fallback. - nsCOMPtr convServ = - do_GetService("@mozilla.org/streamConverters;1"); - bool canConvert = false; - if (convServ) { - rv = convServ->CanConvert(aMimeType.get(), "*/*", &canConvert); - } - return NS_SUCCEEDED(rv) && canConvert; - } + nsCOMPtr webNav; + nsIDocument* currentDoc = thisContent->GetCurrentDoc(); + if (currentDoc) { + webNav = do_GetInterface(currentDoc->GetScriptGlobalObject()); + } + + PRUint32 supported; + nsresult rv = info->IsTypeSupported(aMimeType, webNav, &supported); + if (NS_FAILED(rv)) { + return false; + } + + if (supported != nsIWebNavigationInfo::UNSUPPORTED) { // Don't want to support plugins as documents return supported != nsIWebNavigationInfo::PLUGIN; } - return false; + // Try a stream converter + // NOTE: We treat any type we can convert from as a supported type. If a + // type is not actually supported, the URI loader will detect that and + // return an error, and we'll fallback. + nsCOMPtr convServ = + do_GetService("@mozilla.org/streamConverters;1"); + bool canConvert = false; + if (convServ) { + rv = convServ->CanConvert(aMimeType.get(), "*/*", &canConvert); + } + return NS_SUCCEEDED(rv) && canConvert; } nsresult