uriloader/exthandler/android/nsOSHelperAppService.cpp

branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
equal deleted inserted replaced
-1:000000000000 0:5bc3301027dd
1 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "nsOSHelperAppService.h"
7 #include "nsMIMEInfoAndroid.h"
8 #include "AndroidBridge.h"
9
10 nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
11 {
12 }
13
14 nsOSHelperAppService::~nsOSHelperAppService()
15 {
16 }
17
18 already_AddRefed<nsIMIMEInfo>
19 nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
20 const nsACString& aFileExt,
21 bool* aFound)
22 {
23 nsRefPtr<nsMIMEInfoAndroid> mimeInfo;
24 *aFound = false;
25 if (!aMIMEType.IsEmpty())
26 *aFound =
27 nsMIMEInfoAndroid::GetMimeInfoForMimeType(aMIMEType,
28 getter_AddRefs(mimeInfo));
29 if (!*aFound)
30 *aFound =
31 nsMIMEInfoAndroid::GetMimeInfoForFileExt(aFileExt,
32 getter_AddRefs(mimeInfo));
33
34 // Code that calls this requires an object regardless if the OS has
35 // something for us, so we return the empty object.
36 if (!*aFound)
37 mimeInfo = new nsMIMEInfoAndroid(aMIMEType);
38
39 return mimeInfo.forget();
40 }
41
42 nsresult
43 nsOSHelperAppService::OSProtocolHandlerExists(const char* aScheme,
44 bool* aExists)
45 {
46 *aExists = mozilla::AndroidBridge::Bridge()->GetHandlersForURL(NS_ConvertUTF8toUTF16(aScheme));
47 return NS_OK;
48 }
49
50 nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
51 bool *found,
52 nsIHandlerInfo **info)
53 {
54 return nsMIMEInfoAndroid::GetMimeInfoForURL(aScheme, found, info);
55 }
56
57 nsIHandlerApp*
58 nsOSHelperAppService::CreateAndroidHandlerApp(const nsAString& aName,
59 const nsAString& aDescription,
60 const nsAString& aPackageName,
61 const nsAString& aClassName,
62 const nsACString& aMimeType,
63 const nsAString& aAction)
64 {
65 return new nsAndroidHandlerApp(aName, aDescription, aPackageName,
66 aClassName, aMimeType, aAction);
67 }

mercurial