From ad41d2bdecee599ab0e7106be972a3f39149ad1a Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Thu, 20 May 2021 22:03:05 +0000 Subject: [PATCH] Bug 1701269 - Remove unused code in org.mozilla.gecko. r=owlish Differential Revision: https://phabricator.services.mozilla.com/D109922 --- .../gecko/mozglue/ByteBufferInputStream.java | 64 ------- .../org/mozilla/gecko/mozglue/SafeIntent.java | 163 ------------------ .../gecko/util/GeckoBackgroundThread.java | 4 - 3 files changed, 231 deletions(-) delete mode 100644 mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/ByteBufferInputStream.java delete mode 100644 mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/SafeIntent.java diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/ByteBufferInputStream.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/ByteBufferInputStream.java deleted file mode 100644 index 49b31b652fbe..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/ByteBufferInputStream.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -package org.mozilla.gecko.mozglue; - -import java.io.InputStream; -import java.nio.ByteBuffer; - -class ByteBufferInputStream extends InputStream { - - protected ByteBuffer mBuf; - // Reference to a native object holding the data backing the ByteBuffer. - private final NativeReference mNativeRef; - - protected ByteBufferInputStream(final ByteBuffer buffer, final NativeReference ref) { - mBuf = buffer; - mNativeRef = ref; - } - - @Override - public int available() { - return mBuf.remaining(); - } - - @Override - public void close() { - // Do nothing, we need to keep the native references around for child - // buffers. - } - - @Override - public int read() { - if (!mBuf.hasRemaining() || mNativeRef.isReleased()) { - return -1; - } - - return mBuf.get() & 0xff; // Avoid sign extension - } - - @Override - public int read(final byte[] buffer, final int offset, final int length) { - if (!mBuf.hasRemaining() || mNativeRef.isReleased()) { - return -1; - } - - final int remainingLength = Math.min(length, mBuf.remaining()); - mBuf.get(buffer, offset, remainingLength); - return length; - } - - @Override - public long skip(final long byteCount) { - if (byteCount < 0 || mNativeRef.isReleased()) { - return 0; - } - - final long remainingByteCount = Math.min(byteCount, mBuf.remaining()); - mBuf.position(mBuf.position() + (int) remainingByteCount); - return remainingByteCount; - } - -} diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/SafeIntent.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/SafeIntent.java deleted file mode 100644 index 9e69f34258b7..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/SafeIntent.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. - */ - -// This should be in util/, but is here because of build dependency issues. -package org.mozilla.gecko.mozglue; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import androidx.annotation.Nullable; -import android.util.Log; - -import java.util.ArrayList; - -/** - * External applications can pass values into Intents that can cause us to crash: in defense, - * we wrap {@link Intent} and catch the exceptions they may force us to throw. See bug 1090385 - * for more. - */ -public class SafeIntent { - private static final String LOGTAG = "Gecko" + SafeIntent.class.getSimpleName(); - - private final Intent mIntent; - - public SafeIntent(final Intent intent) { - stripDataUri(intent); - mIntent = intent; - } - - public boolean hasExtra(final String name) { - try { - return mIntent.hasExtra(name); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't determine if intent had an extra: OOM. Malformed?"); - return false; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't determine if intent had an extra.", e); - return false; - } - } - - public @Nullable Bundle getExtras() { - try { - return mIntent.getExtras(); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent extras.", e); - return null; - } - } - - public boolean getBooleanExtra(final String name, final boolean defaultValue) { - try { - return mIntent.getBooleanExtra(name, defaultValue); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?"); - return defaultValue; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent extras.", e); - return defaultValue; - } - } - - public int getIntExtra(final String name, final int defaultValue) { - try { - return mIntent.getIntExtra(name, defaultValue); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?"); - return defaultValue; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent extras.", e); - return defaultValue; - } - } - - public String getStringExtra(final String name) { - try { - return mIntent.getStringExtra(name); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent extras.", e); - return null; - } - } - - public Bundle getBundleExtra(final String name) { - try { - return mIntent.getBundleExtra(name); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent extras.", e); - return null; - } - } - - public String getAction() { - return mIntent.getAction(); - } - - public String getDataString() { - try { - return mIntent.getDataString(); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent data string: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent data string.", e); - return null; - } - } - - public ArrayList getStringArrayListExtra(final String name) { - try { - return mIntent.getStringArrayListExtra(name); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent data string: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent data string.", e); - return null; - } - } - - public Uri getData() { - try { - return mIntent.getData(); - } catch (final OutOfMemoryError e) { - Log.w(LOGTAG, "Couldn't get intent data: OOM. Malformed?"); - return null; - } catch (final RuntimeException e) { - Log.w(LOGTAG, "Couldn't get intent data.", e); - return null; - } - } - - public Intent getUnsafe() { - return mIntent; - } - - private static void stripDataUri(final Intent intent) { - // We should limit intent filters and check incoming intents against white-list - // But for now we just strip 'about:reader?url=' - if (intent != null && intent.getData() != null) { - final String url = intent.getData().toString(); - final String prefix = "about:reader?url="; - if (url != null && url.startsWith(prefix)) { - final String strippedUrl = url.replace(prefix, ""); - if (strippedUrl != null) { - intent.setData(Uri.parse(strippedUrl)); - } - } - } - } -} diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBackgroundThread.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBackgroundThread.java index 657aab9f8fc2..68a923114fe4 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBackgroundThread.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBackgroundThread.java @@ -69,8 +69,4 @@ final class GeckoBackgroundThread extends Thread { } getHandler().post(runnable); } - - /*package*/ static void postDelayed(final Runnable runnable, final long timeout) { - getHandler().postDelayed(runnable, timeout); - } }