OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.content.browser.androidoverlay; |
| 6 |
| 7 import android.os.Handler; |
| 8 import android.os.IBinder; |
| 9 import android.view.Surface; |
| 10 |
| 11 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; |
| 13 |
| 14 /** |
| 15 * Basic impl of DialogOverlayOperations. |
| 16 */ |
| 17 @JNINamespace("content") |
| 18 class DialogOverlayOperationsImpl implements DialogOverlayOperations { |
| 19 private long mNativeHandle; |
| 20 private Handler mOverlayHandler; |
| 21 |
| 22 // Runnable that we'll run when the overlay notifies us that it's been relea
sed. |
| 23 private Runnable mReleasedRunnable; |
| 24 |
| 25 // Listener to which we'll forward window token information. |
| 26 private WindowTokenListener mListener; |
| 27 |
| 28 public DialogOverlayOperationsImpl(Handler overlayHandler, Runnable released
Runnable) { |
| 29 mOverlayHandler = overlayHandler; |
| 30 mReleasedRunnable = releasedRunnable; |
| 31 } |
| 32 |
| 33 @Override |
| 34 public void notifyReleased() { |
| 35 mReleasedRunnable.run(); |
| 36 } |
| 37 |
| 38 @Override |
| 39 public Handler getOverlayHandler() { |
| 40 return mOverlayHandler; |
| 41 } |
| 42 |
| 43 @Override |
| 44 public void registerWindowTokenListener( |
| 45 org.chromium.mojo.common.mojom.UnguessableToken token, WindowTokenLi
stener listener) { |
| 46 mListener = listener; |
| 47 mNativeHandle = nativeRegisterForTokens(token.high, token.low); |
| 48 assert mNativeHandle != 0; |
| 49 } |
| 50 |
| 51 @Override |
| 52 public void unregisterWindowTokenListenerIfNeeded() { |
| 53 if (mNativeHandle == 0) return; |
| 54 |
| 55 nativeUnregisterForTokens(mNativeHandle); |
| 56 mNativeHandle = 0; |
| 57 } |
| 58 |
| 59 @Override |
| 60 public int registerSurface(Surface surface) { |
| 61 return nativeRegisterSurface(surface); |
| 62 } |
| 63 |
| 64 @Override |
| 65 public void unregisterSurface(int surfaceId) { |
| 66 nativeUnregisterSurface(surfaceId); |
| 67 } |
| 68 |
| 69 // Called on the browser UI (not overlay) thread. |
| 70 @CalledByNative |
| 71 private void onWindowToken(final IBinder token) { |
| 72 mListener.onWindowToken(token); |
| 73 } |
| 74 |
| 75 // Called on the browser UI thread. |
| 76 // We're not getting any more window tokens. |
| 77 @CalledByNative |
| 78 private void onDismissed() { |
| 79 mListener.onDismissed(); |
| 80 } |
| 81 |
| 82 // Initializes native side. Will register for onWindowToken callbacks on |t
his|. Returns a |
| 83 // handle that should be provided to nativeUnregisterForTokens. |
| 84 private native long nativeRegisterForTokens(long high, long low); |
| 85 |
| 86 // Stops native side. |
| 87 private static native void nativeUnregisterForTokens(long handle); |
| 88 |
| 89 private static native int nativeRegisterSurface(Surface surface); |
| 90 private static native void nativeUnregisterSurface(int surfaceId); |
| 91 } |
OLD | NEW |