# HG changeset patch # User Ian Neal # Date 1623167323 14400 # Parent 9ba6e3e4a008f103017f6b7a9567ddfebbdcb0d8 Bug 1544739 - Part 6: Update GNOME shell service - Add essential parameter to protocol association. r=frg a=frg diff --git a/suite/components/shell/nsGNOMEShellService.cpp b/suite/components/shell/nsGNOMEShellService.cpp --- a/suite/components/shell/nsGNOMEShellService.cpp +++ b/suite/components/shell/nsGNOMEShellService.cpp @@ -35,31 +35,34 @@ #include #include #include #include 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,79 +174,85 @@ nsGNOMEShellService::CheckHandlerMatches } NS_IMETHODIMP nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps, bool* aIsDefaultClient) { *aIsDefaultClient = false; - nsCString handler; + nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); + nsAutoCString handler; nsCOMPtr app; - nsCOMPtr 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(); + nsDependentCString protocol(gProtocols[i].protocol); giovfs->GetAppForURIScheme(protocol, getter_AddRefs(app)); if (!app) return NS_OK; if (NS_SUCCEEDED(app->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 app; nsCOMPtr 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 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) { diff --git a/suite/components/shell/nsGNOMEShellService.h b/suite/components/shell/nsGNOMEShellService.h --- 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