Commit 266de7d3 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: WebContents.notifyRendererPreferenceUpdate

Replaces Tab.notifyRendererPreferenceUpdate with a new API
on WebContents. This CL addressed a TODO in Tab. Rather
than exposing Java RenderViewHost which requires modification
in already-deprecated native content::RenderViewHostImpl,
the changes follows the direction recommended in the comment
by updating WebContents for this page-specific function.

Bug: 960746
Change-Id: I7bfe3c1d04a7a7ec2906e829912e7906ff30d937
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1630378
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664536}
parent 8c03425c
......@@ -947,17 +947,19 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
markSessionResume();
RecordUserAction.record("MobileComeToForeground");
if (getActivityTab() != null) {
LaunchMetrics.commitLaunchMetrics(getActivityTab().getWebContents());
Tab tab = getActivityTab();
if (tab != null) {
WebContents webContents = tab.getWebContents();
LaunchMetrics.commitLaunchMetrics(webContents);
// For picture-in-picture mode
if (webContents != null) webContents.notifyRendererPreferenceUpdate();
}
FeatureUtilities.setCustomTabVisible(isCustomTab());
FeatureUtilities.setIsInMultiWindowMode(
MultiWindowUtils.getInstance().isInMultiWindowMode(this));
// For picture-in-picture mode
if (getActivityTab() != null) getActivityTab().notifyRendererPreferenceUpdate();
if (mPictureInPictureController != null) {
mPictureInPictureController.cleanup(this);
}
......
......@@ -296,7 +296,7 @@ public class CustomTabActivityTabController implements InflationObserver, Native
TabAssociatedApp.from(tab).setAppId(mConnection.getClientPackageNameForSession(mSession));
if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) {
// Configures web preferences for viewing downloaded media.
tab.notifyRendererPreferenceUpdate();
if (tab.getWebContents() != null) tab.getWebContents().notifyRendererPreferenceUpdate();
}
initializeTab(tab);
return tab;
......@@ -319,7 +319,7 @@ public class CustomTabActivityTabController implements InflationObserver, Native
null, false /*unfreeze*/);
if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) {
tab.notifyRendererPreferenceUpdate();
if (tab.getWebContents() != null) tab.getWebContents().notifyRendererPreferenceUpdate();
}
initializeTab(tab);
......
......@@ -1032,16 +1032,10 @@ public class Tab
assert windowAndroid != null;
mWindowAndroid = windowAndroid;
WebContents webContents = getWebContents();
if (webContents != null) webContents.setTopLevelNativeWindow(mWindowAndroid);
if (getActivity() != null) notifyRendererPreferenceUpdate();
}
/**
* Notify that web preferences needs update for various properties.
* TODO(jinsukkim): Expose RenderViewHost at java layer and remove this method.
*/
public void notifyRendererPreferenceUpdate() {
if (mNativeTabAndroid != 0) nativeNotifyRendererPreferenceUpdate(mNativeTabAndroid);
if (webContents != null) {
webContents.setTopLevelNativeWindow(mWindowAndroid);
webContents.notifyRendererPreferenceUpdate();
}
}
/**
......@@ -1190,7 +1184,7 @@ public class Tab
new TabContextMenuPopulator(
mDelegateFactory.createContextMenuPopulator(this), this));
if (getActivity() != null) notifyRendererPreferenceUpdate();
mWebContents.notifyRendererPreferenceUpdate();
TabHelpers.initWebContentsHelpers(this);
notifyContentChanged();
} finally {
......@@ -1967,5 +1961,4 @@ public class Tab
private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url);
private native void nativeAttachDetachedTab(long nativeTabAndroid);
private native boolean nativeAreRendererInputEventsIgnored(long nativeTabAndroid);
private native void nativeNotifyRendererPreferenceUpdate(long nativeTabAndroid);
}
......@@ -16,6 +16,7 @@ import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.metrics.WebApkSplashscreenMetrics;
import org.chromium.chrome.browser.metrics.WebApkUma;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.content_public.browser.WebContents;
import org.chromium.webapk.lib.common.WebApkConstants;
/**
......@@ -47,7 +48,8 @@ public class WebApkActivity extends WebappActivity {
@Override
protected void initializeUI(Bundle savedInstance) {
super.initializeUI(savedInstance);
getActivityTab().notifyRendererPreferenceUpdate();
WebContents webContents = getActivityTab().getWebContents();
if (webContents != null) webContents.notifyRendererPreferenceUpdate();
}
@Override
......
......@@ -556,13 +556,6 @@ bool TabAndroid::HasPrerenderedUrl(JNIEnv* env,
return HasPrerenderedUrl(gurl);
}
void TabAndroid::NotifyRendererPreferenceUpdate(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
if (web_contents() && web_contents()->GetRenderViewHost())
web_contents()->GetRenderViewHost()->OnWebkitPreferencesChanged();
}
void TabAndroid::AttachDetachedTab(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
......
......@@ -202,9 +202,6 @@ class TabAndroid {
bool AreRendererInputEventsIgnored(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void NotifyRendererPreferenceUpdate(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
private:
prerender::PrerenderManager* GetPrerenderManager() const;
......
......@@ -915,4 +915,12 @@ void WebContentsAndroid::SetDisplayCutoutSafeArea(
gfx::Insets(top, left, bottom, right));
}
void WebContentsAndroid::NotifyRendererPreferenceUpdate(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
RenderViewHost* rvh = web_contents_->GetRenderViewHost();
DCHECK(rvh);
rvh->OnWebkitPreferencesChanged();
}
} // namespace content
......@@ -256,6 +256,9 @@ class CONTENT_EXPORT WebContentsAndroid {
int left,
int bottom,
int right);
void NotifyRendererPreferenceUpdate(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
......
......@@ -958,6 +958,12 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi
mNativeWebContentsAndroid, insets.top, insets.left, insets.bottom, insets.right);
}
@Override
public void notifyRendererPreferenceUpdate() {
if (mNativeWebContentsAndroid == 0) return;
nativeNotifyRendererPreferenceUpdate(mNativeWebContentsAndroid);
}
private void checkNotDestroyed() {
if (mNativeWebContentsAndroid != 0) return;
throw new IllegalStateException(
......@@ -1050,5 +1056,6 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi
private native void nativeSetFocus(long nativeWebContentsAndroid, boolean focused);
private native void nativeSetDisplayCutoutSafeArea(
long nativeWebContentsAndroid, int top, int left, int bottom, int right);
private native void nativeNotifyRendererPreferenceUpdate(long nativeWebContentsAndroid);
private native boolean nativeIsBeingDestroyed(long nativeWebContentsAndroid);
}
......@@ -494,4 +494,9 @@ public interface WebContents extends Parcelable {
* @param insets The insets stored in a Rect.
*/
void setDisplayCutoutSafeArea(Rect insets);
/**
* Notify that web preferences needs update for various properties.
*/
void notifyRendererPreferenceUpdate();
}
......@@ -274,4 +274,7 @@ public class MockWebContents implements WebContents {
@Override
public void setDisplayCutoutSafeArea(Rect insets) {}
@Override
public void notifyRendererPreferenceUpdate() {}
}
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