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