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 "ui/base/base_window.h"
12 #include "ui/gfx/geometry/rect.h"
14 namespace extensions
{
16 ///////////////////////////////////////////////////////////////////////////////
19 WindowController::WindowController(ui::BaseWindow
* window
, Profile
* profile
)
20 : window_(window
), profile_(profile
) {
23 WindowController::~WindowController() {
26 Browser
* WindowController::GetBrowser() const {
30 namespace keys
= tabs_constants
;
32 base::DictionaryValue
* WindowController::CreateWindowValue() const {
33 base::DictionaryValue
* result
= new base::DictionaryValue();
35 result
->SetInteger(keys::kIdKey
, GetWindowId());
36 result
->SetString(keys::kWindowTypeKey
, GetWindowTypeText());
37 result
->SetBoolean(keys::kFocusedKey
, window()->IsActive());
38 result
->SetBoolean(keys::kIncognitoKey
, profile_
->IsOffTheRecord());
39 result
->SetBoolean(keys::kAlwaysOnTopKey
, window()->IsAlwaysOnTop());
41 std::string window_state
;
42 if (window()->IsMinimized()) {
43 window_state
= keys::kShowStateValueMinimized
;
44 } else if (window()->IsFullscreen()) {
45 window_state
= keys::kShowStateValueFullscreen
;
46 } else if (window()->IsMaximized()) {
47 window_state
= keys::kShowStateValueMaximized
;
49 window_state
= keys::kShowStateValueNormal
;
51 result
->SetString(keys::kShowStateKey
, window_state
);
54 if (window()->IsMinimized())
55 bounds
= window()->GetRestoredBounds();
57 bounds
= window()->GetBounds();
58 result
->SetInteger(keys::kLeftKey
, bounds
.x());
59 result
->SetInteger(keys::kTopKey
, bounds
.y());
60 result
->SetInteger(keys::kWidthKey
, bounds
.width());
61 result
->SetInteger(keys::kHeightKey
, bounds
.height());
66 } // namespace extensions