OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/shell/browser/shell_desktop_controller.h" | 5 #include "extensions/shell/browser/shell_desktop_controller.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "extensions/browser/app_window/app_window.h" | 12 #include "extensions/browser/app_window/app_window.h" |
12 #include "extensions/browser/app_window/native_app_window.h" | 13 #include "extensions/browser/app_window/native_app_window.h" |
13 #include "extensions/shell/browser/shell_app_delegate.h" | 14 #include "extensions/shell/browser/shell_app_delegate.h" |
14 #include "extensions/shell/browser/shell_app_window_client.h" | 15 #include "extensions/shell/browser/shell_app_window_client.h" |
15 #include "extensions/shell/common/switches.h" | 16 #include "extensions/shell/common/switches.h" |
16 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 return true; | 154 return true; |
154 } | 155 } |
155 | 156 |
156 private: | 157 private: |
157 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); | 158 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); |
158 }; | 159 }; |
159 | 160 |
160 } // namespace | 161 } // namespace |
161 | 162 |
162 ShellDesktopController::ShellDesktopController() | 163 ShellDesktopController::ShellDesktopController() |
163 : app_window_client_(new ShellAppWindowClient), app_window_(NULL) { | 164 : app_window_client_(new ShellAppWindowClient) { |
164 extensions::AppWindowClient::Set(app_window_client_.get()); | 165 extensions::AppWindowClient::Set(app_window_client_.get()); |
165 | 166 |
166 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
167 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 168 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
168 AddObserver(this); | 169 AddObserver(this); |
169 display_configurator_.reset(new ui::DisplayConfigurator); | 170 display_configurator_.reset(new ui::DisplayConfigurator); |
170 display_configurator_->Init(false); | 171 display_configurator_->Init(false); |
171 display_configurator_->ForceInitialConfigure(0); | 172 display_configurator_->ForceInitialConfigure(0); |
172 display_configurator_->AddObserver(this); | 173 display_configurator_->AddObserver(this); |
173 #endif | 174 #endif |
(...skipping 10 matching lines...) Expand all Loading... | |
184 extensions::AppWindowClient::Set(NULL); | 185 extensions::AppWindowClient::Set(NULL); |
185 } | 186 } |
186 | 187 |
187 aura::WindowTreeHost* ShellDesktopController::GetHost() { | 188 aura::WindowTreeHost* ShellDesktopController::GetHost() { |
188 return host_.get(); | 189 return host_.get(); |
189 } | 190 } |
190 | 191 |
191 AppWindow* ShellDesktopController::CreateAppWindow( | 192 AppWindow* ShellDesktopController::CreateAppWindow( |
192 content::BrowserContext* context, | 193 content::BrowserContext* context, |
193 const Extension* extension) { | 194 const Extension* extension) { |
194 app_window_ = new AppWindow(context, new ShellAppDelegate, extension); | 195 app_windows_.push_back( |
195 return app_window_; | 196 new AppWindow(context, new ShellAppDelegate, extension)); |
197 return app_windows_.back(); | |
196 } | 198 } |
197 | 199 |
198 void ShellDesktopController::AddAppWindow(aura::Window* window) { | 200 void ShellDesktopController::AddAppWindow(aura::Window* window) { |
James Cook
2014/10/23 21:29:53
Aside (not for this CL): The create/add/remove cyc
| |
199 aura::Window* root_window = GetHost()->window(); | 201 aura::Window* root_window = GetHost()->window(); |
200 root_window->AddChild(window); | 202 root_window->AddChild(window); |
201 } | 203 } |
202 | 204 |
205 void ShellDesktopController::RemoveAppWindow(AppWindow* window) { | |
206 auto iter = std::find(app_windows_.begin(), app_windows_.end(), window); | |
207 DCHECK(iter != app_windows_.end()); | |
208 app_windows_.erase(iter); | |
209 } | |
210 | |
203 void ShellDesktopController::CloseAppWindows() { | 211 void ShellDesktopController::CloseAppWindows() { |
204 if (app_window_) { | 212 // Create a copy of the window vector, because closing the windows will |
205 app_window_->GetBaseWindow()->Close(); // Close() deletes |app_window_|. | 213 // trigger RemoveAppWindow, which will invalidate the iterator. |
206 app_window_ = NULL; | 214 // This vector should be small enough that this should not be an issue. |
207 } | 215 std::vector<AppWindow*> app_windows(app_windows_); |
216 for (AppWindow* app_window : app_windows) | |
217 app_window->GetBaseWindow()->Close(); // Close() deletes |app_window_|. | |
James Cook
2014/10/23 21:29:53
|app_window_| -> |app_window|
lfg
2014/10/23 22:04:05
Done.
| |
218 app_windows_.clear(); | |
208 } | 219 } |
209 | 220 |
210 aura::Window* ShellDesktopController::GetDefaultParent( | 221 aura::Window* ShellDesktopController::GetDefaultParent( |
211 aura::Window* context, | 222 aura::Window* context, |
212 aura::Window* window, | 223 aura::Window* window, |
213 const gfx::Rect& bounds) { | 224 const gfx::Rect& bounds) { |
214 return host_->window(); | 225 return host_->window(); |
215 } | 226 } |
216 | 227 |
217 #if defined(OS_CHROMEOS) | 228 #if defined(OS_CHROMEOS) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 if (displays.empty()) | 354 if (displays.empty()) |
344 return gfx::Size(); | 355 return gfx::Size(); |
345 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 356 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
346 return mode ? mode->size() : gfx::Size(); | 357 return mode ? mode->size() : gfx::Size(); |
347 #else | 358 #else |
348 return gfx::Size(); | 359 return gfx::Size(); |
349 #endif | 360 #endif |
350 } | 361 } |
351 | 362 |
352 } // namespace extensions | 363 } // namespace extensions |
OLD | NEW |