Bug 606934 - We don't register Thunderbird as the default .eml handler on linux. r=mconley
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 14 Feb 2012 12:27:17 +0000
changeset 10831 7150237ed78f8477d25e2e14b57092028a4b1284
parent 10830 37481eaa6c69d26b01214beff7ef1028242c620f
child 10832 59943cb43b167bbf343d0dfd53dfee5bb7404d30
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs606934
Bug 606934 - We don't register Thunderbird as the default .eml handler on linux. r=mconley
mail/components/shell/nsMailGNOMEIntegration.cpp
mail/components/shell/nsMailGNOMEIntegration.h
--- a/mail/components/shell/nsMailGNOMEIntegration.cpp
+++ b/mail/components/shell/nsMailGNOMEIntegration.cpp
@@ -67,16 +67,29 @@ static const char* const sNewsProtocols[
   "snews",
   "nntp"
 };
 
 static const char* const sFeedProtocols[] = {
   "feed"
 };
 
+struct AppTypeAssociation {
+  PRUint16 type;
+  const char * const *protocols;
+  const char *mimeType;
+  const char *extensions;
+};
+
+static const AppTypeAssociation sAppTypes[] = {
+  { nsIShellService::MAIL, sMailProtocols, "message/rfc822", "eml" },
+  { nsIShellService::NEWS, sNewsProtocols },
+  { nsIShellService::RSS,  sFeedProtocols, "application/rss+xml", "rss" }
+};
+
 nsMailGNOMEIntegration::nsMailGNOMEIntegration(): 
                           mCheckedThisSession(false),
                           mAppIsInPath(false)
 {}
 
 nsresult
 nsMailGNOMEIntegration::Init()
 {
@@ -139,42 +152,43 @@ nsMailGNOMEIntegration::GetAppPathFromLa
   g_free(tmp);
   return true;
 }
 
 NS_IMETHODIMP
 nsMailGNOMEIntegration::IsDefaultClient(bool aStartupCheck, PRUint16 aApps, bool * aIsDefaultClient)
 {
   *aIsDefaultClient = true;
-  if (aApps & nsIShellService::MAIL)
-    *aIsDefaultClient &= checkDefault(sMailProtocols, NS_ARRAY_LENGTH(sMailProtocols));
-  if (aApps & nsIShellService::NEWS)
-    *aIsDefaultClient &= checkDefault(sNewsProtocols, NS_ARRAY_LENGTH(sNewsProtocols));
-  if (aApps & nsIShellService::RSS)
-    *aIsDefaultClient &= checkDefault(sFeedProtocols, NS_ARRAY_LENGTH(sFeedProtocols));
+
+  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sAppTypes); i++) {
+    if (aApps & sAppTypes[i].type)
+      *aIsDefaultClient &= checkDefault(sAppTypes[i].protocols,
+                                        NS_ARRAY_LENGTH(sAppTypes[i].protocols));
+  }
   
   // If this is the first mail window, maintain internal state that we've
   // checked this session (so that subsequent window opens don't show the 
   // default client dialog).
   if (aStartupCheck)
     mCheckedThisSession = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMailGNOMEIntegration::SetDefaultClient(bool aForAllUsers, PRUint16 aApps)
 {
   nsresult rv = NS_OK;
-  if (aApps & nsIShellService::MAIL)
-    rv |= MakeDefault(sMailProtocols, NS_ARRAY_LENGTH(sMailProtocols));
-  if (aApps & nsIShellService::NEWS)
-    rv |= MakeDefault(sNewsProtocols, NS_ARRAY_LENGTH(sNewsProtocols));
-  if (aApps & nsIShellService::RSS)
-    rv |= MakeDefault(sFeedProtocols, NS_ARRAY_LENGTH(sFeedProtocols));
-  
+  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sAppTypes); i++) {
+    if (aApps & sAppTypes[i].type)
+      rv |= MakeDefault(sAppTypes[i].protocols,
+                        NS_ARRAY_LENGTH(sAppTypes[i].protocols),
+                        sAppTypes[i].mimeType,
+                        sAppTypes[i].extensions);
+  }
+
   return rv;	
 }
 
 NS_IMETHODIMP
 nsMailGNOMEIntegration::GetShouldCheckDefaultClient(bool* aResult)
 {
   if (mCheckedThisSession) 
   {
@@ -270,17 +284,19 @@ nsMailGNOMEIntegration::checkDefault(con
     }
   }
 
   return true;
 }
 
 nsresult
 nsMailGNOMEIntegration::MakeDefault(const char* const *aProtocols,
-                                    unsigned int aLength)
+                                    unsigned int aProtocolsLength,
+                                    const char *aMimeType,
+                                    const char *aExtensions)
 {
   nsCAutoString appKeyValue;
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
   if(mAppIsInPath) {
     // mAppPath is in the users path, so use only the basename as the launcher
     gchar *tmp = g_path_get_basename(mAppPath.get());
     appKeyValue = tmp;
@@ -288,17 +304,17 @@ nsMailGNOMEIntegration::MakeDefault(cons
   } else {
     appKeyValue = mAppPath;
   }
 
   appKeyValue.AppendLiteral(" %s");
 
   nsresult rv;
   if (gconf) {
-    for (unsigned int i = 0; i < aLength; ++i) {
+    for (unsigned int i = 0; i < aProtocolsLength; ++i) {
       rv = gconf->SetAppForProtocol(nsDependentCString(aProtocols[i]),
                                     appKeyValue);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   if (giovfs) {
     nsCOMPtr<nsIStringBundleService> bundleService =
@@ -315,16 +331,22 @@ nsMailGNOMEIntegration::MakeDefault(cons
 
     // use brandShortName as the application id.
     NS_ConvertUTF16toUTF8 id(brandShortName);
 
     nsCOMPtr<nsIGIOMimeApp> app;
     rv = giovfs->CreateAppFromCommand(mAppPath, id, getter_AddRefs(app));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    for (unsigned int i = 0; i < aLength; ++i) {
+    for (unsigned int i = 0; i < aProtocolsLength; ++i) {
       rv = app->SetAsDefaultForURIScheme(nsDependentCString(aProtocols[i]));
       NS_ENSURE_SUCCESS(rv, rv);
+      if (aMimeType)
+        rv = app->SetAsDefaultForMimeType(nsDependentCString(aMimeType));
+      NS_ENSURE_SUCCESS(rv, rv);
+      if (aExtensions)
+        rv = app->SetAsDefaultForFileExtensions(nsDependentCString(aExtensions));
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   return NS_OK;
 }
--- a/mail/components/shell/nsMailGNOMEIntegration.h
+++ b/mail/components/shell/nsMailGNOMEIntegration.h
@@ -56,17 +56,20 @@ public:
   NS_HIDDEN_(nsresult) Init();
   nsMailGNOMEIntegration();
 
 protected:
   virtual ~nsMailGNOMEIntegration() {};
 
   bool KeyMatchesAppName(const char *aKeyValue) const;
   bool checkDefault(const char* const *aProtocols, unsigned int aLength);
-  nsresult MakeDefault(const char* const *aProtocols, unsigned int aLength);
+  nsresult MakeDefault(const char* const *aProtocols,
+                       unsigned int aProtocolsLength,
+                       const char *mimeType,
+                       const char *extensions);
 private:
   bool GetAppPathFromLauncher();
   bool CheckHandlerMatchesAppName(const nsACString& handler) const;
   bool mUseLocaleFilenames;
   bool mCheckedThisSession;
   nsCString mAppPath;
   bool mAppIsInPath;
 };