2003-09-29 22:04:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-09-29 22:04:05 +00:00
|
|
|
|
|
|
|
#include "nsGNOMERegistry.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2007-07-26 05:52:27 +00:00
|
|
|
#include "nsMIMEInfoUnix.h"
|
2004-02-23 22:49:28 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2009-08-25 18:58:11 +00:00
|
|
|
#include "nsIGIOService.h"
|
2003-09-29 22:04:05 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* static */ bool
|
2004-10-16 13:46:17 +00:00
|
|
|
nsGNOMERegistry::HandlerExists(const char *aProtocolScheme)
|
|
|
|
{
|
2011-05-04 04:10:43 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2015-02-16 23:00:32 +00:00
|
|
|
if (!giovfs) {
|
|
|
|
return false;
|
2011-05-04 04:10:43 +00:00
|
|
|
}
|
2004-01-21 04:52:10 +00:00
|
|
|
|
2018-01-12 15:32:53 +00:00
|
|
|
nsCOMPtr<nsIHandlerApp> app;
|
2015-02-16 23:00:32 +00:00
|
|
|
return NS_SUCCEEDED(giovfs->GetAppForURIScheme(nsDependentCString(aProtocolScheme),
|
|
|
|
getter_AddRefs(app)));
|
2003-09-29 22:04:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 18:31:13 +00:00
|
|
|
// XXX Check HandlerExists() before calling LoadURL.
|
|
|
|
|
2003-09-29 22:04:05 +00:00
|
|
|
/* static */ nsresult
|
|
|
|
nsGNOMERegistry::LoadURL(nsIURI *aURL)
|
|
|
|
{
|
2009-08-25 18:58:11 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2015-02-16 23:00:32 +00:00
|
|
|
if (!giovfs) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-05-11 13:10:00 +00:00
|
|
|
|
2015-02-16 23:00:32 +00:00
|
|
|
return giovfs->ShowURI(aURL);
|
2003-09-29 22:04:05 +00:00
|
|
|
}
|
|
|
|
|
2004-10-16 13:46:17 +00:00
|
|
|
/* static */ void
|
|
|
|
nsGNOMERegistry::GetAppDescForScheme(const nsACString& aScheme,
|
|
|
|
nsAString& aDesc)
|
|
|
|
{
|
2011-05-04 04:10:43 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2015-02-16 23:00:32 +00:00
|
|
|
if (!giovfs)
|
2008-01-30 04:36:11 +00:00
|
|
|
return;
|
2004-10-16 13:46:17 +00:00
|
|
|
|
2018-01-12 15:32:53 +00:00
|
|
|
nsCOMPtr<nsIHandlerApp> app;
|
2015-02-16 23:00:32 +00:00
|
|
|
if (NS_FAILED(giovfs->GetAppForURIScheme(aScheme, getter_AddRefs(app))))
|
|
|
|
return;
|
|
|
|
|
2017-12-29 07:27:42 +00:00
|
|
|
app->GetName(aDesc);
|
2004-10-16 13:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-23 22:49:28 +00:00
|
|
|
/* static */ already_AddRefed<nsMIMEInfoBase>
|
2008-01-30 04:36:11 +00:00
|
|
|
nsGNOMERegistry::GetFromExtension(const nsACString& aFileExt)
|
2003-09-29 22:04:05 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString mimeType;
|
2009-08-25 18:58:11 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2015-02-16 23:00:32 +00:00
|
|
|
if (!giovfs) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2009-08-25 18:58:11 +00:00
|
|
|
|
2015-02-16 23:00:32 +00:00
|
|
|
// Get the MIME type from the extension, then call GetFromType to
|
|
|
|
// fill in the MIMEInfo.
|
|
|
|
if (NS_FAILED(giovfs->GetMimeTypeFromExtension(aFileExt, mimeType)) ||
|
|
|
|
mimeType.EqualsLiteral("application/octet-stream")) {
|
|
|
|
return nullptr;
|
2009-08-25 18:58:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsMIMEInfoBase> mi = GetFromType(mimeType);
|
2013-03-21 13:51:30 +00:00
|
|
|
if (mi) {
|
|
|
|
mi->AppendExtension(aFileExt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mi.forget();
|
2003-09-29 22:04:05 +00:00
|
|
|
}
|
|
|
|
|
2004-02-23 22:49:28 +00:00
|
|
|
/* static */ already_AddRefed<nsMIMEInfoBase>
|
2008-01-30 04:36:11 +00:00
|
|
|
nsGNOMERegistry::GetFromType(const nsACString& aMIMEType)
|
2003-09-29 22:04:05 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ENSURE_TRUE(mimeInfo, nullptr);
|
2011-05-11 13:10:00 +00:00
|
|
|
|
2017-12-29 07:27:42 +00:00
|
|
|
nsAutoString name;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString description;
|
2003-09-29 22:04:05 +00:00
|
|
|
|
2011-05-11 13:10:00 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2015-02-16 23:00:32 +00:00
|
|
|
if (!giovfs) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-12 15:32:53 +00:00
|
|
|
nsCOMPtr<nsIHandlerApp> handlerApp;
|
|
|
|
if (NS_FAILED(giovfs->GetAppForMimeType(aMIMEType, getter_AddRefs(handlerApp))) ||
|
|
|
|
!handlerApp) {
|
2015-02-16 23:00:32 +00:00
|
|
|
return nullptr;
|
2011-05-11 13:10:00 +00:00
|
|
|
}
|
2018-01-12 15:32:53 +00:00
|
|
|
handlerApp->GetName(name);
|
2015-02-16 23:00:32 +00:00
|
|
|
giovfs->GetDescriptionForMimeType(aMIMEType, description);
|
2009-08-25 18:58:11 +00:00
|
|
|
|
2017-12-29 07:27:42 +00:00
|
|
|
mimeInfo->SetDefaultDescription(name);
|
2008-02-27 00:58:15 +00:00
|
|
|
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
2011-05-11 13:10:00 +00:00
|
|
|
mimeInfo->SetDescription(NS_ConvertUTF8toUTF16(description));
|
2004-01-29 22:20:44 +00:00
|
|
|
|
2013-04-22 11:15:59 +00:00
|
|
|
return mimeInfo.forget();
|
2003-09-29 22:04:05 +00:00
|
|
|
}
|