Index: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
diff --git a/chrome/browser/ui/ash/launcher/app_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
similarity index 60% |
copy from chrome/browser/ui/ash/launcher/app_window_launcher_controller.cc |
copy to chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
index fdb4e03f1c98e3074be4f11d52dbd1e3f9d2fb90..05cd17360af12941b2e28fad9ac4ba5c77d18ba7 100644 |
--- a/chrome/browser/ui/ash/launcher/app_window_launcher_controller.cc |
+++ b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
@@ -1,21 +1,21 @@ |
-// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
+#include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.h" |
#include "ash/shelf/shelf_util.h" |
#include "ash/shell.h" |
#include "ash/wm/window_util.h" |
#include "base/strings/stringprintf.h" |
#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
+#include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.h" |
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
#include "extensions/browser/app_window/app_window.h" |
+#include "extensions/browser/app_window/native_app_window.h" |
#include "extensions/common/extension.h" |
#include "ui/aura/window_event_dispatcher.h" |
-#include "ui/wm/public/activation_client.h" |
using extensions::AppWindow; |
using extensions::AppWindowRegistry; |
@@ -30,39 +30,27 @@ std::string GetAppShelfId(AppWindow* app_window) { |
} // namespace |
-AppWindowLauncherController::AppWindowLauncherController( |
+ExtensionAppWindowLauncherController::ExtensionAppWindowLauncherController( |
ChromeLauncherController* owner) |
- : owner_(owner), activation_client_(NULL) { |
-AppWindowRegistry* registry = AppWindowRegistry::Get(owner->profile()); |
+ : AppWindowLauncherController(owner) { |
+ AppWindowRegistry* registry = AppWindowRegistry::Get(owner->profile()); |
registry_.insert(registry); |
registry->AddObserver(this); |
- if (ash::Shell::HasInstance()) { |
- if (ash::Shell::GetInstance()->GetPrimaryRootWindow()) { |
- activation_client_ = aura::client::GetActivationClient( |
- ash::Shell::GetInstance()->GetPrimaryRootWindow()); |
- if (activation_client_) |
- activation_client_->AddObserver(this); |
- } |
- } |
} |
-AppWindowLauncherController::~AppWindowLauncherController() { |
+ExtensionAppWindowLauncherController::~ExtensionAppWindowLauncherController() { |
for (std::set<AppWindowRegistry*>::iterator it = registry_.begin(); |
- it != registry_.end(); |
- ++it) |
+ it != registry_.end(); ++it) |
(*it)->RemoveObserver(this); |
- if (activation_client_) |
- activation_client_->RemoveObserver(this); |
for (WindowToAppShelfIdMap::iterator iter = |
window_to_app_shelf_id_map_.begin(); |
- iter != window_to_app_shelf_id_map_.end(); |
- ++iter) { |
+ iter != window_to_app_shelf_id_map_.end(); ++iter) { |
iter->first->RemoveObserver(this); |
} |
} |
-void AppWindowLauncherController::AdditionalUserAddedToSession( |
+void ExtensionAppWindowLauncherController::AdditionalUserAddedToSession( |
Profile* profile) { |
// TODO(skuhne): This was added for the legacy side by side mode in M32. If |
// this mode gets no longer pursued this special case can be removed. |
@@ -78,26 +66,28 @@ void AppWindowLauncherController::AdditionalUserAddedToSession( |
registry_.insert(registry); |
} |
-void AppWindowLauncherController::OnAppWindowIconChanged( |
+void ExtensionAppWindowLauncherController::OnAppWindowIconChanged( |
AppWindow* app_window) { |
const std::string app_shelf_id = GetAppShelfId(app_window); |
AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); |
if (iter == app_controller_map_.end()) |
return; |
- AppWindowLauncherItemController* controller = iter->second; |
+ ExtensionAppWindowLauncherItemController* controller = iter->second; |
controller->set_image_set_by_controller(true); |
- owner_->SetLauncherItemImage(controller->shelf_id(), |
- app_window->app_icon().AsImageSkia()); |
+ owner()->SetLauncherItemImage(controller->shelf_id(), |
+ app_window->app_icon().AsImageSkia()); |
} |
-void AppWindowLauncherController::OnAppWindowShown(AppWindow* app_window, |
- bool was_hidden) { |
+void ExtensionAppWindowLauncherController::OnAppWindowShown( |
+ AppWindow* app_window, |
+ bool was_hidden) { |
aura::Window* window = app_window->GetNativeWindow(); |
if (!IsRegisteredApp(window)) |
RegisterApp(app_window); |
} |
-void AppWindowLauncherController::OnAppWindowHidden(AppWindow* app_window) { |
+void ExtensionAppWindowLauncherController::OnAppWindowHidden( |
+ AppWindow* app_window) { |
aura::Window* window = app_window->GetNativeWindow(); |
if (IsRegisteredApp(window)) |
UnregisterApp(window); |
@@ -106,30 +96,12 @@ void AppWindowLauncherController::OnAppWindowHidden(AppWindow* app_window) { |
// Called from aura::Window::~Window(), before delegate_->OnWindowDestroyed() |
// which destroys AppWindow, so both |window| and the associated AppWindow |
// are valid here. |
-void AppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
+void ExtensionAppWindowLauncherController::OnWindowDestroying( |
+ aura::Window* window) { |
UnregisterApp(window); |
} |
-void AppWindowLauncherController::OnWindowActivated( |
- aura::client::ActivationChangeObserver::ActivationReason reason, |
- aura::Window* new_active, |
- aura::Window* old_active) { |
- // Make the newly active window the active (first) entry in the controller. |
- AppWindowLauncherItemController* new_controller = |
- ControllerForWindow(new_active); |
- if (new_controller) { |
- new_controller->SetActiveWindow(new_active); |
- owner_->SetItemStatus(new_controller->shelf_id(), ash::STATUS_ACTIVE); |
- } |
- |
- // Mark the old active window's launcher item as running (if different). |
- AppWindowLauncherItemController* old_controller = |
- ControllerForWindow(old_active); |
- if (old_controller && old_controller != new_controller) |
- owner_->SetItemStatus(old_controller->shelf_id(), ash::STATUS_RUNNING); |
-} |
- |
-void AppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
+void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
// Windows created by IME extension should be treated the same way as the |
// virtual keyboard window, which does not register itself in launcher. |
if (app_window->is_ime_window()) |
@@ -151,41 +123,42 @@ void AppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); |
ash::ShelfID shelf_id = 0; |
if (iter != app_controller_map_.end()) { |
- AppWindowLauncherItemController* controller = iter->second; |
+ ExtensionAppWindowLauncherItemController* controller = iter->second; |
DCHECK(controller->app_id() == app_id); |
shelf_id = controller->shelf_id(); |
- controller->AddAppWindow(app_window, status); |
+ controller->AddAppWindow(app_window); |
} else { |
LauncherItemController::Type type = |
app_window->window_type_is_panel() |
? LauncherItemController::TYPE_APP_PANEL |
: LauncherItemController::TYPE_APP; |
- AppWindowLauncherItemController* controller = |
- new AppWindowLauncherItemController(type, app_shelf_id, app_id, owner_); |
- controller->AddAppWindow(app_window, status); |
+ ExtensionAppWindowLauncherItemController* controller = |
+ new ExtensionAppWindowLauncherItemController(type, app_shelf_id, app_id, |
+ owner()); |
+ controller->AddAppWindow(app_window); |
// If the app shelf id is not unique, and there is already a shelf |
// item for this app id (e.g. pinned), use that shelf item. |
if (app_shelf_id == app_id) |
- shelf_id = owner_->GetShelfIDForAppID(app_id); |
+ shelf_id = owner()->GetShelfIDForAppID(app_id); |
if (shelf_id == 0) { |
- shelf_id = owner_->CreateAppLauncherItem(controller, app_id, status); |
+ shelf_id = owner()->CreateAppLauncherItem(controller, app_id, status); |
// Restore any existing app icon and flag as set. |
const gfx::Image& app_icon = app_window->app_icon(); |
if (!app_icon.IsEmpty()) { |
- owner_->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia()); |
+ owner()->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia()); |
controller->set_image_set_by_controller(true); |
} |
} else { |
- owner_->SetItemController(shelf_id, controller); |
+ owner()->SetItemController(shelf_id, controller); |
} |
const std::string app_shelf_id = GetAppShelfId(app_window); |
app_controller_map_[app_shelf_id] = controller; |
} |
- owner_->SetItemStatus(shelf_id, status); |
+ owner()->SetItemStatus(shelf_id, status); |
ash::SetShelfIDForWindow(shelf_id, window); |
} |
-void AppWindowLauncherController::UnregisterApp(aura::Window* window) { |
+void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
WindowToAppShelfIdMap::iterator iter1 = |
window_to_app_shelf_id_map_.find(window); |
DCHECK(iter1 != window_to_app_shelf_id_map_.end()); |
@@ -195,18 +168,19 @@ void AppWindowLauncherController::UnregisterApp(aura::Window* window) { |
AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
DCHECK(iter2 != app_controller_map_.end()); |
- AppWindowLauncherItemController* controller = iter2->second; |
- controller->RemoveAppWindowForWindow(window); |
- if (controller->app_window_count() == 0) { |
+ ExtensionAppWindowLauncherItemController* controller = iter2->second; |
+ controller->RemoveWindowForNativeWindow(window); |
+ if (controller->window_count() == 0) { |
// If this is the last window associated with the app shelf id, close the |
// shelf item. |
ash::ShelfID shelf_id = controller->shelf_id(); |
- owner_->CloseLauncherItem(shelf_id); |
+ owner()->CloseLauncherItem(shelf_id); |
app_controller_map_.erase(iter2); |
} |
} |
-bool AppWindowLauncherController::IsRegisteredApp(aura::Window* window) { |
+bool ExtensionAppWindowLauncherController::IsRegisteredApp( |
+ aura::Window* window) { |
return window_to_app_shelf_id_map_.find(window) != |
window_to_app_shelf_id_map_.end(); |
} |
@@ -214,14 +188,15 @@ bool AppWindowLauncherController::IsRegisteredApp(aura::Window* window) { |
// Private Methods |
AppWindowLauncherItemController* |
-AppWindowLauncherController::ControllerForWindow(aura::Window* window) { |
+ExtensionAppWindowLauncherController::ControllerForWindow( |
+ aura::Window* window) { |
WindowToAppShelfIdMap::iterator iter1 = |
window_to_app_shelf_id_map_.find(window); |
if (iter1 == window_to_app_shelf_id_map_.end()) |
- return NULL; |
+ return nullptr; |
std::string app_shelf_id = iter1->second; |
AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
if (iter2 == app_controller_map_.end()) |
- return NULL; |
+ return nullptr; |
return iter2->second; |
} |