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

Side by Side Diff: apps/app_shim/extension_app_shim_handler_mac.cc

Issue 403743002: [Mac] Hide all shims when Chrome is hidden. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « apps/app_shim/extension_app_shim_handler_mac.h ('k') | chrome/browser/app_controller_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "apps/app_shim/extension_app_shim_handler_mac.h" 5 #include "apps/app_shim/extension_app_shim_handler_mac.h"
6 6
7 #include "apps/app_lifetime_monitor_factory.h" 7 #include "apps/app_lifetime_monitor_factory.h"
8 #include "apps/app_shim/app_shim_host_manager_mac.h" 8 #include "apps/app_shim/app_shim_host_manager_mac.h"
9 #include "apps/app_shim/app_shim_messages.h" 9 #include "apps/app_shim/app_shim_messages.h"
10 #include "apps/app_window.h" 10 #include "apps/app_window.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 AppShimHandler::Host* ExtensionAppShimHandler::FindHost( 221 AppShimHandler::Host* ExtensionAppShimHandler::FindHost(
222 Profile* profile, 222 Profile* profile,
223 const std::string& app_id) { 223 const std::string& app_id) {
224 HostMap::iterator it = hosts_.find(make_pair(profile, app_id)); 224 HostMap::iterator it = hosts_.find(make_pair(profile, app_id));
225 return it == hosts_.end() ? NULL : it->second; 225 return it == hosts_.end() ? NULL : it->second;
226 } 226 }
227 227
228 // static 228 // static
229 void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) { 229 void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) {
230 ExtensionAppShimHandler* handler = 230 ExtensionAppShimHandler* handler = GetInstance();
231 g_browser_process->platform_part()->app_shim_host_manager()->
232 extension_app_shim_handler();
233 Host* host = handler->FindHost( 231 Host* host = handler->FindHost(
234 Profile::FromBrowserContext(app_window->browser_context()), 232 Profile::FromBrowserContext(app_window->browser_context()),
235 app_window->extension_id()); 233 app_window->extension_id());
236 if (host) { 234 if (host) {
237 handler->OnShimQuit(host); 235 handler->OnShimQuit(host);
238 } else { 236 } else {
239 // App shims might be disabled or the shim is still starting up. 237 // App shims might be disabled or the shim is still starting up.
240 AppWindowRegistry::Get( 238 AppWindowRegistry::Get(
241 Profile::FromBrowserContext(app_window->browser_context())) 239 Profile::FromBrowserContext(app_window->browser_context()))
242 ->CloseAllAppWindowsForApp(app_window->extension_id()); 240 ->CloseAllAppWindowsForApp(app_window->extension_id());
243 } 241 }
244 } 242 }
245 243
246 void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) { 244 void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) {
247 ExtensionAppShimHandler* handler = 245 ExtensionAppShimHandler* handler = GetInstance();
248 g_browser_process->platform_part()->app_shim_host_manager()->
249 extension_app_shim_handler();
250 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 246 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
251 Host* host = handler->FindHost(profile, app_window->extension_id()); 247 Host* host = handler->FindHost(profile, app_window->extension_id());
252 if (host) 248 if (host)
253 host->OnAppHide(); 249 host->OnAppHide();
254 else 250 else
255 SetAppHidden(profile, app_window->extension_id(), true); 251 SetAppHidden(profile, app_window->extension_id(), true);
256 } 252 }
257 253
258 void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) { 254 void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) {
259 ExtensionAppShimHandler* handler = 255 ExtensionAppShimHandler* handler = GetInstance();
260 g_browser_process->platform_part()->app_shim_host_manager()->
261 extension_app_shim_handler();
262 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 256 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
263 const std::string& app_id = app_window->extension_id(); 257 const std::string& app_id = app_window->extension_id();
264 Host* host = handler->FindHost(profile, app_id); 258 Host* host = handler->FindHost(profile, app_id);
265 if (host) { 259 if (host) {
266 handler->OnShimFocus(host, 260 handler->OnShimFocus(host,
267 APP_SHIM_FOCUS_NORMAL, 261 APP_SHIM_FOCUS_NORMAL,
268 std::vector<base::FilePath>()); 262 std::vector<base::FilePath>());
269 } else { 263 } else {
270 FocusWindows( 264 FocusWindows(
271 apps::AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id)); 265 apps::AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id));
272 } 266 }
273 } 267 }
274 268
275 // static 269 // static
276 bool ExtensionAppShimHandler::RequestUserAttentionForWindow( 270 bool ExtensionAppShimHandler::RequestUserAttentionForWindow(
277 AppWindow* app_window) { 271 AppWindow* app_window) {
278 ExtensionAppShimHandler* handler = 272 ExtensionAppShimHandler* handler = GetInstance();
279 g_browser_process->platform_part()->app_shim_host_manager()->
280 extension_app_shim_handler();
281 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 273 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
282 Host* host = handler->FindHost(profile, app_window->extension_id()); 274 Host* host = handler->FindHost(profile, app_window->extension_id());
283 if (host) { 275 if (host) {
284 // Bring the window to the front without showing it. 276 // Bring the window to the front without showing it.
285 AppWindowRegistry::Get(profile)->AppWindowActivated(app_window); 277 AppWindowRegistry::Get(profile)->AppWindowActivated(app_window);
286 host->OnAppRequestUserAttention(); 278 host->OnAppRequestUserAttention();
287 return true; 279 return true;
288 } else { 280 } else {
289 // Just show the app. 281 // Just show the app.
290 SetAppHidden(profile, app_window->extension_id(), false); 282 SetAppHidden(profile, app_window->extension_id(), false);
291 return false; 283 return false;
292 } 284 }
293 } 285 }
294 286
287 // static
288 void ExtensionAppShimHandler::OnChromeWillHide() {
289 // Send OnAppHide to all the shims so that they go into the hidden state.
290 // This is necessary so that when the shim is next focused, it will know to
291 // unhide.
292 ExtensionAppShimHandler* handler = GetInstance();
293 for (HostMap::iterator it = handler->hosts_.begin();
294 it != handler->hosts_.end();
295 ++it) {
296 it->second->OnAppHide();
297 }
298 }
299
295 void ExtensionAppShimHandler::OnShimLaunch( 300 void ExtensionAppShimHandler::OnShimLaunch(
296 Host* host, 301 Host* host,
297 AppShimLaunchType launch_type, 302 AppShimLaunchType launch_type,
298 const std::vector<base::FilePath>& files) { 303 const std::vector<base::FilePath>& files) {
299 const std::string& app_id = host->GetAppId(); 304 const std::string& app_id = host->GetAppId();
300 DCHECK(extensions::Extension::IdIsValid(app_id)); 305 DCHECK(extensions::Extension::IdIsValid(app_id));
301 306
302 const base::FilePath& profile_path = host->GetProfilePath(); 307 const base::FilePath& profile_path = host->GetProfilePath();
303 DCHECK(!profile_path.empty()); 308 DCHECK(!profile_path.empty());
304 309
(...skipping 19 matching lines...) Expand all
324 DCHECK_EQ(APP_SHIM_LAUNCH_NORMAL, launch_type); 329 DCHECK_EQ(APP_SHIM_LAUNCH_NORMAL, launch_type);
325 delegate_->LoadProfileAsync( 330 delegate_->LoadProfileAsync(
326 profile_path, 331 profile_path,
327 base::Bind(&ExtensionAppShimHandler::OnProfileLoaded, 332 base::Bind(&ExtensionAppShimHandler::OnProfileLoaded,
328 weak_factory_.GetWeakPtr(), 333 weak_factory_.GetWeakPtr(),
329 host, launch_type, files)); 334 host, launch_type, files));
330 335
331 // Return now. OnAppLaunchComplete will be called when the app is activated. 336 // Return now. OnAppLaunchComplete will be called when the app is activated.
332 } 337 }
333 338
339 // static
340 ExtensionAppShimHandler* ExtensionAppShimHandler::GetInstance() {
341 return g_browser_process->platform_part()
342 ->app_shim_host_manager()
343 ->extension_app_shim_handler();
344 }
345
334 void ExtensionAppShimHandler::OnProfileLoaded( 346 void ExtensionAppShimHandler::OnProfileLoaded(
335 Host* host, 347 Host* host,
336 AppShimLaunchType launch_type, 348 AppShimLaunchType launch_type,
337 const std::vector<base::FilePath>& files, 349 const std::vector<base::FilePath>& files,
338 Profile* profile) { 350 Profile* profile) {
339 const std::string& app_id = host->GetAppId(); 351 const std::string& app_id = host->GetAppId();
340 352
341 // The first host to claim this (profile, app_id) becomes the main host. 353 // The first host to claim this (profile, app_id) becomes the main host.
342 // For any others, focus or relaunch the app. 354 // For any others, focus or relaunch the app.
343 if (!hosts_.insert(make_pair(make_pair(profile, app_id), host)).second) { 355 if (!hosts_.insert(make_pair(make_pair(profile, app_id), host)).second) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if (hosts_.empty()) 535 if (hosts_.empty())
524 delegate_->MaybeTerminate(); 536 delegate_->MaybeTerminate();
525 } 537 }
526 538
527 void ExtensionAppShimHandler::OnAppStop(Profile* profile, 539 void ExtensionAppShimHandler::OnAppStop(Profile* profile,
528 const std::string& app_id) {} 540 const std::string& app_id) {}
529 541
530 void ExtensionAppShimHandler::OnChromeTerminating() {} 542 void ExtensionAppShimHandler::OnChromeTerminating() {}
531 543
532 } // namespace apps 544 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_shim/extension_app_shim_handler_mac.h ('k') | chrome/browser/app_controller_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698