| Index: ui/android/java/src/org/chromium/ui/base/Clipboard.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/base/Clipboard.java b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
|
| index abfdf2e01f6d2492f36baedef83074d7432509f0..5f145fca0aab6898fc5064b39c93d1c53bfca3fa 100644
|
| --- a/ui/android/java/src/org/chromium/ui/base/Clipboard.java
|
| +++ b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
|
| @@ -9,19 +9,13 @@ import android.content.ClipboardManager;
|
| import android.content.Context;
|
|
|
| import org.chromium.base.ContextUtils;
|
| -import org.chromium.base.Log;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| -import org.chromium.base.metrics.RecordHistogram;
|
| import org.chromium.base.metrics.RecordUserAction;
|
| import org.chromium.ui.R;
|
| import org.chromium.ui.widget.Toast;
|
|
|
| -import java.security.MessageDigest;
|
| -import java.security.NoSuchAlgorithmException;
|
| -import java.util.Arrays;
|
| -
|
| /**
|
| * Simple proxy that provides C++ code with an access pathway to the Android clipboard.
|
| */
|
| @@ -29,25 +23,12 @@ import java.util.Arrays;
|
| public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener {
|
| private static Clipboard sInstance;
|
|
|
| - private static final String TAG = "Clipboard";
|
| -
|
| // Necessary for coercing clipboard contents to text if they require
|
| // access to network resources, etceteras (e.g., URI in clipboard)
|
| private final Context mContext;
|
|
|
| private final ClipboardManager mClipboardManager;
|
|
|
| - // A message hasher that's used to hash clipboard contents so we can tell
|
| - // when a clipboard changes without storing the full contents.
|
| - private MessageDigest mMd5Hasher;
|
| - // The hash of the current clipboard.
|
| - // TODO(mpearson): unsuppress this warning once saving and restoring
|
| - // the hash from prefs is added.
|
| - @SuppressFBWarnings("URF_UNREAD_FIELD")
|
| - private byte[] mClipboardMd5;
|
| - // The time when the clipboard was last updated. Set to 0 if unknown.
|
| - private long mClipboardChangeTime;
|
| -
|
| /**
|
| * Get the singleton Clipboard instance (creating it if needed).
|
| */
|
| @@ -65,19 +46,6 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
|
| (ClipboardManager) ContextUtils.getApplicationContext().getSystemService(
|
| Context.CLIPBOARD_SERVICE);
|
| mClipboardManager.addPrimaryClipChangedListener(this);
|
| - try {
|
| - mMd5Hasher = MessageDigest.getInstance("MD5");
|
| - mClipboardMd5 = weakMd5Hash();
|
| - } catch (NoSuchAlgorithmException e) {
|
| - Log.e(TAG,
|
| - "Unable to construct MD5 MessageDigest: %s; assume "
|
| - + "clipboard last update time is start of epoch.",
|
| - e);
|
| - mMd5Hasher = null;
|
| - mClipboardMd5 = new byte[] {};
|
| - }
|
| - RecordHistogram.recordBooleanHistogram("Clipboard.ConstructedHasher", mMd5Hasher != null);
|
| - mClipboardChangeTime = 0;
|
| }
|
|
|
| /**
|
| @@ -129,21 +97,6 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
|
| }
|
|
|
| /**
|
| - * Gets the time the clipboard content last changed.
|
| - *
|
| - * This is calculated according to the device's clock. E.g., it continues
|
| - * increasing when the device is suspended. Likewise, it can be in the
|
| - * future if the user's clock updated after this information was recorded.
|
| - *
|
| - * @return a Java long recording the last changed time in milliseconds since
|
| - * epoch, or 0 if the time could not be determined.
|
| - */
|
| - @CalledByNative
|
| - public long getClipboardContentChangeTimeInMillis() {
|
| - return mClipboardChangeTime;
|
| - }
|
| -
|
| - /**
|
| * Emulates the behavior of the now-deprecated
|
| * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the
|
| * clipboard's current primary clip to a plain-text clip that consists of
|
| @@ -190,35 +143,17 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
|
| }
|
|
|
| /**
|
| - * Updates mClipboardMd5 and mClipboardChangeTime when the clipboard updates.
|
| + * Tells the C++ Clipboard that the clipboard has changed.
|
| *
|
| * Implements OnPrimaryClipChangedListener to listen for clipboard updates.
|
| */
|
| @Override
|
| public void onPrimaryClipChanged() {
|
| - if (mMd5Hasher == null) return;
|
| RecordUserAction.record("MobileClipboardChanged");
|
| - mClipboardMd5 = weakMd5Hash();
|
| - // Always update the clipboard change time even if the clipboard
|
| - // content hasn't changed. This is because if the user put something
|
| - // in the clipboard recently (even if it was not necessary because it
|
| - // was already there), that content should be considered recent.
|
| - mClipboardChangeTime = System.currentTimeMillis();
|
| + long nativeClipboardAndroid = nativeInit();
|
| + if (nativeClipboardAndroid != 0) nativeOnPrimaryClipChanged(nativeClipboardAndroid);
|
| }
|
|
|
| - /**
|
| - * Returns a weak hash of getCoercedText().
|
| - *
|
| - * @return a Java byte[] with the weak hash.
|
| - */
|
| - private byte[] weakMd5Hash() {
|
| - if (getCoercedText() == null) {
|
| - return new byte[] {};
|
| - }
|
| - // Compute a hash consisting of the first 4 bytes of the MD5 hash of
|
| - // getCoercedText(). This value is used to detect clipboard content
|
| - // change. Keeping only 4 bytes is a privacy requirement to introduce
|
| - // collision and allow deniability of having copied a given string.
|
| - return Arrays.copyOfRange(mMd5Hasher.digest(getCoercedText().getBytes()), 0, 4);
|
| - }
|
| + private native long nativeInit();
|
| + private native void nativeOnPrimaryClipChanged(long nativeClipboardAndroid);
|
| }
|
|
|