[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 | |||||
dcheng | a500b69 | 2016-04-08 19:55:42 | [diff] [blame] | 10 | #include <memory> |
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 11 | #include <string> |
Devlin Cronin | 7050f8e | 2018-02-07 19:52:04 | [diff] [blame] | 12 | #include <vector> |
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 13 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 15 | #include "base/macros.h" |
limasdf | 6dcdc44 | 2016-02-26 04:58:26 | [diff] [blame] | 16 | #include "chrome/common/extensions/api/tabs.h" |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 17 | #include "chrome/common/extensions/api/windows.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 18 | |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 19 | class Browser; // TODO(stevenjb) eliminate this dependency. |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 20 | class Profile; |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 21 | |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 22 | namespace ui { |
23 | class BaseWindow; | ||||
24 | } | ||||
25 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 26 | namespace extensions { |
27 | class Extension; | ||||
28 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 29 | // This API needs to be implemented by any window that might be accessed |
Devlin Cronin | 7050f8e | 2018-02-07 19:52:04 | [diff] [blame] | 30 | // through various extension APIs for modifying or finding the window. |
[email protected] | 163ed19 | 2012-07-24 19:31:07 | [diff] [blame] | 31 | // Subclasses must add/remove themselves from the WindowControllerList |
32 | // upon construction/destruction. | ||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 33 | class WindowController { |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 34 | public: |
35 | enum Reason { | ||||
36 | REASON_NONE, | ||||
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 37 | REASON_NOT_EDITABLE, |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 38 | }; |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 39 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 40 | // A bitmaks used as filter on window types. |
41 | using TypeFilter = uint32_t; | ||||
42 | |||||
lionel.g.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 43 | // Represents the lack of any window filter, implying |
44 | // IsVisibleToExtension will be used as non-filtered behavior. | ||||
45 | static const TypeFilter kNoWindowFilter = 0; | ||||
46 | |||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 47 | // Returns a filter allowing all window types to be manipulated |
48 | // through the chrome.windows APIs. | ||||
49 | static TypeFilter GetAllWindowFilter(); | ||||
50 | |||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 51 | // Builds a filter out of a vector of window types. |
52 | static TypeFilter GetFilterFromWindowTypes( | ||||
53 | const std::vector<api::windows::WindowType>& types); | ||||
54 | |||||
lionel.g.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 55 | static TypeFilter GetFilterFromWindowTypesValues( |
56 | const base::ListValue* types); | ||||
57 | |||||
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 58 | WindowController(ui::BaseWindow* window, Profile* profile); |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 59 | virtual ~WindowController(); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 60 | |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 61 | ui::BaseWindow* window() const { return window_; } |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 62 | |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 63 | Profile* profile() const { return profile_; } |
64 | |||||
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 65 | // Return an id uniquely identifying the window. |
66 | virtual int GetWindowId() const = 0; | ||||
67 | |||||
68 | // Return the type name for the window. | ||||
Devlin Cronin | 7050f8e | 2018-02-07 19:52:04 | [diff] [blame] | 69 | // TODO(devlin): Remove this in favor of the method on ExtensionTabUtil. |
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 70 | virtual std::string GetWindowTypeText() const = 0; |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 71 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 72 | // Returns false if the window is in a state where closing the window is not |
73 | // permitted and sets |reason| if not NULL. | ||||
74 | virtual bool CanClose(Reason* reason) const = 0; | ||||
75 | |||||
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 76 | // Returns a Browser if available. Defaults to returning NULL. |
77 | // TODO(stevenjb): Temporary workaround. Eliminate this. | ||||
78 | virtual Browser* GetBrowser() const; | ||||
79 | |||||
Devlin Cronin | f620cde | 2018-02-01 05:40:04 | [diff] [blame] | 80 | // Returns true if the window is visible to the tabs API, when used by the |
81 | // given |extension|. | ||||
82 | // |allow_dev_tools_windows| indicates whether dev tools windows should be | ||||
83 | // treated as visible. | ||||
84 | // TODO(devlin): Remove include_dev_tools_windows. | ||||
85 | virtual bool IsVisibleToTabsAPIForExtension( | ||||
86 | const Extension* extension, | ||||
87 | bool include_dev_tools_windows) const = 0; | ||||
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 88 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 89 | // Returns true if the window type of the controller matches the |filter|. |
90 | bool MatchesFilter(TypeFilter filter) const; | ||||
91 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 92 | private: |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 93 | ui::BaseWindow* window_; |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 94 | Profile* profile_; |
95 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(WindowController); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 97 | }; |
98 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 99 | } // namespace extensions |
100 | |||||
101 | #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ |