1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/android/nsExternalSharingAppService.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsExternalSharingAppService.h" 1.9 + 1.10 +#include "mozilla/ModuleUtils.h" 1.11 +#include "nsIClassInfoImpl.h" 1.12 + 1.13 +#include "AndroidBridge.h" 1.14 +#include "nsArrayUtils.h" 1.15 +#include "nsISupportsUtils.h" 1.16 +#include "nsComponentManagerUtils.h" 1.17 + 1.18 +using namespace mozilla; 1.19 + 1.20 +NS_IMPL_ISUPPORTS(nsExternalSharingAppService, nsIExternalSharingAppService) 1.21 + 1.22 +nsExternalSharingAppService::nsExternalSharingAppService() 1.23 +{ 1.24 +} 1.25 + 1.26 +nsExternalSharingAppService::~nsExternalSharingAppService() 1.27 +{ 1.28 +} 1.29 + 1.30 +NS_IMETHODIMP 1.31 +nsExternalSharingAppService::ShareWithDefault(const nsAString & data, 1.32 + const nsAString & mime, 1.33 + const nsAString & title) 1.34 +{ 1.35 + NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND"); 1.36 + const nsString emptyString = EmptyString(); 1.37 + return mozilla::widget::android::GeckoAppShell::OpenUriExternal(data, 1.38 + mime, emptyString,emptyString, sendAction, title) ? NS_OK : NS_ERROR_FAILURE; 1.39 +} 1.40 + 1.41 +NS_IMETHODIMP 1.42 +nsExternalSharingAppService::GetSharingApps(const nsAString & aMIMEType, 1.43 + uint32_t *aLen, 1.44 + nsISharingHandlerApp ***aHandlers) 1.45 +{ 1.46 + nsresult rv; 1.47 + NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND"); 1.48 + nsCOMPtr<nsIMutableArray> array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); 1.49 + NS_ENSURE_SUCCESS(rv, rv); 1.50 + if (!AndroidBridge::Bridge()) 1.51 + return NS_OK; 1.52 + AndroidBridge::Bridge()->GetHandlersForMimeType(aMIMEType, array, 1.53 + nullptr, sendAction); 1.54 + array->GetLength(aLen); 1.55 + *aHandlers = 1.56 + static_cast<nsISharingHandlerApp**>(NS_Alloc(sizeof(nsISharingHandlerApp*) 1.57 + * *aLen)); 1.58 + for (uint32_t i = 0; i < *aLen; i++) { 1.59 + rv = array->QueryElementAt(i, NS_GET_IID(nsISharingHandlerApp), 1.60 + (void**)(*aHandlers + i)); 1.61 + NS_ENSURE_SUCCESS(rv, rv); 1.62 + } 1.63 + return NS_OK; 1.64 +}