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 // Represents the lack of any window filter, implying
49 // IsVisibleToExtension will be used as non-filtered behavior.
50 static const TypeFilter kNoWindowFilter
= 0;
52 // Returns a filter allowing all window types to be manipulated
53 // through the chrome.windows APIs.
54 static TypeFilter
GetAllWindowFilter();
56 // Builds a filter out of a vector of window types.
57 static TypeFilter
GetFilterFromWindowTypes(
58 const std::vector
<api::windows::WindowType
>& types
);
60 static TypeFilter
GetFilterFromWindowTypesValues(
61 const base::ListValue
* types
);
63 WindowController(ui::BaseWindow
* window
, Profile
* profile
);
64 virtual ~WindowController();
66 ui::BaseWindow
* window() const { return window_
; }
68 Profile
* profile() const { return profile_
; }
70 // Return an id uniquely identifying the window.
71 virtual int GetWindowId() const = 0;
73 // Return the type name for the window.
74 virtual std::string
GetWindowTypeText() const = 0;
76 // Populates a dictionary for the Window object. Override this to set
77 // implementation specific properties (call the base implementation first to
78 // set common properties).
79 virtual base::DictionaryValue
* CreateWindowValue() const;
81 // Populates a dictionary for the Window object, including a list of tabs.
82 virtual base::DictionaryValue
* CreateWindowValueWithTabs(
83 const extensions::Extension
* extension
) const = 0;
85 virtual base::DictionaryValue
* CreateTabValue(
86 const extensions::Extension
* extension
, int tab_index
) const = 0;
88 // Returns false if the window is in a state where closing the window is not
89 // permitted and sets |reason| if not NULL.
90 virtual bool CanClose(Reason
* reason
) const = 0;
92 // Set the window's fullscreen state. |extension_url| provides the url
93 // associated with the extension (used by FullscreenController).
94 virtual void SetFullscreenMode(bool is_fullscreen
,
95 const GURL
& extension_url
) const = 0;
97 // Returns a Browser if available. Defaults to returning NULL.
98 // TODO(stevenjb): Temporary workaround. Eliminate this.
99 virtual Browser
* GetBrowser() const;
101 // Extension/window visibility and ownership is window-specific, subclasses
102 // need to define this behavior.
103 virtual bool IsVisibleToExtension(const Extension
* extension
) const = 0;
105 // Returns true if the window type of the controller matches the |filter|.
106 bool MatchesFilter(TypeFilter filter
) const;
109 ui::BaseWindow
* window_
;
112 DISALLOW_COPY_AND_ASSIGN(WindowController
);
115 } // namespace extensions
117 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_