blob: 431d7d927290e075bfc0c44bc0c31cb7de7bb53e [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
dchenga500b692016-04-08 19:55:4210#include <memory>
[email protected]c80ed692012-04-18 19:51:1011#include <string>
Devlin Cronin7050f8e2018-02-07 19:52:0412#include <vector>
[email protected]c80ed692012-04-18 19:51:1013
[email protected]41d9faf2012-02-28 23:46:0214#include "base/compiler_specific.h"
avia2f4804a2015-12-24 23:11:1315#include "base/macros.h"
limasdf6dcdc442016-02-26 04:58:2616#include "chrome/common/extensions/api/tabs.h"
lionel.g.landwerlin56b2a722015-08-06 00:04:1017#include "chrome/common/extensions/api/windows.h"
[email protected]41d9faf2012-02-28 23:46:0218
[email protected]b51f35622012-05-05 22:01:4319class Browser; // TODO(stevenjb) eliminate this dependency.
[email protected]41d9faf2012-02-28 23:46:0220class Profile;
[email protected]41d9faf2012-02-28 23:46:0221
[email protected]5f39adc2013-05-23 11:50:4622namespace ui {
23class BaseWindow;
24}
25
[email protected]44f4b132012-07-17 20:36:5726namespace extensions {
27class Extension;
28
[email protected]41d9faf2012-02-28 23:46:0229// This API needs to be implemented by any window that might be accessed
Devlin Cronin7050f8e2018-02-07 19:52:0430// through various extension APIs for modifying or finding the window.
[email protected]163ed192012-07-24 19:31:0731// Subclasses must add/remove themselves from the WindowControllerList
32// upon construction/destruction.
[email protected]44f4b132012-07-17 20:36:5733class WindowController {
[email protected]41d9faf2012-02-28 23:46:0234 public:
35 enum Reason {
36 REASON_NONE,
[email protected]b51f35622012-05-05 22:01:4337 REASON_NOT_EDITABLE,
[email protected]41d9faf2012-02-28 23:46:0238 };
[email protected]b51f35622012-05-05 22:01:4339
lionel.g.landwerlin56b2a722015-08-06 00:04:1040 // A bitmaks used as filter on window types.
41 using TypeFilter = uint32_t;
42
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5743 // 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.landwerlin56b2a722015-08-06 00:04:1047 // Returns a filter allowing all window types to be manipulated
48 // through the chrome.windows APIs.
49 static TypeFilter GetAllWindowFilter();
50
lionel.g.landwerlin56b2a722015-08-06 00:04:1051 // 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.landwerlin63f0e25e2015-08-24 21:26:5755 static TypeFilter GetFilterFromWindowTypesValues(
56 const base::ListValue* types);
57
[email protected]5f39adc2013-05-23 11:50:4658 WindowController(ui::BaseWindow* window, Profile* profile);
[email protected]44f4b132012-07-17 20:36:5759 virtual ~WindowController();
[email protected]41d9faf2012-02-28 23:46:0260
[email protected]5f39adc2013-05-23 11:50:4661 ui::BaseWindow* window() const { return window_; }
[email protected]41d9faf2012-02-28 23:46:0262
[email protected]b51f35622012-05-05 22:01:4363 Profile* profile() const { return profile_; }
64
[email protected]c80ed692012-04-18 19:51:1065 // Return an id uniquely identifying the window.
66 virtual int GetWindowId() const = 0;
67
68 // Return the type name for the window.
Devlin Cronin7050f8e2018-02-07 19:52:0469 // TODO(devlin): Remove this in favor of the method on ExtensionTabUtil.
[email protected]c80ed692012-04-18 19:51:1070 virtual std::string GetWindowTypeText() const = 0;
[email protected]41d9faf2012-02-28 23:46:0271
[email protected]41d9faf2012-02-28 23:46:0272 // 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]b51f35622012-05-05 22:01:4376 // Returns a Browser if available. Defaults to returning NULL.
77 // TODO(stevenjb): Temporary workaround. Eliminate this.
78 virtual Browser* GetBrowser() const;
79
Devlin Croninf620cde2018-02-01 05:40:0480 // 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]31bdbfef2012-05-22 19:59:1588
lionel.g.landwerlin56b2a722015-08-06 00:04:1089 // Returns true if the window type of the controller matches the |filter|.
90 bool MatchesFilter(TypeFilter filter) const;
91
[email protected]41d9faf2012-02-28 23:46:0292 private:
[email protected]5f39adc2013-05-23 11:50:4693 ui::BaseWindow* window_;
[email protected]41d9faf2012-02-28 23:46:0294 Profile* profile_;
95
[email protected]44f4b132012-07-17 20:36:5796 DISALLOW_COPY_AND_ASSIGN(WindowController);
[email protected]41d9faf2012-02-28 23:46:0297};
98
[email protected]44f4b132012-07-17 20:36:5799} // namespace extensions
100
101#endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_