| 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.content.browser; | 5 package org.chromium.content.browser; |
| 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.app.SearchManager; | 9 import android.app.SearchManager; |
| 10 import android.content.ContentResolver; | 10 import android.content.ContentResolver; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import android.os.Bundle; | 22 import android.os.Bundle; |
| 23 import android.os.Handler; | 23 import android.os.Handler; |
| 24 import android.os.ResultReceiver; | 24 import android.os.ResultReceiver; |
| 25 import android.os.SystemClock; | 25 import android.os.SystemClock; |
| 26 import android.provider.Browser; | 26 import android.provider.Browser; |
| 27 import android.provider.Settings; | 27 import android.provider.Settings; |
| 28 import android.text.Editable; | 28 import android.text.Editable; |
| 29 import android.text.Selection; | 29 import android.text.Selection; |
| 30 import android.text.TextUtils; | 30 import android.text.TextUtils; |
| 31 import android.util.Log; | 31 import android.util.Log; |
| 32 import android.util.Pair; |
| 32 import android.view.ActionMode; | 33 import android.view.ActionMode; |
| 33 import android.view.HapticFeedbackConstants; | 34 import android.view.HapticFeedbackConstants; |
| 34 import android.view.InputDevice; | 35 import android.view.InputDevice; |
| 35 import android.view.KeyEvent; | 36 import android.view.KeyEvent; |
| 36 import android.view.MotionEvent; | 37 import android.view.MotionEvent; |
| 37 import android.view.View; | 38 import android.view.View; |
| 38 import android.view.ViewGroup; | 39 import android.view.ViewGroup; |
| 39 import android.view.accessibility.AccessibilityEvent; | 40 import android.view.accessibility.AccessibilityEvent; |
| 40 import android.view.accessibility.AccessibilityManager; | 41 import android.view.accessibility.AccessibilityManager; |
| 41 import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeL
istener; | 42 import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeL
istener; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 private static final int TEXT_HANDLE_FADE_IN_DELAY = 300; | 112 private static final int TEXT_HANDLE_FADE_IN_DELAY = 300; |
| 112 | 113 |
| 113 // If the embedder adds a JavaScript interface object that contains an indir
ect reference to | 114 // If the embedder adds a JavaScript interface object that contains an indir
ect reference to |
| 114 // the ContentViewCore, then storing a strong ref to the interface object on
the native | 115 // the ContentViewCore, then storing a strong ref to the interface object on
the native |
| 115 // side would prevent garbage collection of the ContentViewCore (as that str
ong ref would | 116 // side would prevent garbage collection of the ContentViewCore (as that str
ong ref would |
| 116 // create a new GC root). | 117 // create a new GC root). |
| 117 // For that reason, we store only a weak reference to the interface object o
n the | 118 // For that reason, we store only a weak reference to the interface object o
n the |
| 118 // native side. However we still need a strong reference on the Java side to | 119 // native side. However we still need a strong reference on the Java side to |
| 119 // prevent garbage collection if the embedder doesn't maintain their own ref
to the | 120 // prevent garbage collection if the embedder doesn't maintain their own ref
to the |
| 120 // interface object - the Java side ref won't create a new GC root. | 121 // interface object - the Java side ref won't create a new GC root. |
| 121 // This map stores those refernces. We put into the map on addJavaScriptInte
rface() | 122 // This map stores those references. We put into the map on addJavaScriptInt
erface() |
| 122 // and remove from it in removeJavaScriptInterface(). | 123 // and remove from it in removeJavaScriptInterface(). The annotation class i
s stored for |
| 123 private final Map<String, Object> mJavaScriptInterfaces = new HashMap<String
, Object>(); | 124 // the purpose of migrating injected objects from one instance of CVC to ano
ther, which |
| 125 // is used by Android WebView to support WebChromeClient.onCreateWindow scen
ario. |
| 126 private final Map<String, Pair<Object, Class>> mJavaScriptInterfaces = |
| 127 new HashMap<String, Pair<Object, Class>>(); |
| 124 | 128 |
| 125 // Additionally, we keep track of all Java bound JS objects that are in use
on the | 129 // Additionally, we keep track of all Java bound JS objects that are in use
on the |
| 126 // current page to ensure that they are not garbage collected until the page
is | 130 // current page to ensure that they are not garbage collected until the page
is |
| 127 // navigated. This includes interface objects that have been removed | 131 // navigated. This includes interface objects that have been removed |
| 128 // via the removeJavaScriptInterface API and transient objects returned from
methods | 132 // via the removeJavaScriptInterface API and transient objects returned from
methods |
| 129 // on the interface object. Note we use HashSet rather than Set as the nativ
e side | 133 // on the interface object. Note we use HashSet rather than Set as the nativ
e side |
| 130 // expects HashSet (no bindings for interfaces). | 134 // expects HashSet (no bindings for interfaces). |
| 131 private final HashSet<Object> mRetainedJavaScriptObjects = new HashSet<Objec
t>(); | 135 private final HashSet<Object> mRetainedJavaScriptObjects = new HashSet<Objec
t>(); |
| 132 | 136 |
| 133 /** | 137 /** |
| (...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2670 * when debugging hybrid Android apps, but can't be enabled for legacy appli
cations due | 2674 * when debugging hybrid Android apps, but can't be enabled for legacy appli
cations due |
| 2671 * to compatibility risks. | 2675 * to compatibility risks. |
| 2672 * | 2676 * |
| 2673 * @param allow Whether to allow JavaScript objects inspection. | 2677 * @param allow Whether to allow JavaScript objects inspection. |
| 2674 */ | 2678 */ |
| 2675 public void setAllowJavascriptInterfacesInspection(boolean allow) { | 2679 public void setAllowJavascriptInterfacesInspection(boolean allow) { |
| 2676 nativeSetAllowJavascriptInterfacesInspection(mNativeContentViewCore, all
ow); | 2680 nativeSetAllowJavascriptInterfacesInspection(mNativeContentViewCore, all
ow); |
| 2677 } | 2681 } |
| 2678 | 2682 |
| 2679 /** | 2683 /** |
| 2684 * Returns JavaScript interface objects previously injected via |
| 2685 * {@link #addJavascriptInterface(Object, String)}. |
| 2686 * |
| 2687 * @return the mapping of names to interface objects and corresponding annot
ation classes |
| 2688 */ |
| 2689 public Map<String, Pair<Object, Class>> getJavascriptInterfaces() { |
| 2690 return mJavaScriptInterfaces; |
| 2691 } |
| 2692 |
| 2693 /** |
| 2680 * This will mimic {@link #addPossiblyUnsafeJavascriptInterface(Object, Stri
ng, Class)} | 2694 * This will mimic {@link #addPossiblyUnsafeJavascriptInterface(Object, Stri
ng, Class)} |
| 2681 * and automatically pass in {@link JavascriptInterface} as the required ann
otation. | 2695 * and automatically pass in {@link JavascriptInterface} as the required ann
otation. |
| 2682 * | 2696 * |
| 2683 * @param object The Java object to inject into the ContentViewCore's JavaSc
ript context. Null | 2697 * @param object The Java object to inject into the ContentViewCore's JavaSc
ript context. Null |
| 2684 * values are ignored. | 2698 * values are ignored. |
| 2685 * @param name The name used to expose the instance in JavaScript. | 2699 * @param name The name used to expose the instance in JavaScript. |
| 2686 */ | 2700 */ |
| 2687 public void addJavascriptInterface(Object object, String name) { | 2701 public void addJavascriptInterface(Object object, String name) { |
| 2688 addPossiblyUnsafeJavascriptInterface(object, name, JavascriptInterface.c
lass); | 2702 addPossiblyUnsafeJavascriptInterface(object, name, JavascriptInterface.c
lass); |
| 2689 } | 2703 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 * @param name The name used to expose the instance in | 2740 * @param name The name used to expose the instance in |
| 2727 * JavaScript. | 2741 * JavaScript. |
| 2728 * @param requiredAnnotation Restrict exposed methods to ones with this | 2742 * @param requiredAnnotation Restrict exposed methods to ones with this |
| 2729 * annotation. If {@code null} all methods are | 2743 * annotation. If {@code null} all methods are |
| 2730 * exposed. | 2744 * exposed. |
| 2731 * | 2745 * |
| 2732 */ | 2746 */ |
| 2733 public void addPossiblyUnsafeJavascriptInterface(Object object, String name, | 2747 public void addPossiblyUnsafeJavascriptInterface(Object object, String name, |
| 2734 Class<? extends Annotation> requiredAnnotation) { | 2748 Class<? extends Annotation> requiredAnnotation) { |
| 2735 if (mNativeContentViewCore != 0 && object != null) { | 2749 if (mNativeContentViewCore != 0 && object != null) { |
| 2736 mJavaScriptInterfaces.put(name, object); | 2750 mJavaScriptInterfaces.put(name, new Pair<Object, Class>(object, requ
iredAnnotation)); |
| 2737 nativeAddJavascriptInterface(mNativeContentViewCore, object, name, r
equiredAnnotation); | 2751 nativeAddJavascriptInterface(mNativeContentViewCore, object, name, r
equiredAnnotation); |
| 2738 } | 2752 } |
| 2739 } | 2753 } |
| 2740 | 2754 |
| 2741 /** | 2755 /** |
| 2742 * Removes a previously added JavaScript interface with the given name. | 2756 * Removes a previously added JavaScript interface with the given name. |
| 2743 * | 2757 * |
| 2744 * @param name The name of the interface to remove. | 2758 * @param name The name of the interface to remove. |
| 2745 */ | 2759 */ |
| 2746 public void removeJavascriptInterface(String name) { | 2760 public void removeJavascriptInterface(String name) { |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3327 | 3341 |
| 3328 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp
l, | 3342 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp
l, |
| 3329 int x, int y, int w, int h); | 3343 int x, int y, int w, int h); |
| 3330 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl
, boolean opaque); | 3344 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl
, boolean opaque); |
| 3331 | 3345 |
| 3332 private native void nativeResumeResponseDeferredAtStart( | 3346 private native void nativeResumeResponseDeferredAtStart( |
| 3333 long nativeContentViewCoreImpl); | 3347 long nativeContentViewCoreImpl); |
| 3334 private native void nativeSetHasPendingNavigationTransitionForTesting( | 3348 private native void nativeSetHasPendingNavigationTransitionForTesting( |
| 3335 long nativeContentViewCoreImpl); | 3349 long nativeContentViewCoreImpl); |
| 3336 } | 3350 } |
| OLD | NEW |