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 "nsExternalSharingAppService.h" michael@0: michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "nsIClassInfoImpl.h" michael@0: michael@0: #include "AndroidBridge.h" michael@0: #include "nsArrayUtils.h" michael@0: #include "nsISupportsUtils.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: NS_IMPL_ISUPPORTS(nsExternalSharingAppService, nsIExternalSharingAppService) michael@0: michael@0: nsExternalSharingAppService::nsExternalSharingAppService() michael@0: { michael@0: } michael@0: michael@0: nsExternalSharingAppService::~nsExternalSharingAppService() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsExternalSharingAppService::ShareWithDefault(const nsAString & data, michael@0: const nsAString & mime, michael@0: const nsAString & title) michael@0: { michael@0: NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND"); michael@0: const nsString emptyString = EmptyString(); michael@0: return mozilla::widget::android::GeckoAppShell::OpenUriExternal(data, michael@0: mime, emptyString,emptyString, sendAction, title) ? NS_OK : NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsExternalSharingAppService::GetSharingApps(const nsAString & aMIMEType, michael@0: uint32_t *aLen, michael@0: nsISharingHandlerApp ***aHandlers) michael@0: { michael@0: nsresult rv; michael@0: NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND"); michael@0: nsCOMPtr array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: if (!AndroidBridge::Bridge()) michael@0: return NS_OK; michael@0: AndroidBridge::Bridge()->GetHandlersForMimeType(aMIMEType, array, michael@0: nullptr, sendAction); michael@0: array->GetLength(aLen); michael@0: *aHandlers = michael@0: static_cast(NS_Alloc(sizeof(nsISharingHandlerApp*) michael@0: * *aLen)); michael@0: for (uint32_t i = 0; i < *aLen; i++) { michael@0: rv = array->QueryElementAt(i, NS_GET_IID(nsISharingHandlerApp), michael@0: (void**)(*aHandlers + i)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: } michael@0: return NS_OK; michael@0: }