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 ///////////////////////////////////////////////////////////////////////////////
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
));
34 WindowController::TypeFilter
WindowController::GetFilterFromWindowTypes(
35 const std::vector
<api::windows::WindowType
>& types
) {
36 WindowController::TypeFilter filter
= kNoWindowFilter
;
37 for (auto& window_type
: types
)
38 filter
|= 1 << window_type
;
43 WindowController::TypeFilter
WindowController::GetFilterFromWindowTypesValues(
44 const base::ListValue
* types
) {
45 WindowController::TypeFilter filter
= WindowController::kNoWindowFilter
;
48 for (size_t i
= 0; i
< types
->GetSize(); i
++) {
49 std::string window_type
;
50 if (types
->GetString(i
, &window_type
))
51 filter
|= 1 << api::windows::ParseWindowType(window_type
);
56 WindowController::WindowController(ui::BaseWindow
* window
, Profile
* profile
)
57 : window_(window
), profile_(profile
) {
60 WindowController::~WindowController() {
63 Browser
* WindowController::GetBrowser() const {
67 namespace keys
= tabs_constants
;
69 base::DictionaryValue
* WindowController::CreateWindowValue() const {
70 base::DictionaryValue
* result
= new base::DictionaryValue();
72 result
->SetInteger(keys::kIdKey
, GetWindowId());
73 result
->SetString(keys::kWindowTypeKey
, GetWindowTypeText());
74 result
->SetBoolean(keys::kFocusedKey
, window()->IsActive());
75 result
->SetBoolean(keys::kIncognitoKey
, profile_
->IsOffTheRecord());
76 result
->SetBoolean(keys::kAlwaysOnTopKey
, window()->IsAlwaysOnTop());
78 std::string window_state
;
79 if (window()->IsMinimized()) {
80 window_state
= keys::kShowStateValueMinimized
;
81 } else if (window()->IsFullscreen()) {
82 window_state
= keys::kShowStateValueFullscreen
;
83 } else if (window()->IsMaximized()) {
84 window_state
= keys::kShowStateValueMaximized
;
86 window_state
= keys::kShowStateValueNormal
;
88 result
->SetString(keys::kShowStateKey
, window_state
);
91 if (window()->IsMinimized())
92 bounds
= window()->GetRestoredBounds();
94 bounds
= window()->GetBounds();
95 result
->SetInteger(keys::kLeftKey
, bounds
.x());
96 result
->SetInteger(keys::kTopKey
, bounds
.y());
97 result
->SetInteger(keys::kWidthKey
, bounds
.width());
98 result
->SetInteger(keys::kHeightKey
, bounds
.height());
103 bool WindowController::MatchesFilter(TypeFilter filter
) const {
104 TypeFilter type
= 1 << api::windows::ParseWindowType(GetWindowTypeText());
105 return (type
& filter
) != 0;
108 } // namespace extensions