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 { ...@@ -39,7 +39,7 @@ class RemoteObjectHostImpl implements RemoteObjectHost {
*/ */
private final WeakReference<RemoteObjectRegistry> mRegistry; private final WeakReference<RemoteObjectRegistry> mRegistry;
private final boolean mAllowInspection; private boolean mAllowInspection;
RemoteObjectHostImpl(RemoteObjectImpl.Auditor auditor, RemoteObjectRegistry registry, RemoteObjectHostImpl(RemoteObjectImpl.Auditor auditor, RemoteObjectRegistry registry,
boolean allowInspection) { boolean allowInspection) {
...@@ -48,6 +48,10 @@ class RemoteObjectHostImpl implements RemoteObjectHost { ...@@ -48,6 +48,10 @@ class RemoteObjectHostImpl implements RemoteObjectHost {
mAllowInspection = allowInspection; mAllowInspection = allowInspection;
} }
public void setAllowInspection(boolean allow) {
mAllowInspection = allow;
}
@Override @Override
public void getObject(int objectId, InterfaceRequest<RemoteObject> request) { public void getObject(int objectId, InterfaceRequest<RemoteObject> request) {
try (InterfaceRequest<RemoteObject> autoClose = request) { try (InterfaceRequest<RemoteObject> autoClose = request) {
......
...@@ -31,11 +31,13 @@ public final class RemoteObjectInjector extends WebContentsObserver { ...@@ -31,11 +31,13 @@ public final class RemoteObjectInjector extends WebContentsObserver {
*/ */
private static class RemoteObjectGatewayHelper { private static class RemoteObjectGatewayHelper {
public RemoteObjectGateway.Proxy gateway; public RemoteObjectGateway.Proxy gateway;
public RemoteObjectHostImpl host;
public RemoteObjectRegistry registry; public RemoteObjectRegistry registry;
public RemoteObjectGatewayHelper( public RemoteObjectGatewayHelper(RemoteObjectGateway.Proxy newGateway,
RemoteObjectGateway.Proxy newGateway, RemoteObjectRegistry newRegistry) { RemoteObjectHostImpl newHost, RemoteObjectRegistry newRegistry) {
gateway = newGateway; gateway = newGateway;
host = newHost;
registry = newRegistry; registry = newRegistry;
} }
} }
...@@ -104,7 +106,14 @@ public final class RemoteObjectInjector extends WebContentsObserver { ...@@ -104,7 +106,14 @@ public final class RemoteObjectInjector extends WebContentsObserver {
} }
public void setAllowInspection(boolean allow) { public void setAllowInspection(boolean allow) {
WebContents webContents = mWebContents.get();
if (webContents == null) return;
mAllowInspection = allow; 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, private void addInterfaceForFrame(RenderFrameHost frameHost, String name, Object object,
...@@ -122,6 +131,13 @@ public final class RemoteObjectInjector extends WebContentsObserver { ...@@ -122,6 +131,13 @@ public final class RemoteObjectInjector extends WebContentsObserver {
helper.registry.unrefObjectByObject(object); 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( private RemoteObjectGatewayHelper getRemoteObjectGatewayHelperForFrame(
RenderFrameHost frameHost) { RenderFrameHost frameHost) {
// Only create one instance of RemoteObjectHostImpl per frame and store it in a map so it is // 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 { ...@@ -140,7 +156,7 @@ public final class RemoteObjectInjector extends WebContentsObserver {
RemoteObjectGateway.MANAGER.getInterfaceRequest(CoreImpl.getInstance()); RemoteObjectGateway.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
factory.createRemoteObjectGateway(host, result.second); factory.createRemoteObjectGateway(host, result.second);
mRemoteObjectGatewayHelpers.put( mRemoteObjectGatewayHelpers.put(
frameHost, new RemoteObjectGatewayHelper(result.first, registry)); frameHost, new RemoteObjectGatewayHelper(result.first, host, registry));
} }
return mRemoteObjectGatewayHelpers.get(frameHost); return mRemoteObjectGatewayHelpers.get(frameHost);
......
...@@ -969,7 +969,7 @@ public class JavaBridgeBasicsTest { ...@@ -969,7 +969,7 @@ public class JavaBridgeBasicsTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testObjectsInspection(boolean useMojo) throws Throwable { public void testObjectsInspection(boolean useMojo) throws Throwable {
class Test { class Test {
@JavascriptInterface @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