[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 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. | ||||
4 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ |
6 | #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ | ||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 7 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 10 | #include <string> |
11 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 13 | #include "base/macros.h" |
limasdf | 6dcdc44 | 2016-02-26 04:58:26 | [diff] [blame^] | 14 | #include "chrome/common/extensions/api/tabs.h" |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 15 | #include "chrome/common/extensions/api/windows.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 16 | |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 17 | class Browser; // TODO(stevenjb) eliminate this dependency. |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 18 | class GURL; |
19 | class Profile; | ||||
20 | class SessionID; | ||||
21 | |||||
22 | namespace base { | ||||
23 | class DictionaryValue; | ||||
24 | } | ||||
25 | |||||
26 | namespace gfx { | ||||
27 | class Rect; | ||||
28 | } | ||||
29 | |||||
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 30 | namespace ui { |
31 | class BaseWindow; | ||||
32 | } | ||||
33 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 34 | namespace extensions { |
35 | class Extension; | ||||
36 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 37 | // 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] | 163ed19 | 2012-07-24 19:31:07 | [diff] [blame] | 39 | // Subclasses must add/remove themselves from the WindowControllerList |
40 | // upon construction/destruction. | ||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 41 | class WindowController { |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 42 | public: |
43 | enum Reason { | ||||
44 | REASON_NONE, | ||||
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 45 | REASON_NOT_EDITABLE, |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 46 | }; |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 47 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 48 | // A bitmaks used as filter on window types. |
49 | using TypeFilter = uint32_t; | ||||
50 | |||||
lionel.g.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 51 | // 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.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 55 | // Returns a filter allowing all window types to be manipulated |
56 | // through the chrome.windows APIs. | ||||
57 | static TypeFilter GetAllWindowFilter(); | ||||
58 | |||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 59 | // 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.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 63 | static TypeFilter GetFilterFromWindowTypesValues( |
64 | const base::ListValue* types); | ||||
65 | |||||
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 66 | WindowController(ui::BaseWindow* window, Profile* profile); |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 67 | virtual ~WindowController(); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 68 | |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 69 | ui::BaseWindow* window() const { return window_; } |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 70 | |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 71 | Profile* profile() const { return profile_; } |
72 | |||||
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 73 | // 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] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 78 | |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 79 | // 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] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 84 | // Populates a dictionary for the Window object, including a list of tabs. |
[email protected] | f34706be | 2012-09-04 07:32:09 | [diff] [blame] | 85 | virtual base::DictionaryValue* CreateWindowValueWithTabs( |
86 | const extensions::Extension* extension) const = 0; | ||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 87 | |
limasdf | 6dcdc44 | 2016-02-26 04:58:26 | [diff] [blame^] | 88 | 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] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 93 | virtual base::DictionaryValue* CreateTabValue( |
94 | const extensions::Extension* extension, int tab_index) const = 0; | ||||
95 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 96 | // 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] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 105 | // Returns a Browser if available. Defaults to returning NULL. |
106 | // TODO(stevenjb): Temporary workaround. Eliminate this. | ||||
107 | virtual Browser* GetBrowser() const; | ||||
108 | |||||
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 109 | // Extension/window visibility and ownership is window-specific, subclasses |
110 | // need to define this behavior. | ||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 111 | virtual bool IsVisibleToExtension(const Extension* extension) const = 0; |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 112 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 113 | // Returns true if the window type of the controller matches the |filter|. |
114 | bool MatchesFilter(TypeFilter filter) const; | ||||
115 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 116 | private: |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 117 | ui::BaseWindow* window_; |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 118 | Profile* profile_; |
119 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 120 | DISALLOW_COPY_AND_ASSIGN(WindowController); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 121 | }; |
122 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 123 | } // namespace extensions |
124 | |||||
125 | #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ |