[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 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 9 | #include "base/values.h" |
[email protected] | b19451b | 2012-06-08 17:36:19 | [diff] [blame] | 10 | #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 11 | #include "chrome/browser/extensions/window_controller_list.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 13 | #include "chrome/common/extensions/api/windows.h" |
[email protected] | 5f39adc | 2013-05-23 11:50:46 | [diff] [blame] | 14 | #include "ui/base/base_window.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 15 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [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 | |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 69 | namespace keys = tabs_constants; |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 70 | |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 71 | base::DictionaryValue* WindowController::CreateWindowValue() const { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 72 | base::DictionaryValue* result = new base::DictionaryValue(); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 73 | |
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 74 | result->SetInteger(keys::kIdKey, GetWindowId()); |
| 75 | result->SetString(keys::kWindowTypeKey, GetWindowTypeText()); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 76 | result->SetBoolean(keys::kFocusedKey, window()->IsActive()); |
| 77 | result->SetBoolean(keys::kIncognitoKey, profile_->IsOffTheRecord()); |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 78 | result->SetBoolean(keys::kAlwaysOnTopKey, window()->IsAlwaysOnTop()); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 79 | |
[email protected] | c80ed69 | 2012-04-18 19:51:10 | [diff] [blame] | 80 | 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] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 92 | 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] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 104 | |
lionel.g.landwerlin | 56b2a72 | 2015-08-06 00:04:10 | [diff] [blame] | 105 | bool WindowController::MatchesFilter(TypeFilter filter) const { |
| 106 | TypeFilter type = 1 << api::windows::ParseWindowType(GetWindowTypeText()); |
| 107 | return (type & filter) != 0; |
| 108 | } |
| 109 | |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 110 | } // namespace extensions |