[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 | #include "chrome/browser/extensions/window_controller.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 6 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
8 | |||||
dcheng | 85f24da | 2016-05-20 22:20:26 | [diff] [blame] | 9 | #include <memory> |
10 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 11 | #include "base/values.h" |
[email protected] | b19451b | 2012-06-08 17:36:19 | [diff] [blame] | 12 | #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 13 | #include "chrome/browser/extensions/window_controller_list.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile.h" |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 15 | #include "chrome/common/extensions/api/windows.h" |
Ivan Sandrk | c30341b | 2017-11-09 19:13:26 | [diff] [blame] | 16 | |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 17 | namespace extensions { |
18 | |||||
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 19 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 20 | // WindowController |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 21 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 22 | // static |
23 | WindowController::TypeFilter WindowController::GetAllWindowFilter() { | ||||
24 | // This needs to be updated if there is a change to | ||||
25 | // extensions::api::windows:WindowType. | ||||
avi | 0cc1cac | 2015-11-24 19:12:13 | [diff] [blame] | 26 | static_assert(api::windows::WINDOW_TYPE_LAST == 5, |
27 | "Update extensions WindowController to match WindowType"); | ||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 28 | return ((1 << api::windows::WINDOW_TYPE_NORMAL) | |
29 | (1 << api::windows::WINDOW_TYPE_PANEL) | | ||||
30 | (1 << api::windows::WINDOW_TYPE_POPUP) | | ||||
31 | (1 << api::windows::WINDOW_TYPE_APP) | | ||||
32 | (1 << api::windows::WINDOW_TYPE_DEVTOOLS)); | ||||
33 | } | ||||
34 | |||||
35 | // static | ||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 36 | WindowController::TypeFilter WindowController::GetFilterFromWindowTypes( |
37 | const std::vector<api::windows::WindowType>& types) { | ||||
lionel.g.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 38 | WindowController::TypeFilter filter = kNoWindowFilter; |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 39 | for (auto& window_type : types) |
40 | filter |= 1 << window_type; | ||||
41 | return filter; | ||||
42 | } | ||||
43 | |||||
lionel.g.landwerlin | 63f0e25e | 2015-08-24 21:26:57 | [diff] [blame] | 44 | // static |
45 | WindowController::TypeFilter WindowController::GetFilterFromWindowTypesValues( | ||||
46 | const base::ListValue* types) { | ||||
47 | WindowController::TypeFilter filter = WindowController::kNoWindowFilter; | ||||
48 | if (!types) | ||||
49 | return filter; | ||||
50 | for (size_t i = 0; i < types->GetSize(); i++) { | ||||
51 | std::string window_type; | ||||
52 | if (types->GetString(i, &window_type)) | ||||
53 | filter |= 1 << api::windows::ParseWindowType(window_type); | ||||
54 | } | ||||
55 | return filter; | ||||
56 | } | ||||
57 | |||||
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 58 | WindowController::WindowController(ui::BaseWindow* window, Profile* profile) |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 59 | : window_(window), profile_(profile) { |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 60 | } |
61 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 62 | WindowController::~WindowController() { |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 63 | } |
64 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 65 | Browser* WindowController::GetBrowser() const { |
[email protected] | b51f3562 | 2012-05-05 22:01:43 | [diff] [blame] | 66 | return NULL; |
67 | } | ||||
68 | |||||
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 69 | bool WindowController::MatchesFilter(TypeFilter filter) const { |
70 | TypeFilter type = 1 << api::windows::ParseWindowType(GetWindowTypeText()); | ||||
71 | return (type & filter) != 0; | ||||
72 | } | ||||
73 | |||||
Sangwoo Ko | 26256e92 | 2020-07-31 05:12:40 | [diff] [blame^] | 74 | void WindowController::NotifyWindowBoundsChanged() { |
75 | WindowControllerList::GetInstance()->NotifyWindowBoundsChanged(this); | ||||
76 | } | ||||
77 | |||||
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 78 | } // namespace extensions |