Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / extensions / window_controller.cc
blob7c9a961ebb06516e94811c4bb687bc579717b504
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.
5 #include "chrome/browser/extensions/window_controller.h"
7 #include "base/values.h"
8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
9 #include "chrome/browser/extensions/window_controller_list.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/windows.h"
12 #include "ui/base/base_window.h"
13 #include "ui/gfx/geometry/rect.h"
15 namespace extensions {
17 ///////////////////////////////////////////////////////////////////////////////
18 // WindowController
20 // static
21 WindowController::TypeFilter WindowController::GetAllWindowFilter() {
22 // This needs to be updated if there is a change to
23 // extensions::api::windows:WindowType.
24 COMPILE_ASSERT(api::windows::WINDOW_TYPE_LAST == 5,
25 Update_extensions_WindowController_to_match_WindowType);
26 return ((1 << api::windows::WINDOW_TYPE_NORMAL) |
27 (1 << api::windows::WINDOW_TYPE_PANEL) |
28 (1 << api::windows::WINDOW_TYPE_POPUP) |
29 (1 << api::windows::WINDOW_TYPE_APP) |
30 (1 << api::windows::WINDOW_TYPE_DEVTOOLS));
33 // static
34 WindowController::TypeFilter WindowController::GetDefaultWindowFilter() {
35 return ((1 << api::windows::WINDOW_TYPE_NORMAL) |
36 (1 << api::windows::WINDOW_TYPE_PANEL) |
37 (1 << api::windows::WINDOW_TYPE_POPUP));
40 WindowController::TypeFilter WindowController::GetFilterFromWindowTypes(
41 const std::vector<api::windows::WindowType>& types) {
42 WindowController::TypeFilter filter = 0;
43 for (auto& window_type : types)
44 filter |= 1 << window_type;
45 return filter;
48 WindowController::WindowController(ui::BaseWindow* window, Profile* profile)
49 : window_(window), profile_(profile) {
52 WindowController::~WindowController() {
55 Browser* WindowController::GetBrowser() const {
56 return NULL;
59 namespace keys = tabs_constants;
61 base::DictionaryValue* WindowController::CreateWindowValue() const {
62 base::DictionaryValue* result = new base::DictionaryValue();
64 result->SetInteger(keys::kIdKey, GetWindowId());
65 result->SetString(keys::kWindowTypeKey, GetWindowTypeText());
66 result->SetBoolean(keys::kFocusedKey, window()->IsActive());
67 result->SetBoolean(keys::kIncognitoKey, profile_->IsOffTheRecord());
68 result->SetBoolean(keys::kAlwaysOnTopKey, window()->IsAlwaysOnTop());
70 std::string window_state;
71 if (window()->IsMinimized()) {
72 window_state = keys::kShowStateValueMinimized;
73 } else if (window()->IsFullscreen()) {
74 window_state = keys::kShowStateValueFullscreen;
75 } else if (window()->IsMaximized()) {
76 window_state = keys::kShowStateValueMaximized;
77 } else {
78 window_state = keys::kShowStateValueNormal;
80 result->SetString(keys::kShowStateKey, window_state);
82 gfx::Rect bounds;
83 if (window()->IsMinimized())
84 bounds = window()->GetRestoredBounds();
85 else
86 bounds = window()->GetBounds();
87 result->SetInteger(keys::kLeftKey, bounds.x());
88 result->SetInteger(keys::kTopKey, bounds.y());
89 result->SetInteger(keys::kWidthKey, bounds.width());
90 result->SetInteger(keys::kHeightKey, bounds.height());
92 return result;
95 bool WindowController::MatchesFilter(TypeFilter filter) const {
96 TypeFilter type = 1 << api::windows::ParseWindowType(GetWindowTypeText());
97 return (type & filter) != 0;
100 } // namespace extensions