New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 709627 link

Starred by 6 users

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Feature



Sign in to add a comment

Android WebView retains visited link list after clearHistory(), doesn't offer any other API to clear it

Reported by ah...@mozilla.com, Apr 7 2017

Issue description

Steps to reproduce the problem:
1. Create a WebView, open to e.g. https://nytimes.com
2. Click on any link
3. Call WebView.clearHistory()
4. (Optional: remove the WebView from your View hierarchy, create a new WebView.)
5. Reopen "http://nytimes.com"

What is the expected behavior?
The link you clicked on in step 1 should not appear visited.

What went wrong?
The link opened in step 1 is coloured as visited.

See the circled link in the attached screenshot: the text should be black (unvisited link), and not grey (visited link).

Did this work before? No 

Chrome version:   Channel: stable
OS Version: 
Flash Version: 

We have code which does this as part of Mozilla's Focus for Android app (currently unreleased): We use WebView as part of a fragment. When that fragment is removed, we call a cleanup method which lives at:
https://github.com/mozilla-mobile/focus-android/blob/a172571ea508bb6aee5bf7e76a225bcfb2727f61/app/src/webkit/java/org/mozilla/focus/web/WebViewProvider.java#L248
The user expects _all_ data to be cleared when this happens, however they will still see links they previously visited being coloured - the app needs to be completely killed (i.e. process restarted) for link colouring to be reset.

The visited link list is stored as part of AwBrowserContext, on the C++ side.:
https://chromium.googlesource.com/chromium/src.git/+/03a0356e4e8839701627209ce25c0edaeca3a10f/android_webview/browser/aw_browser_context.h#143
This list can only be appended to using WebChromeClient.getVisitedHistory() (which only appears to be called when creating a new WebView, and doesn't clear the existing history list) - that ends up in:
https://chromium.googlesource.com/chromium/src.git/+/03a0356e4e8839701627209ce25c0edaeca3a10f/android_webview/browser/aw_browser_context.cc#222

There doesn't appear to be any java-side API to explicitly clear that list. Clearing it as part of WebView.clearHistory() is possibly the most obvious (although that would affect any other webviews that are currently running, but that's probably not unexpected if clearing history). Perhaps the visited link list could be cleared when creating a new webview (i.e. clear the list, and only add what getVisitedHistory() supplies - but that would affect all applications that use multiple WebViews. Adding a new "clearVisitedLinksList()" would perhaps be cleanest, but I'm guessing that requires a new Android release and would therefore only be supported on newer devices (which would be less than ideal for the purposed of Focus).

(In any case, it seems to be impossible to clear the visited links list while the app is running, short of running an Activity in a separate process, and killing that Activity and Process every time you want to clear the list of visited links. Even when using reflection, there's no way to get at the list since it's on the C++ side.)
 
webview_visited.png
384 KB View Download

Comment 1 by ah...@mozilla.com, Apr 7 2017

Sorry I messed up the title. It should be something along the lines of "Android WebView retains visited link list after clearHistory(), doesn't offer any other API to clear it".
Components: Mobile>WebView
Cc: gsennton@chromium.org torne@chromium.org
Labels: -Pri-2 Pri-3
Hmm, do we only have one AwBrowserContext per process? Then it seems strange to store visited-links in there.
Torne, do you have any thoughts here?

Comment 4 by torne@chromium.org, Jun 16 2017

Summary: Android WebView retains visited link list after clearHistory(), doesn't offer any other API to clear it (was: WebView retains visited link list aftert)
It's not weird to store it in AwBrowserContext - that's the WebView equivalent of Profile in Chrome, which is where the visited link history lives there, and in a browser-like app it's expected that visited links are global. The unexpected thing here is actually that killing the process will clear it - probably just because we haven't bothered implementing persisting it to disk. If we'd copied Chrome more closely here then even restarting the process wouldn't clear it, but our implementation relies on the embedding app to do this persistence if it wants it (which is why the ability to add things to the list exists).

I'm not sure clearing it when a single WebView's history is cleared makes sense; I think it'd be surprising to have a piece of global state be affected by a webview-specific call that never previously behaved that way. (do any CTS tests actually cover this behaviour closely enough to be affected?)

We should add a real API for this, but as you say that won't make it possible to clear it on existing OS versions; I think that since it's not written to disk this probably isn't enough of a privacy issue to justify a breaking behaviour change.

-

This also raises the more general fact that it's pretty hard to clear all browsing state in WebView - you have to call a bunch of different methods, there's no documented list of them, and even calling all of the ones that exist doesn't guarantee nothing else is retained (as this bug demonstrates). Maybe we should also have a single method to do this, equivalent to "clear browsing data" in Chrome? Though we'd still have to make sure everything was actually hooked up to it..

Comment 5 by s.kasp...@gmail.com, Jul 21 2017

With all the clear and settings method on a WebView instance (as opposed to something like static methods on the class) I was expecting that this state is not shared between instances.

There's already a method (getVisitedHistory() in WebChromeClient) to backfill the cache for link coloring. So I do not agree that the "actual bug" is that this data is not persisted. Isn't keeping track of the history something for the application level and dependent on the use cases?

Regarding missing "clear" methods: We noticed this too. There's more data persisted (like service workers) that cannot be cleared via methods.

While I would like to see more options for clearing, I also fear that this would only be available for developers with a new Android versions and a WebView interface change?

Is there any path forward here?

Comment 6 by torne@chromium.org, Jul 21 2017

WebView's API designs are not very consistent about what's the app's responsibility vs what's WebView's, unfortunately - this is a legacy of it being originally part of Browser and the split between what functionality was in WebView vs in Browser not being particularly well defined. For compatibility we're stuck with existing APIs working pretty much how they happen to work, in most cases (it's hard to prove that intentional behavioural changes aren't going to break existing app use cases). So, yes, you can point to lots of things that don't really make sense or aren't consistent, but.. that's just how it is. :/

You are correct that any improvements we make here are likely to only apply to new Android versions with a WebView interface change. However, we're trying to fix that situation as well: we're attempting to develop a support library that will give you access to some new APIs on older Android versions (back to L only), as long as the device has a new enough WebView version. If we're able to solve that then adding new APIs to deal with cases like this is more viable.

Comment 7 by s.kasp...@gmail.com, Jul 21 2017

Moving new functionality in a support library sounds like a great plan (I guess this is another advantage of using Chrome as WebView provider?). I'm looking forward to it and hope it's not too far away. :-)

As link coloring is a visual indicator that the URL has been visited before: Wouldn't it be expected that the (already existing) clearHistory() method clears this memory cache that is responsible for link coloring too? Is this a fix that is also considered too risky and potentially breaking existing apps (Hard to imagine why an app requires link coloring without history)?

Comment 8 by torne@chromium.org, Jul 21 2017

It's an advantage of the WebView being a separately updateable component; it doesn't have anything to do with Chrome.

As I said in earlier comments I don't think it makes sense to clear a piece of global state (visited link cache) when you ask to clear the history of one particular webview. There isn't a "clear all history" API in WebView right now; if there was then it would make sense for it to also clear the visited link cache.
Cc: ntfschr@chromium.org
> Maybe we should also have a single method to do this, equivalent to "clear browsing data" in Chrome? Though we'd still have to make sure everything was actually hooked up to it..

Reasonable suggestion. I think there may be value in fine-grained control (multiple clearFoo() APIs), and just request that apps call all of them (documentation is easy). Either way (one big API or multiple small APIs), we definitely should cover all things to clear.
I'm not sure that we can reasonably do that - Chrome doesn't really work this way, and so when new things are introduced I think we're likely to miss them. I would guess that our best chance of having reliable data-clearing APIs would be to imitate the Chrome "clear browsing data" feature as much as possible and reuse the plumbing in content, since that's more likely to do the right thing as the engine evolves. Our current different distinctions of what you can clear already don't match up with that, I think..
 ntfschr@, are you planning to add this functionality in the support library?
Status: Available (was: Unconfirmed)
No, we cannot add APIs straight into the support library, they must first become android.webkit APIs. We have no definite plans to add an API for this.

---

Passing this to the pool of available bugs. This is probably a good API to add. Unfortunately, I don't think we have bandwidth to add such an API for P.
Project Member

Comment 13 by sheriffbot@chromium.org, Nov 21

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Labels: -Type-Bug Type-Feature

Sign in to add a comment