Bug 1544739 - Part 6: Update GNOME shell service - Add essential parameter to protocol association. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 24 Apr 2019 18:54:00 +0200
changeset 32185 efe6ede30b74f68834e39462412a246d75047f9e
parent 32184 c12542ef7b070d72ed6aa23b6d598fe6d4e6debf
child 32186 88e664e02706550303c46775597ab97bcada55f0
push id187
push userfrgrahl@gmx.net
push dateWed, 24 Apr 2019 16:55:18 +0000
treeherdercomm-esr60@33e9c7be6768 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1544739
Bug 1544739 - Part 6: Update GNOME shell service - Add essential parameter to protocol association. r=frg a=frg
suite/components/shell/nsGNOMEShellService.cpp
suite/components/shell/nsGNOMEShellService.h
--- a/suite/components/shell/nsGNOMEShellService.cpp
+++ b/suite/components/shell/nsGNOMEShellService.cpp
@@ -35,31 +35,34 @@
 #include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <limits.h>
 #include <stdlib.h>
 
 struct ProtocolAssociation {
   uint16_t app;
   const char* protocol;
+  bool essential;
 };
 
 struct MimeTypeAssociation {
   uint16_t app;
   const char* mimeType;
   const char* extensions;
 };
 
 static const ProtocolAssociation gProtocols[] = {
-  { nsIShellService::BROWSER, "http" },
-  { nsIShellService::BROWSER, "https" },
-  { nsIShellService::MAIL, "mailto" },
-  { nsIShellService::NEWS, "news" },
-  { nsIShellService::NEWS, "snews" },
-  { nsIShellService::RSS, "feed" }
+  { nsIShellService::BROWSER, "http", true },
+  { nsIShellService::BROWSER, "https", true },
+  { nsIShellService::BROWSER, "ftp", false },
+  { nsIShellService::BROWSER, "chrome", false },
+  { nsIShellService::MAIL, "mailto", true },
+  { nsIShellService::NEWS, "news", true },
+  { nsIShellService::NEWS, "snews", true },
+  { nsIShellService::RSS, "feed", true }
 };
 
 static const MimeTypeAssociation gMimeTypes[] = {
   { nsIShellService::BROWSER, "text/html", "htm html shtml" },
   { nsIShellService::BROWSER, "application/xhtml+xml", "xhtml xht" },
   { nsIShellService::MAIL, "message/rfc822", "eml" },
   { nsIShellService::RSS, "application/rss+xml", "rss" }
 };
@@ -171,82 +174,88 @@ nsGNOMEShellService::CheckHandlerMatches
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps,
                                      bool* aIsDefaultClient)
 {
   *aIsDefaultClient = false;
 
-  nsCString handler;
+  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
+  nsAutoCString handler;
   nsCOMPtr<nsIGIOMimeApp> gioApp;
-  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
 
   for (unsigned i = 0; i < mozilla::ArrayLength(gProtocols); i++) {
     if (aApps & gProtocols[i].app) {
       nsDependentCString protocol(gProtocols[i].protocol);
+      if (!gProtocols[i].essential)
+        continue;
+
       if (giovfs) {
+        handler.Truncate();
         nsCOMPtr<nsIHandlerApp> handlerApp;
+        nsDependentCString protocol(gProtocols[i].protocol);
         giovfs->GetAppForURIScheme(protocol, getter_AddRefs(handlerApp));
-
         gioApp = do_QueryInterface(handlerApp);
         if (!gioApp)
           return NS_OK;
-        
+
         if (NS_SUCCEEDED(gioApp->GetCommand(handler)) &&
             !CheckHandlerMatchesAppName(handler))
          return NS_OK;
       }
     }
   }
 
   *aIsDefaultClient = true;
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::SetDefaultClient(bool aForAllUsers,
                                       bool aClaimAllTypes, uint16_t aApps)
 {
-  nsresult rv;
-
-  nsCOMPtr<nsIGIOMimeApp> app;
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
   if (giovfs) {
+    nsresult rv;
     nsCString brandName;
     rv = GetBrandName(brandName);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = giovfs->FindAppFromCommand(mAppPath, getter_AddRefs(app));
+    nsCOMPtr<nsIGIOMimeApp> appInfo;
+    rv = giovfs->FindAppFromCommand(mAppPath, getter_AddRefs(appInfo));
     if (NS_FAILED(rv)) {
       // Application was not found in the list of installed applications
       // provided by OS. Fallback to create appInfo from command and name.
-      rv = giovfs->CreateAppFromCommand(mAppPath, brandName, getter_AddRefs(app));
+      rv = giovfs->CreateAppFromCommand(mAppPath, brandName,
+                                        getter_AddRefs(appInfo));
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // set handler for the protocols
     for (unsigned int i = 0; i < mozilla::ArrayLength(gProtocols); ++i) {
       if (aApps & gProtocols[i].app) {
-        nsDependentCString protocol(gProtocols[i].protocol);
-        if (app) {
-          rv = app->SetAsDefaultForURIScheme(protocol);
-          NS_ENSURE_SUCCESS(rv, rv);
+        if (appInfo && (gProtocols[i].essential || aClaimAllTypes)) {
+          nsDependentCString protocol(gProtocols[i].protocol);
+          appInfo->SetAsDefaultForURIScheme(protocol);
         }
       }
     }
 
-    for (unsigned i = 0; i < mozilla::ArrayLength(gMimeTypes); i++) {
-      if (aApps & gMimeTypes[i].app) {
-        rv = app->SetAsDefaultForMimeType(nsDependentCString(gMimeTypes[i].mimeType));
-        NS_ENSURE_SUCCESS(rv, rv);
-        rv = app->SetAsDefaultForFileExtensions(nsDependentCString(gMimeTypes[i].extensions));
-        NS_ENSURE_SUCCESS(rv, rv);
-      }
-    }
+    if (aClaimAllTypes) {
+      for (unsigned int i = 0; i < mozilla::ArrayLength(gMimeTypes); i++) {
+        if (aApps & gMimeTypes[i].app) {
+          nsDependentCString type(gMimeTypes[i].mimeType);
+          appInfo->SetAsDefaultForMimeType(type);
+          nsDependentCString extensions(gMimeTypes[i].extensions);
+          appInfo->SetAsDefaultForFileExtensions(extensions);
+        }
+       }
+     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::GetCanSetDesktopBackground(bool* aResult)
 {
--- a/suite/components/shell/nsGNOMEShellService.h
+++ b/suite/components/shell/nsGNOMEShellService.h
@@ -6,18 +6,16 @@
 #ifndef nsgnomeshellservice_h____
 #define nsgnomeshellservice_h____
 
 #include "nsIGNOMEShellService.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 #include "nsSuiteCID.h"
 
-struct ProtocolAssociation;
-
 class nsGNOMEShellService final : public nsIGNOMEShellService
 {
 public:
   nsGNOMEShellService() : mAppIsInPath(false) {}
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISHELLSERVICE
   NS_DECL_NSIGNOMESHELLSERVICE