blob: 67b3d47c4738ef0125a6d8b12440d2b145cef8e5 [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
[email protected]41d9faf2012-02-28 23:46:029#include "base/values.h"
[email protected]b19451b2012-06-08 17:36:1910#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
[email protected]44f4b132012-07-17 20:36:5711#include "chrome/browser/extensions/window_controller_list.h"
[email protected]41d9faf2012-02-28 23:46:0212#include "chrome/browser/profiles/profile.h"
lionel.g.landwerlin56b2a722015-08-06 00:04:1013#include "chrome/common/extensions/api/windows.h"
[email protected]5f39adc2013-05-23 11:50:4614#include "ui/base/base_window.h"
tfarina3b0452d2014-12-31 15:20:0915#include "ui/gfx/geometry/rect.h"
[email protected]41d9faf2012-02-28 23:46:0216
[email protected]44f4b132012-07-17 20:36:5717namespace extensions {
18
[email protected]41d9faf2012-02-28 23:46:0219///////////////////////////////////////////////////////////////////////////////
[email protected]44f4b132012-07-17 20:36:5720// WindowController
[email protected]41d9faf2012-02-28 23:46:0221
lionel.g.landwerlin56b2a722015-08-06 00:04:1022// static
23WindowController::TypeFilter WindowController::GetAllWindowFilter() {
24 // This needs to be updated if there is a change to
25 // extensions::api::windows:WindowType.
avi0cc1cac2015-11-24 19:12:1326 static_assert(api::windows::WINDOW_TYPE_LAST == 5,
27 "Update extensions WindowController to match WindowType");
lionel.g.landwerlin56b2a722015-08-06 00:04:1028 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.landwerlin56b2a722015-08-06 00:04:1036WindowController::TypeFilter WindowController::GetFilterFromWindowTypes(
37 const std::vector<api::windows::WindowType>& types) {
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5738 WindowController::TypeFilter filter = kNoWindowFilter;
lionel.g.landwerlin56b2a722015-08-06 00:04:1039 for (auto& window_type : types)
40 filter |= 1 << window_type;
41 return filter;
42}
43
lionel.g.landwerlin63f0e25e2015-08-24 21:26:5744// static
45WindowController::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]5f39adc2013-05-23 11:50:4658WindowController::WindowController(ui::BaseWindow* window, Profile* profile)
[email protected]44f4b132012-07-17 20:36:5759 : window_(window), profile_(profile) {
[email protected]41d9faf2012-02-28 23:46:0260}
61
[email protected]44f4b132012-07-17 20:36:5762WindowController::~WindowController() {
[email protected]41d9faf2012-02-28 23:46:0263}
64
[email protected]44f4b132012-07-17 20:36:5765Browser* WindowController::GetBrowser() const {
[email protected]b51f35622012-05-05 22:01:4366 return NULL;
67}
68
[email protected]44f4b132012-07-17 20:36:5769namespace keys = tabs_constants;
[email protected]41d9faf2012-02-28 23:46:0270
[email protected]44f4b132012-07-17 20:36:5771base::DictionaryValue* WindowController::CreateWindowValue() const {
[email protected]cb1078de2013-12-23 20:04:2272 base::DictionaryValue* result = new base::DictionaryValue();
[email protected]41d9faf2012-02-28 23:46:0273
[email protected]c80ed692012-04-18 19:51:1074 result->SetInteger(keys::kIdKey, GetWindowId());
75 result->SetString(keys::kWindowTypeKey, GetWindowTypeText());
[email protected]41d9faf2012-02-28 23:46:0276 result->SetBoolean(keys::kFocusedKey, window()->IsActive());
77 result->SetBoolean(keys::kIncognitoKey, profile_->IsOffTheRecord());
[email protected]d101b0c2012-03-16 00:30:5778 result->SetBoolean(keys::kAlwaysOnTopKey, window()->IsAlwaysOnTop());
[email protected]41d9faf2012-02-28 23:46:0279
[email protected]c80ed692012-04-18 19:51:1080 std::string window_state;
81 if (window()->IsMinimized()) {
82 window_state = keys::kShowStateValueMinimized;
83 } else if (window()->IsFullscreen()) {
84 window_state = keys::kShowStateValueFullscreen;
85 } else if (window()->IsMaximized()) {
86 window_state = keys::kShowStateValueMaximized;
87 } else {
88 window_state = keys::kShowStateValueNormal;
89 }
90 result->SetString(keys::kShowStateKey, window_state);
91
[email protected]41d9faf2012-02-28 23:46:0292 gfx::Rect bounds;
93 if (window()->IsMinimized())
94 bounds = window()->GetRestoredBounds();
95 else
96 bounds = window()->GetBounds();
97 result->SetInteger(keys::kLeftKey, bounds.x());
98 result->SetInteger(keys::kTopKey, bounds.y());
99 result->SetInteger(keys::kWidthKey, bounds.width());
100 result->SetInteger(keys::kHeightKey, bounds.height());
101
102 return result;
103}
[email protected]44f4b132012-07-17 20:36:57104
lionel.g.landwerlin56b2a722015-08-06 00:04:10105bool WindowController::MatchesFilter(TypeFilter filter) const {
106 TypeFilter type = 1 << api::windows::ParseWindowType(GetWindowTypeText());
107 return (type & filter) != 0;
108}
109
[email protected]44f4b132012-07-17 20:36:57110} // namespace extensions