Index: chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
index 2f573f6189295b7ac05c85ae2d4a2a1fbea1ffff..23975fa627135516c4512f03d666c1899273fd39 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
@@ -106,6 +106,7 @@ import org.chromium.printing.PrintingController; |
import org.chromium.printing.PrintingControllerImpl; |
import org.chromium.ui.base.LocalizationUtils; |
import org.chromium.ui.base.PageTransition; |
+import org.chromium.ui.base.ViewRoot; |
import org.chromium.ui.base.WindowAndroid; |
import org.chromium.ui.mojom.WindowOpenDisposition; |
@@ -162,6 +163,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
*/ |
private final Context mThemedApplicationContext; |
+ /** {@link ViewRoot} used to forward input/view events down to native. */ |
+ private ViewRoot mViewRoot; |
+ |
/** Gives {@link Tab} a way to interact with the Android window. */ |
private WindowAndroid mWindowAndroid; |
@@ -474,10 +478,10 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* |
* @param id The id this tab should be identified with. |
* @param incognito Whether or not this tab is incognito. |
- * @param window An instance of a {@link WindowAndroid}. |
+ * @param viewRoot An instance of a {@link ViewRoot}. |
*/ |
- public Tab(int id, boolean incognito, WindowAndroid window) { |
- this(id, INVALID_TAB_ID, incognito, null, window, null, null, null); |
+ public Tab(int id, boolean incognito, ViewRoot viewRoot) { |
+ this(id, INVALID_TAB_ID, incognito, null, viewRoot, null, null, null); |
} |
/** |
@@ -490,21 +494,21 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* @param parentId The id id of the tab that caused this tab to be opened. |
* @param incognito Whether or not this tab is incognito. |
* @param context An instance of a {@link Context}. |
- * @param window An instance of a {@link WindowAndroid}. |
+ * @param viewRoot An instance of a {@link ViewRoot}. |
* @param creationState State in which the tab is created, needed to initialize TabUma |
* accounting. When null, TabUma will not be initialized. |
* @param frozenState State containing information about this Tab, if it was persisted. |
*/ |
@SuppressLint("HandlerLeak") |
- public Tab(int id, int parentId, boolean incognito, Context context, |
- WindowAndroid window, TabLaunchType type, TabCreationState creationState, |
- TabState frozenState) { |
+ public Tab(int id, int parentId, boolean incognito, Context context, ViewRoot viewRoot, |
+ TabLaunchType type, TabCreationState creationState, TabState frozenState) { |
mId = TabIdManager.getInstance().generateValidId(id); |
mParentId = parentId; |
mIncognito = incognito; |
mThemedApplicationContext = context != null ? new ContextThemeWrapper( |
context.getApplicationContext(), ChromeActivity.getThemeId()) : null; |
- mWindowAndroid = window; |
+ mViewRoot = viewRoot; |
+ mWindowAndroid = viewRoot != null ? viewRoot.getWindowAndroid() : null; |
mLaunchType = type; |
if (mThemedApplicationContext != null) { |
Resources resources = mThemedApplicationContext.getResources(); |
@@ -1400,7 +1404,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
// TODO(yusufo): We can't call updateWindowAndroid here and set mWindowAndroid to null |
// because many code paths (including navigation) expect the tab to always be associated |
// with an activity, and will crash. crbug.com/657007 |
- if (mContentViewCore != null) mContentViewCore.updateWindowAndroid(null); |
+ if (mContentViewCore != null) mContentViewCore.updateViewRoot(null); |
attachTabContentManager(null); |
} |
@@ -1422,7 +1426,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
// TODO(yusufo): Share these calls with the construction related calls. |
// crbug.com/590281 |
- updateWindowAndroid(activity.getWindowAndroid()); |
+ updateViewRoot(activity.getViewRoot()); |
// Update for the controllers that need the Compositor from the new Activity. |
attachTabContentManager(activity.getTabContentManager()); |
@@ -1454,14 +1458,15 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
} |
/** |
- * Update and propagate the new WindowAndroid. |
- * @param windowAndroid The WindowAndroid to propagate. |
+ * Update and propagate the new ViewRoot and the accompanying WindowAndroid. |
+ * @param viewRoot The viewRoot to update. |
*/ |
- public void updateWindowAndroid(WindowAndroid windowAndroid) { |
+ public void updateViewRoot(ViewRoot viewRoot) { |
// TODO(yusufo): mWindowAndroid can never be null until crbug.com/657007 is fixed. |
- assert windowAndroid != null; |
- mWindowAndroid = windowAndroid; |
- if (mContentViewCore != null) mContentViewCore.updateWindowAndroid(mWindowAndroid); |
+ assert viewRoot.getWindowAndroid() != null; |
+ mViewRoot = viewRoot; |
+ mWindowAndroid = viewRoot.getWindowAndroid(); |
+ if (mContentViewCore != null) mContentViewCore.updateViewRoot(viewRoot); |
} |
/** |
@@ -1500,6 +1505,13 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
} |
/** |
+ * @return @{@link ViewRoot} instance used to forward view/input events. |
+ */ |
+ public ViewRoot getViewRoot() { |
+ return mViewRoot; |
+ } |
+ |
+ /** |
* Called when a navigation begins and no navigation was in progress |
* @param toDifferentDocument Whether this navigation will transition between |
* documents (i.e., not a fragment navigation or JS History API call). |
@@ -1594,8 +1606,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc); |
cv.setContentDescription(mThemedApplicationContext.getResources().getString( |
R.string.accessibility_content_view)); |
- cvc.initialize(new TabViewAndroidDelegate(this, cv), cv, webContents, |
- getWindowAndroid()); |
+ cvc.initialize(new TabViewAndroidDelegate(this, cv), cv, webContents, mViewRoot); |
ChromeActionModeCallback actionModeCallback = new ChromeActionModeCallback( |
mThemedApplicationContext, this, cvc.getActionModeCallbackHelper()); |
cvc.setActionModeCallback(actionModeCallback); |
@@ -2845,12 +2856,11 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* on cold start that should be loaded when switched to. initialize() needs to be called |
* afterwards to complete the second level initialization. |
*/ |
- public static Tab createFrozenTabFromState( |
- int id, ChromeActivity activity, boolean incognito, |
- WindowAndroid nativeWindow, int parentId, TabState state) { |
+ public static Tab createFrozenTabFromState(int id, ChromeActivity activity, boolean incognito, |
+ ViewRoot viewRoot, int parentId, TabState state) { |
assert state != null; |
- return new Tab(id, parentId, incognito, activity, nativeWindow, |
- TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, state); |
+ return new Tab(id, parentId, incognito, activity, viewRoot, TabLaunchType.FROM_RESTORE, |
+ TabCreationState.FROZEN_ON_RESTORE, state); |
} |
/** |
@@ -2890,10 +2900,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* complete the second level initialization. |
*/ |
public static Tab createTabForLazyLoad(ChromeActivity activity, boolean incognito, |
- WindowAndroid nativeWindow, TabLaunchType type, int parentId, |
- LoadUrlParams loadUrlParams) { |
- Tab tab = new Tab( |
- INVALID_TAB_ID, parentId, incognito, activity, nativeWindow, type, |
+ ViewRoot viewRoot, TabLaunchType type, int parentId, LoadUrlParams loadUrlParams) { |
+ Tab tab = new Tab(INVALID_TAB_ID, parentId, incognito, activity, viewRoot, type, |
TabCreationState.FROZEN_FOR_LAZY_LOAD, null); |
tab.setPendingLoadParams(loadUrlParams); |
return tab; |
@@ -2905,10 +2913,11 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* @param initiallyHidden true iff the tab being created is initially in background |
*/ |
public static Tab createLiveTab(int id, ChromeActivity activity, boolean incognito, |
- WindowAndroid nativeWindow, TabLaunchType type, int parentId, boolean initiallyHidden) { |
- return new Tab(id, parentId, incognito, activity, nativeWindow, type, initiallyHidden |
- ? TabCreationState.LIVE_IN_BACKGROUND |
- : TabCreationState.LIVE_IN_FOREGROUND, null); |
+ ViewRoot viewRoot, TabLaunchType type, int parentId, boolean initiallyHidden) { |
+ return new Tab(id, parentId, incognito, activity, viewRoot, type, |
+ initiallyHidden ? TabCreationState.LIVE_IN_BACKGROUND |
+ : TabCreationState.LIVE_IN_FOREGROUND, |
+ null); |
} |
/** |