OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ObserverList; | 7 import org.chromium.base.ObserverList; |
8 import org.chromium.chrome.browser.tab.Tab; | 8 import org.chromium.chrome.browser.tab.Tab; |
9 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 9 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
10 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 10 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
11 import org.chromium.content_public.browser.WebContents; | |
12 | 11 |
13 import java.util.ArrayList; | 12 import java.util.ArrayList; |
14 import java.util.Collections; | 13 import java.util.Collections; |
15 import java.util.List; | 14 import java.util.List; |
16 | 15 |
17 /** | 16 /** |
18 * Implement methods shared across the different model implementations. | 17 * Implement methods shared across the different model implementations. |
19 */ | 18 */ |
20 public abstract class TabModelSelectorBase implements TabModelSelector { | 19 public abstract class TabModelSelectorBase implements TabModelSelector { |
21 public static final int NORMAL_TAB_MODEL_INDEX = 0; | 20 public static final int NORMAL_TAB_MODEL_INDEX = 0; |
(...skipping 25 matching lines...) Expand all Loading... |
47 TabModelObserver tabModelObserver = new EmptyTabModelObserver() { | 46 TabModelObserver tabModelObserver = new EmptyTabModelObserver() { |
48 @Override | 47 @Override |
49 public void didAddTab(Tab tab, TabLaunchType type) { | 48 public void didAddTab(Tab tab, TabLaunchType type) { |
50 notifyChanged(); | 49 notifyChanged(); |
51 notifyNewTabCreated(tab); | 50 notifyNewTabCreated(tab); |
52 } | 51 } |
53 | 52 |
54 @Override | 53 @Override |
55 public void didSelectTab(Tab tab, TabSelectionType type, int lastId)
{ | 54 public void didSelectTab(Tab tab, TabSelectionType type, int lastId)
{ |
56 notifyChanged(); | 55 notifyChanged(); |
57 | |
58 Tab oldTab = getTabById(lastId); | |
59 if (tab.getId() != lastId) { | |
60 WebContents oldWebContents = (oldTab == null) ? null : oldTa
b.getWebContents(); | |
61 nativeOnActiveTabChanged(oldWebContents, tab.getWebContents(
)); | |
62 } | |
63 } | 56 } |
64 | 57 |
65 @Override | 58 @Override |
66 public void didMoveTab(Tab tab, int newIndex, int curIndex) { | 59 public void didMoveTab(Tab tab, int newIndex, int curIndex) { |
67 notifyChanged(); | 60 notifyChanged(); |
68 } | 61 } |
69 }; | 62 }; |
70 for (TabModel model : models) { | 63 for (TabModel model : models) { |
71 model.addObserver(tabModelObserver); | 64 model.addObserver(tabModelObserver); |
72 } | 65 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 235 |
243 /** | 236 /** |
244 * Notifies all the listeners that a new tab has been created. | 237 * Notifies all the listeners that a new tab has been created. |
245 * @param tab The tab that has been created. | 238 * @param tab The tab that has been created. |
246 */ | 239 */ |
247 private void notifyNewTabCreated(Tab tab) { | 240 private void notifyNewTabCreated(Tab tab) { |
248 for (TabModelSelectorObserver listener : mObservers) { | 241 for (TabModelSelectorObserver listener : mObservers) { |
249 listener.onNewTabCreated(tab); | 242 listener.onNewTabCreated(tab); |
250 } | 243 } |
251 } | 244 } |
252 | |
253 static native void nativeOnActiveTabChanged(WebContents oldContents, WebCont
ents newContents); | |
254 } | 245 } |
OLD | NEW |