OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/tab_closeable_state_watcher.h" | 5 #include "chrome/browser/chromeos/tab_closeable_state_watcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" |
9 #include "chrome/browser/defaults.h" | 9 #include "chrome/browser/defaults.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/browser/tab_contents/tab_contents_view.h" | 12 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 13 #include "chrome/browser/tab_contents_wrapper.h" |
13 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
21 // TabCloseableStateWatcher::TabStripWatcher, public: | 22 // TabCloseableStateWatcher::TabStripWatcher, public: |
22 | 23 |
23 TabCloseableStateWatcher::TabStripWatcher::TabStripWatcher( | 24 TabCloseableStateWatcher::TabStripWatcher::TabStripWatcher( |
24 TabCloseableStateWatcher* main_watcher, const Browser* browser) | 25 TabCloseableStateWatcher* main_watcher, const Browser* browser) |
25 : main_watcher_(main_watcher), | 26 : main_watcher_(main_watcher), |
26 browser_(browser) { | 27 browser_(browser) { |
27 browser_->tabstrip_model()->AddObserver(this); | 28 browser_->tabstrip_model()->AddObserver(this); |
28 } | 29 } |
29 | 30 |
30 TabCloseableStateWatcher::TabStripWatcher::~TabStripWatcher() { | 31 TabCloseableStateWatcher::TabStripWatcher::~TabStripWatcher() { |
31 browser_->tabstrip_model()->RemoveObserver(this); | 32 browser_->tabstrip_model()->RemoveObserver(this); |
32 } | 33 } |
33 | 34 |
34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
35 // TabCloseableStateWatcher::TabStripWatcher, | 36 // TabCloseableStateWatcher::TabStripWatcher, |
36 // TabStripModelObserver implementation: | 37 // TabStripModelObserver implementation: |
37 | 38 |
38 void TabCloseableStateWatcher::TabStripWatcher::TabInsertedAt( | 39 void TabCloseableStateWatcher::TabStripWatcher::TabInsertedAt( |
39 TabContents* tab_contents, int index, bool foreground) { | 40 TabContentsWrapper* tab_contents, int index, bool foreground) { |
40 main_watcher_->OnTabStripChanged(browser_, false); | 41 main_watcher_->OnTabStripChanged(browser_, false); |
41 } | 42 } |
42 | 43 |
43 void TabCloseableStateWatcher::TabStripWatcher::TabClosingAt( | 44 void TabCloseableStateWatcher::TabStripWatcher::TabClosingAt( |
44 TabStripModel* tab_strip_model, TabContents* tab_contents, int index) { | 45 TabStripModel* tab_strip_model, |
| 46 TabContentsWrapper* tab_contents, |
| 47 int index) { |
45 // Check if the last tab is closing. | 48 // Check if the last tab is closing. |
46 if (tab_strip_model->count() == 1) | 49 if (tab_strip_model->count() == 1) |
47 main_watcher_->OnTabStripChanged(browser_, true); | 50 main_watcher_->OnTabStripChanged(browser_, true); |
48 } | 51 } |
49 | 52 |
50 void TabCloseableStateWatcher::TabStripWatcher::TabDetachedAt( | 53 void TabCloseableStateWatcher::TabStripWatcher::TabDetachedAt( |
51 TabContents* tab_contents, int index) { | 54 TabContentsWrapper* tab_contents, int index) { |
52 main_watcher_->OnTabStripChanged(browser_, false); | 55 main_watcher_->OnTabStripChanged(browser_, false); |
53 } | 56 } |
54 | 57 |
55 void TabCloseableStateWatcher::TabStripWatcher::TabChangedAt( | 58 void TabCloseableStateWatcher::TabStripWatcher::TabChangedAt( |
56 TabContents* tab_contents, int index, TabChangeType change_type) { | 59 TabContentsWrapper* tab_contents, int index, TabChangeType change_type) { |
57 main_watcher_->OnTabStripChanged(browser_, false); | 60 main_watcher_->OnTabStripChanged(browser_, false); |
58 } | 61 } |
59 | 62 |
60 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
61 // TabCloseableStateWatcher, public: | 64 // TabCloseableStateWatcher, public: |
62 | 65 |
63 TabCloseableStateWatcher::TabCloseableStateWatcher() | 66 TabCloseableStateWatcher::TabCloseableStateWatcher() |
64 : can_close_tab_(true), | 67 : can_close_tab_(true), |
65 signing_off_(false), | 68 signing_off_(false), |
66 guest_session_( | 69 guest_session_( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (tabstrip_watchers_.size() > 1) { | 187 if (tabstrip_watchers_.size() > 1) { |
185 new_can_close = true; | 188 new_can_close = true; |
186 } else { // There's only 1 normal browser. | 189 } else { // There's only 1 normal browser. |
187 if (!browser_to_check) | 190 if (!browser_to_check) |
188 browser_to_check = tabstrip_watchers_[0]->browser(); | 191 browser_to_check = tabstrip_watchers_[0]->browser(); |
189 if (browser_to_check->profile()->IsOffTheRecord() && !guest_session_) { | 192 if (browser_to_check->profile()->IsOffTheRecord() && !guest_session_) { |
190 new_can_close = true; | 193 new_can_close = true; |
191 } else { | 194 } else { |
192 TabStripModel* tabstrip_model = browser_to_check->tabstrip_model(); | 195 TabStripModel* tabstrip_model = browser_to_check->tabstrip_model(); |
193 if (tabstrip_model->count() == 1) { | 196 if (tabstrip_model->count() == 1) { |
194 new_can_close = tabstrip_model->GetTabContentsAt(0)->GetURL() != | 197 new_can_close = |
195 GURL(chrome::kChromeUINewTabURL); // Tab is not NewTabPage. | 198 tabstrip_model->GetTabContentsAt(0)->tab_contents()->GetURL() != |
| 199 GURL(chrome::kChromeUINewTabURL); // Tab is not NewTabPage. |
196 } else { | 200 } else { |
197 new_can_close = true; | 201 new_can_close = true; |
198 } | 202 } |
199 } | 203 } |
200 } | 204 } |
201 | 205 |
202 SetCloseableState(new_can_close); | 206 SetCloseableState(new_can_close); |
203 } | 207 } |
204 | 208 |
205 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { | 209 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (!can_close_tab_) | 246 if (!can_close_tab_) |
243 return false; | 247 return false; |
244 | 248 |
245 // Otherwise, close existing tabs, and deny closing of browser. | 249 // Otherwise, close existing tabs, and deny closing of browser. |
246 // TabClosingAt will open NTP when the last tab is being closed. | 250 // TabClosingAt will open NTP when the last tab is being closed. |
247 *action_type = OPEN_NTP; | 251 *action_type = OPEN_NTP; |
248 return false; | 252 return false; |
249 } | 253 } |
250 | 254 |
251 } // namespace chromeos | 255 } // namespace chromeos |
OLD | NEW |