uriloader/exthandler/android/nsOSHelperAppService.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     6 #include "nsOSHelperAppService.h"
     7 #include "nsMIMEInfoAndroid.h"
     8 #include "AndroidBridge.h"
    10 nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
    11 {
    12 }
    14 nsOSHelperAppService::~nsOSHelperAppService()
    15 {
    16 }
    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));
    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);
    39     return mimeInfo.forget();
    40 }
    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 }
    50 nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
    51                                       bool *found,
    52                                       nsIHandlerInfo **info)
    53 {
    54     return nsMIMEInfoAndroid::GetMimeInfoForURL(aScheme, found, info);
    55 }
    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