Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadDelegate.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadDelegate.java b/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadDelegate.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9df0b0549a2193493331851df39238ab02266661 |
| --- /dev/null |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadDelegate.java |
| @@ -0,0 +1,50 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview; |
| + |
| +import org.chromium.base.CalledByNative; |
| + |
| +import java.util.concurrent.atomic.AtomicReference; |
| + |
| +/** |
| + * Delegate for URLRequest intercepting. |
| + * |
| + * The shouldInterceptRequest method will be called on the IO thread. |
| + * You should create a separate instance of this class for every WebContents that requires the |
| + * provided functionality. |
| + */ |
| +public class AwContentsIoThreadDelegate { |
| + public interface AwContentsIoThreadDelegateImpl { |
|
joth
2012/09/11 02:06:50
Seems funky to have an "interface" that carries th
mkosiba (inactive)
2012/09/13 01:48:26
Done. Removed inner interface, added setter to AwC
|
| + InterceptedRequestData shouldInterceptRequest(String url); |
| + } |
| + private AtomicReference<AwContentsIoThreadDelegateImpl> mImpl = |
|
joth
2012/09/11 02:06:50
FWIW: all Java references are atomic for assign an
mkosiba (inactive)
2012/09/13 01:48:26
this is removed.
|
| + new AtomicReference<AwContentsIoThreadDelegateImpl>(); |
| + |
| + // Called on the UI thread. |
| + public AwContentsIoThreadDelegate(int nativeWebContents, |
| + AwContentsIoThreadDelegateImpl impl) { |
| + mImpl.set(impl); |
| + nativeInit(nativeWebContents); |
| + } |
| + |
| + // Called on the IO thread. |
| + @CalledByNative |
| + private InterceptedRequestData shouldInterceptRequest(String url) { |
| + AwContentsIoThreadDelegateImpl impl = mImpl.get(); |
| + if (impl == null) { |
| + return null; |
| + } else { |
| + return impl.shouldInterceptRequest(url); |
| + } |
| + } |
| + |
| + // Called on the UI thread. |
| + @CalledByNative |
| + private void onWebContentsDestroyed() { |
| + mImpl.set(null); |
| + } |
| + |
| + private native void nativeInit(int webContents); |
| +} |