• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_TAB_CLOSEABLE_STATE_WATCHER_H_
6 #define CHROME_BROWSER_TAB_CLOSEABLE_STATE_WATCHER_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 
11 class Browser;
12 
13 // Base class for watching closeable state of tabs, which always returns true
14 // to allow closing for all tabs and browsers.  Classes that desire otherwise
15 // can inherit this class and override the methods as deemed appropriate to
16 // allow or disallow tabs or browsers to be closed.
17 
18 class TabCloseableStateWatcher {
19  public:
TabCloseableStateWatcher()20   TabCloseableStateWatcher() {}
~TabCloseableStateWatcher()21   virtual ~TabCloseableStateWatcher() {}
22 
23   // Creates the appropriate TabCloseableStateWatcher.  The caller owns the
24   // returned object.
25   static TabCloseableStateWatcher* Create();
26 
27   // Called from Browser::CanCloseTab which overrides TabStripModelDelegate::
28   // CanCloseTab, and returns true if tab of browser is closeable.
29   // Browser::CanCloseTab is in turn called by Browser, TabStripModel and
30   // BrowserTabStripController when:
31   // - rendering tab to determine if close button should be drawn
32   // - setting up tab's context menu to determine if "Close tab" should
33   //   should be enabled
34   // - determining if accelerator keys to close tab should be processed
35   virtual bool CanCloseTab(const Browser* browser) const;
36 
37   // Called from Browser::IsClosingPermitted which is in turn called from
38   // Browser::ShouldCloseWindow to check if |browser| can be closed.
39   virtual bool CanCloseBrowser(Browser* browser);
40 
41   // Called from Browser::CancelWindowClose when closing of window is canceled.
42   // Watcher is potentially interested in this, especially when the closing of
43   // window was initiated by application exiting.
OnWindowCloseCanceled(Browser * browser)44   virtual void OnWindowCloseCanceled(Browser* browser) {}
45 
46  private:
47   DISALLOW_COPY_AND_ASSIGN(TabCloseableStateWatcher);
48 };
49 
50 #endif  // CHROME_BROWSER_TAB_CLOSEABLE_STATE_WATCHER_H_
51