Bug 1701269 - Remove unused code in org.mozilla.gecko. r=owlish

Differential Revision: https://phabricator.services.mozilla.com/D109922
This commit is contained in:
Agi Sferro 2021-05-20 22:03:05 +00:00
Родитель c6730b3c16
Коммит ad41d2bdec
3 изменённых файлов: 0 добавлений и 231 удалений

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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<String> 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));
}
}
}
}
}

Просмотреть файл

@ -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);
}
}