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 #ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chrome/common/extensions/api/windows.h"
14 class Browser
; // TODO(stevenjb) eliminate this dependency.
20 class DictionaryValue
;
31 namespace extensions
{
34 // This API needs to be implemented by any window that might be accessed
35 // through chrome.windows or chrome.tabs (e.g. browser windows and panels).
36 // Subclasses must add/remove themselves from the WindowControllerList
37 // upon construction/destruction.
38 class WindowController
{
45 // A bitmaks used as filter on window types.
46 using TypeFilter
= uint32_t;
48 // Returns a filter allowing all window types to be manipulated
49 // through the chrome.windows APIs.
50 static TypeFilter
GetAllWindowFilter();
52 // Returns the default filter to be used when operating on the windows
53 // from WindowControllerList when using the chrome.windows APIs.
54 static TypeFilter
GetDefaultWindowFilter();
56 // Builds a filter out of a vector of window types.
57 static TypeFilter
GetFilterFromWindowTypes(
58 const std::vector
<api::windows::WindowType
>& types
);
60 WindowController(ui::BaseWindow
* window
, Profile
* profile
);
61 virtual ~WindowController();
63 ui::BaseWindow
* window() const { return window_
; }
65 Profile
* profile() const { return profile_
; }
67 // Return an id uniquely identifying the window.
68 virtual int GetWindowId() const = 0;
70 // Return the type name for the window.
71 virtual std::string
GetWindowTypeText() const = 0;
73 // Populates a dictionary for the Window object. Override this to set
74 // implementation specific properties (call the base implementation first to
75 // set common properties).
76 virtual base::DictionaryValue
* CreateWindowValue() const;
78 // Populates a dictionary for the Window object, including a list of tabs.
79 virtual base::DictionaryValue
* CreateWindowValueWithTabs(
80 const extensions::Extension
* extension
) const = 0;
82 virtual base::DictionaryValue
* CreateTabValue(
83 const extensions::Extension
* extension
, int tab_index
) const = 0;
85 // Returns false if the window is in a state where closing the window is not
86 // permitted and sets |reason| if not NULL.
87 virtual bool CanClose(Reason
* reason
) const = 0;
89 // Set the window's fullscreen state. |extension_url| provides the url
90 // associated with the extension (used by FullscreenController).
91 virtual void SetFullscreenMode(bool is_fullscreen
,
92 const GURL
& extension_url
) const = 0;
94 // Returns a Browser if available. Defaults to returning NULL.
95 // TODO(stevenjb): Temporary workaround. Eliminate this.
96 virtual Browser
* GetBrowser() const;
98 // Extension/window visibility and ownership is window-specific, subclasses
99 // need to define this behavior.
100 virtual bool IsVisibleToExtension(const Extension
* extension
) const = 0;
102 // Returns true if the window type of the controller matches the |filter|.
103 bool MatchesFilter(TypeFilter filter
) const;
106 ui::BaseWindow
* window_
;
109 DISALLOW_COPY_AND_ASSIGN(WindowController
);
112 } // namespace extensions
114 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_