Commit 528c2a7c authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Add onBackgroundColorChanged

Bug: 1076473
Change-Id: I2c5de6c967dca2b2efe536c04d383e1d51c05ac1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264256
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781954}
parent b61f6a04
......@@ -321,4 +321,33 @@ public class TabCallbackTest {
Assert.assertEquals("foobar", titles[0]);
CriteriaHelper.pollUiThread(() -> Criteria.checkThat(titles[0], Matchers.is("foobar")));
}
@MinWebLayerVersion(85)
@Test
@SmallTest
public void testOnBackgroundColorChanged() throws TimeoutException {
String startupUrl = "about:blank";
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(startupUrl);
Integer backgroundColors[] = new Integer[1];
CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Tab tab = activity.getTab();
TabCallback callback = new TabCallback() {
@Override
public void onBackgroundColorChanged(int color) {
backgroundColors[0] = color;
callbackHelper.notifyCalled();
}
};
tab.registerTabCallback(callback);
});
mActivityTestRule.executeScriptSync(
"document.body.style.backgroundColor = \"rgb(255, 0, 0)\"",
/*useSeparateIsolate=*/false);
callbackHelper.waitForFirst();
Assert.assertEquals(0xffff0000, (int) backgroundColors[0]);
}
}
......@@ -170,6 +170,17 @@ public final class TabImpl extends ITab.Stub implements LoginPrompt.Observer {
viewController.onBottomControlsChanged(bottomControlsOffsetY);
}
}
@Override
public void onBackgroundColorChanged(int color) {
if (WebLayerFactoryImpl.getClientMajorVersion() >= 85) {
try {
mClient.onBackgroundColorChanged(color);
} catch (RemoteException e) {
throw new APICallException(e);
}
}
}
}
public static TabImpl fromWebContents(WebContents webContents) {
......
......@@ -36,4 +36,7 @@ interface ITabClient {
// Added in M84.
void onTabDestroyed() = 8;
// Added in M85.
void onBackgroundColorChanged(in int color) = 9;
}
......@@ -726,6 +726,14 @@ public class Tab {
callback.bringTabToFront();
}
}
@Override
public void onBackgroundColorChanged(int color) {
StrictModeWorkaround.apply();
for (TabCallback callback : mCallbacks) {
callback.onBackgroundColorChanged(color);
}
}
}
private static final class ErrorPageCallbackClientImpl extends IErrorPageCallbackClient.Stub {
......
......@@ -54,4 +54,14 @@ public abstract class TabCallback {
* containing Activity, and the task to be foregrounded.
*/
public void bringTabToFront() {}
/**
* Called when then background color of the page changes. The background color typically comes
* from css background-color, but heuristics and blending may be used depending upon the page.
* This is mostly useful for filling in gaps around the web page during resize, but it will
* not necessarily match the full background of the page.
* @param color The new ARGB color of the page background.
* @since 85
*/
public void onBackgroundColorChanged(int color) {}
}
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