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

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

Issue 2462753002: Use Ash's ShelfWindowWatcher for app panel windows. (Closed)
Patch Set: Add ShelfWindowWatcherTest, remove ChromeLauncherControllerImplTest panel use. Created 4 years, 1 month 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/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shelf/shelf_delegate.h" 8 #include "ash/common/shelf/shelf_delegate.h"
9 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window_property.h" 11 #include "ash/common/wm_window_property.h"
12 #include "ash/wm/window_properties.h"
11 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
12 #include "base/stl_util.h" 14 #include "base/stl_util.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h" 18 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h"
17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
20 #include "chrome/browser/ui/ash/property_util.h"
18 #include "extensions/browser/app_window/app_window.h" 21 #include "extensions/browser/app_window/app_window.h"
19 #include "extensions/browser/app_window/native_app_window.h" 22 #include "extensions/browser/app_window/native_app_window.h"
20 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
21 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
22 #include "ui/aura/window_event_dispatcher.h" 25 #include "ui/aura/window_event_dispatcher.h"
23 26
24 using extensions::AppWindow; 27 using extensions::AppWindow;
25 using extensions::AppWindowRegistry; 28 using extensions::AppWindowRegistry;
26 29
27 namespace { 30 namespace {
28 31
29 std::string GetLaunchId(AppWindow* app_window) { 32 std::string GetLaunchId(AppWindow* app_window) {
30 // Set launch_id default value to an empty string. If showInShelf parameter 33 // Set launch_id default value to an empty string. If showInShelf parameter
31 // is true or the window type is panel and the window key is not empty, its 34 // is true and the window key is not empty, its value is appended to the
32 // value is appended to the launch_id. Otherwise, if the window key is 35 // launch_id. Otherwise, if the window key is empty, the session_id is used.
33 // empty, the session_id is used.
34 std::string launch_id; 36 std::string launch_id;
35 if (app_window->show_in_shelf() || app_window->window_type_is_panel()) { 37 if (app_window->show_in_shelf()) {
James Cook 2016/11/02 17:53:44 Can you tell me more about this? This sounds like
msw 2016/11/10 21:07:46 I aimed to remove all panel use/control from this
36 if (!app_window->window_key().empty()) 38 if (!app_window->window_key().empty())
37 launch_id = app_window->window_key(); 39 launch_id = app_window->window_key();
38 else 40 else
39 launch_id = base::StringPrintf("%d", app_window->session_id().id()); 41 launch_id = base::StringPrintf("%d", app_window->session_id().id());
40 } 42 }
41 return launch_id; 43 return launch_id;
42 } 44 }
43 45
44 std::string GetAppShelfId(AppWindow* app_window) { 46 std::string GetAppShelfId(AppWindow* app_window) {
45 // Set app_shelf_id value to app_id and then append launch_id. 47 // Set app_shelf_id value to app_id and then append launch_id.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 aura::Window* window) { 122 aura::Window* window) {
121 UnregisterApp(window); 123 UnregisterApp(window);
122 } 124 }
123 125
124 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { 126 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) {
125 // Windows created by IME extension should be treated the same way as the 127 // Windows created by IME extension should be treated the same way as the
126 // virtual keyboard window, which does not register itself in launcher. 128 // virtual keyboard window, which does not register itself in launcher.
127 if (app_window->is_ime_window()) 129 if (app_window->is_ime_window())
128 return; 130 return;
129 131
132 // Ash's ShelfWindowWatcher handles app panel windows once their type is set.
130 aura::Window* window = app_window->GetNativeWindow(); 133 aura::Window* window = app_window->GetNativeWindow();
134 if (app_window->window_type_is_panel()) {
135 property_util::SetIntProperty(window, ash::kShelfItemTypeKey,
136 ash::TYPE_APP_PANEL);
137 return;
138 }
139
131 // Get the app's shelf identifier and add an entry to the map. 140 // Get the app's shelf identifier and add an entry to the map.
132 DCHECK(window_to_app_shelf_id_map_.find(window) == 141 DCHECK(window_to_app_shelf_id_map_.find(window) ==
133 window_to_app_shelf_id_map_.end()); 142 window_to_app_shelf_id_map_.end());
134 const std::string app_shelf_id = GetAppShelfId(app_window); 143 const std::string app_shelf_id = GetAppShelfId(app_window);
135 window_to_app_shelf_id_map_[window] = app_shelf_id; 144 window_to_app_shelf_id_map_[window] = app_shelf_id;
136 window->AddObserver(this); 145 window->AddObserver(this);
137 146
138 // Find or create an item controller and launcher item. 147 // Find or create an item controller and launcher item.
139 std::string app_id = app_window->extension_id(); 148 std::string app_id = app_window->extension_id();
140 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) 149 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window)
141 ? ash::STATUS_ACTIVE 150 ? ash::STATUS_ACTIVE
142 : ash::STATUS_RUNNING; 151 : ash::STATUS_RUNNING;
143 AppControllerMap::iterator app_controller_iter = 152 AppControllerMap::iterator app_controller_iter =
144 app_controller_map_.find(app_shelf_id); 153 app_controller_map_.find(app_shelf_id);
145 ash::ShelfID shelf_id = 0; 154 ash::ShelfID shelf_id = 0;
146 155
147 if (app_controller_iter != app_controller_map_.end()) { 156 if (app_controller_iter != app_controller_map_.end()) {
148 ExtensionAppWindowLauncherItemController* controller = 157 ExtensionAppWindowLauncherItemController* controller =
149 app_controller_iter->second; 158 app_controller_iter->second;
150 DCHECK(controller->app_id() == app_id); 159 DCHECK(controller->app_id() == app_id);
151 shelf_id = controller->shelf_id(); 160 shelf_id = controller->shelf_id();
152 controller->AddAppWindow(app_window); 161 controller->AddAppWindow(app_window);
153 } else { 162 } else {
154 LauncherItemController::Type type = 163 LauncherItemController::Type type = LauncherItemController::TYPE_APP;
155 app_window->window_type_is_panel()
156 ? LauncherItemController::TYPE_APP_PANEL
157 : LauncherItemController::TYPE_APP;
158 std::string launch_id = GetLaunchId(app_window); 164 std::string launch_id = GetLaunchId(app_window);
159 ExtensionAppWindowLauncherItemController* controller = 165 ExtensionAppWindowLauncherItemController* controller =
160 new ExtensionAppWindowLauncherItemController(type, app_id, launch_id, 166 new ExtensionAppWindowLauncherItemController(type, app_id, launch_id,
161 owner()); 167 owner());
162 controller->AddAppWindow(app_window); 168 controller->AddAppWindow(app_window);
163 // If there is already a shelf id mapped to this app_shelf_id (e.g. pinned), 169 // If there is already a shelf id mapped to this app_shelf_id (e.g. pinned),
164 // use that shelf item. 170 // use that shelf item.
165 shelf_id = 171 shelf_id =
166 ash::WmShell::Get()->shelf_delegate()->GetShelfIDForAppIDAndLaunchID( 172 ash::WmShell::Get()->shelf_delegate()->GetShelfIDForAppIDAndLaunchID(
167 app_id, launch_id); 173 app_id, launch_id);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 WindowToAppShelfIdMap::iterator window_iter = 230 WindowToAppShelfIdMap::iterator window_iter =
225 window_to_app_shelf_id_map_.find(window); 231 window_to_app_shelf_id_map_.find(window);
226 if (window_iter == window_to_app_shelf_id_map_.end()) 232 if (window_iter == window_to_app_shelf_id_map_.end())
227 return nullptr; 233 return nullptr;
228 AppControllerMap::iterator app_controller_iter = 234 AppControllerMap::iterator app_controller_iter =
229 app_controller_map_.find(window_iter->second); 235 app_controller_map_.find(window_iter->second);
230 if (app_controller_iter == app_controller_map_.end()) 236 if (app_controller_iter == app_controller_map_.end())
231 return nullptr; 237 return nullptr;
232 return app_controller_iter->second; 238 return app_controller_iter->second;
233 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698