Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 import org.chromium.base.CalledByNative; | 42 import org.chromium.base.CalledByNative; |
| 43 import org.chromium.base.JNINamespace; | 43 import org.chromium.base.JNINamespace; |
| 44 import org.chromium.base.ThreadUtils; | 44 import org.chromium.base.ThreadUtils; |
| 45 import org.chromium.base.VisibleForTesting; | 45 import org.chromium.base.VisibleForTesting; |
| 46 import org.chromium.components.navigation_interception.InterceptNavigationDelega te; | 46 import org.chromium.components.navigation_interception.InterceptNavigationDelega te; |
| 47 import org.chromium.components.navigation_interception.NavigationParams; | 47 import org.chromium.components.navigation_interception.NavigationParams; |
| 48 import org.chromium.content.browser.ContentSettings; | 48 import org.chromium.content.browser.ContentSettings; |
| 49 import org.chromium.content.browser.ContentViewClient; | 49 import org.chromium.content.browser.ContentViewClient; |
| 50 import org.chromium.content.browser.ContentViewCore; | 50 import org.chromium.content.browser.ContentViewCore; |
| 51 import org.chromium.content.browser.ContentViewStatics; | 51 import org.chromium.content.browser.ContentViewStatics; |
| 52 import org.chromium.content.browser.SmartClipProvider; | |
| 52 import org.chromium.content.browser.WebContentsObserver; | 53 import org.chromium.content.browser.WebContentsObserver; |
| 53 import org.chromium.content.common.CleanupReference; | 54 import org.chromium.content.common.CleanupReference; |
| 54 import org.chromium.content_public.browser.GestureStateListener; | 55 import org.chromium.content_public.browser.GestureStateListener; |
| 55 import org.chromium.content_public.browser.JavaScriptCallback; | 56 import org.chromium.content_public.browser.JavaScriptCallback; |
| 56 import org.chromium.content_public.browser.LoadUrlParams; | 57 import org.chromium.content_public.browser.LoadUrlParams; |
| 57 import org.chromium.content_public.browser.NavigationController; | 58 import org.chromium.content_public.browser.NavigationController; |
| 58 import org.chromium.content_public.browser.NavigationHistory; | 59 import org.chromium.content_public.browser.NavigationHistory; |
| 59 import org.chromium.content_public.browser.WebContents; | 60 import org.chromium.content_public.browser.WebContents; |
| 60 import org.chromium.content_public.common.Referrer; | 61 import org.chromium.content_public.common.Referrer; |
| 61 import org.chromium.ui.base.ActivityWindowAndroid; | 62 import org.chromium.ui.base.ActivityWindowAndroid; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 74 | 75 |
| 75 /** | 76 /** |
| 76 * Exposes the native AwContents class, and together these classes wrap the Cont entViewCore | 77 * Exposes the native AwContents class, and together these classes wrap the Cont entViewCore |
| 77 * and Browser components that are required to implement Android WebView API. Th is is the | 78 * and Browser components that are required to implement Android WebView API. Th is is the |
| 78 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob ject | 79 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob ject |
| 79 * relationship with application WebView instances. | 80 * relationship with application WebView instances. |
| 80 * (We define this class independent of the hidden WebViewProvider interfaces, t o allow | 81 * (We define this class independent of the hidden WebViewProvider interfaces, t o allow |
| 81 * continuous build & test in the open source SDK-based tree). | 82 * continuous build & test in the open source SDK-based tree). |
| 82 */ | 83 */ |
| 83 @JNINamespace("android_webview") | 84 @JNINamespace("android_webview") |
| 84 public class AwContents { | 85 public class AwContents implements SmartClipProvider { |
|
boliu
2014/11/07 01:12:23
drive-by suggestion: pull this out into a helper c
| |
| 85 private static final String TAG = "AwContents"; | 86 private static final String TAG = "AwContents"; |
| 86 | 87 |
| 87 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; | 88 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; |
| 88 | 89 |
| 89 // Used to avoid enabling zooming in / out if resulting zooming will | 90 // Used to avoid enabling zooming in / out if resulting zooming will |
| 90 // produce little visible difference. | 91 // produce little visible difference. |
| 91 private static final float ZOOM_CONTROLS_EPSILON = 0.007f; | 92 private static final float ZOOM_CONTROLS_EPSILON = 0.007f; |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * WebKit hit test related data strcutre. These are used to implement | 95 * WebKit hit test related data strcutre. These are used to implement |
| (...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2227 | 2228 |
| 2228 for (int i = 1; i < 100; i++) { | 2229 for (int i = 1; i < 100; i++) { |
| 2229 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; | 2230 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; |
| 2230 if (!new File(testName).exists()) return testName; | 2231 if (!new File(testName).exists()) return testName; |
| 2231 } | 2232 } |
| 2232 | 2233 |
| 2233 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName) ; | 2234 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName) ; |
| 2234 return null; | 2235 return null; |
| 2235 } | 2236 } |
| 2236 | 2237 |
| 2238 @Override | |
| 2237 public void extractSmartClipData(int x, int y, int width, int height) { | 2239 public void extractSmartClipData(int x, int y, int width, int height) { |
| 2238 if (!isDestroyed()) mContentViewCore.extractSmartClipData(x, y, width, h eight); | 2240 if (!isDestroyed()) mContentViewCore.extractSmartClipData(x, y, width, h eight); |
| 2239 } | 2241 } |
| 2240 | 2242 |
| 2241 public void setSmartClipDataListener(ContentViewCore.SmartClipDataListener l istener) { | 2243 @Override |
| 2242 if (!isDestroyed()) mContentViewCore.setSmartClipDataListener(listener); | 2244 public void setSmartClipResultHandler(final Handler resultHandler) { |
| 2245 if (isDestroyed()) return; | |
| 2246 | |
| 2247 if (resultHandler == null) { | |
| 2248 mContentViewCore.setSmartClipDataListener(null); | |
| 2249 return; | |
| 2250 } | |
| 2251 mContentViewCore.setSmartClipDataListener(new ContentViewCore.SmartClipD ataListener() { | |
| 2252 public void onSmartClipDataExtracted(String text, String html, Rect clipRect) { | |
| 2253 Bundle bundle = new Bundle(); | |
| 2254 bundle.putString("url", mContentViewCore.getWebContents().getVis ibleUrl()); | |
| 2255 bundle.putString("title", mContentViewCore.getWebContents().getT itle()); | |
| 2256 bundle.putParcelable("rect", clipRect); | |
| 2257 bundle.putString("text", text); | |
| 2258 bundle.putString("html", html); | |
| 2259 try { | |
| 2260 Message msg = Message.obtain(resultHandler, 0); | |
| 2261 msg.setData(bundle); | |
| 2262 msg.sendToTarget(); | |
| 2263 } catch (Exception e) { | |
| 2264 Log.e(TAG, "Error calling handler for smart clip data: ", e) ; | |
| 2265 } | |
| 2266 } | |
| 2267 }); | |
| 2243 } | 2268 } |
| 2244 | 2269 |
| 2245 // ------------------------------------------------------------------------- ------------------- | 2270 // ------------------------------------------------------------------------- ------------------- |
| 2246 // This is the AwViewMethods implementation that does real work. The AwViewM ethodsImpl is | 2271 // This is the AwViewMethods implementation that does real work. The AwViewM ethodsImpl is |
| 2247 // hooked up to the WebView in embedded mode and to the FullScreenView in fu llscreen mode, | 2272 // hooked up to the WebView in embedded mode and to the FullScreenView in fu llscreen mode, |
| 2248 // but not to both at the same time. | 2273 // but not to both at the same time. |
| 2249 private class AwViewMethodsImpl implements AwViewMethods { | 2274 private class AwViewMethodsImpl implements AwViewMethods { |
| 2250 private int mLayerType = View.LAYER_TYPE_NONE; | 2275 private int mLayerType = View.LAYER_TYPE_NONE; |
| 2251 private ComponentCallbacks2 mComponentCallbacks; | 2276 private ComponentCallbacks2 mComponentCallbacks; |
| 2252 | 2277 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2612 | 2637 |
| 2613 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean networkUp); | 2638 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean networkUp); |
| 2614 | 2639 |
| 2615 private native void nativeTrimMemory(long nativeAwContents, int level, boole an visible); | 2640 private native void nativeTrimMemory(long nativeAwContents, int level, boole an visible); |
| 2616 | 2641 |
| 2617 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); | 2642 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); |
| 2618 | 2643 |
| 2619 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, | 2644 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, |
| 2620 long resources); | 2645 long resources); |
| 2621 } | 2646 } |
| OLD | NEW |