Commit dfc2af94 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Unfork weblayer ContentView

WebLayer forked ContentView for expediency, and now we are unforking it.
Features that are added to ContentView in components:
* support for using EventOffsetHandler with ContentView
* ability to set and change WebContents later
* setIsObscuredForAccessibility to disable accessibility

Features kept in weblayer:
* autofill

Note also ContentView is now a FrameLayout, which does not matter to
weblayer since weblayer does not add child views to ContentView anymore.

Change-Id: I995aad7a3cd9c4a6d8f819d9fd9080548e14cd75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213064Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771976}
parent f3327971
...@@ -328,7 +328,8 @@ public class OverlayPanelContent { ...@@ -328,7 +328,8 @@ public class OverlayPanelContent {
// Creates an initially hidden WebContents which gets shown when the panel is opened. // Creates an initially hidden WebContents which gets shown when the panel is opened.
mWebContents = WebContentsFactory.createWebContents(mIsIncognito, true); mWebContents = WebContentsFactory.createWebContents(mIsIncognito, true);
ContentView cv = ContentView.createContentView(mActivity, mWebContents); ContentView cv = ContentView.createContentView(
mActivity, null /* eventOffsetHandler */, mWebContents);
if (mContentViewWidth != 0 || mContentViewHeight != 0) { if (mContentViewWidth != 0 || mContentViewHeight != 0) {
int width = mContentViewWidth == 0 ? ContentView.DEFAULT_MEASURE_SPEC int width = mContentViewWidth == 0 ? ContentView.DEFAULT_MEASURE_SPEC
: MeasureSpec.makeMeasureSpec(mContentViewWidth, MeasureSpec.EXACTLY); : MeasureSpec.makeMeasureSpec(mContentViewWidth, MeasureSpec.EXACTLY);
......
...@@ -194,7 +194,8 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener { ...@@ -194,7 +194,8 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
// Creates an initially hidden WebContents which gets shown when the panel is opened. // Creates an initially hidden WebContents which gets shown when the panel is opened.
mWebContents = WebContentsFactory.createWebContents(incognito, true); mWebContents = WebContentsFactory.createWebContents(incognito, true);
mContentView = ContentView.createContentView(mContext, mWebContents); mContentView = ContentView.createContentView(
mContext, null /* eventOffsetHandler */, mWebContents);
mWebContents.initialize(ChromeVersionInfo.getProductVersion(), mWebContents.initialize(ChromeVersionInfo.getProductVersion(),
ViewAndroidDelegate.createBasicDelegate(mContentView), mContentView, mWindow, ViewAndroidDelegate.createBasicDelegate(mContentView), mContentView, mWindow,
......
...@@ -80,7 +80,8 @@ public class PaymentHandlerCoordinator { ...@@ -80,7 +80,8 @@ public class PaymentHandlerCoordinator {
assert mHider == null : "Already showing payment-handler UI"; assert mHider == null : "Already showing payment-handler UI";
mWebContents = WebContentsFactory.createWebContents(isIncognito, /*initiallyHidden=*/false); mWebContents = WebContentsFactory.createWebContents(isIncognito, /*initiallyHidden=*/false);
ContentView webContentView = ContentView.createContentView(activity, mWebContents); ContentView webContentView = ContentView.createContentView(
activity, null /* eventOffsetHandler */, mWebContents);
initializeWebContents(activity, webContentView, webContentsObserver, url); initializeWebContents(activity, webContentView, webContentsObserver, url);
mToolbarCoordinator = new PaymentHandlerToolbarCoordinator(activity, mWebContents, url); mToolbarCoordinator = new PaymentHandlerToolbarCoordinator(activity, mWebContents, url);
......
...@@ -1262,7 +1262,8 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer { ...@@ -1262,7 +1262,8 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
WebContents oldWebContents = mWebContents; WebContents oldWebContents = mWebContents;
mWebContents = webContents; mWebContents = webContents;
ContentView cv = ContentView.createContentView(mThemedApplicationContext, webContents); ContentView cv = ContentView.createContentView(
mThemedApplicationContext, null /* eventOffsetHandler */, webContents);
cv.setContentDescription(mThemedApplicationContext.getResources().getString( cv.setContentDescription(mThemedApplicationContext.getResources().getString(
R.string.accessibility_content_view)); R.string.accessibility_content_view));
mContentView = cv; mContentView = cv;
......
...@@ -99,7 +99,8 @@ public class ContextualSearchTapEventTest { ...@@ -99,7 +99,8 @@ public class ContextualSearchTapEventTest {
super(activity, null); super(activity, null);
setSelectionController(new MockCSSelectionController(activity, this)); setSelectionController(new MockCSSelectionController(activity, this));
WebContents webContents = WebContentsFactory.createWebContents(false, false); WebContents webContents = WebContentsFactory.createWebContents(false, false);
ContentView cv = ContentView.createContentView(activity, webContents); ContentView cv = ContentView.createContentView(
activity, null /* eventOffsetHandler */, webContents);
webContents.initialize(null, ViewAndroidDelegate.createBasicDelegate(cv), null, webContents.initialize(null, ViewAndroidDelegate.createBasicDelegate(cv), null,
activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder()); activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder());
SelectionPopupController selectionPopupController = SelectionPopupController selectionPopupController =
......
...@@ -100,7 +100,8 @@ public class SelectPopupOtherContentViewTest { ...@@ -100,7 +100,8 @@ public class SelectPopupOtherContentViewTest {
WebContents webContents = WebContentsFactory.createWebContents(false, false); WebContents webContents = WebContentsFactory.createWebContents(false, false);
ChromeActivity activity = mActivityTestRule.getActivity(); ChromeActivity activity = mActivityTestRule.getActivity();
ContentView cv = ContentView.createContentView(activity, webContents); ContentView cv = ContentView.createContentView(
activity, null /* eventOffsetHandler */, webContents);
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(cv), cv,
activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder()); activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder());
webContents.destroy(); webContents.destroy();
......
...@@ -69,7 +69,8 @@ class CastWebContentsScopes { ...@@ -69,7 +69,8 @@ class CastWebContentsScopes {
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
layout.addView(contentViewRenderView, matchParent); layout.addView(contentViewRenderView, matchParent);
ContentView contentView = ContentView.createContentView(context, webContents); ContentView contentView = ContentView.createContentView(
context, null /* eventOffsetHandler */, webContents);
WebContentsRegistry.initializeWebContents(webContents, contentView, window); WebContentsRegistry.initializeWebContents(webContents, contentView, window);
// Enable display of current webContents. // Enable display of current webContents.
...@@ -93,7 +94,8 @@ class CastWebContentsScopes { ...@@ -93,7 +94,8 @@ class CastWebContentsScopes {
public static Observer<WebContents> withoutLayout(Context context) { public static Observer<WebContents> withoutLayout(Context context) {
return (WebContents webContents) -> { return (WebContents webContents) -> {
WindowAndroid window = new WindowAndroid(context); WindowAndroid window = new WindowAndroid(context);
ContentView contentView = ContentView.createContentView(context, webContents); ContentView contentView = ContentView.createContentView(
context, null /* eventOffsetHandler */, webContents);
WebContentsRegistry.initializeWebContents(webContents, contentView, window); WebContentsRegistry.initializeWebContents(webContents, contentView, window);
// Enable display of current webContents. // Enable display of current webContents.
webContents.onShow(); webContents.onShow();
......
...@@ -294,7 +294,8 @@ public class Shell extends LinearLayout { ...@@ -294,7 +294,8 @@ public class Shell extends LinearLayout {
@CalledByNative @CalledByNative
private void initFromNativeTabContents(WebContents webContents) { private void initFromNativeTabContents(WebContents webContents) {
Context context = getContext(); Context context = getContext();
ContentView cv = ContentView.createContentView(context, webContents); ContentView cv =
ContentView.createContentView(context, null /* eventOffsetHandler */, webContents);
mViewAndroidDelegate = new ShellViewAndroidDelegate(cv); mViewAndroidDelegate = new ShellViewAndroidDelegate(cv);
assert (mWebContents != webContents); assert (mWebContents != webContents);
if (mWebContents != null) mWebContents.clearNativeReference(); if (mWebContents != null) mWebContents.clearNativeReference();
......
...@@ -67,8 +67,8 @@ android_library("java") { ...@@ -67,8 +67,8 @@ android_library("java") {
"org/chromium/weblayer_private/BrowserImpl.java", "org/chromium/weblayer_private/BrowserImpl.java",
"org/chromium/weblayer_private/BrowserViewController.java", "org/chromium/weblayer_private/BrowserViewController.java",
"org/chromium/weblayer_private/ChildProcessServiceImpl.java", "org/chromium/weblayer_private/ChildProcessServiceImpl.java",
"org/chromium/weblayer_private/ContentView.java",
"org/chromium/weblayer_private/ContentViewRenderView.java", "org/chromium/weblayer_private/ContentViewRenderView.java",
"org/chromium/weblayer_private/ContentViewWithAutofill.java",
"org/chromium/weblayer_private/CookieManagerImpl.java", "org/chromium/weblayer_private/CookieManagerImpl.java",
"org/chromium/weblayer_private/CrashReporterControllerImpl.java", "org/chromium/weblayer_private/CrashReporterControllerImpl.java",
"org/chromium/weblayer_private/DownloadCallbackProxy.java", "org/chromium/weblayer_private/DownloadCallbackProxy.java",
...@@ -130,6 +130,7 @@ android_library("java") { ...@@ -130,6 +130,7 @@ android_library("java") {
"//components/download/internal/common:internal_java", "//components/download/internal/common:internal_java",
"//components/embedder_support/android:application_java", "//components/embedder_support/android:application_java",
"//components/embedder_support/android:browser_context_java", "//components/embedder_support/android:browser_context_java",
"//components/embedder_support/android:content_view_java",
"//components/embedder_support/android:context_menu_java", "//components/embedder_support/android:context_menu_java",
"//components/embedder_support/android:util_java", "//components/embedder_support/android:util_java",
"//components/embedder_support/android:web_contents_delegate_java", "//components/embedder_support/android:web_contents_delegate_java",
......
...@@ -17,6 +17,7 @@ import android.widget.RelativeLayout; ...@@ -17,6 +17,7 @@ import android.widget.RelativeLayout;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.components.browser_ui.modaldialog.AppModalPresenter; import org.chromium.components.browser_ui.modaldialog.AppModalPresenter;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
...@@ -73,7 +74,7 @@ public final class BrowserViewController ...@@ -73,7 +74,7 @@ public final class BrowserViewController
mBottomControlsContainerView = mBottomControlsContainerView =
new BrowserControlsContainerView(context, mContentViewRenderView, this, false); new BrowserControlsContainerView(context, mContentViewRenderView, this, false);
mBottomControlsContainerView.setId(View.generateViewId()); mBottomControlsContainerView.setId(View.generateViewId());
mContentView = ContentView.createContentView( mContentView = ContentViewWithAutofill.createContentView(
context, mTopControlsContainerView.getEventOffsetHandler()); context, mTopControlsContainerView.getEventOffsetHandler());
mContentViewRenderView.addView(mContentView, mContentViewRenderView.addView(mContentView,
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
...@@ -147,7 +148,7 @@ public final class BrowserViewController ...@@ -147,7 +148,7 @@ public final class BrowserViewController
mGestureStateTracker = mGestureStateTracker =
new WebContentsGestureStateTracker(mContentView, webContents, this); new WebContentsGestureStateTracker(mContentView, webContents, this);
} }
mContentView.setTab(mTab); mContentView.setWebContents(webContents);
mContentViewRenderView.setWebContents(webContents); mContentViewRenderView.setWebContents(webContents);
mTopControlsContainerView.setWebContents(webContents); mTopControlsContainerView.setWebContents(webContents);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer_private;
import android.content.Context;
import android.os.Build;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewStructure;
import android.view.autofill.AutofillValue;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.EventOffsetHandler;
/**
* API level 26 implementation that includes autofill.
*/
public class ContentViewWithAutofill extends ContentView.ContentViewApi23 {
public static ContentView createContentView(
Context context, EventOffsetHandler eventOffsetHandler) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return new ContentViewWithAutofill(context, eventOffsetHandler);
}
return ContentView.createContentView(context, eventOffsetHandler, null /* webContents */);
}
private TabImpl mTab;
private ContentViewWithAutofill(Context context, EventOffsetHandler eventOffsetHandler) {
super(context, eventOffsetHandler, null /* webContents */);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// The Autofill system-level infrastructure has heuristics for which Views it considers
// important for autofill; only these Views will be queried for their autofill
// structure on notifications that a new (virtual) View was entered. By default,
// FrameLayout is not considered important for autofill. Thus, for ContentView to be
// queried for its autofill structure, we must explicitly inform the autofill system
// that this View is important for autofill.
setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_YES);
}
}
@Override
public void setWebContents(WebContents webContents) {
mTab = TabImpl.fromWebContents(webContents);
super.setWebContents(webContents);
}
@Override
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
// A new (virtual) View has been entered, and the autofill system-level
// infrastructure wants us to populate |structure| with the autofill structure of the
// (virtual) View. Forward this on to TabImpl to accomplish.
if (mTab != null) {
mTab.onProvideAutofillVirtualStructure(structure, flags);
}
}
@Override
public void autofill(final SparseArray<AutofillValue> values) {
// The autofill system-level infrastructure has information that we can use to
// autofill the current (virtual) View. Forward this on to TabImpl to
// accomplish.
if (mTab != null) {
mTab.autofill(values);
}
}
}
...@@ -167,6 +167,11 @@ public final class TabImpl extends ITab.Stub { ...@@ -167,6 +167,11 @@ public final class TabImpl extends ITab.Stub {
} }
} }
public static TabImpl fromWebContents(WebContents webContents) {
if (webContents == null || webContents.isDestroyed()) return null;
return TabImplJni.get().fromWebContents(webContents);
}
public static TabImpl getTabById(int tabId) { public static TabImpl getTabById(int tabId) {
return sTabMap.get(tabId); return sTabMap.get(tabId);
} }
...@@ -784,6 +789,7 @@ public final class TabImpl extends ITab.Stub { ...@@ -784,6 +789,7 @@ public final class TabImpl extends ITab.Stub {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
TabImpl fromWebContents(WebContents webContents);
long createTab(long profile, TabImpl caller); long createTab(long profile, TabImpl caller);
void setJavaImpl(long nativeTabImpl, TabImpl impl); void setJavaImpl(long nativeTabImpl, TabImpl impl);
void onAutofillProviderChanged(long nativeTabImpl, AutofillProvider autofillProvider); void onAutofillProviderChanged(long nativeTabImpl, AutofillProvider autofillProvider);
......
...@@ -211,6 +211,18 @@ void OnScreenShotCaptured(const ScopedJavaGlobalRef<jobject>& value_callback, ...@@ -211,6 +211,18 @@ void OnScreenShotCaptured(const ScopedJavaGlobalRef<jobject>& value_callback,
} // namespace } // namespace
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
static ScopedJavaLocalRef<jobject> JNI_TabImpl_FromWebContents(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& j_web_contents) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(j_web_contents);
TabImpl* tab = TabImpl::FromWebContents(web_contents);
if (tab)
return ScopedJavaLocalRef<jobject>(tab->GetJavaTab());
return nullptr;
}
TabImpl::TabImpl(ProfileImpl* profile, const JavaParamRef<jobject>& java_impl) TabImpl::TabImpl(ProfileImpl* profile, const JavaParamRef<jobject>& java_impl)
: TabImpl(profile) { : TabImpl(profile) {
java_impl_ = java_impl; java_impl_ = java_impl;
......
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