From 789b04a378782cac67dfb94654f86b5cd70ac79d Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Fri, 15 Mar 2019 21:20:20 +0000 Subject: [PATCH] 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 --- .../java/org/mozilla/gecko/CrashHandler.java | 24 ++++++----- .../java/org/mozilla/gecko/GeckoAppShell.java | 20 ++++++---- .../java/org/mozilla/gecko/GeckoProfile.java | 9 +++-- .../mozilla/gecko/GeckoScreenOrientation.java | 11 ++--- .../java/org/mozilla/gecko/PrefsHelper.java | 9 ++++- .../main/java/org/mozilla/gecko/SysInfo.java | 17 ++++---- .../gecko/gfx/GeckoSurfaceTexture.java | 13 +++--- .../org/mozilla/gecko/gfx/StackScroller.java | 40 ++++++++++--------- .../gecko/mozglue/ByteBufferInputStream.java | 10 ++--- .../gecko/sqlite/MatrixBlobCursor.java | 7 ++-- .../org/mozilla/gecko/util/ActivityUtils.java | 1 - .../org/mozilla/gecko/util/FileUtils.java | 7 ++-- .../org/mozilla/gecko/util/GamepadUtils.java | 9 +++-- .../mozilla/gecko/util/GeckoJarReader.java | 15 +++---- .../java/org/mozilla/gecko/util/IOUtils.java | 4 +- .../org/mozilla/gecko/util/StringUtils.java | 10 ++--- .../org/mozilla/geckoview/GeckoEditable.java | 22 +++++----- .../geckoview/GeckoInputConnection.java | 6 +-- .../mozilla/geckoview/PanZoomController.java | 11 ++--- 19 files changed, 134 insertions(+), 111 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java index 05a34829c5a0..039b4be623c5 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java @@ -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(); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java index 03b0a0f3bdab..bd209994c953 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java @@ -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(); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoProfile.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoProfile.java index 8cb9d380c149..7e39c0dea5ee 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoProfile.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoProfile.java @@ -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) { diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java index 365124ce45f1..4b9acf7888d5 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java @@ -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(); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/PrefsHelper.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/PrefsHelper.java index 08994d5af446..4367d4a38ea9 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/PrefsHelper.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/PrefsHelper.java @@ -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); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SysInfo.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SysInfo.java index 7fb72e8478a5..a34a0eef219e 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SysInfo.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SysInfo.java @@ -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; } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java index af5c1a83c863..8cd7f1b68402 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java @@ -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; } } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java index b05aaaff7fd0..c5613281d6dc 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java @@ -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); } /** 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 index bc9e0a143c2f..9c906a0e2c31 100644 --- 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 @@ -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; } } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/sqlite/MatrixBlobCursor.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/sqlite/MatrixBlobCursor.java index 4d75c3e27193..bc686382593b 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/sqlite/MatrixBlobCursor.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/sqlite/MatrixBlobCursor.java @@ -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"); } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java index c76074bd7bb5..c6fb2b0c9cb9 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java @@ -73,7 +73,6 @@ public class ActivityUtils { if (context instanceof Activity) { return (Activity) context; } - context = ((ContextWrapper) context).getBaseContext(); } return null; } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/FileUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/FileUtils.java index 62ce10ad784a..4250c70e2ff9 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/FileUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/FileUtils.java @@ -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; } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GamepadUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GamepadUtils.java index 520daaa5cc38..a82b017e5c73 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GamepadUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GamepadUtils.java @@ -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) { diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoJarReader.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoJarReader.java index 26a9c714c915..d37770da8563 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoJarReader.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoJarReader.java @@ -187,6 +187,7 @@ public final class GeckoJarReader { private static InputStream getStream(NativeZip zip, Stack 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 parseUrl(String url) { - return parseUrl(url, null); + private static Stack parseUrl(final String url) { + return parseUrl(url, new Stack<>()); } - private static Stack parseUrl(String url, Stack results) { - if (results == null) { - results = new Stack(); - } - + private static Stack parseUrl(final String url, final Stack results) { if (url.startsWith("jar:")) { int jarEnd = url.lastIndexOf("!"); String subStr = url.substring(4, jarEnd); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IOUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IOUtils.java index 9e48413816d3..54e20fb6073a 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IOUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IOUtils.java @@ -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); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java index 1df18f00d932..eb00f387c82a 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java @@ -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) { diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java index 4a9281fb3014..57aa7c3b3f13 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java @@ -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; } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java index efb35a5dfa7c..8278aa8629a0 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java @@ -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 } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/PanZoomController.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/PanZoomController.java index b43c58094a64..316582619425 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/PanZoomController.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/PanZoomController.java @@ -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");