uriloader/exthandler/android/nsOSHelperAppService.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/uriloader/exthandler/android/nsOSHelperAppService.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsOSHelperAppService.h"
    1.10 +#include "nsMIMEInfoAndroid.h"
    1.11 +#include "AndroidBridge.h"
    1.12 +
    1.13 +nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
    1.14 +{
    1.15 +}
    1.16 +
    1.17 +nsOSHelperAppService::~nsOSHelperAppService()
    1.18 +{
    1.19 +}
    1.20 +
    1.21 +already_AddRefed<nsIMIMEInfo>
    1.22 +nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
    1.23 +                                        const nsACString& aFileExt,
    1.24 +                                        bool* aFound)
    1.25 +{
    1.26 +    nsRefPtr<nsMIMEInfoAndroid> mimeInfo;
    1.27 +    *aFound = false;
    1.28 +    if (!aMIMEType.IsEmpty())
    1.29 +        *aFound = 
    1.30 +            nsMIMEInfoAndroid::GetMimeInfoForMimeType(aMIMEType, 
    1.31 +                                                      getter_AddRefs(mimeInfo));
    1.32 +    if (!*aFound)
    1.33 +        *aFound =
    1.34 +            nsMIMEInfoAndroid::GetMimeInfoForFileExt(aFileExt, 
    1.35 +                                                     getter_AddRefs(mimeInfo));
    1.36 +
    1.37 +    // Code that calls this requires an object regardless if the OS has
    1.38 +    // something for us, so we return the empty object.
    1.39 +    if (!*aFound)
    1.40 +        mimeInfo = new nsMIMEInfoAndroid(aMIMEType);
    1.41 +
    1.42 +    return mimeInfo.forget();
    1.43 +}
    1.44 +
    1.45 +nsresult
    1.46 +nsOSHelperAppService::OSProtocolHandlerExists(const char* aScheme,
    1.47 +                                              bool* aExists)
    1.48 +{
    1.49 +    *aExists = mozilla::AndroidBridge::Bridge()->GetHandlersForURL(NS_ConvertUTF8toUTF16(aScheme));    
    1.50 +    return NS_OK;
    1.51 +}
    1.52 +
    1.53 +nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
    1.54 +                                      bool *found,
    1.55 +                                      nsIHandlerInfo **info)
    1.56 +{
    1.57 +    return nsMIMEInfoAndroid::GetMimeInfoForURL(aScheme, found, info);
    1.58 +}
    1.59 +
    1.60 +nsIHandlerApp*
    1.61 +nsOSHelperAppService::CreateAndroidHandlerApp(const nsAString& aName,
    1.62 +                                              const nsAString& aDescription,
    1.63 +                                              const nsAString& aPackageName,
    1.64 +                                              const nsAString& aClassName, 
    1.65 +                                              const nsACString& aMimeType,
    1.66 +                                              const nsAString& aAction)
    1.67 +{
    1.68 +    return new nsAndroidHandlerApp(aName, aDescription, aPackageName,
    1.69 +                                   aClassName, aMimeType, aAction);
    1.70 +}

mercurial