Commit 03b6e317 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

[remoteobjects] Fix JavaBridgeBasicsTest#testObjectsInspection__MojoUsed

This fixes a test failure of
JavaBridgeBasicsTest#testObjectsInspection__MojoUsed since the
‘allow inspection’ variable is not updated when
RemoteObjectGatewayHelper corresponding to the frame is already
created.

Bug: 1105933b
Change-Id: I80c6fd3bcde77ea69b8bc445a3448c8ac69f5d8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398071
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816573}
parent 8feb9b9f
......@@ -39,7 +39,7 @@ class RemoteObjectHostImpl implements RemoteObjectHost {
*/
private final WeakReference<RemoteObjectRegistry> mRegistry;
private final boolean mAllowInspection;
private boolean mAllowInspection;
RemoteObjectHostImpl(RemoteObjectImpl.Auditor auditor, RemoteObjectRegistry registry,
boolean allowInspection) {
......@@ -48,6 +48,10 @@ class RemoteObjectHostImpl implements RemoteObjectHost {
mAllowInspection = allowInspection;
}
public void setAllowInspection(boolean allow) {
mAllowInspection = allow;
}
@Override
public void getObject(int objectId, InterfaceRequest<RemoteObject> request) {
try (InterfaceRequest<RemoteObject> autoClose = request) {
......
......@@ -31,11 +31,13 @@ public final class RemoteObjectInjector extends WebContentsObserver {
*/
private static class RemoteObjectGatewayHelper {
public RemoteObjectGateway.Proxy gateway;
public RemoteObjectHostImpl host;
public RemoteObjectRegistry registry;
public RemoteObjectGatewayHelper(
RemoteObjectGateway.Proxy newGateway, RemoteObjectRegistry newRegistry) {
public RemoteObjectGatewayHelper(RemoteObjectGateway.Proxy newGateway,
RemoteObjectHostImpl newHost, RemoteObjectRegistry newRegistry) {
gateway = newGateway;
host = newHost;
registry = newRegistry;
}
}
......@@ -104,7 +106,14 @@ public final class RemoteObjectInjector extends WebContentsObserver {
}
public void setAllowInspection(boolean allow) {
WebContents webContents = mWebContents.get();
if (webContents == null) return;
mAllowInspection = allow;
// TODO(crbug.com/1105935): the objects host needs to update the allow status from all
// frames, not just the main one.
setAllowInspectionForFrame(webContents.getMainFrame());
}
private void addInterfaceForFrame(RenderFrameHost frameHost, String name, Object object,
......@@ -122,6 +131,13 @@ public final class RemoteObjectInjector extends WebContentsObserver {
helper.registry.unrefObjectByObject(object);
}
private void setAllowInspectionForFrame(RenderFrameHost frameHost) {
RemoteObjectGatewayHelper helper = mRemoteObjectGatewayHelpers.get(frameHost);
if (helper == null) return;
helper.host.setAllowInspection(mAllowInspection);
}
private RemoteObjectGatewayHelper getRemoteObjectGatewayHelperForFrame(
RenderFrameHost frameHost) {
// Only create one instance of RemoteObjectHostImpl per frame and store it in a map so it is
......@@ -140,7 +156,7 @@ public final class RemoteObjectInjector extends WebContentsObserver {
RemoteObjectGateway.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
factory.createRemoteObjectGateway(host, result.second);
mRemoteObjectGatewayHelpers.put(
frameHost, new RemoteObjectGatewayHelper(result.first, registry));
frameHost, new RemoteObjectGatewayHelper(result.first, host, registry));
}
return mRemoteObjectGatewayHelpers.get(frameHost);
......
......@@ -969,7 +969,7 @@ public class JavaBridgeBasicsTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testObjectsInspection(boolean useMojo) throws Throwable {
class Test {
@JavascriptInterface
......
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