michael@0: /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsOSHelperAppService.h" michael@0: #include "nsMIMEInfoAndroid.h" michael@0: #include "AndroidBridge.h" michael@0: michael@0: nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() michael@0: { michael@0: } michael@0: michael@0: nsOSHelperAppService::~nsOSHelperAppService() michael@0: { michael@0: } michael@0: michael@0: already_AddRefed michael@0: nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType, michael@0: const nsACString& aFileExt, michael@0: bool* aFound) michael@0: { michael@0: nsRefPtr mimeInfo; michael@0: *aFound = false; michael@0: if (!aMIMEType.IsEmpty()) michael@0: *aFound = michael@0: nsMIMEInfoAndroid::GetMimeInfoForMimeType(aMIMEType, michael@0: getter_AddRefs(mimeInfo)); michael@0: if (!*aFound) michael@0: *aFound = michael@0: nsMIMEInfoAndroid::GetMimeInfoForFileExt(aFileExt, michael@0: getter_AddRefs(mimeInfo)); michael@0: michael@0: // Code that calls this requires an object regardless if the OS has michael@0: // something for us, so we return the empty object. michael@0: if (!*aFound) michael@0: mimeInfo = new nsMIMEInfoAndroid(aMIMEType); michael@0: michael@0: return mimeInfo.forget(); michael@0: } michael@0: michael@0: nsresult michael@0: nsOSHelperAppService::OSProtocolHandlerExists(const char* aScheme, michael@0: bool* aExists) michael@0: { michael@0: *aExists = mozilla::AndroidBridge::Bridge()->GetHandlersForURL(NS_ConvertUTF8toUTF16(aScheme)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme, michael@0: bool *found, michael@0: nsIHandlerInfo **info) michael@0: { michael@0: return nsMIMEInfoAndroid::GetMimeInfoForURL(aScheme, found, info); michael@0: } michael@0: michael@0: nsIHandlerApp* michael@0: nsOSHelperAppService::CreateAndroidHandlerApp(const nsAString& aName, michael@0: const nsAString& aDescription, michael@0: const nsAString& aPackageName, michael@0: const nsAString& aClassName, michael@0: const nsACString& aMimeType, michael@0: const nsAString& aAction) michael@0: { michael@0: return new nsAndroidHandlerApp(aName, aDescription, aPackageName, michael@0: aClassName, aMimeType, aAction); michael@0: }