Bug 1512274 - [geckoview] Don't change value of method arguments. r=geckoview-reviewers,snorp

Differential Revision: https://phabricator.services.mozilla.com/D23682

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2019-03-15 21:20:20 +00:00
Родитель c92d430c9e
Коммит 789b04a378
19 изменённых файлов: 134 добавлений и 111 удалений

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

@ -56,11 +56,11 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
* @param exc An exception
* @return The root exception
*/
public static Throwable getRootException(Throwable exc) {
for (Throwable cause = exc; cause != null; cause = cause.getCause()) {
exc = cause;
}
return exc;
public static Throwable getRootException(final Throwable exc) {
Throwable cause;
for (cause = exc; cause != null; cause = cause.getCause()) {}
return cause;
}
/**
@ -453,20 +453,22 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
return;
}
if (thread == null) {
Thread resolvedThread = thread;
if (resolvedThread == null) {
// Gecko may pass in null for thread to denote the current thread.
thread = Thread.currentThread();
resolvedThread = Thread.currentThread();
}
try {
Throwable rootException = exc;
if (!this.unregistered) {
// Only process crash ourselves if we have not been unregistered.
this.crashing = true;
exc = getRootException(exc);
logException(thread, exc);
rootException = getRootException(exc);
logException(resolvedThread, rootException);
if (reportException(thread, exc)) {
if (reportException(resolvedThread, rootException)) {
// Reporting succeeded; we can terminate our process now.
return;
}
@ -474,7 +476,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
if (systemUncaughtHandler != null) {
// Follow the chain of uncaught handlers.
systemUncaughtHandler.uncaughtException(thread, exc);
systemUncaughtHandler.uncaughtException(resolvedThread, rootException);
}
} finally {
terminateProcess();

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

@ -1421,24 +1421,28 @@ public class GeckoAppShell
@WrapForJNI(calledFrom = "gecko")
private static byte[] getIconForExtension(String aExt, int iconSize) {
try {
if (iconSize <= 0)
iconSize = 16;
int resolvedIconSize = iconSize;
if (iconSize <= 0) {
resolvedIconSize = 16;
}
if (aExt != null && aExt.length() > 1 && aExt.charAt(0) == '.')
aExt = aExt.substring(1);
String resolvedExt = aExt;
if (aExt != null && aExt.length() > 1 && aExt.charAt(0) == '.') {
resolvedExt = aExt.substring(1);
}
PackageManager pm = getApplicationContext().getPackageManager();
Drawable icon = getDrawableForExtension(pm, aExt);
Drawable icon = getDrawableForExtension(pm, resolvedExt);
if (icon == null) {
// Use a generic icon
icon = pm.getDefaultActivityIcon();
}
Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
if (bitmap.getWidth() != iconSize || bitmap.getHeight() != iconSize)
bitmap = Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, true);
if (bitmap.getWidth() != resolvedIconSize || bitmap.getHeight() != resolvedIconSize)
bitmap = Bitmap.createScaledBitmap(bitmap, resolvedIconSize, resolvedIconSize, true);
ByteBuffer buf = ByteBuffer.allocate(iconSize * iconSize * 4);
ByteBuffer buf = ByteBuffer.allocate(resolvedIconSize * resolvedIconSize * 4);
bitmap.copyPixelsToBuffer(buf);
return buf.array();

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

@ -218,6 +218,7 @@ public final class GeckoProfile {
// ------------------------------------------
// Yes | Yes | Active profile or default profile
String resolvedProfileName = profileName;
if (TextUtils.isEmpty(profileName) && profileDir == null) {
// If no profile info was passed in, look for the active profile or a default profile.
final GeckoProfile profile = GeckoThread.getActiveProfile();
@ -230,25 +231,25 @@ public final class GeckoProfile {
return GeckoProfile.initFromArgs(context, sIntentArgs);
} else if (profileName == null) {
// If only profile dir was passed in, use custom (anonymous) profile.
profileName = CUSTOM_PROFILE;
resolvedProfileName = CUSTOM_PROFILE;
}
// We require the profile dir to exist if specified, so create it here if needed.
final boolean init = profileDir != null && profileDir.mkdirs();
// Actually try to look up the profile.
GeckoProfile profile = sProfileCache.get(profileName);
GeckoProfile profile = sProfileCache.get(resolvedProfileName);
GeckoProfile newProfile = null;
if (profile == null) {
try {
newProfile = new GeckoProfile(context, profileName, profileDir);
newProfile = new GeckoProfile(context, resolvedProfileName, profileDir);
} catch (NoMozillaDirectoryException e) {
// We're unable to do anything sane here.
throw new RuntimeException(e);
}
profile = sProfileCache.putIfAbsent(profileName, newProfile);
profile = sProfileCache.putIfAbsent(resolvedProfileName, newProfile);
}
if (profile == null) {

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

@ -164,21 +164,22 @@ public class GeckoScreenOrientation {
if (mShouldNotify) {
// Gecko expects a definite screen orientation, so we default to the
// primary orientations.
ScreenOrientation primaryOrientation = aScreenOrientation;
if (aScreenOrientation == ScreenOrientation.PORTRAIT) {
aScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
primaryOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
} else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
aScreenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
primaryOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
} else if (aScreenOrientation == ScreenOrientation.DEFAULT) {
aScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
primaryOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
} else if (aScreenOrientation == ScreenOrientation.NONE) {
return false;
}
if (GeckoThread.isRunning()) {
onOrientationChange(aScreenOrientation.value, getAngle());
onOrientationChange(primaryOrientation.value, getAngle());
} else {
GeckoThread.queueNativeCall(GeckoScreenOrientation.class, "onOrientationChange",
aScreenOrientation.value, getAngle());
primaryOrientation.value, getAngle());
}
}
ScreenManagerHelper.refreshScreenInfo();

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

@ -209,13 +209,18 @@ public final class PrefsHelper {
}
@WrapForJNI(calledFrom = "gecko")
private static void callPrefHandler(final PrefHandler handler, int type, final String pref,
boolean boolVal, int intVal, String strVal) {
private static void callPrefHandler(final PrefHandler handler, final int originalType,
final String pref, final boolean originalBoolVal,
final int intVal, final String originalStrVal) {
// Some Gecko preferences use integers or strings to reference state instead of
// directly representing the value. Since the Java UI uses the type to determine
// which ui elements to show and how to handle them, we need to normalize these
// preferences to the correct type.
int type = originalType;
String strVal = originalStrVal;
boolean boolVal = originalBoolVal;
if (INT_TO_STRING_PREFS.contains(pref)) {
type = PREF_STRING;
strVal = String.valueOf(intVal);

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

@ -109,17 +109,16 @@ public final class SysInfo {
return 0;
}
while (offset < length && buffer[offset] != '\n') {
if (buffer[offset] >= '0' && buffer[offset] <= '9') {
int start = offset++;
while (offset < length &&
buffer[offset] >= '0' &&
buffer[offset] <= '9') {
++offset;
int i = offset;
while (i < length && buffer[i] != '\n') {
if (buffer[i] >= '0' && buffer[i] <= '9') {
int start = i++;
while (i < length && buffer[i] >= '0' && buffer[i] <= '9') {
++i;
}
return Integer.parseInt(new String(buffer, start, offset - start), 10);
return Integer.parseInt(new String(buffer, start, i - start), 10);
}
++offset;
++i;
}
return 0;
}

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

@ -261,24 +261,25 @@ import org.mozilla.gecko.mozglue.JNIObject;
return null;
}
if (handle == 0) {
int resolvedHandle = handle;
if (resolvedHandle == 0) {
// Generate new handle value when none specified.
handle = sNextHandle++;
resolvedHandle = sNextHandle++;
}
final GeckoSurfaceTexture gst;
if (isSingleBufferSupported()) {
gst = new GeckoSurfaceTexture(handle, singleBufferMode);
gst = new GeckoSurfaceTexture(resolvedHandle, singleBufferMode);
} else {
gst = new GeckoSurfaceTexture(handle);
gst = new GeckoSurfaceTexture(resolvedHandle);
}
if (sSurfaceTextures.containsKey(handle)) {
if (sSurfaceTextures.containsKey(resolvedHandle)) {
gst.release();
throw new IllegalArgumentException("Already have a GeckoSurfaceTexture with that handle");
}
sSurfaceTextures.put(handle, gst);
sSurfaceTextures.put(resolvedHandle, gst);
return gst;
}
}

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

@ -124,17 +124,17 @@ import org.mozilla.gecko.annotation.WrapForJNI;
mScrollerX.setFinalPosition(x);
}
private static float viscousFluid(float x) {
x *= sViscousFluidScale;
if (x < 1.0f) {
x -= (1.0f - (float) Math.exp(-x));
private static float viscousFluid(final float x) {
float y = x * sViscousFluidScale;
if (y < 1.0f) {
y -= (1.0f - (float) Math.exp(-y));
} else {
float start = 0.36787944117f; // 1/e == exp(-1)
x = 1.0f - (float) Math.exp(1.0f - x);
x = start + x * (1.0f - start);
y = 1.0f - (float) Math.exp(1.0f - y);
y = start + y * (1.0f - start);
}
x *= sViscousFluidNormalize;
return x;
y *= sViscousFluidNormalize;
return y;
}
/**
@ -255,27 +255,31 @@ import org.mozilla.gecko.annotation.WrapForJNI;
* @param overY Overfling range. If > 0, vertical overfling in either
* direction will be possible.
*/
public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX,
int minY, int maxY, int overX, int overY, long time) {
public void fling(final int startX, final int startY, final int velocityX, final int velocityY,
final int minX, final int maxX, final int minY, final int maxY,
final int overX, final int overY, final long time) {
int newVelocityX = velocityX;
int newVelocityY = velocityY;
// Continue a scroll or fling in progress
if (mFlywheel && !isFinished()) {
float oldVelocityX = mScrollerX.mCurrVelocity;
float oldVelocityY = mScrollerY.mCurrVelocity;
boolean sameXDirection = (velocityX == 0) || (oldVelocityX == 0) ||
((velocityX < 0) == (oldVelocityX < 0));
boolean sameYDirection = (velocityY == 0) || (oldVelocityY == 0) ||
((velocityY < 0) == (oldVelocityY < 0));
boolean sameXDirection = (newVelocityX == 0) || (oldVelocityX == 0) ||
((newVelocityX < 0) == (oldVelocityX < 0));
boolean sameYDirection = (newVelocityY == 0) || (oldVelocityY == 0) ||
((newVelocityY < 0) == (oldVelocityY < 0));
if (sameXDirection) {
velocityX += oldVelocityX;
newVelocityX += + oldVelocityX;
}
if (sameYDirection) {
velocityY += oldVelocityY;
newVelocityY += oldVelocityY;
}
}
mMode = FLING_MODE;
mScrollerX.fling(startX, velocityX, minX, maxX, overX, time);
mScrollerY.fling(startY, velocityY, minY, maxY, overY, time);
mScrollerX.fling(startX, newVelocityX, minX, maxX, overX, time);
mScrollerY.fling(startY, newVelocityY, minY, maxY, overY, time);
}
/**

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

@ -45,8 +45,8 @@ class ByteBufferInputStream extends InputStream {
return -1;
}
length = Math.min(length, mBuf.remaining());
mBuf.get(buffer, offset, length);
int remainingLength = Math.min(length, mBuf.remaining());
mBuf.get(buffer, offset, remainingLength);
return length;
}
@ -56,9 +56,9 @@ class ByteBufferInputStream extends InputStream {
return 0;
}
byteCount = Math.min(byteCount, mBuf.remaining());
mBuf.position(mBuf.position() + (int)byteCount);
return byteCount;
long remainingByteCount = Math.min(byteCount, mBuf.remaining());
mBuf.position(mBuf.position() + (int) remainingByteCount);
return remainingByteCount;
}
}

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

@ -60,11 +60,12 @@ public class MatrixBlobCursor extends AbstractCursor {
this.columnNames = columnNames;
this.columnCount = columnNames.length;
if (initialCapacity < 1) {
initialCapacity = 1;
int capacity = initialCapacity;
if (capacity < 1) {
capacity = 1;
}
this.data = new Object[columnCount * initialCapacity];
this.data = new Object[columnCount * capacity];
this.allocationStack = new Throwable("allocationStack");
}

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

@ -73,7 +73,6 @@ public class ActivityUtils {
if (context instanceof Activity) {
return (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
return null;
}

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

@ -286,14 +286,15 @@ public class FileUtils {
if (prefix.length() < 3) {
throw new IllegalArgumentException("prefix must be at least 3 characters");
}
if (directory == null) {
File tempDirectory = directory;
if (tempDirectory == null) {
String tmpDir = System.getProperty("java.io.tmpdir", ".");
directory = new File(tmpDir);
tempDirectory = new File(tmpDir);
}
File result;
Random random = new Random();
do {
result = new File(directory, prefix + random.nextInt());
result = new File(tempDirectory, prefix + random.nextInt());
} while (!result.mkdirs());
return result;
}

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

@ -88,22 +88,25 @@ public final class GamepadUtils {
// determine if they are swapped so the proper key codes can be mapped to the keys
boolean areKeysSwapped = areSonyXperiaGamepadKeysSwapped();
int translatedKeyCode = keyCode;
// If a Sony Xperia, remap the cross and circle buttons to buttons
// A and B for the gamepad API
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
keyCode = (areKeysSwapped ? KeyEvent.KEYCODE_BUTTON_A : KeyEvent.KEYCODE_BUTTON_B);
translatedKeyCode = (areKeysSwapped ? KeyEvent.KEYCODE_BUTTON_A
: KeyEvent.KEYCODE_BUTTON_B);
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
keyCode = (areKeysSwapped ? KeyEvent.KEYCODE_BUTTON_B : KeyEvent.KEYCODE_BUTTON_A);
translatedKeyCode = (areKeysSwapped ? KeyEvent.KEYCODE_BUTTON_B
: KeyEvent.KEYCODE_BUTTON_A);
break;
default:
return event;
}
return new KeyEvent(event.getAction(), keyCode);
return new KeyEvent(event.getAction(), translatedKeyCode);
}
public static boolean isSonyXperiaGamepadKeyEvent(KeyEvent event) {

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

@ -187,6 +187,7 @@ public final class GeckoJarReader {
private static InputStream getStream(NativeZip zip, Stack<String> jarUrls, String origUrl) {
InputStream inputStream = null;
NativeZip currentZip = zip;
// loop through children jar files until we reach the innermost one
while (!jarUrls.empty()) {
String fileName = jarUrls.pop();
@ -194,7 +195,7 @@ public final class GeckoJarReader {
if (inputStream != null) {
// intermediate NativeZips and InputStreams will be garbage collected.
try {
zip = new NativeZip(inputStream);
currentZip = new NativeZip(inputStream);
} catch (IllegalArgumentException e) {
String description = "!!! BUG 849589 !!! origUrl=" + origUrl;
Log.e(LOGTAG, description, e);
@ -202,7 +203,7 @@ public final class GeckoJarReader {
}
}
inputStream = zip.getInputStream(fileName);
inputStream = currentZip.getInputStream(fileName);
if (inputStream == null) {
Log.d(LOGTAG, "No Entry for " + fileName);
return null;
@ -221,15 +222,11 @@ public final class GeckoJarReader {
* omni.ja
* chrome/chrome/content/branding/favicon32.png
*/
private static Stack<String> parseUrl(String url) {
return parseUrl(url, null);
private static Stack<String> parseUrl(final String url) {
return parseUrl(url, new Stack<>());
}
private static Stack<String> parseUrl(String url, Stack<String> results) {
if (results == null) {
results = new Stack<String>();
}
private static Stack<String> parseUrl(final String url, final Stack<String> results) {
if (url.startsWith("jar:")) {
int jarEnd = url.lastIndexOf("!");
String subStr = url.substring(4, jarEnd);

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

@ -77,8 +77,8 @@ public class IOUtils {
// If buffer has overflowed, double its size and carry on.
if (bPointer == buffer.length) {
bufferSize *= 2;
byte[] newBuffer = new byte[bufferSize];
int newBufferSize = bufferSize * 2;
byte[] newBuffer = new byte[newBufferSize];
// Copy the contents of the old buffer into the new buffer.
System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);

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

@ -50,13 +50,13 @@ public class StringUtils {
*/
public static boolean isSearchQuery(String text, boolean wasSearchQuery) {
// We remove leading and trailing white spaces when decoding URLs
text = text.trim();
if (text.length() == 0) {
String trimmedText = text.trim();
if (trimmedText.length() == 0) {
return wasSearchQuery;
}
int colon = text.indexOf(':');
int dot = text.indexOf('.');
int space = text.indexOf(' ');
int colon = trimmedText.indexOf(':');
int dot = trimmedText.indexOf('.');
int space = trimmedText.indexOf(' ');
// If a space is found in a trimmed string, we assume this is a search query(Bug 1278245)
if (space > -1) {

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

@ -897,26 +897,26 @@ import android.view.inputmethod.EditorInfo;
public void sendKeyEvent(final @Nullable View view, final int action, @NonNull KeyEvent event) {
final Editable editable = mProxy;
final KeyListener keyListener = TextKeyListener.getInstance();
event = translateKey(event.getKeyCode(), event);
KeyEvent translatedEvent = translateKey(event.getKeyCode(), event);
// We only let TextKeyListener do UI things on the UI thread.
final View v = ThreadUtils.isOnUiThread() ? view : null;
final int keyCode = event.getKeyCode();
final int keyCode = translatedEvent.getKeyCode();
final boolean handled;
if (shouldSkipKeyListener(keyCode, event)) {
if (shouldSkipKeyListener(keyCode, translatedEvent)) {
handled = false;
} else if (action == KeyEvent.ACTION_DOWN) {
setSuppressKeyUp(true);
handled = keyListener.onKeyDown(v, editable, keyCode, event);
handled = keyListener.onKeyDown(v, editable, keyCode, translatedEvent);
} else if (action == KeyEvent.ACTION_UP) {
handled = keyListener.onKeyUp(v, editable, keyCode, event);
handled = keyListener.onKeyUp(v, editable, keyCode, translatedEvent);
} else {
handled = keyListener.onKeyOther(v, editable, event);
handled = keyListener.onKeyOther(v, editable, translatedEvent);
}
if (!handled) {
sendKeyEvent(event, action, TextKeyListener.getMetaState(editable));
sendKeyEvent(translatedEvent, action, TextKeyListener.getMetaState(editable));
}
if (action == KeyEvent.ACTION_DOWN) {
@ -1384,7 +1384,7 @@ import android.view.inputmethod.EditorInfo;
});
}
/* package */ void icNotifyIMEContext(int state, final String typeHint,
/* package */ void icNotifyIMEContext(final int originalState, final String typeHint,
final String modeHint, final String actionHint,
final int flags) {
if (DEBUG) {
@ -1394,12 +1394,15 @@ import android.view.inputmethod.EditorInfo;
// For some input type we will use a widget to display the ui, for those we must not
// display the ime. We can display a widget for date and time types and, if the sdk version
// is 11 or greater, for datetime/month/week as well.
int state;
if (typeHint != null && (typeHint.equalsIgnoreCase("date") ||
typeHint.equalsIgnoreCase("time") ||
typeHint.equalsIgnoreCase("month") ||
typeHint.equalsIgnoreCase("week") ||
typeHint.equalsIgnoreCase("datetime-local"))) {
state = SessionTextInput.EditableListener.IME_STATE_DISABLED;
} else {
state = originalState;
}
final int oldState = mIMEState;
@ -2090,12 +2093,13 @@ import android.view.inputmethod.EditorInfo;
return true;
}
while ((repeatCount--) > 0) {
for (int i = 0; i < repeatCount; i++) {
if (!processKey(view, KeyEvent.ACTION_DOWN, keyCode, event) ||
!processKey(view, KeyEvent.ACTION_UP, keyCode, event)) {
return false;
}
}
return true;
}

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

@ -591,9 +591,9 @@ import java.lang.reflect.Proxy;
}
@Override
public boolean sendKeyEvent(@NonNull KeyEvent event) {
event = translateKey(event.getKeyCode(), event);
mEditableClient.sendKeyEvent(getView(), event.getAction(), event);
public boolean sendKeyEvent(final @NonNull KeyEvent event) {
KeyEvent translatedEvent = translateKey(event.getKeyCode(), event);
mEditableClient.sendKeyEvent(getView(), event.getAction(), translatedEvent);
return false; // seems to always return false
}

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

@ -428,10 +428,10 @@ public class PanZoomController extends JNIObject {
}
}
private void synthesizeNativePointer(int source, int pointerId, int eventType,
int clientX, int clientY, double pressure,
int orientation)
{
private void synthesizeNativePointer(final int source, final int pointerId,
final int originalEventType,
final int clientX, final int clientY,
final double pressure, final int orientation) {
if (mPointerState == null) {
mPointerState = new SynthesizedEventState();
}
@ -440,7 +440,8 @@ public class PanZoomController extends JNIObject {
int pointerIndex = mPointerState.getPointerIndex(pointerId);
// Event-specific handling
switch (eventType) {
int eventType = originalEventType;
switch (originalEventType) {
case MotionEvent.ACTION_POINTER_UP:
if (pointerIndex < 0) {
Log.w(LOGTAG, "Pointer-up for invalid pointer");