OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.Manifest.permission; | 7 import android.Manifest.permission; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
11 import android.support.v7.app.AlertDialog; | 11 import android.support.v7.app.AlertDialog; |
12 import android.view.View; | 12 import android.view.View; |
13 import android.widget.TextView; | 13 import android.widget.TextView; |
14 | 14 |
15 import org.chromium.base.ApplicationStatus; | 15 import org.chromium.base.ApplicationStatus; |
16 import org.chromium.base.ContextUtils; | |
16 import org.chromium.base.annotations.CalledByNative; | 17 import org.chromium.base.annotations.CalledByNative; |
17 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
18 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
20 import org.chromium.chrome.browser.tab.Tab; | |
21 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | |
22 import org.chromium.content_public.browser.WebContents; | |
19 import org.chromium.ui.base.WindowAndroid; | 23 import org.chromium.ui.base.WindowAndroid; |
20 import org.chromium.ui.base.WindowAndroid.PermissionCallback; | 24 import org.chromium.ui.base.WindowAndroid.PermissionCallback; |
21 | 25 |
22 /** | 26 /** |
23 * Java counterpart of android DownloadController. | 27 * Java counterpart of android DownloadController. |
24 * | 28 * |
25 * Its a singleton class instantiated by the C++ DownloadController. | 29 * Its a singleton class instantiated by the C++ DownloadController. |
26 */ | 30 */ |
27 public class DownloadController { | 31 public class DownloadController { |
28 private static final String LOGTAG = "DownloadController"; | 32 private static final String LOGTAG = "DownloadController"; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 }) | 183 }) |
180 .setOnCancelListener(new DialogInterface.OnCancelListene r() { | 184 .setOnCancelListener(new DialogInterface.OnCancelListene r() { |
181 @Override | 185 @Override |
182 public void onCancel(DialogInterface dialog) { | 186 public void onCancel(DialogInterface dialog) { |
183 nativeOnAcquirePermissionResult(callbackId, fals e, null); | 187 nativeOnAcquirePermissionResult(callbackId, fals e, null); |
184 } | 188 } |
185 }); | 189 }); |
186 builder.create().show(); | 190 builder.create().show(); |
187 } | 191 } |
188 | 192 |
193 /** | |
194 * Called when a download is started. | |
195 */ | |
196 @CalledByNative | |
197 private void onDownloadStarted() { | |
198 DownloadUtils.showDownloadStartToast(ContextUtils.getApplicationContext( )); | |
199 } | |
200 | |
201 /** | |
202 * 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.
| |
203 * @param Tab Tab to close | |
204 * @return true iff the tab was (already) closed. | |
205 */ | |
206 @CalledByNative | |
207 static boolean closeTabIfBlank(Tab tab) { | |
208 if (tab == null) return true; | |
209 WebContents contents = tab.getWebContents(); | |
210 boolean isInitialNavigation = contents == null | |
211 || contents.getNavigationController().isInitialNavigation(); | |
212 if (isInitialNavigation) { | |
213 // Tab is created just for download, close it. | |
214 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.
| |
215 if (!(activity instanceof ChromeActivity)) return true; | |
216 | |
217 TabModelSelector selector = ((ChromeActivity) activity).getTabModelS elector(); | |
218 if (selector == null) return true; | |
219 if (selector.getModel(tab.isIncognito()).getCount() == 1) return fal se; | |
220 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
| |
221 } | |
222 return false; | |
223 } | |
224 | |
189 // native methods | 225 // native methods |
190 private native void nativeInit(); | 226 private native void nativeInit(); |
191 private native void nativeOnAcquirePermissionResult( | 227 private native void nativeOnAcquirePermissionResult( |
192 long callbackId, boolean granted, String permissionToUpdate); | 228 long callbackId, boolean granted, String permissionToUpdate); |
193 } | 229 } |
OLD | NEW |