blob: 5bd45cbaa7f2ff146978ace3cc46cd4b36665bbd [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"
limasdf6dcdc442016-02-26 04:58:2614#include "chrome/common/extensions/api/tabs.h"
lionel.g.landwerlin56b2a722015-08-06 00:04:1015#include "chrome/common/extensions/api/windows.h"
[email protected]41d9faf2012-02-28 23:46:0216
[email protected]b51f35622012-05-05 22:01:4317class Browser; // TODO(stevenjb) eliminate this dependency.
[email protected]41d9faf2012-02-28 23:46:0218class GURL;
19class Profile;
20class SessionID;
21
22namespace base {
23class DictionaryValue;
24}
25
26namespace gfx {
27class Rect;
28}
29
[email protected]5f39adc2013-05-23 11:50:4630namespace ui {
31class BaseWindow;
32}
33
[email protected]44f4b132012-07-17 20:36:5734namespace extensions {
35class Extension;
36
[email protected]41d9faf2012-02-28 23:46:0237// This API needs to be implemented by any window that might be accessed
38// through chrome.windows or chrome.tabs (e.g. browser windows and panels).
[email protected]163ed192012-07-24 19:31:0739// Subclasses must add/remove themselves from the WindowControllerList
40// upon construction/destruction.
[email protected]44f4b132012-07-17 20:36:5741class WindowController {
[email protected]41d9faf2012-02-28 23:46:0242 public:
43 enum Reason {
44 REASON_NONE,
[email protected]b51f35622012-05-05 22:01:4345 REASON_NOT_EDITABLE,
[email protected]41d9faf2012-02-28 23:46:0246 };
[email protected]b51f35622012-05-05 22:01:4347
lionel.g.landwerlin56b2a722015-08-06 00:04:1048 // A bitmaks used as filter on window types.
49 using TypeFilter = uint32_t;
50
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5751 // Represents the lack of any window filter, implying
52 // IsVisibleToExtension will be used as non-filtered behavior.
53 static const TypeFilter kNoWindowFilter = 0;
54
lionel.g.landwerlin56b2a722015-08-06 00:04:1055 // Returns a filter allowing all window types to be manipulated
56 // through the chrome.windows APIs.
57 static TypeFilter GetAllWindowFilter();
58
lionel.g.landwerlin56b2a722015-08-06 00:04:1059 // Builds a filter out of a vector of window types.
60 static TypeFilter GetFilterFromWindowTypes(
61 const std::vector<api::windows::WindowType>& types);
62
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5763 static TypeFilter GetFilterFromWindowTypesValues(
64 const base::ListValue* types);
65
[email protected]5f39adc2013-05-23 11:50:4666 WindowController(ui::BaseWindow* window, Profile* profile);
[email protected]44f4b132012-07-17 20:36:5767 virtual ~WindowController();
[email protected]41d9faf2012-02-28 23:46:0268
[email protected]5f39adc2013-05-23 11:50:4669 ui::BaseWindow* window() const { return window_; }
[email protected]41d9faf2012-02-28 23:46:0270
[email protected]b51f35622012-05-05 22:01:4371 Profile* profile() const { return profile_; }
72
[email protected]c80ed692012-04-18 19:51:1073 // Return an id uniquely identifying the window.
74 virtual int GetWindowId() const = 0;
75
76 // Return the type name for the window.
77 virtual std::string GetWindowTypeText() const = 0;
[email protected]41d9faf2012-02-28 23:46:0278
[email protected]b51f35622012-05-05 22:01:4379 // Populates a dictionary for the Window object. Override this to set
80 // implementation specific properties (call the base implementation first to
81 // set common properties).
82 virtual base::DictionaryValue* CreateWindowValue() const;
83
[email protected]41d9faf2012-02-28 23:46:0284 // Populates a dictionary for the Window object, including a list of tabs.
[email protected]f34706be2012-09-04 07:32:0985 virtual base::DictionaryValue* CreateWindowValueWithTabs(
86 const extensions::Extension* extension) const = 0;
[email protected]41d9faf2012-02-28 23:46:0287
limasdf6dcdc442016-02-26 04:58:2688 virtual scoped_ptr<api::tabs::Tab> CreateTabObject(
89 const extensions::Extension* extension,
90 int tab_index) const = 0;
91
92 // DEPRECATED: Use scoped_ptr<api::tabs::Tab> CreateTabObject(...)
[email protected]f1c102b2013-02-15 07:44:1293 virtual base::DictionaryValue* CreateTabValue(
94 const extensions::Extension* extension, int tab_index) const = 0;
95
[email protected]41d9faf2012-02-28 23:46:0296 // Returns false if the window is in a state where closing the window is not
97 // permitted and sets |reason| if not NULL.
98 virtual bool CanClose(Reason* reason) const = 0;
99
100 // Set the window's fullscreen state. |extension_url| provides the url
101 // associated with the extension (used by FullscreenController).
102 virtual void SetFullscreenMode(bool is_fullscreen,
103 const GURL& extension_url) const = 0;
104
[email protected]b51f35622012-05-05 22:01:43105 // Returns a Browser if available. Defaults to returning NULL.
106 // TODO(stevenjb): Temporary workaround. Eliminate this.
107 virtual Browser* GetBrowser() const;
108
[email protected]31bdbfef2012-05-22 19:59:15109 // Extension/window visibility and ownership is window-specific, subclasses
110 // need to define this behavior.
[email protected]44f4b132012-07-17 20:36:57111 virtual bool IsVisibleToExtension(const Extension* extension) const = 0;
[email protected]31bdbfef2012-05-22 19:59:15112
lionel.g.landwerlin56b2a722015-08-06 00:04:10113 // Returns true if the window type of the controller matches the |filter|.
114 bool MatchesFilter(TypeFilter filter) const;
115
[email protected]41d9faf2012-02-28 23:46:02116 private:
[email protected]5f39adc2013-05-23 11:50:46117 ui::BaseWindow* window_;
[email protected]41d9faf2012-02-28 23:46:02118 Profile* profile_;
119
[email protected]44f4b132012-07-17 20:36:57120 DISALLOW_COPY_AND_ASSIGN(WindowController);
[email protected]41d9faf2012-02-28 23:46:02121};
122
[email protected]44f4b132012-07-17 20:36:57123} // namespace extensions
124
125#endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_