Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_strip_model_observer_bridge.mm
blob248862ca378ab276ac913e4c611bf0ae447bbd48
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 using content::WebContents;
11 TabStripModelObserverBridge::TabStripModelObserverBridge(TabStripModel* model,
12                                                          id controller)
13     : controller_(controller), model_(model) {
14   DCHECK(model && controller);
15   // Register to be a listener on the model so we can get updates and tell
16   // |controller_| about them in the future.
17   model_->AddObserver(this);
20 TabStripModelObserverBridge::~TabStripModelObserverBridge() {
21   // Remove ourselves from receiving notifications.
22   model_->RemoveObserver(this);
25 void TabStripModelObserverBridge::TabInsertedAt(WebContents* contents,
26                                                 int index,
27                                                 bool foreground) {
28   if ([controller_ respondsToSelector:
29           @selector(insertTabWithContents:atIndex:inForeground:)]) {
30     [controller_ insertTabWithContents:contents
31                                atIndex:index
32                           inForeground:foreground];
33   }
36 void TabStripModelObserverBridge::TabClosingAt(TabStripModel* tab_strip_model,
37                                                WebContents* contents,
38                                                int index) {
39   if ([controller_ respondsToSelector:
40           @selector(tabClosingWithContents:atIndex:)]) {
41     [controller_ tabClosingWithContents:contents atIndex:index];
42   }
45 void TabStripModelObserverBridge::TabDetachedAt(WebContents* contents,
46                                                 int index) {
47   if ([controller_ respondsToSelector:
48           @selector(tabDetachedWithContents:atIndex:)]) {
49     [controller_ tabDetachedWithContents:contents atIndex:index];
50   }
53 void TabStripModelObserverBridge::TabDeactivated(WebContents* contents) {
54   if ([controller_ respondsToSelector:@selector(tabDeactivatedWithContents:)])
55     [controller_ tabDeactivatedWithContents:contents];
58 void TabStripModelObserverBridge::ActiveTabChanged(WebContents* old_contents,
59                                                    WebContents* new_contents,
60                                                    int index,
61                                                    int reason) {
62   if ([controller_ respondsToSelector:@selector(
63           activateTabWithContents:previousContents:atIndex:reason:)]) {
64     [controller_ activateTabWithContents:new_contents
65                         previousContents:old_contents
66                                  atIndex:index
67                                   reason:reason];
68   }
71 void TabStripModelObserverBridge::TabSelectionChanged(
72     TabStripModel* tab_strip_model,
73     const ui::ListSelectionModel& old_model) {
74   if ([controller_ respondsToSelector:@selector(tabSelectionChanged)]) {
75     [controller_ tabSelectionChanged];
76   }
79 void TabStripModelObserverBridge::TabMoved(WebContents* contents,
80                                            int from_index,
81                                            int to_index) {
82   if ([controller_ respondsToSelector:
83        @selector(tabMovedWithContents:fromIndex:toIndex:)]) {
84     [controller_ tabMovedWithContents:contents
85                             fromIndex:from_index
86                               toIndex:to_index];
87   }
90 void TabStripModelObserverBridge::TabChangedAt(WebContents* contents,
91                                                int index,
92                                                TabChangeType change_type) {
93   if ([controller_ respondsToSelector:
94           @selector(tabChangedWithContents:atIndex:changeType:)]) {
95     [controller_ tabChangedWithContents:contents
96                                 atIndex:index
97                              changeType:change_type];
98   }
101 void TabStripModelObserverBridge::TabReplacedAt(TabStripModel* tab_strip_model,
102                                                 WebContents* old_contents,
103                                                 WebContents* new_contents,
104                                                 int index) {
105   if ([controller_ respondsToSelector:
106           @selector(tabReplacedWithContents:previousContents:atIndex:)]) {
107     [controller_ tabReplacedWithContents:new_contents
108                         previousContents:old_contents
109                                  atIndex:index];
110   } else {
111     TabChangedAt(new_contents, index, ALL);
112   }
115 void TabStripModelObserverBridge::TabPinnedStateChanged(WebContents* contents,
116                                                         int index) {
117   if ([controller_ respondsToSelector:
118           @selector(tabPinnedStateChangedWithContents:atIndex:)]) {
119     [controller_ tabPinnedStateChangedWithContents:contents
120                                            atIndex:index];
121   }
124 void TabStripModelObserverBridge::TabStripEmpty() {
125   if ([controller_ respondsToSelector:@selector(tabStripEmpty)])
126     [controller_ tabStripEmpty];
129 void TabStripModelObserverBridge::TabStripModelDeleted() {
130   if ([controller_ respondsToSelector:@selector(tabStripModelDeleted)])
131     [controller_ tabStripModelDeleted];