Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2418)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 353163002: [Android] Switch to Gin Java Bridge implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index cc03f07afb6cb69518eafded59c9f2841968dda9..fcfbdf1c68f8c7635b3f0b82421dda11f00ecce7 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -29,6 +29,7 @@ import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Pair;
import android.view.ActionMode;
import android.view.HapticFeedbackConstants;
import android.view.InputDevice;
@@ -118,9 +119,12 @@ public class ContentViewCore
// native side. However we still need a strong reference on the Java side to
// prevent garbage collection if the embedder doesn't maintain their own ref to the
// interface object - the Java side ref won't create a new GC root.
- // This map stores those refernces. We put into the map on addJavaScriptInterface()
- // and remove from it in removeJavaScriptInterface().
- private final Map<String, Object> mJavaScriptInterfaces = new HashMap<String, Object>();
+ // This map stores those references. We put into the map on addJavaScriptInterface()
+ // and remove from it in removeJavaScriptInterface(). The annotation class is stored for
+ // the purpose of migrating injected objects from one instance of CVC to another, which
+ // is used by Android WebView to support WebChromeClient.onCreateWindow scenario.
+ private final Map<String, Pair<Object, Class>> mJavaScriptInterfaces =
+ new HashMap<String, Pair<Object, Class>>();
// Additionally, we keep track of all Java bound JS objects that are in use on the
// current page to ensure that they are not garbage collected until the page is
@@ -2676,6 +2680,16 @@ public class ContentViewCore
}
/**
+ * Returns JavaScript interface objects previously injected via
+ * {@link #addJavascriptInterface(Object, String)}.
+ *
+ * @return the mapping of names to interface objects and corresponding annotation classes
+ */
+ public Map<String, Pair<Object, Class>> getJavascriptInterfaces() {
+ return mJavaScriptInterfaces;
+ }
+
+ /**
* This will mimic {@link #addPossiblyUnsafeJavascriptInterface(Object, String, Class)}
* and automatically pass in {@link JavascriptInterface} as the required annotation.
*
@@ -2732,7 +2746,7 @@ public class ContentViewCore
public void addPossiblyUnsafeJavascriptInterface(Object object, String name,
Class<? extends Annotation> requiredAnnotation) {
if (mNativeContentViewCore != 0 && object != null) {
- mJavaScriptInterfaces.put(name, object);
+ mJavaScriptInterfaces.put(name, new Pair<Object, Class>(object, requiredAnnotation));
nativeAddJavascriptInterface(mNativeContentViewCore, object, name, requiredAnnotation);
}
}

Powered by Google App Engine
This is Rietveld 408576698