Commit 6bd9422b authored by Mehran Mahmoudi's avatar Mehran Mahmoudi Committed by Commit Bot

[Touchless] Fix progress bar loading issue

This fixes the following issues:
1. For some websites, the progress bar resets back to 0
while loading the website.
2. For some websites, the progress bar doesn't hide after
loading is complete.

Bug: 982881,982898
Change-Id: I1b82c7cb66133ba018540c259641629505c818ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1696382
Commit-Queue: Mehran Mahmoudi <mahmoudi@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676419}
parent ee26c080
......@@ -28,6 +28,7 @@ public class ProgressBarMediator {
private boolean mSkipShowingOnNextActivityStart;
private static final int MINIMUM_DISPLAY_DURATION_MS = 3 * 1000;
private static final int MAXIMUM_PROGRESS = 100;
ProgressBarMediator(PropertyModel model, ActivityTabProvider activityTabProvider) {
mProgressBarTabObserver = new ProgressBarTabObserver(activityTabProvider);
......@@ -73,11 +74,16 @@ public class ProgressBarMediator {
show();
}
private void stopLoadProgress() {
private void finishLoadProgress() {
mCanHideProgressBar = true;
hide();
}
private void updateLoadProgress(int progress) {
mModel.set(ProgressBarProperties.PROGRESS_FRACTION, progress / ((float) MAXIMUM_PROGRESS));
if (progress == MAXIMUM_PROGRESS) finishLoadProgress();
}
void destroy() {
if (mHideTask != null) mHideTask.cancel(false);
mProgressBarTabObserver.destroy();
......@@ -94,15 +100,23 @@ public class ProgressBarMediator {
public void onDidStartNavigation(Tab tab, NavigationHandle navigation) {
if (!navigation.isInMainFrame()) return;
if (tab.getWebContents() != null
&& tab.getWebContents().getNavigationController() != null
&& tab.getWebContents().getNavigationController().isInitialNavigation()) {
updateUrl(tab);
}
if (navigation.isSameDocument()) return;
if (NativePageFactory.isNativePageUrl(navigation.getUrl(), tab.isIncognito())) {
mModel.set(ProgressBarProperties.IS_ENABLED, false);
stopLoadProgress();
finishLoadProgress();
return;
}
mModel.set(ProgressBarProperties.IS_ENABLED, true);
updateUrl(tab);
startLoadProgress();
updateLoadProgress(tab.getProgress());
}
@Override
......@@ -117,15 +131,21 @@ public class ProgressBarMediator {
@Override
public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
updateUrl(tab);
stopLoadProgress();
if (!toDifferentDocument) return;
// If we made some progress, fast-forward to complete.
if (tab.getProgress() < MAXIMUM_PROGRESS) {
updateLoadProgress(MAXIMUM_PROGRESS);
} else {
finishLoadProgress();
}
}
@Override
public void onLoadProgressChanged(Tab tab, int progress) {
if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito())) return;
mModel.set(ProgressBarProperties.PROGRESS_FRACTION, progress / 100f);
updateLoadProgress(progress);
}
@Override
......@@ -133,12 +153,12 @@ public class ProgressBarMediator {
if (!didStartLoad) return;
updateUrl(tab);
if (didFinishLoad) stopLoadProgress();
if (didFinishLoad) finishLoadProgress();
}
@Override
public void onCrash(Tab tab) {
stopLoadProgress();
finishLoadProgress();
}
private void updateUrl(Tab tab) {
......
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