Bug 306471 part 2 - Do not query handler service for content-type of file extension. r=bz draft
authorXidorn Quan <me@upsuper.org>
Fri, 12 Aug 2016 20:58:31 +1000
changeset 404740 b223c630266294dc157e88d1a6090a1c99dd8746
parent 404738 825308563f4d1ebdb3e672d088975df30bf89392
child 529249 378168901904ebbeb1c8c20f38cd0a6a2a4834c9
push id27279
push usermozilla@upsuper.org
push dateTue, 23 Aug 2016 23:33:52 +0000
reviewersbz
bugs306471
milestone51.0a1
Bug 306471 part 2 - Do not query handler service for content-type of file extension. r=bz MozReview-Commit-ID: FP1J6Qk3fsM
uriloader/exthandler/nsExternalHelperAppService.cpp
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -2723,44 +2723,36 @@ NS_IMETHODIMP nsExternalHelperAppService
 }
 
 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
-  // 2. User-set preferences (managed by the handler service)
-  // 3. OS-provided information
-  // 4. our "extras" array
-  // 5. Information from plugins
-  // 6. The "ext-to-type-mapping" category
+  // 2. OS-provided information
+  // 3. our "extras" array
+  // 4. Information from plugins
+  // 5. The "ext-to-type-mapping" category
+  // Note that, we are intentionally not looking at the handler service, because
+  // that can be affected by websites, which leads to undesired behavior.
 
   // Early return if called with an empty extension parameter
   if (aFileExt.IsEmpty()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // First of all, check our default entries
   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) {
-    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) {
     return mi->GetMIMEType(aContentType);
   }
 
   // Check extras array.