| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "content/browser/tab_contents/tab_contents_view.h" | 16 #include "content/browser/tab_contents/tab_contents_view.h" |
| 17 #include "content/common/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 22 // TabCloseableStateWatcher::TabStripWatcher, public: | 22 // TabCloseableStateWatcher::TabStripWatcher, public: |
| 23 | 23 |
| 24 TabCloseableStateWatcher::TabStripWatcher::TabStripWatcher( | 24 TabCloseableStateWatcher::TabStripWatcher::TabStripWatcher( |
| 25 TabCloseableStateWatcher* main_watcher, const Browser* browser) | 25 TabCloseableStateWatcher* main_watcher, const Browser* browser) |
| 26 : main_watcher_(main_watcher), | 26 : main_watcher_(main_watcher), |
| 27 browser_(browser) { | 27 browser_(browser) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 TabCloseableStateWatcher::TabCloseableStateWatcher() | 66 TabCloseableStateWatcher::TabCloseableStateWatcher() |
| 67 : can_close_tab_(true), | 67 : can_close_tab_(true), |
| 68 signing_off_(false), | 68 signing_off_(false), |
| 69 guest_session_( | 69 guest_session_( |
| 70 CommandLine::ForCurrentProcess()->HasSwitch( | 70 CommandLine::ForCurrentProcess()->HasSwitch( |
| 71 switches::kGuestSession)), | 71 switches::kGuestSession)), |
| 72 waiting_for_browser_(false) { | 72 waiting_for_browser_(false) { |
| 73 BrowserList::AddObserver(this); | 73 BrowserList::AddObserver(this); |
| 74 notification_registrar_.Add(this, content::NOTIFICATION_APP_EXITING, | 74 notification_registrar_.Add(this, content::NOTIFICATION_APP_EXITING, |
| 75 NotificationService::AllSources()); | 75 content::NotificationService::AllSources()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TabCloseableStateWatcher::~TabCloseableStateWatcher() { | 78 TabCloseableStateWatcher::~TabCloseableStateWatcher() { |
| 79 BrowserList::RemoveObserver(this); | 79 BrowserList::RemoveObserver(this); |
| 80 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) | 80 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 81 DCHECK(tabstrip_watchers_.empty()); | 81 DCHECK(tabstrip_watchers_.empty()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool TabCloseableStateWatcher::CanCloseTab(const Browser* browser) const { | 84 bool TabCloseableStateWatcher::CanCloseTab(const Browser* browser) const { |
| 85 return browser->is_type_tabbed() ? | 85 return browser->is_type_tabbed() ? |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 SetCloseableState(new_can_close); | 254 SetCloseableState(new_can_close); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { | 257 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { |
| 258 if (can_close_tab_ == closeable) // No change in state. | 258 if (can_close_tab_ == closeable) // No change in state. |
| 259 return; | 259 return; |
| 260 | 260 |
| 261 can_close_tab_ = closeable; | 261 can_close_tab_ = closeable; |
| 262 | 262 |
| 263 // Notify of change in tab closeable state. | 263 // Notify of change in tab closeable state. |
| 264 NotificationService::current()->Notify( | 264 content::NotificationService::current()->Notify( |
| 265 chrome::NOTIFICATION_TAB_CLOSEABLE_STATE_CHANGED, | 265 chrome::NOTIFICATION_TAB_CLOSEABLE_STATE_CHANGED, |
| 266 NotificationService::AllSources(), | 266 content::NotificationService::AllSources(), |
| 267 content::Details<bool>(&can_close_tab_)); | 267 content::Details<bool>(&can_close_tab_)); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool TabCloseableStateWatcher::CanCloseBrowserImpl( | 270 bool TabCloseableStateWatcher::CanCloseBrowserImpl( |
| 271 const Browser* browser, | 271 const Browser* browser, |
| 272 BrowserActionType* action_type) { | 272 BrowserActionType* action_type) { |
| 273 *action_type = NONE; | 273 *action_type = NONE; |
| 274 | 274 |
| 275 // If we're waiting for a new browser allow the close. | 275 // If we're waiting for a new browser allow the close. |
| 276 if (waiting_for_browser_) | 276 if (waiting_for_browser_) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 302 if (!can_close_tab_) | 302 if (!can_close_tab_) |
| 303 return false; | 303 return false; |
| 304 | 304 |
| 305 // Otherwise, close existing tabs, and deny closing of browser. | 305 // Otherwise, close existing tabs, and deny closing of browser. |
| 306 // TabClosingAt will open NTP when the last tab is being closed. | 306 // TabClosingAt will open NTP when the last tab is being closed. |
| 307 *action_type = OPEN_NTP; | 307 *action_type = OPEN_NTP; |
| 308 return false; | 308 return false; |
| 309 } | 309 } |
| 310 | 310 |
| 311 } // namespace chromeos | 311 } // namespace chromeos |
| OLD | NEW |