Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "shareuiinterface.h"
6 #include <MDataUri>
7 #include "nsExternalSharingAppService.h"
8 #include "nsString.h"
10 NS_IMPL_ISUPPORTS(nsExternalSharingAppService, nsIExternalSharingAppService)
12 nsExternalSharingAppService::nsExternalSharingAppService()
13 : mShareUi(nullptr)
14 {
15 }
17 nsExternalSharingAppService::~nsExternalSharingAppService()
18 {
19 }
21 NS_IMETHODIMP
22 nsExternalSharingAppService::ShareWithDefault(const nsAString & aData,
23 const nsAString & aMime,
24 const nsAString & aTitle)
25 {
26 if (!mShareUi)
27 mShareUi = new ShareUiInterface();
29 if (!mShareUi || !mShareUi->isValid())
30 return NS_ERROR_NOT_AVAILABLE;
32 if (aData.IsEmpty())
33 return NS_ERROR_INVALID_ARG;
35 MDataUri uri;
36 uri.setTextData(QString::fromUtf16(aData.BeginReading(), aData.Length()));
37 uri.setMimeType(QString::fromUtf16(aMime.BeginReading(), aMime.Length()));
38 uri.setAttribute("title", QString::fromUtf16(aTitle.BeginReading(), 0));
40 mShareUi->share(QStringList(uri.toString()));
42 return NS_OK;
43 }
45 NS_IMETHODIMP
46 nsExternalSharingAppService::GetSharingApps(const nsAString & aMIMEType,
47 uint32_t *aLen,
48 nsISharingHandlerApp ***aHandlers)
49 {
50 return NS_ERROR_NOT_IMPLEMENTED;
51 }