OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.tabmodel; |
| 6 |
| 7 import org.chromium.chrome.browser.ChromeActivity; |
| 8 import org.chromium.chrome.browser.Tab; |
| 9 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
| 10 import org.chromium.chrome.browser.device.DeviceClassManager; |
| 11 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; |
| 12 import org.chromium.content_public.browser.LoadUrlParams; |
| 13 import org.chromium.content_public.browser.WebContents; |
| 14 |
| 15 /** |
| 16 * This class contains additions to the base TabModel implementation (notificati
ons |
| 17 * and overrides of existing methods). |
| 18 * |
| 19 * TODO: merge this into TabModelBase after upstreaming. |
| 20 */ |
| 21 public class TabModelImpl extends TabModelBase { |
| 22 /** |
| 23 * The application ID used for tabs opened from an application that does not
specify an app ID |
| 24 * in its VIEW intent extras. |
| 25 */ |
| 26 public static final String UNKNOWN_APP_ID = "com.google.android.apps.chrome.
unknown_app"; |
| 27 |
| 28 private final ChromeActivity mActivity; |
| 29 private final TabModelSelectorUma mUma; |
| 30 private final TabContentManager mTabContentManager; |
| 31 private final TabPersistentStore mTabSaver; |
| 32 |
| 33 public TabModelImpl(boolean incognito, |
| 34 ChromeActivity activity, TabModelSelectorUma uma, |
| 35 TabModelOrderController orderController, TabContentManager tabConten
tManager, |
| 36 TabPersistentStore tabSaver, TabModelDelegate modelDelegate) { |
| 37 super(incognito, orderController, modelDelegate); |
| 38 mActivity = activity; |
| 39 mUma = uma; |
| 40 mTabContentManager = tabContentManager; |
| 41 mTabSaver = tabSaver; |
| 42 addObserver(mObserver); |
| 43 } |
| 44 |
| 45 private final TabModelObserver mObserver = new EmptyTabModelObserver() { |
| 46 @Override |
| 47 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { |
| 48 boolean wasAlreadySelected = tab.getId() == lastId; |
| 49 |
| 50 // TODO(joth): Make this even faster, ChromeTab.show() can still blo
ck for over 50ms. |
| 51 // See http://b/5278198 and http://b/5035061 |
| 52 if (!wasAlreadySelected) { |
| 53 if (type == TabSelectionType.FROM_USER) { |
| 54 // We only want to record when the user actively switches to
a different tab. |
| 55 mUma.userSwitchedToTab(); |
| 56 } |
| 57 } |
| 58 } |
| 59 |
| 60 @Override |
| 61 public void didCloseTab(Tab tab) { |
| 62 mTabContentManager.removeTabThumbnail(tab.getId()); |
| 63 mTabSaver.removeTabFromQueues(tab); |
| 64 |
| 65 if (!isIncognito()) tab.createHistoricalTab(); |
| 66 } |
| 67 }; |
| 68 |
| 69 @Override |
| 70 public boolean supportsPendingClosures() { |
| 71 return super.supportsPendingClosures() && DeviceClassManager.enableUndo(
mActivity); |
| 72 } |
| 73 |
| 74 @Override |
| 75 public void closeAllTabs(boolean allowDelegation, boolean uponExit) { |
| 76 mTabSaver.cancelLoadingTabs(isIncognito()); |
| 77 |
| 78 if (uponExit) { |
| 79 super.closeAllTabs(allowDelegation, uponExit); |
| 80 return; |
| 81 } |
| 82 |
| 83 if (allowDelegation && mModelDelegate.closeAllTabsRequest(isIncognito())
) return; |
| 84 |
| 85 if (HomepageManager.isHomepageEnabled(mActivity)) { |
| 86 super.closeAllTabs(false, uponExit); |
| 87 return; |
| 88 } |
| 89 |
| 90 if (getCount() == 1) { |
| 91 closeTab(getTabAt(0), true, false, true); |
| 92 return; |
| 93 } |
| 94 |
| 95 super.closeAllTabs(true, false, true); |
| 96 } |
| 97 |
| 98 @Override |
| 99 protected Tab createTabWithWebContents(boolean incognito, WebContents webCon
tents, |
| 100 int parentId) { |
| 101 return mActivity.getTabCreator(incognito).createTabWithWebContents(webCo
ntents, |
| 102 parentId, TabLaunchType.FROM_LONGPRESS_BACKGROUND); |
| 103 } |
| 104 |
| 105 @Override |
| 106 protected Tab createNewTabForDevTools(String url) { |
| 107 return mActivity.getTabCreator(false).createNewTab(new LoadUrlParams(url
), |
| 108 TabModel.TabLaunchType.FROM_MENU_OR_OVERVIEW, null); |
| 109 } |
| 110 } |
OLD | NEW |