| 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 #ifndef CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" |
| 11 #include "chrome/browser/tab_closeable_state_watcher.h" | 12 #include "chrome/browser/tab_closeable_state_watcher.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model_observer.h" | 13 #include "chrome/browser/tabs/tab_strip_model_observer.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 | 18 |
| 18 // This class overrides ::TabCloseableStateWatcher to allow or disallow tabs or | 19 // This class overrides ::TabCloseableStateWatcher to allow or disallow tabs or |
| 19 // browsers to be closed based on increase or decrease in number of tabs or | 20 // browsers to be closed based on increase or decrease in number of tabs or |
| 20 // browsers. We only do this on Chromeos and only for non-tests. | 21 // browsers. We only do this on Chromeos and only for non-tests. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 // NewTabPage is open. | 41 // NewTabPage is open. |
| 41 | 42 |
| 42 class TabCloseableStateWatcher : public ::TabCloseableStateWatcher, | 43 class TabCloseableStateWatcher : public ::TabCloseableStateWatcher, |
| 43 public BrowserList::Observer, | 44 public BrowserList::Observer, |
| 44 public content::NotificationObserver { | 45 public content::NotificationObserver { |
| 45 public: | 46 public: |
| 46 TabCloseableStateWatcher(); | 47 TabCloseableStateWatcher(); |
| 47 virtual ~TabCloseableStateWatcher(); | 48 virtual ~TabCloseableStateWatcher(); |
| 48 | 49 |
| 49 // TabCloseableStateWatcher implementation: | 50 // TabCloseableStateWatcher implementation: |
| 50 virtual bool CanCloseTab(const Browser* browser) const; | 51 virtual bool CanCloseTab(const Browser* browser) const OVERRIDE; |
| 51 virtual bool CanCloseTabs(const Browser* browser, | 52 virtual bool CanCloseTabs(const Browser* browser, |
| 52 std::vector<int>* indices) const; | 53 std::vector<int>* indices) const OVERRIDE; |
| 53 virtual bool CanCloseBrowser(Browser* browser); | 54 virtual bool CanCloseBrowser(Browser* browser) OVERRIDE; |
| 54 virtual void OnWindowCloseCanceled(Browser* browser); | 55 virtual void OnWindowCloseCanceled(Browser* browser) OVERRIDE; |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 enum BrowserActionType { | 58 enum BrowserActionType { |
| 58 NONE = 0, // Nothing to do. | 59 NONE = 0, // Nothing to do. |
| 59 OPEN_WINDOW = 1, // Opens a regular (i.e. non-incognito) normal browser. | 60 OPEN_WINDOW = 1, // Opens a regular (i.e. non-incognito) normal browser. |
| 60 OPEN_NTP = 2, // Opens a NewTabPage. | 61 OPEN_NTP = 2, // Opens a NewTabPage. |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // BrowserList::Observer implementation: | 64 // BrowserList::Observer implementation: |
| 64 virtual void OnBrowserAdded(const Browser* browser); | 65 virtual void OnBrowserAdded(const Browser* browser) OVERRIDE; |
| 65 virtual void OnBrowserRemoved(const Browser* browser); | 66 virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE; |
| 66 | 67 |
| 67 // NotificationObserver implementation: | 68 // NotificationObserver implementation: |
| 68 virtual void Observe(int type, const content::NotificationSource& source, | 69 virtual void Observe(int type, const content::NotificationSource& source, |
| 69 const content::NotificationDetails& details); | 70 const content::NotificationDetails& details) OVERRIDE; |
| 70 | 71 |
| 71 // Called by private class TabStripWatcher for TabStripModelObserver | 72 // Called by private class TabStripWatcher for TabStripModelObserver |
| 72 // notifications. | 73 // notifications. |
| 73 // |closing_last_tab| is true if the tab strip is closing the last tab. | 74 // |closing_last_tab| is true if the tab strip is closing the last tab. |
| 74 void OnTabStripChanged(const Browser* browser, bool closing_last_tab); | 75 void OnTabStripChanged(const Browser* browser, bool closing_last_tab); |
| 75 | 76 |
| 76 // Utility functions. | 77 // Utility functions. |
| 77 | 78 |
| 78 // Checks the closeable state of tab. If it has changed, updates it and | 79 // Checks the closeable state of tab. If it has changed, updates it and |
| 79 // notifies all normal browsers. | 80 // notifies all normal browsers. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // needed so we know which browser the TabStripModelObserver method relates | 116 // needed so we know which browser the TabStripModelObserver method relates |
| 116 // to. | 117 // to. |
| 117 class TabStripWatcher : public TabStripModelObserver { | 118 class TabStripWatcher : public TabStripModelObserver { |
| 118 public: | 119 public: |
| 119 TabStripWatcher(TabCloseableStateWatcher* main_watcher, | 120 TabStripWatcher(TabCloseableStateWatcher* main_watcher, |
| 120 const Browser* browser); | 121 const Browser* browser); |
| 121 virtual ~TabStripWatcher(); | 122 virtual ~TabStripWatcher(); |
| 122 | 123 |
| 123 // TabStripModelObserver implementation: | 124 // TabStripModelObserver implementation: |
| 124 virtual void TabInsertedAt(TabContentsWrapper* contents, int index, | 125 virtual void TabInsertedAt(TabContentsWrapper* contents, int index, |
| 125 bool foreground); | 126 bool foreground) OVERRIDE; |
| 126 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 127 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
| 127 TabContentsWrapper* contents, | 128 TabContentsWrapper* contents, |
| 128 int index); | 129 int index) OVERRIDE; |
| 129 virtual void TabDetachedAt(TabContentsWrapper* contents, int index); | 130 virtual void TabDetachedAt(TabContentsWrapper* contents, |
| 131 int index) OVERRIDE; |
| 130 virtual void TabChangedAt(TabContentsWrapper* contents, int index, | 132 virtual void TabChangedAt(TabContentsWrapper* contents, int index, |
| 131 TabChangeType change_type); | 133 TabChangeType change_type) OVERRIDE; |
| 132 | 134 |
| 133 const Browser* browser() const { | 135 const Browser* browser() const { |
| 134 return browser_; | 136 return browser_; |
| 135 } | 137 } |
| 136 | 138 |
| 137 private: | 139 private: |
| 138 TabCloseableStateWatcher* main_watcher_; | 140 TabCloseableStateWatcher* main_watcher_; |
| 139 const Browser* browser_; | 141 const Browser* browser_; |
| 140 | 142 |
| 141 DISALLOW_COPY_AND_ASSIGN(TabStripWatcher); | 143 DISALLOW_COPY_AND_ASSIGN(TabStripWatcher); |
| 142 }; | 144 }; |
| 143 | 145 |
| 144 friend class TabStripWatcher; | 146 friend class TabStripWatcher; |
| 145 | 147 |
| 146 std::vector<TabStripWatcher*> tabstrip_watchers_; | 148 std::vector<TabStripWatcher*> tabstrip_watchers_; |
| 147 | 149 |
| 148 DISALLOW_COPY_AND_ASSIGN(TabCloseableStateWatcher); | 150 DISALLOW_COPY_AND_ASSIGN(TabCloseableStateWatcher); |
| 149 }; | 151 }; |
| 150 | 152 |
| 151 } // namespace chromeos | 153 } // namespace chromeos |
| 152 | 154 |
| 153 #endif // CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ | 155 #endif // CHROME_BROWSER_CHROMEOS_TAB_CLOSEABLE_STATE_WATCHER_H_ |
| OLD | NEW |