blob: 2f0546c96da66e28aa9f013791c8a1712bb9194d [file] [log] [blame]
[email protected]41d9faf2012-02-28 23:46:021// 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.
4
[email protected]44f4b132012-07-17 20:36:575#ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_
6#define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_
[email protected]41d9faf2012-02-28 23:46:027
avia2f4804a2015-12-24 23:11:138#include <stdint.h>
9
[email protected]c80ed692012-04-18 19:51:1010#include <string>
11
[email protected]41d9faf2012-02-28 23:46:0212#include "base/compiler_specific.h"
avia2f4804a2015-12-24 23:11:1313#include "base/macros.h"
lionel.g.landwerlin56b2a722015-08-06 00:04:1014#include "chrome/common/extensions/api/windows.h"
[email protected]41d9faf2012-02-28 23:46:0215
[email protected]b51f35622012-05-05 22:01:4316class Browser; // TODO(stevenjb) eliminate this dependency.
[email protected]41d9faf2012-02-28 23:46:0217class GURL;
18class Profile;
19class SessionID;
20
21namespace base {
22class DictionaryValue;
23}
24
25namespace gfx {
26class Rect;
27}
28
[email protected]5f39adc2013-05-23 11:50:4629namespace ui {
30class BaseWindow;
31}
32
[email protected]44f4b132012-07-17 20:36:5733namespace extensions {
34class Extension;
35
[email protected]41d9faf2012-02-28 23:46:0236// This API needs to be implemented by any window that might be accessed
37// through chrome.windows or chrome.tabs (e.g. browser windows and panels).
[email protected]163ed192012-07-24 19:31:0738// Subclasses must add/remove themselves from the WindowControllerList
39// upon construction/destruction.
[email protected]44f4b132012-07-17 20:36:5740class WindowController {
[email protected]41d9faf2012-02-28 23:46:0241 public:
42 enum Reason {
43 REASON_NONE,
[email protected]b51f35622012-05-05 22:01:4344 REASON_NOT_EDITABLE,
[email protected]41d9faf2012-02-28 23:46:0245 };
[email protected]b51f35622012-05-05 22:01:4346
lionel.g.landwerlin56b2a722015-08-06 00:04:1047 // A bitmaks used as filter on window types.
48 using TypeFilter = uint32_t;
49
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5750 // Represents the lack of any window filter, implying
51 // IsVisibleToExtension will be used as non-filtered behavior.
52 static const TypeFilter kNoWindowFilter = 0;
53
lionel.g.landwerlin56b2a722015-08-06 00:04:1054 // Returns a filter allowing all window types to be manipulated
55 // through the chrome.windows APIs.
56 static TypeFilter GetAllWindowFilter();
57
lionel.g.landwerlin56b2a722015-08-06 00:04:1058 // Builds a filter out of a vector of window types.
59 static TypeFilter GetFilterFromWindowTypes(
60 const std::vector<api::windows::WindowType>& types);
61
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5762 static TypeFilter GetFilterFromWindowTypesValues(
63 const base::ListValue* types);
64
[email protected]5f39adc2013-05-23 11:50:4665 WindowController(ui::BaseWindow* window, Profile* profile);
[email protected]44f4b132012-07-17 20:36:5766 virtual ~WindowController();
[email protected]41d9faf2012-02-28 23:46:0267
[email protected]5f39adc2013-05-23 11:50:4668 ui::BaseWindow* window() const { return window_; }
[email protected]41d9faf2012-02-28 23:46:0269
[email protected]b51f35622012-05-05 22:01:4370 Profile* profile() const { return profile_; }
71
[email protected]c80ed692012-04-18 19:51:1072 // Return an id uniquely identifying the window.
73 virtual int GetWindowId() const = 0;
74
75 // Return the type name for the window.
76 virtual std::string GetWindowTypeText() const = 0;
[email protected]41d9faf2012-02-28 23:46:0277
[email protected]b51f35622012-05-05 22:01:4378 // Populates a dictionary for the Window object. Override this to set
79 // implementation specific properties (call the base implementation first to
80 // set common properties).
81 virtual base::DictionaryValue* CreateWindowValue() const;
82
[email protected]41d9faf2012-02-28 23:46:0283 // Populates a dictionary for the Window object, including a list of tabs.
[email protected]f34706be2012-09-04 07:32:0984 virtual base::DictionaryValue* CreateWindowValueWithTabs(
85 const extensions::Extension* extension) const = 0;
[email protected]41d9faf2012-02-28 23:46:0286
[email protected]f1c102b2013-02-15 07:44:1287 virtual base::DictionaryValue* CreateTabValue(
88 const extensions::Extension* extension, int tab_index) const = 0;
89
[email protected]41d9faf2012-02-28 23:46:0290 // Returns false if the window is in a state where closing the window is not
91 // permitted and sets |reason| if not NULL.
92 virtual bool CanClose(Reason* reason) const = 0;
93
94 // Set the window's fullscreen state. |extension_url| provides the url
95 // associated with the extension (used by FullscreenController).
96 virtual void SetFullscreenMode(bool is_fullscreen,
97 const GURL& extension_url) const = 0;
98
[email protected]b51f35622012-05-05 22:01:4399 // Returns a Browser if available. Defaults to returning NULL.
100 // TODO(stevenjb): Temporary workaround. Eliminate this.
101 virtual Browser* GetBrowser() const;
102
[email protected]31bdbfef2012-05-22 19:59:15103 // Extension/window visibility and ownership is window-specific, subclasses
104 // need to define this behavior.
[email protected]44f4b132012-07-17 20:36:57105 virtual bool IsVisibleToExtension(const Extension* extension) const = 0;
[email protected]31bdbfef2012-05-22 19:59:15106
lionel.g.landwerlin56b2a722015-08-06 00:04:10107 // Returns true if the window type of the controller matches the |filter|.
108 bool MatchesFilter(TypeFilter filter) const;
109
[email protected]41d9faf2012-02-28 23:46:02110 private:
[email protected]5f39adc2013-05-23 11:50:46111 ui::BaseWindow* window_;
[email protected]41d9faf2012-02-28 23:46:02112 Profile* profile_;
113
[email protected]44f4b132012-07-17 20:36:57114 DISALLOW_COPY_AND_ASSIGN(WindowController);
[email protected]41d9faf2012-02-28 23:46:02115};
116
[email protected]44f4b132012-07-17 20:36:57117} // namespace extensions
118
119#endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_