Chromium Code Reviews| 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 aaa500ea6dec0a58c941f9e461844608253c7c66..4724ed1deb477e281a884bde0a03b5c91554505b 100644 |
| --- a/ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| +++ b/ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| @@ -27,11 +27,31 @@ public class Clipboard { |
| private final ClipboardManager mClipboardManager; |
| /** |
| + * Simple helper class to proxy the clipboard change callback to C++. |
| + */ |
| + private class Listener implements ClipboardManager.OnPrimaryClipChangedListener { |
|
bulach
2014/01/14 14:45:05
wild guess: in the test, it's doing base::RunLoop(
|
| + /** The native C++ object that receives the callback. */ |
| + private final long mNativeClipboardChangeListener; |
| + |
| + private Listener(long nativeClipboardChangeListener) { |
| + mNativeClipboardChangeListener = nativeClipboardChangeListener; |
| + } |
| + |
| + /** |
| + * Callback that is invoked by ClipboardManager when the primary clip changes. |
| + */ |
| + @Override |
| + public void onPrimaryClipChanged() { |
| + Clipboard.this.nativeOnChange(mNativeClipboardChangeListener); |
| + } |
| + }; |
| + |
| + /** |
| * Use the factory constructor instead. |
| * |
| * @param context for accessing the clipboard |
| */ |
| - public Clipboard(final Context context) { |
| + private Clipboard(final Context context) { |
| mContext = context; |
| mClipboardManager = (ClipboardManager) |
| context.getSystemService(Context.CLIPBOARD_SERVICE); |
| @@ -44,7 +64,7 @@ public class Clipboard { |
| * @return the new object |
| */ |
| @CalledByNative |
| - private static Clipboard create(final Context context) { |
| + public static Clipboard create(final Context context) { |
| return new Clipboard(context); |
| } |
| @@ -153,6 +173,15 @@ public class Clipboard { |
| return ApiCompatibilityUtils.isHTMLClipboardSupported(); |
| } |
| + /** |
| + * Adds a listener to detect when the clipboard contents change. |
| + */ |
| + @CalledByNative |
| + public void addChangeListener(long nativeClipboardChangeListener) { |
| + mClipboardManager.addPrimaryClipChangedListener( |
| + new Listener(nativeClipboardChangeListener)); |
| + } |
| + |
| private void setPrimaryClipNoException(ClipData clip) { |
| try { |
| mClipboardManager.setPrimaryClip(clip); |
| @@ -162,4 +191,6 @@ public class Clipboard { |
| Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show(); |
| } |
| } |
| + |
| + private native void nativeOnChange(long nativeClipboardChangeListener); |
| } |