New issue
Advanced search Search tips

Issue 884597 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

WebContents API getUserData/setUserData

Project Member Reported by jinsuk...@chromium.org, Sep 17

Issue description

I'm thinking of adding new public API's {get|set}UserData in WebContents. It used to be present but got removed by https://crrev.com/c/1159559 as there was no use case found up to that time. 

But recently found a couple of use cases for it in Chrome - namely TabGestureStateListener (https://crrev.com/c/1215428), SwipeRefreshHandler (https://crrev.com/c/1227862) Being designed as Tab's UserData, their lifetime actually coincide with that of WebContents, so they should ideally be WebContents' UserData. The new API will allow them to define a new UserData, and get/set them.

The new API doesn't mean that embedders can access random WebContents' UserData objects defined for internal purpose only since they use private class literals (WindowObserverListenerManagerImpl.class, for instance) not visible outside the content layer.

boliu@ wdyt?


 
sgtm. expose the API in the same CL that adds the embedder use case
Status: Assigned (was: Available)
I was hoping the new API would make it easy to manage the objects of WebContents lifecycle created by a Tab using |destroy()| but just realized that WebContents doesn't invoke the method on its UserDataHost...

Alternatively, Tab could define its own UserDataHost dedicated for WebContents for these objects, rather than relying on WebContents-internal UserDataHost accessible via the proposed API. Calling |destroy| on this UserDataHost will work since Tab knows when its the objects need to be destroyed.

This requires that Tab manage 2 UserDataHost instances - one for those of Tab's lifecycle, the other for WebContents'. I think it will be desirable to have compile-time check in place to avoid the two different UserData types being mixed by confusion.

Classes that can be Tab's WebContents UserData:
 - TabGestureStateListener
 - SwipeRefreshHandler
 - TabWebContentsObserver
 - ContentView (maybe)
 - TabWebContentsDelegateAndroid

Project Member

Comment 3 by bugdroid1@chromium.org, Oct 4

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8151f1dd4e49750fbb301f5ad04989e42377884a

commit 8151f1dd4e49750fbb301f5ad04989e42377884a
Author: Jinsuk Kim <jinsukkim@chromium.org>
Date: Thu Oct 04 05:35:48 2018

Android: TabWebContentsUserData

Tab is managing numerous classes used for the active WebContents
it is showing. This CL defines a TabWebContentsUserData that they
can inherit from. New interface initWebContents/cleanupWebContents
are to be defined by child classes.

It is first applied to TabGestureStateListener. The other classes
will follow.

Bug: 884597
Change-Id: I7d31b5a2d4c64aef49697fb0bbe8e3db4e3b2443
Reviewed-on: https://chromium-review.googlesource.com/c/1229734
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596515}
[modify] https://crrev.com/8151f1dd4e49750fbb301f5ad04989e42377884a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
[modify] https://crrev.com/8151f1dd4e49750fbb301f5ad04989e42377884a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabGestureStateListener.java
[add] https://crrev.com/8151f1dd4e49750fbb301f5ad04989e42377884a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsUserData.java
[modify] https://crrev.com/8151f1dd4e49750fbb301f5ad04989e42377884a/chrome/android/java_sources.gni

Sign in to add a comment