Skip to content

Commit

Permalink
Bug 1694481 - Remove unused code from exthandler/android. r=droeh,esawin
Browse files Browse the repository at this point in the history
  • Loading branch information
agi committed Mar 10, 2021
1 parent 9ec0fac commit 1113437
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 353 deletions.
6 changes: 0 additions & 6 deletions docshell/build/components.conf
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ if defined('MOZ_ENABLE_DBUS'):

if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] == 'android':
Classes += [
{
'cid': '{4bf1f8ef-d947-4ba3-9cd3-8c9a54a63a1c}',
'contract_ids': ['@mozilla.org/uriloader/external-url-handler-service;1'],
'type': 'nsExternalURLHandlerService',
'headers': ['nsExternalURLHandlerService.h'],
},
# Android has its own externel-helper-app-service, so we omit
# that here for nsExternalHelperAppService.
{
Expand Down
9 changes: 0 additions & 9 deletions docshell/build/nsDocShellCID.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
*/
#define NS_IHISTORY_CONTRACTID "@mozilla.org/browser/history;1"

/**
* A contract for a service that is used for finding
* platform-specific applications for handling particular URLs.
*
* @implements nsIExternalURLHandlerService
*/
#define NS_EXTERNALURLHANDLERSERVICE_CONTRACTID \
"@mozilla.org/uriloader/external-url-handler-service;1"

/**
* An observer service topic that can be listened to to catch creation
* of content browsing areas (both toplevel ones and subframes). The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,21 +840,6 @@ private static boolean hasHWVP8Decoder() {
return HardwareCodecCapabilityUtils.hasHWVP8(false /* aIsEncoder */);
}

static List<ResolveInfo> queryIntentActivities(final Intent intent) {
final PackageManager pm = getApplicationContext().getPackageManager();

// Exclude any non-exported activities: we can't open them even if we want to!
// Bug 1031569 has some details.
final ArrayList<ResolveInfo> list = new ArrayList<>();
for (ResolveInfo ri: pm.queryIntentActivities(intent, 0)) {
if (ri.activityInfo.exported) {
list.add(ri);
}
}

return list;
}

@WrapForJNI(calledFrom = "gecko")
public static String getExtensionFromMimeType(final String aMimeType) {
return MimeTypeMap.getSingleton().getExtensionFromMimeType(aMimeType);
Expand Down
86 changes: 0 additions & 86 deletions uriloader/exthandler/android/nsAndroidHandlerApp.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions uriloader/exthandler/android/nsAndroidHandlerApp.h

This file was deleted.

21 changes: 0 additions & 21 deletions uriloader/exthandler/android/nsExternalURLHandlerService.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions uriloader/exthandler/android/nsExternalURLHandlerService.h

This file was deleted.

108 changes: 17 additions & 91 deletions uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMIMEInfoAndroid.h"
#include "AndroidBridge.h"
#include "nsAndroidHandlerApp.h"
#include "nsArrayUtils.h"
#include "nsISupportsUtils.h"
#include "nsStringEnumerator.h"
#include "nsNetUtil.h"
#include "mozilla/Utf8.h"

using namespace mozilla;

Expand All @@ -22,74 +17,31 @@ nsMIMEInfoAndroid::LaunchDefaultWithFile(nsIFile* aFile) {

NS_IMETHODIMP
nsMIMEInfoAndroid::LoadUriInternal(nsIURI* aURI) {
nsCString uriSpec;
aURI->GetSpec(uriSpec);

nsCString uriScheme;
aURI->GetScheme(uriScheme);

nsAutoString mimeType;
if (mType.Equals(uriScheme) || mType.Equals(uriSpec)) {
mimeType.Truncate();
} else {
CopyUTF8toUTF16(mType, mimeType);
}

if (java::GeckoAppShell::OpenUriExternal(NS_ConvertUTF8toUTF16(uriSpec),
mimeType, u""_ns, u""_ns, u""_ns,
u""_ns)) {
return NS_OK;
}
return NS_ERROR_FAILURE;
return NS_ERROR_NOT_IMPLEMENTED;
}

bool nsMIMEInfoAndroid::GetMimeInfoForMimeType(const nsACString& aMimeType,
nsMIMEInfoAndroid** aMimeInfo) {
RefPtr<nsMIMEInfoAndroid> info = new nsMIMEInfoAndroid(aMimeType);
mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
// we don't have access to the bridge, so just assume we can handle
// the mime type for now and let the system deal with it
if (!bridge) {
info.forget(aMimeInfo);
return false;
}

nsIHandlerApp* systemDefault = nullptr;

if (!IsUtf8(aMimeType)) return false;

NS_ConvertUTF8toUTF16 mimeType(aMimeType);

bridge->GetHandlersForMimeType(mimeType, info->mHandlerApps, &systemDefault);

if (systemDefault) info->mPrefApp = systemDefault;

nsAutoCString fileExt;
bridge->GetExtensionFromMimeType(aMimeType, fileExt);
info->SetPrimaryExtension(fileExt);

uint32_t len;
info->mHandlerApps->GetLength(&len);
if (len == 1) {
info.forget(aMimeInfo);
return false;
}

info.forget(aMimeInfo);
return true;
return false;
}

bool nsMIMEInfoAndroid::GetMimeInfoForFileExt(const nsACString& aFileExt,
nsMIMEInfoAndroid** aMimeInfo) {
nsCString mimeType;
if (mozilla::AndroidBridge::Bridge())
mozilla::AndroidBridge::Bridge()->GetMimeTypeFromExtensions(aFileExt,
mimeType);
if (jni::IsAvailable()) {
auto javaString = java::GeckoAppShell::GetMimeTypeFromExtensions(aFileExt);
if (javaString) {
mimeType = javaString->ToCString();
}
}

// "*/*" means that the bridge didn't know.
if (mimeType.Equals(nsDependentCString("*/*"),
nsCaseInsensitiveCStringComparator))
nsCaseInsensitiveCStringComparator)) {
return false;
}

bool found = GetMimeInfoForMimeType(mimeType, aMimeInfo);
(*aMimeInfo)->SetPrimaryExtension(aFileExt);
Expand All @@ -105,36 +57,7 @@ nsresult nsMIMEInfoAndroid::GetMimeInfoForURL(const nsACString& aURL,
nsIHandlerInfo** info) {
nsMIMEInfoAndroid* mimeinfo = new nsMIMEInfoAndroid(aURL);
NS_ADDREF(*info = mimeinfo);
*found = true;

mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
if (!bridge) {
// we don't have access to the bridge, so just assume we can handle
// the protocol for now and let the system deal with it
return NS_OK;
}

nsIHandlerApp* systemDefault = nullptr;
bridge->GetHandlersForURL(NS_ConvertUTF8toUTF16(aURL), mimeinfo->mHandlerApps,
&systemDefault);

if (systemDefault) mimeinfo->mPrefApp = systemDefault;

nsAutoCString fileExt;
nsAutoCString mimeType;
mimeinfo->GetType(mimeType);
bridge->GetExtensionFromMimeType(mimeType, fileExt);
mimeinfo->SetPrimaryExtension(fileExt);

uint32_t len;
mimeinfo->mHandlerApps->GetLength(&len);
if (len == 1) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
*found = false;
return NS_OK;
}

*found = false;
return NS_OK;
}

Expand Down Expand Up @@ -258,9 +181,12 @@ nsMIMEInfoAndroid::ExtensionExists(const nsACString& aExtension,
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");

nsCString mimeType;
if (mozilla::AndroidBridge::Bridge()) {
mozilla::AndroidBridge::Bridge()->GetMimeTypeFromExtensions(aExtension,
mimeType);
if (jni::IsAvailable()) {
auto javaString =
java::GeckoAppShell::GetMimeTypeFromExtensions(aExtension);
if (javaString) {
mimeType = javaString->ToCString();
}
}

// "*/*" means the bridge didn't find anything (i.e., extension doesn't
Expand Down
2 changes: 1 addition & 1 deletion uriloader/exthandler/android/nsMIMEInfoAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "nsMIMEInfoImpl.h"
#include "nsIMutableArray.h"
#include "nsAndroidHandlerApp.h"
#include "mozilla/java/GeckoAppShellWrappers.h"

class nsMIMEInfoAndroid final : public nsIMIMEInfo {
public:
Expand Down
9 changes: 0 additions & 9 deletions uriloader/exthandler/android/nsOSHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "nsOSHelperAppService.h"
#include "nsMIMEInfoAndroid.h"
#include "AndroidBridge.h"

nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() {}

Expand Down Expand Up @@ -60,11 +59,3 @@ nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(
// should take care of that in NavigationDelegate.onLoadRequest().
return NS_ERROR_NOT_IMPLEMENTED;
}

nsIHandlerApp* nsOSHelperAppService::CreateAndroidHandlerApp(
const nsAString& aName, const nsAString& aDescription,
const nsAString& aPackageName, const nsAString& aClassName,
const nsACString& aMimeType, const nsAString& aAction) {
return new nsAndroidHandlerApp(aName, aDescription, aPackageName, aClassName,
aMimeType, aAction);
}
Loading

0 comments on commit 1113437

Please sign in to comment.