| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.content.ClipData; | 7 import android.content.ClipData; |
| 8 import android.content.ClipboardManager; | 8 import android.content.ClipboardManager; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 | 10 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 190 } |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Updates mClipboardMd5 and mClipboardChangeTime when the clipboard updates
. | 193 * Updates mClipboardMd5 and mClipboardChangeTime when the clipboard updates
. |
| 194 * | 194 * |
| 195 * Implements OnPrimaryClipChangedListener to listen for clipboard updates. | 195 * Implements OnPrimaryClipChangedListener to listen for clipboard updates. |
| 196 */ | 196 */ |
| 197 @Override | 197 @Override |
| 198 public void onPrimaryClipChanged() { | 198 public void onPrimaryClipChanged() { |
| 199 if (mMd5Hasher == null) return; | 199 if (mMd5Hasher == null) return; |
| 200 RecordUserAction.record("MobileOmniboxClipboardChanged"); | 200 RecordUserAction.record("MobileClipboardChanged"); |
| 201 mClipboardMd5 = weakMd5Hash(); | 201 mClipboardMd5 = weakMd5Hash(); |
| 202 // Always update the clipboard change time even if the clipboard | 202 // Always update the clipboard change time even if the clipboard |
| 203 // content hasn't changed. This is because if the user put something | 203 // content hasn't changed. This is because if the user put something |
| 204 // in the clipboard recently (even if it was not necessary because it | 204 // in the clipboard recently (even if it was not necessary because it |
| 205 // was already there), that content should be considered recent. | 205 // was already there), that content should be considered recent. |
| 206 mClipboardChangeTime = System.currentTimeMillis(); | 206 mClipboardChangeTime = System.currentTimeMillis(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * Returns a weak hash of getCoercedText(). | 210 * Returns a weak hash of getCoercedText(). |
| 211 * | 211 * |
| 212 * @return a Java byte[] with the weak hash. | 212 * @return a Java byte[] with the weak hash. |
| 213 */ | 213 */ |
| 214 private byte[] weakMd5Hash() { | 214 private byte[] weakMd5Hash() { |
| 215 if (getCoercedText() == null) { | 215 if (getCoercedText() == null) { |
| 216 return new byte[] {}; | 216 return new byte[] {}; |
| 217 } | 217 } |
| 218 // Compute a hash consisting of the first 4 bytes of the MD5 hash of | 218 // Compute a hash consisting of the first 4 bytes of the MD5 hash of |
| 219 // getCoercedText(). This value is used to detect clipboard content | 219 // getCoercedText(). This value is used to detect clipboard content |
| 220 // change. Keeping only 4 bytes is a privacy requirement to introduce | 220 // change. Keeping only 4 bytes is a privacy requirement to introduce |
| 221 // collision and allow deniability of having copied a given string. | 221 // collision and allow deniability of having copied a given string. |
| 222 return Arrays.copyOfRange(mMd5Hasher.digest(getCoercedText().getBytes())
, 0, 4); | 222 return Arrays.copyOfRange(mMd5Hasher.digest(getCoercedText().getBytes())
, 0, 4); |
| 223 } | 223 } |
| 224 } | 224 } |
| OLD | NEW |