Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadController.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadController.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadController.java |
| index 44a09a0e0bea3c73723d6b21805923ab47e6cf49..37a2777081016085f4d5f9051f90c9e2b074be73 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadController.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadController.java |
| @@ -13,9 +13,13 @@ import android.view.View; |
| import android.widget.TextView; |
| import org.chromium.base.ApplicationStatus; |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.ChromeActivity; |
| +import org.chromium.chrome.browser.tab.Tab; |
| +import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| +import org.chromium.content_public.browser.WebContents; |
| import org.chromium.ui.base.WindowAndroid; |
| import org.chromium.ui.base.WindowAndroid.PermissionCallback; |
| @@ -186,6 +190,38 @@ public class DownloadController { |
| builder.create().show(); |
| } |
| + /** |
| + * Called when a download is started. |
| + */ |
| + @CalledByNative |
| + private void onDownloadStarted() { |
| + DownloadUtils.showDownloadStartToast(ContextUtils.getApplicationContext()); |
| + } |
| + |
| + /** |
| + * Close a tab if it is blank.' |
|
David Trainor- moved to gerrit
2017/05/09 05:57:09
Remove ' at the end?
qinmin
2017/05/10 16:09:03
Done.
|
| + * @param Tab Tab to close |
| + * @return true iff the tab was (already) closed. |
| + */ |
| + @CalledByNative |
| + static boolean closeTabIfBlank(Tab tab) { |
| + if (tab == null) return true; |
| + WebContents contents = tab.getWebContents(); |
| + boolean isInitialNavigation = contents == null |
| + || contents.getNavigationController().isInitialNavigation(); |
| + if (isInitialNavigation) { |
| + // Tab is created just for download, close it. |
| + Activity activity = tab.getWindowAndroid().getActivity().get(); |
|
David Trainor- moved to gerrit
2017/05/09 05:57:09
tab.getTabModelSelector()? Can we ever host this
qinmin
2017/05/10 16:09:03
Done.
|
| + if (!(activity instanceof ChromeActivity)) return true; |
| + |
| + TabModelSelector selector = ((ChromeActivity) activity).getTabModelSelector(); |
| + if (selector == null) return true; |
| + if (selector.getModel(tab.isIncognito()).getCount() == 1) return false; |
| + return selector.closeTab(tab); |
|
David Trainor- moved to gerrit
2017/05/09 05:57:09
If this is correct, can we update the javadoc? Do
qinmin
2017/05/10 16:09:03
selector.closeTab() returns true if the tab is fou
|
| + } |
| + return false; |
| + } |
| + |
| // native methods |
| private native void nativeInit(); |
| private native void nativeOnAcquirePermissionResult( |