Commit 5e66400e authored by Tim Volodine's avatar Tim Volodine Committed by Chromium LUCI CQ

[AW] Add kWebViewJavaJsBridgeMojo feature.

Add kWebViewJavaJsBridgeMojo feature for Android WebView, to
enable/disable the new Java/JS bridge code path using mojo. The feature
is currently disabled by default. When the feature is enabled the mojo
interface for the addJavascriptInterface() API in Android WebView is
used.

This CL also adds the feature to the ProductionSupportedFlagList and
removes the 1-arg version of JavascriptInjector.fromWebContents().

BUG=1164434

Change-Id: Ic4ecdbb78ca18e5455ddbac3367ddbe301bdb67e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630905Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Tim Volodine <timvolodine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844856}
parent 6eb8bc01
......@@ -29,6 +29,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&features::kWebViewMixedContentAutoupgrades,
&features::kWebViewTestFeature,
&features::kWebViewMeasureScreenCoverage,
&features::kWebViewJavaJsBridgeMojo,
};
const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
......
......@@ -59,5 +59,9 @@ const base::Feature kWebViewTestFeature{"WebViewTestFeature",
const base::Feature kWebViewWideColorGamutSupport{
"WebViewWideColorGamutSupport", base::FEATURE_ENABLED_BY_DEFAULT};
// Enable the new Java/JS Bridge code path with mojo implementation.
const base::Feature kWebViewJavaJsBridgeMojo{"WebViewJavaJsBridgeMojo",
base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
} // namespace android_webview
......@@ -23,6 +23,7 @@ extern const base::Feature kWebViewMeasureScreenCoverage;
extern const base::Feature kWebViewMixedContentAutoupgrades;
extern const base::Feature kWebViewTestFeature;
extern const base::Feature kWebViewWideColorGamutSupport;
extern const base::Feature kWebViewJavaJsBridgeMojo;
} // namespace features
} // namespace android_webview
......
......@@ -1502,7 +1502,8 @@ public class AwContents implements SmartClipProvider {
private JavascriptInjector getJavascriptInjector() {
if (mJavascriptInjector == null) {
mJavascriptInjector = JavascriptInjector.fromWebContents(mWebContents);
mJavascriptInjector = JavascriptInjector.fromWebContents(
mWebContents, AwFeatureList.isEnabled(AwFeatures.WEBVIEW_JAVA_JS_BRIDGE_MOJO));
}
return mJavascriptInjector;
}
......
......@@ -109,5 +109,7 @@ public final class ProductionSupportedFlagList {
Flag.baseFeature(UiFeatures.SWIPE_TO_MOVE_CURSOR,
"Enables swipe to move cursor feature."
+ "This flag will only take effect on Android 11 and above."),
Flag.baseFeature(AwFeatures.WEBVIEW_JAVA_JS_BRIDGE_MOJO,
"Enables the new Java/JS Bridge code path with mojo implementation."),
};
}
......@@ -442,7 +442,7 @@ public class VisualStateTest {
};
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
JavascriptInjector.fromWebContents(awContents.getWebContents())
JavascriptInjector.fromWebContents(awContents.getWebContents(), false)
.addPossiblyUnsafeInterface(pageChangeNotifier, "pageChangeNotifier", null);
awContents.loadUrl(WAIT_FOR_JS_DETACHED_TEST_URL);
});
......
......@@ -4,6 +4,8 @@
package org.chromium.android_webview.test.util;
import org.chromium.android_webview.AwFeatureList;
import org.chromium.android_webview.common.AwFeatures;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.content_public.browser.JavascriptInjector;
import org.chromium.content_public.browser.WebContents;
......@@ -30,7 +32,9 @@ public class JavascriptEventObserver {
* @param name the name of object used in javascript
*/
public void register(WebContents webContents, String name) {
JavascriptInjector.fromWebContents(webContents)
JavascriptInjector
.fromWebContents(webContents,
AwFeatureList.isEnabled(AwFeatures.WEBVIEW_JAVA_JS_BRIDGE_MOJO))
.addPossiblyUnsafeInterface(this, name, null);
}
......
......@@ -16,15 +16,6 @@ import java.util.Map;
* custom Javascript interfaces.
*/
public interface JavascriptInjector {
/**
* @param webContents {@link WebContents} object.
* @return {@link JavascriptInjector} object used for the give WebContents.
* Creates one if not present.
*/
static JavascriptInjector fromWebContents(WebContents webContents) {
return fromWebContents(webContents, false);
}
/**
* @param webContents {@link WebContents} object.
* @param useMojo Whether to use {@link RemoteObjectInjector} methods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment