diff options
| author | Leon Scroggins <scroggo@google.com> | 2010-02-23 17:26:37 -0500 |
|---|---|---|
| committer | Leon Scroggins <scroggo@google.com> | 2010-02-24 13:47:53 -0500 |
| commit | dcc5eeb63eadd597587a0b2b49998c267b0bcc11 (patch) | |
| tree | f1a61b6b4faddee16944b2efd57e87c43c569bc4 /src | |
| parent | 6250474346aebe596f96fc86f998bc4d0dfcc2f0 (diff) | |
| download | packages_apps_Browser-dcc5eeb63eadd597587a0b2b49998c267b0bcc11.tar.gz packages_apps_Browser-dcc5eeb63eadd597587a0b2b49998c267b0bcc11.tar.bz2 packages_apps_Browser-dcc5eeb63eadd597587a0b2b49998c267b0bcc11.zip | |
If a tab was opened solely to download a file, close the tab.
Fix for http://b/issue?id=2217707
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/android/browser/BrowserActivity.java | 2 | ||||
| -rw-r--r-- | src/com/android/browser/Tab.java | 48 | ||||
| -rw-r--r-- | src/com/android/browser/TabControl.java | 5 |
3 files changed, 47 insertions, 8 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index d4a016dc3..b55071467 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -2149,7 +2149,7 @@ public class BrowserActivity extends Activity resetTitleIconAndProgress(); } - private void goBackOnePageOrQuit() { + /* package */ void goBackOnePageOrQuit() { Tab current = mTabControl.getCurrentTab(); if (current == null) { /* diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index afd9b0972..512f2b74a 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -48,6 +48,7 @@ import android.view.ViewGroup; import android.view.View.OnClickListener; import android.webkit.ConsoleMessage; import android.webkit.CookieSyncManager; +import android.webkit.DownloadListener; import android.webkit.GeolocationPermissions; import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; @@ -123,6 +124,9 @@ class Tab { private final LayoutInflater mInflateService; // The BrowserActivity which owners the Tab private final BrowserActivity mActivity; + // The listener that gets invoked when a download is started from the + // mMainView + private final DownloadListener mDownloadListener; // AsyncTask for downloading touch icons DownloadTouchIcon mTouchIconLoader; @@ -1224,6 +1228,27 @@ class Tab { (GeolocationPermissionsPrompt) mContainer.findViewById( R.id.geolocation_permissions_prompt); + mDownloadListener = new DownloadListener() { + public void onDownloadStart(String url, String userAgent, + String contentDisposition, String mimetype, + long contentLength) { + mActivity.onDownloadStart(url, userAgent, contentDisposition, + mimetype, contentLength); + if (mMainView.copyBackForwardList().getSize() == 0) { + // This Tab was opened for the sole purpose of downloading a + // file. Remove it. + if (mActivity.getTabControl().getCurrentWebView() + == mMainView) { + // In this case, the Tab is still on top. + mActivity.goBackOnePageOrQuit(); + } else { + // In this case, it is not. + mActivity.closeTab(Tab.this); + } + } + } + }; + setWebView(w); } @@ -1246,10 +1271,15 @@ class Tab { // set the new one mMainView = w; - // attached the WebViewClient and WebChromeClient + // attach the WebViewClient, WebChromeClient and DownloadListener if (mMainView != null) { mMainView.setWebViewClient(mWebViewClient); mMainView.setWebChromeClient(mWebChromeClient); + // Attach DownloadManager so that downloads can start in an active + // or a non-active window. This can happen when going to a site that + // does a redirect after a period of time. The user could have + // switched to another tab while waiting for the download to start. + mMainView.setDownloadListener(mDownloadListener); } } @@ -1297,7 +1327,21 @@ class Tab { mSubView.setWebViewClient(new SubWindowClient(mWebViewClient)); mSubView.setWebChromeClient(new SubWindowChromeClient( mWebChromeClient)); - mSubView.setDownloadListener(mActivity); + // Set a different DownloadListener for the mSubView, since it will + // just need to dismiss the mSubView, rather than close the Tab + mSubView.setDownloadListener(new DownloadListener() { + public void onDownloadStart(String url, String userAgent, + String contentDisposition, String mimetype, + long contentLength) { + mActivity.onDownloadStart(url, userAgent, + contentDisposition, mimetype, contentLength); + if (mSubView.copyBackForwardList().getSize() == 0) { + // This subwindow was opened for the sole purpose of + // downloading a file. Remove it. + dismissSubWindow(); + } + } + }); mSubView.setOnCreateContextMenuListener(mActivity); final BrowserSettings s = BrowserSettings.getInstance(); s.addObserver(mSubView.getSettings()).update(s, null); diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index 33b73e8cf..e64f3fb69 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -533,11 +533,6 @@ class TabControl { w.setMapTrackballToArrowKeys(false); // use trackball directly // Enable the built-in zoom w.getSettings().setBuiltInZoomControls(true); - // Attach DownloadManager so that downloads can start in an active or - // a non-active window. This can happen when going to a site that does - // a redirect after a period of time. The user could have switched to - // another tab while waiting for the download to start. - w.setDownloadListener(mActivity); // Add this WebView to the settings observer list and update the // settings final BrowserSettings s = BrowserSettings.getInstance(); |
