| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" |
| 6 | 6 |
| 7 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/stl_util.h" | |
| 11 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 14 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" | 13 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" |
| 15 #include "ui/aura/client/activation_client.h" | 14 #include "ui/aura/client/activation_client.h" |
| 16 | 15 |
| 17 using apps::ShellWindow; | 16 using apps::ShellWindow; |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 if (ash::Shell::HasInstance()) { | 34 if (ash::Shell::HasInstance()) { |
| 36 if (ash::Shell::GetInstance()->GetPrimaryRootWindow()) { | 35 if (ash::Shell::GetInstance()->GetPrimaryRootWindow()) { |
| 37 activation_client_ = aura::client::GetActivationClient( | 36 activation_client_ = aura::client::GetActivationClient( |
| 38 ash::Shell::GetInstance()->GetPrimaryRootWindow()); | 37 ash::Shell::GetInstance()->GetPrimaryRootWindow()); |
| 39 if (activation_client_) | 38 if (activation_client_) |
| 40 activation_client_->AddObserver(this); | 39 activation_client_->AddObserver(this); |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 | 43 |
| 45 | |
| 46 ShellWindowLauncherController::~ShellWindowLauncherController() { | 44 ShellWindowLauncherController::~ShellWindowLauncherController() { |
| 47 registry_->RemoveObserver(this); | 45 registry_->RemoveObserver(this); |
| 48 if (activation_client_) | 46 if (activation_client_) |
| 49 activation_client_->RemoveObserver(this); | 47 activation_client_->RemoveObserver(this); |
| 50 for (WindowToAppLauncherIdMap::iterator iter = | 48 for (WindowToAppLauncherIdMap::iterator iter = |
| 51 window_to_app_launcher_id_map_.begin(); | 49 window_to_app_launcher_id_map_.begin(); |
| 52 iter != window_to_app_launcher_id_map_.end(); ++iter) { | 50 iter != window_to_app_launcher_id_map_.end(); ++iter) { |
| 53 iter->first->RemoveObserver(this); | 51 iter->first->RemoveObserver(this); |
| 54 } | 52 } |
| 55 STLDeleteContainerPairSecondPointers( | |
| 56 app_controller_map_.begin(), app_controller_map_.end()); | |
| 57 } | 53 } |
| 58 | 54 |
| 59 void ShellWindowLauncherController::OnShellWindowAdded( | 55 void ShellWindowLauncherController::OnShellWindowAdded( |
| 60 ShellWindow* shell_window) { | 56 ShellWindow* shell_window) { |
| 61 aura::Window* window = shell_window->GetNativeWindow(); | 57 aura::Window* window = shell_window->GetNativeWindow(); |
| 62 // Get the app's launcher identifier and add an entry to the map. | 58 // Get the app's launcher identifier and add an entry to the map. |
| 63 DCHECK(window_to_app_launcher_id_map_.find(window) == | 59 DCHECK(window_to_app_launcher_id_map_.find(window) == |
| 64 window_to_app_launcher_id_map_.end()); | 60 window_to_app_launcher_id_map_.end()); |
| 65 const std::string app_launcher_id = GetAppLauncherId(shell_window); | 61 const std::string app_launcher_id = GetAppLauncherId(shell_window); |
| 66 window_to_app_launcher_id_map_[window] = app_launcher_id; | 62 window_to_app_launcher_id_map_[window] = app_launcher_id; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); | 127 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); |
| 132 DCHECK(iter2 != app_controller_map_.end()); | 128 DCHECK(iter2 != app_controller_map_.end()); |
| 133 ShellWindowLauncherItemController* controller = iter2->second; | 129 ShellWindowLauncherItemController* controller = iter2->second; |
| 134 controller->RemoveShellWindowForWindow(window); | 130 controller->RemoveShellWindowForWindow(window); |
| 135 if (controller->shell_window_count() == 0) { | 131 if (controller->shell_window_count() == 0) { |
| 136 // If this is the last window associated with the app launcher id, close the | 132 // If this is the last window associated with the app launcher id, close the |
| 137 // launcher item. | 133 // launcher item. |
| 138 ash::LauncherID launcher_id = controller->launcher_id(); | 134 ash::LauncherID launcher_id = controller->launcher_id(); |
| 139 owner_->CloseLauncherItem(launcher_id); | 135 owner_->CloseLauncherItem(launcher_id); |
| 140 app_controller_map_.erase(iter2); | 136 app_controller_map_.erase(iter2); |
| 141 delete controller; | |
| 142 } | 137 } |
| 143 } | 138 } |
| 144 | 139 |
| 145 void ShellWindowLauncherController::OnWindowActivated( | 140 void ShellWindowLauncherController::OnWindowActivated( |
| 146 aura::Window* new_active, | 141 aura::Window* new_active, |
| 147 aura::Window* old_active) { | 142 aura::Window* old_active) { |
| 148 // Make the newly active window the active (first) entry in the controller. | 143 // Make the newly active window the active (first) entry in the controller. |
| 149 ShellWindowLauncherItemController* new_controller = | 144 ShellWindowLauncherItemController* new_controller = |
| 150 ControllerForWindow(new_active); | 145 ControllerForWindow(new_active); |
| 151 if (new_controller) { | 146 if (new_controller) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 WindowToAppLauncherIdMap::iterator iter1 = | 163 WindowToAppLauncherIdMap::iterator iter1 = |
| 169 window_to_app_launcher_id_map_.find(window); | 164 window_to_app_launcher_id_map_.find(window); |
| 170 if (iter1 == window_to_app_launcher_id_map_.end()) | 165 if (iter1 == window_to_app_launcher_id_map_.end()) |
| 171 return NULL; | 166 return NULL; |
| 172 std::string app_launcher_id = iter1->second; | 167 std::string app_launcher_id = iter1->second; |
| 173 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); | 168 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); |
| 174 if (iter2 == app_controller_map_.end()) | 169 if (iter2 == app_controller_map_.end()) |
| 175 return NULL; | 170 return NULL; |
| 176 return iter2->second; | 171 return iter2->second; |
| 177 } | 172 } |
| OLD | NEW |