blob: c3e666ae2ad474fd68f747b148c699811e6ebaae [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#include "chrome/browser/extensions/window_controller.h"
[email protected]41d9faf2012-02-28 23:46:026
avia2f4804a2015-12-24 23:11:137#include <stddef.h>
8
dcheng85f24da2016-05-20 22:20:269#include <memory>
10
[email protected]41d9faf2012-02-28 23:46:0211#include "base/values.h"
[email protected]44f4b132012-07-17 20:36:5712#include "chrome/browser/extensions/window_controller_list.h"
[email protected]41d9faf2012-02-28 23:46:0213#include "chrome/browser/profiles/profile.h"
lionel.g.landwerlin56b2a722015-08-06 00:04:1014#include "chrome/common/extensions/api/windows.h"
Ivan Sandrkc30341b2017-11-09 19:13:2615
[email protected]44f4b132012-07-17 20:36:5716namespace extensions {
17
[email protected]41d9faf2012-02-28 23:46:0218///////////////////////////////////////////////////////////////////////////////
[email protected]44f4b132012-07-17 20:36:5719// WindowController
[email protected]41d9faf2012-02-28 23:46:0220
lionel.g.landwerlin56b2a722015-08-06 00:04:1021// static
22WindowController::TypeFilter WindowController::GetAllWindowFilter() {
23 // This needs to be updated if there is a change to
24 // extensions::api::windows:WindowType.
avi0cc1cac2015-11-24 19:12:1325 static_assert(api::windows::WINDOW_TYPE_LAST == 5,
26 "Update extensions WindowController to match WindowType");
lionel.g.landwerlin56b2a722015-08-06 00:04:1027 return ((1 << api::windows::WINDOW_TYPE_NORMAL) |
28 (1 << api::windows::WINDOW_TYPE_PANEL) |
29 (1 << api::windows::WINDOW_TYPE_POPUP) |
30 (1 << api::windows::WINDOW_TYPE_APP) |
31 (1 << api::windows::WINDOW_TYPE_DEVTOOLS));
32}
33
34// static
lionel.g.landwerlin56b2a722015-08-06 00:04:1035WindowController::TypeFilter WindowController::GetFilterFromWindowTypes(
36 const std::vector<api::windows::WindowType>& types) {
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5737 WindowController::TypeFilter filter = kNoWindowFilter;
lionel.g.landwerlin56b2a722015-08-06 00:04:1038 for (auto& window_type : types)
39 filter |= 1 << window_type;
40 return filter;
41}
42
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5743// static
44WindowController::TypeFilter WindowController::GetFilterFromWindowTypesValues(
45 const base::ListValue* types) {
46 WindowController::TypeFilter filter = WindowController::kNoWindowFilter;
47 if (!types)
48 return filter;
Daniel Cheng354945d2022-02-02 23:39:1749 for (const base::Value& type : types->GetListDeprecated()) {
Maks Orlovichab5bbab2021-11-26 16:30:3550 const std::string* window_type = type.GetIfString();
51 if (window_type)
52 filter |= 1 << api::windows::ParseWindowType(*window_type);
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5753 }
54 return filter;
55}
56
[email protected]5f39adc2013-05-23 11:50:4657WindowController::WindowController(ui::BaseWindow* window, Profile* profile)
[email protected]44f4b132012-07-17 20:36:5758 : window_(window), profile_(profile) {
[email protected]41d9faf2012-02-28 23:46:0259}
60
[email protected]44f4b132012-07-17 20:36:5761WindowController::~WindowController() {
[email protected]41d9faf2012-02-28 23:46:0262}
63
[email protected]44f4b132012-07-17 20:36:5764Browser* WindowController::GetBrowser() const {
David Bienvenu27be7932020-08-20 20:41:2765 return nullptr;
[email protected]b51f35622012-05-05 22:01:4366}
67
lionel.g.landwerlin56b2a722015-08-06 00:04:1068bool WindowController::MatchesFilter(TypeFilter filter) const {
69 TypeFilter type = 1 << api::windows::ParseWindowType(GetWindowTypeText());
70 return (type & filter) != 0;
71}
72
Sangwoo Ko26256e922020-07-31 05:12:4073void WindowController::NotifyWindowBoundsChanged() {
74 WindowControllerList::GetInstance()->NotifyWindowBoundsChanged(this);
75}
76
[email protected]44f4b132012-07-17 20:36:5777} // namespace extensions