Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc

Issue 2927693002: mash: Limit ShelfWindowWatcher to panels and dialogs. (Closed)
Patch Set: Disable WindowSelectorTest.MultipleDisplays in mash. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extension_app_window_launcher_controlle r.h" 5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_controlle r.h"
6 6
7 #include "ash/public/cpp/shelf_model.h" 7 #include "ash/public/cpp/shelf_model.h"
8 #include "ash/public/cpp/shelf_types.h" 8 #include "ash/public/cpp/shelf_types.h"
9 #include "ash/public/cpp/window_properties.h" 9 #include "ash/public/cpp/window_properties.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/browser/chromeos/ash_config.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h" 16 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h"
16 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
17 #include "extensions/browser/app_window/app_window.h" 18 #include "extensions/browser/app_window/app_window.h"
18 #include "extensions/browser/app_window/native_app_window.h" 19 #include "extensions/browser/app_window/native_app_window.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/aura/window_event_dispatcher.h" 22 #include "ui/aura/window_event_dispatcher.h"
22 23
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return; 69 return;
69 70
70 AppWindowRegistry* registry = AppWindowRegistry::Get(profile); 71 AppWindowRegistry* registry = AppWindowRegistry::Get(profile);
71 if (registry_.find(registry) != registry_.end()) 72 if (registry_.find(registry) != registry_.end())
72 return; 73 return;
73 74
74 registry->AddObserver(this); 75 registry->AddObserver(this);
75 registry_.insert(registry); 76 registry_.insert(registry);
76 } 77 }
77 78
79 void ExtensionAppWindowLauncherController::OnAppWindowAdded(
80 extensions::AppWindow* app_window) {
81 // TODO(msw): Determine why this only seems to be called in Mash. Setting the
James Cook 2017/06/08 17:14:00 File a bug for this.
82 // ShelfItemType as early as possible is important on Mash, to prevent Ash's
83 // ShelfWindowWatcher from creating a conflicting ShelfItem. Set the item type
84 // here for the mash config, and later on in RegisterApp for classic ash.
85 if (chromeos::GetAshConfig() != ash::Config::MASH)
86 return;
87
88 const ash::ShelfID shelf_id = GetShelfId(app_window);
89 DCHECK(!shelf_id.IsNull());
90 aura::Window* window = app_window->GetNativeWindow();
91 window->SetProperty<int>(
92 ash::kShelfItemTypeKey,
93 app_window->window_type_is_panel() ? ash::TYPE_APP_PANEL : ash::TYPE_APP);
94 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize()));
95 }
96
78 void ExtensionAppWindowLauncherController::OnAppWindowShown( 97 void ExtensionAppWindowLauncherController::OnAppWindowShown(
79 AppWindow* app_window, 98 AppWindow* app_window,
80 bool was_hidden) { 99 bool was_hidden) {
81 aura::Window* window = app_window->GetNativeWindow(); 100 aura::Window* window = app_window->GetNativeWindow();
82 if (!IsRegisteredApp(window)) 101 if (!IsRegisteredApp(window))
83 RegisterApp(app_window); 102 RegisterApp(app_window);
84 } 103 }
85 104
86 void ExtensionAppWindowLauncherController::OnAppWindowHidden( 105 void ExtensionAppWindowLauncherController::OnAppWindowHidden(
87 AppWindow* app_window) { 106 AppWindow* app_window) {
88 aura::Window* window = app_window->GetNativeWindow(); 107 aura::Window* window = app_window->GetNativeWindow();
89 if (IsRegisteredApp(window)) 108 if (IsRegisteredApp(window))
90 UnregisterApp(window); 109 UnregisterApp(window);
91 } 110 }
92 111
93 // Called from aura::Window::~Window(), before delegate_->OnWindowDestroyed() 112 // Called from aura::Window::~Window(), before delegate_->OnWindowDestroyed()
94 // which destroys AppWindow, so both |window| and the associated AppWindow 113 // which destroys AppWindow, so both |window| and the associated AppWindow
95 // are valid here. 114 // are valid here.
96 void ExtensionAppWindowLauncherController::OnWindowDestroying( 115 void ExtensionAppWindowLauncherController::OnWindowDestroying(
97 aura::Window* window) { 116 aura::Window* window) {
98 UnregisterApp(window); 117 UnregisterApp(window);
99 } 118 }
100 119
101 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { 120 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) {
121 aura::Window* window = app_window->GetNativeWindow();
102 const ash::ShelfID shelf_id = GetShelfId(app_window); 122 const ash::ShelfID shelf_id = GetShelfId(app_window);
103 DCHECK(!shelf_id.IsNull()); 123 DCHECK(!shelf_id.IsNull());
104 aura::Window* window = app_window->GetNativeWindow(); 124
105 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); 125 // TODO(msw): Determine why OnAppWindowAdded only seems to be called in Mash.
126 if (chromeos::GetAshConfig() != ash::Config::MASH) {
127 window->SetProperty(ash::kShelfIDKey,
128 new std::string(shelf_id.Serialize()));
129 window->SetProperty<int>(ash::kShelfItemTypeKey,
130 app_window->window_type_is_panel()
131 ? ash::TYPE_APP_PANEL
132 : ash::TYPE_APP);
133 }
106 134
107 // Windows created by IME extension should be treated the same way as the 135 // Windows created by IME extension should be treated the same way as the
108 // virtual keyboard window, which does not register itself in launcher. 136 // virtual keyboard window, which does not register itself in launcher.
109 // Ash's ShelfWindowWatcher handles app panel windows separately. 137 // Ash's ShelfWindowWatcher handles app panel windows separately.
110 if (app_window->is_ime_window() || app_window->window_type_is_panel()) 138 if (app_window->is_ime_window() || app_window->window_type_is_panel())
111 return; 139 return;
112 140
113 // Get the app's shelf identifier and add an entry to the map. 141 // Get the app's shelf identifier and add an entry to the map.
114 DCHECK_EQ(window_to_shelf_id_map_.count(window), 0u); 142 DCHECK_EQ(window_to_shelf_id_map_.count(window), 0u);
115 window_to_shelf_id_map_[window] = shelf_id; 143 window_to_shelf_id_map_[window] = shelf_id;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 ExtensionAppWindowLauncherController::ControllerForWindow( 209 ExtensionAppWindowLauncherController::ControllerForWindow(
182 aura::Window* window) { 210 aura::Window* window) {
183 const auto window_iter = window_to_shelf_id_map_.find(window); 211 const auto window_iter = window_to_shelf_id_map_.find(window);
184 if (window_iter == window_to_shelf_id_map_.end()) 212 if (window_iter == window_to_shelf_id_map_.end())
185 return nullptr; 213 return nullptr;
186 const auto controller_iter = app_controller_map_.find(window_iter->second); 214 const auto controller_iter = app_controller_map_.find(window_iter->second);
187 if (controller_iter == app_controller_map_.end()) 215 if (controller_iter == app_controller_map_.end())
188 return nullptr; 216 return nullptr;
189 return controller_iter->second; 217 return controller_iter->second;
190 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698