Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.tabmodel; | 5 package org.chromium.chrome.browser.tabmodel; |
| 6 | 6 |
| 7 import org.chromium.base.ContextUtils; | 7 import org.chromium.base.ContextUtils; |
| 8 import org.chromium.base.ObserverList; | 8 import org.chromium.base.ObserverList; |
| 9 import org.chromium.base.TraceEvent; | 9 import org.chromium.base.TraceEvent; |
| 10 import org.chromium.chrome.browser.ChromeTabbedActivity; | 10 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 11 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; | 11 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
| 12 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge; | |
| 12 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; | 13 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; |
| 13 import org.chromium.chrome.browser.tab.Tab; | 14 import org.chromium.chrome.browser.tab.Tab; |
| 14 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; | 15 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; |
| 15 import org.chromium.chrome.browser.util.MathUtils; | 16 import org.chromium.chrome.browser.util.MathUtils; |
| 16 import org.chromium.content_public.browser.WebContents; | 17 import org.chromium.content_public.browser.WebContents; |
| 17 | 18 |
| 18 import java.util.ArrayList; | 19 import java.util.ArrayList; |
| 19 import java.util.List; | 20 import java.util.List; |
| 20 | 21 |
| 21 /** | 22 /** |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 38 private final List<Tab> mTabs = new ArrayList<Tab>(); | 39 private final List<Tab> mTabs = new ArrayList<Tab>(); |
| 39 | 40 |
| 40 private final TabCreator mRegularTabCreator; | 41 private final TabCreator mRegularTabCreator; |
| 41 private final TabCreator mIncognitoTabCreator; | 42 private final TabCreator mIncognitoTabCreator; |
| 42 private final TabModelSelectorUma mUma; | 43 private final TabModelSelectorUma mUma; |
| 43 private final TabModelOrderController mOrderController; | 44 private final TabModelOrderController mOrderController; |
| 44 private final TabContentManager mTabContentManager; | 45 private final TabContentManager mTabContentManager; |
| 45 private final TabPersistentStore mTabSaver; | 46 private final TabPersistentStore mTabSaver; |
| 46 private final TabModelDelegate mModelDelegate; | 47 private final TabModelDelegate mModelDelegate; |
| 47 private final ObserverList<TabModelObserver> mObservers; | 48 private final ObserverList<TabModelObserver> mObservers; |
| 49 private RecentlyClosedBridge mRecentlyClosedBridge; | |
| 48 | 50 |
| 49 // Undo State Tracking ----------------------------------------------------- -------------------- | 51 // Undo State Tracking ----------------------------------------------------- -------------------- |
| 50 | 52 |
| 51 /** | 53 /** |
| 52 * A {@link TabList} that represents the complete list of {@link Tab}s. This is so that | 54 * A {@link TabList} that represents the complete list of {@link Tab}s. This is so that |
| 53 * certain UI elements can call {@link TabModel#getComprehensiveModel()} to get a full list of | 55 * certain UI elements can call {@link TabModel#getComprehensiveModel()} to get a full list of |
| 54 * {@link Tab}s that includes rewindable entries, as the typical {@link TabM odel} does not | 56 * {@link Tab}s that includes rewindable entries, as the typical {@link TabM odel} does not |
| 55 * return rewindable entries. | 57 * return rewindable entries. |
| 56 */ | 58 */ |
| 57 private final RewoundList mRewoundList = new RewoundList(); | 59 private final RewoundList mRewoundList = new RewoundList(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 initializeNative(); | 76 initializeNative(); |
| 75 mRegularTabCreator = regularTabCreator; | 77 mRegularTabCreator = regularTabCreator; |
| 76 mIncognitoTabCreator = incognitoTabCreator; | 78 mIncognitoTabCreator = incognitoTabCreator; |
| 77 mUma = uma; | 79 mUma = uma; |
| 78 mOrderController = orderController; | 80 mOrderController = orderController; |
| 79 mTabContentManager = tabContentManager; | 81 mTabContentManager = tabContentManager; |
| 80 mTabSaver = tabSaver; | 82 mTabSaver = tabSaver; |
| 81 mModelDelegate = modelDelegate; | 83 mModelDelegate = modelDelegate; |
| 82 mIsUndoSupported = supportUndo; | 84 mIsUndoSupported = supportUndo; |
| 83 mObservers = new ObserverList<TabModelObserver>(); | 85 mObservers = new ObserverList<TabModelObserver>(); |
| 86 mRecentlyClosedBridge = new RecentlyClosedBridge(getProfile()); | |
| 84 } | 87 } |
| 85 | 88 |
| 86 @Override | 89 @Override |
| 87 public void removeTab(Tab tab) { | 90 public void removeTab(Tab tab) { |
| 88 removeTabAndSelectNext(tab, TabSelectionType.FROM_USER, false, true); | 91 removeTabAndSelectNext(tab, TabSelectionType.FROM_USER, false, true); |
| 89 | 92 |
| 90 for (TabModelObserver obs : mObservers) obs.tabRemoved(tab); | 93 for (TabModelObserver obs : mObservers) obs.tabRemoved(tab); |
| 91 } | 94 } |
| 92 | 95 |
| 93 @Override | 96 @Override |
| 94 public void destroy() { | 97 public void destroy() { |
| 95 for (Tab tab : mTabs) { | 98 for (Tab tab : mTabs) { |
| 96 if (tab.isInitialized()) tab.destroy(); | 99 if (tab.isInitialized()) tab.destroy(); |
| 97 } | 100 } |
| 98 | 101 |
| 99 mRewoundList.destroy(); | 102 mRewoundList.destroy(); |
| 100 mTabs.clear(); | 103 mTabs.clear(); |
| 101 mObservers.clear(); | 104 mObservers.clear(); |
| 102 | 105 mRecentlyClosedBridge.destroy(); |
| 103 super.destroy(); | 106 super.destroy(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 @Override | 109 @Override |
| 107 public void addObserver(TabModelObserver observer) { | 110 public void addObserver(TabModelObserver observer) { |
| 108 mObservers.addObserver(observer); | 111 mObservers.addObserver(observer); |
| 109 } | 112 } |
| 110 | 113 |
| 111 @Override | 114 @Override |
| 112 public void removeObserver(TabModelObserver observer) { | 115 public void removeObserver(TabModelObserver observer) { |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 | 717 |
| 715 @Override | 718 @Override |
| 716 protected TabCreator getTabCreator(boolean incognito) { | 719 protected TabCreator getTabCreator(boolean incognito) { |
| 717 return incognito ? mIncognitoTabCreator : mRegularTabCreator; | 720 return incognito ? mIncognitoTabCreator : mRegularTabCreator; |
| 718 } | 721 } |
| 719 | 722 |
| 720 @Override | 723 @Override |
| 721 protected boolean createTabWithWebContents(Tab parent, boolean incognito, | 724 protected boolean createTabWithWebContents(Tab parent, boolean incognito, |
| 722 WebContents webContents, int parentId) { | 725 WebContents webContents, int parentId) { |
| 723 return getTabCreator(incognito).createTabWithWebContents(parent, webCont ents, parentId, | 726 return getTabCreator(incognito).createTabWithWebContents(parent, webCont ents, parentId, |
| 724 TabLaunchType.FROM_LONGPRESS_BACKGROUND); | 727 TabLaunchType.FROM_LONGPRESS_FOREGROUND); |
|
Theresa
2016/06/29 23:53:29
I suspect that changing this affects other places
xingliu
2016/06/30 05:43:55
Used to investigate this a little bit, this change
Theresa
2016/06/30 20:50:24
If you go to "Recent tabs", long press on a recent
| |
| 725 } | 728 } |
| 726 | 729 |
| 727 @Override | 730 @Override |
| 728 public int getCount() { | 731 public int getCount() { |
| 729 return mTabs.size(); | 732 return mTabs.size(); |
| 730 } | 733 } |
| 731 | 734 |
| 732 @Override | 735 @Override |
| 733 public int index() { | 736 public int index() { |
| 734 return mIndex; | 737 return mIndex; |
| 735 } | 738 } |
| 736 | 739 |
| 737 @Override | 740 @Override |
| 738 protected boolean isSessionRestoreInProgress() { | 741 protected boolean isSessionRestoreInProgress() { |
| 739 return mModelDelegate.isSessionRestoreInProgress(); | 742 return mModelDelegate.isSessionRestoreInProgress(); |
| 740 } | 743 } |
| 744 | |
| 745 /** | |
| 746 * Open most recent closed tab. first check if android tab model has pending closures. | |
| 747 * if not, use native code to fetch data from tab restore service. | |
| 748 */ | |
| 749 @Override | |
| 750 public void openRecentClosedTab() { | |
| 751 // recover tab from rewind list in java, same as the undo snackbar. | |
|
Theresa
2016/06/29 23:53:29
nit: use proper sentence capitalization/punctuatio
xingliu
2016/06/30 05:43:55
Done.
| |
| 752 // {@link UndoBarController}. | |
| 753 if (mRewoundList.hasPendingClosures()) { | |
| 754 Tab tab = mRewoundList.getNextRewindableTab(); | |
| 755 if (tab == null) return; | |
| 756 cancelTabClosure(tab.getId()); | |
| 757 return; | |
| 758 } | |
| 759 | |
| 760 // if no pending closure in java, open it from tab restore service in na tive code. | |
|
Theresa
2016/06/29 23:53:29
nit: "If there are no pending closures in Java, ..
xingliu
2016/06/30 05:43:55
Done.
| |
| 761 mRecentlyClosedBridge.openRecentClosedTab(); | |
| 762 } | |
| 741 } | 763 } |
| OLD | NEW |