OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.ComponentCallbacks2; | 9 import android.content.ComponentCallbacks2; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 176 } |
177 | 177 |
178 public AwScrollOffsetManager createScrollOffsetManager( | 178 public AwScrollOffsetManager createScrollOffsetManager( |
179 AwScrollOffsetManager.Delegate delegate, OverScroller overScroll
er) { | 179 AwScrollOffsetManager.Delegate delegate, OverScroller overScroll
er) { |
180 return new AwScrollOffsetManager(delegate, overScroller); | 180 return new AwScrollOffsetManager(delegate, overScroller); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 /** | 184 /** |
185 * Callback used when flushing the visual state, see {@link #flushVisualStat
e}. | 185 * Callback used when flushing the visual state, see {@link #flushVisualStat
e}. |
| 186 * |
| 187 * <p>The {@code requestId} is the unique request id returned by |
| 188 * {@link AwContents#flushVisualState} which can be used to match callbacks
with requests. |
186 */ | 189 */ |
187 @VisibleForTesting | 190 @VisibleForTesting |
188 public abstract static class VisualStateFlushCallback { | 191 public abstract static class VisualStateFlushCallback { |
189 public abstract void onComplete(); | 192 public abstract void onComplete(long requestId); |
190 public abstract void onFailure(); | 193 public abstract void onFailure(long requestId); |
191 } | 194 } |
192 | 195 |
| 196 private static long sNextVisualStateRequestId = 1; |
| 197 |
193 private long mNativeAwContents; | 198 private long mNativeAwContents; |
194 private final AwBrowserContext mBrowserContext; | 199 private final AwBrowserContext mBrowserContext; |
195 private ViewGroup mContainerView; | 200 private ViewGroup mContainerView; |
196 private final AwLayoutChangeListener mLayoutChangeListener; | 201 private final AwLayoutChangeListener mLayoutChangeListener; |
197 private final Context mContext; | 202 private final Context mContext; |
198 private ContentViewCore mContentViewCore; | 203 private ContentViewCore mContentViewCore; |
199 private WindowAndroid mWindowAndroid; | 204 private WindowAndroid mWindowAndroid; |
200 private WebContents mWebContents; | 205 private WebContents mWebContents; |
201 private NavigationController mNavigationController; | 206 private NavigationController mNavigationController; |
202 private final AwContentsClient mContentsClient; | 207 private final AwContentsClient mContentsClient; |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 /** | 2047 /** |
2043 * Flush the visual state. | 2048 * Flush the visual state. |
2044 * | 2049 * |
2045 * Flushing the visual state means queuing a callback in Blink that will be
invoked when the | 2050 * Flushing the visual state means queuing a callback in Blink that will be
invoked when the |
2046 * contents of the DOM tree at the moment that the callback was enqueued (or
later) are drawn | 2051 * contents of the DOM tree at the moment that the callback was enqueued (or
later) are drawn |
2047 * into the screen. In other words, the following events need to happen befo
re the callback is | 2052 * into the screen. In other words, the following events need to happen befo
re the callback is |
2048 * invoked: | 2053 * invoked: |
2049 * 1. The DOM tree is committed becoming the pending tree - see ThreadProxy:
:BeginMainFrame | 2054 * 1. The DOM tree is committed becoming the pending tree - see ThreadProxy:
:BeginMainFrame |
2050 * 2. The pending tree is activated becoming the active tree | 2055 * 2. The pending tree is activated becoming the active tree |
2051 * 3. A frame swap happens that draws the active tree into the screen | 2056 * 3. A frame swap happens that draws the active tree into the screen |
| 2057 * |
| 2058 * @return an unique id that identifies this request. It can be used to matc
h this request |
| 2059 * to the corresponding callback to allow reuse of {@link VisualStateFlushCa
llback} objects. |
2052 */ | 2060 */ |
2053 public void flushVisualState(VisualStateFlushCallback callback) { | 2061 public long flushVisualState(VisualStateFlushCallback callback) { |
2054 nativeFlushVisualState(mNativeAwContents, callback); | 2062 long requestId = sNextVisualStateRequestId++; |
| 2063 nativeFlushVisualState(mNativeAwContents, callback, requestId); |
| 2064 return requestId; |
2055 } | 2065 } |
2056 | 2066 |
2057 //--------------------------------------------------------------------------
------------------ | 2067 //--------------------------------------------------------------------------
------------------ |
2058 // Methods called from native via JNI | 2068 // Methods called from native via JNI |
2059 //--------------------------------------------------------------------------
------------------ | 2069 //--------------------------------------------------------------------------
------------------ |
2060 | 2070 |
2061 @CalledByNative | 2071 @CalledByNative |
2062 private static void onDocumentHasImagesResponse(boolean result, Message mess
age) { | 2072 private static void onDocumentHasImagesResponse(boolean result, Message mess
age) { |
2063 message.arg1 = result ? 1 : 0; | 2073 message.arg1 = result ? 1 : 0; |
2064 message.sendToTarget(); | 2074 message.sendToTarget(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 mContentsClient.getCallbackHelper().postOnNewPicture(mPictureListenerCon
tentProvider); | 2167 mContentsClient.getCallbackHelper().postOnNewPicture(mPictureListenerCon
tentProvider); |
2158 } | 2168 } |
2159 | 2169 |
2160 /** | 2170 /** |
2161 * Invokes the given {@link VisualStateFlushCallback}. | 2171 * Invokes the given {@link VisualStateFlushCallback}. |
2162 * | 2172 * |
2163 * @param result true if the flush request was successful and false otherwis
e | 2173 * @param result true if the flush request was successful and false otherwis
e |
2164 */ | 2174 */ |
2165 @CalledByNative | 2175 @CalledByNative |
2166 public void flushVisualStateCallback( | 2176 public void flushVisualStateCallback( |
2167 final VisualStateFlushCallback callback, final boolean result) { | 2177 final VisualStateFlushCallback callback, final long requestId, final
boolean result) { |
2168 // Posting avoids invoking the callback inside invoking_composite_ | 2178 // Posting avoids invoking the callback inside invoking_composite_ |
2169 // (see synchronous_compositor_impl.cc and crbug/452530). | 2179 // (see synchronous_compositor_impl.cc and crbug/452530). |
2170 mContainerView.getHandler().post(new Runnable() { | 2180 mContainerView.getHandler().post(new Runnable() { |
2171 @Override | 2181 @Override |
2172 public void run() { | 2182 public void run() { |
2173 if (result) { | 2183 if (result) { |
2174 callback.onComplete(); | 2184 callback.onComplete(requestId); |
2175 } else { | 2185 } else { |
2176 callback.onFailure(); | 2186 callback.onFailure(requestId); |
2177 } | 2187 } |
2178 } | 2188 } |
2179 }); | 2189 }); |
2180 } | 2190 } |
2181 | 2191 |
2182 // Called as a result of nativeUpdateLastHitTestData. | 2192 // Called as a result of nativeUpdateLastHitTestData. |
2183 @CalledByNative | 2193 @CalledByNative |
2184 private void updateHitTestData( | 2194 private void updateHitTestData( |
2185 int type, String extra, String href, String anchorText, String imgSr
c) { | 2195 int type, String extra, String href, String anchorText, String imgSr
c) { |
2186 mPossiblyStaleHitTestData.hitTestResultType = type; | 2196 mPossiblyStaleHitTestData.hitTestResultType = type; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2729 private native boolean nativeRestoreFromOpaqueState(long nativeAwContents, b
yte[] state); | 2739 private native boolean nativeRestoreFromOpaqueState(long nativeAwContents, b
yte[] state); |
2730 | 2740 |
2731 private native long nativeReleasePopupAwContents(long nativeAwContents); | 2741 private native long nativeReleasePopupAwContents(long nativeAwContents); |
2732 private native void nativeFocusFirstNode(long nativeAwContents); | 2742 private native void nativeFocusFirstNode(long nativeAwContents); |
2733 private native void nativeSetBackgroundColor(long nativeAwContents, int colo
r); | 2743 private native void nativeSetBackgroundColor(long nativeAwContents, int colo
r); |
2734 | 2744 |
2735 private native long nativeGetAwDrawGLViewContext(long nativeAwContents); | 2745 private native long nativeGetAwDrawGLViewContext(long nativeAwContents); |
2736 private native long nativeCapturePicture(long nativeAwContents, int width, i
nt height); | 2746 private native long nativeCapturePicture(long nativeAwContents, int width, i
nt height); |
2737 private native void nativeEnableOnNewPicture(long nativeAwContents, boolean
enabled); | 2747 private native void nativeEnableOnNewPicture(long nativeAwContents, boolean
enabled); |
2738 private native void nativeFlushVisualState( | 2748 private native void nativeFlushVisualState( |
2739 long nativeAwContents, VisualStateFlushCallback callback); | 2749 long nativeAwContents, VisualStateFlushCallback callback, long reque
stId); |
2740 private native void nativeClearView(long nativeAwContents); | 2750 private native void nativeClearView(long nativeAwContents); |
2741 private native void nativeSetExtraHeadersForUrl(long nativeAwContents, | 2751 private native void nativeSetExtraHeadersForUrl(long nativeAwContents, |
2742 String url, String extraHeaders); | 2752 String url, String extraHeaders); |
2743 | 2753 |
2744 private native void nativeInvokeGeolocationCallback( | 2754 private native void nativeInvokeGeolocationCallback( |
2745 long nativeAwContents, boolean value, String requestingFrame); | 2755 long nativeAwContents, boolean value, String requestingFrame); |
2746 | 2756 |
2747 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean
networkUp); | 2757 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean
networkUp); |
2748 | 2758 |
2749 private native void nativeTrimMemory(long nativeAwContents, int level, boole
an visible); | 2759 private native void nativeTrimMemory(long nativeAwContents, int level, boole
an visible); |
2750 | 2760 |
2751 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); | 2761 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); |
2752 | 2762 |
2753 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, | 2763 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, |
2754 long resources); | 2764 long resources); |
2755 | 2765 |
2756 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 2766 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
2757 String message, String sourceOrigin, String targetOrigin, int[] msgP
orts); | 2767 String message, String sourceOrigin, String targetOrigin, int[] msgP
orts); |
2758 | 2768 |
2759 private native void nativeCreateMessageChannel(long nativeAwContents, | 2769 private native void nativeCreateMessageChannel(long nativeAwContents, |
2760 ValueCallback<MessagePort[]> callback); | 2770 ValueCallback<MessagePort[]> callback); |
2761 } | 2771 } |
OLD | NEW |