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