1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/apps/app_window_registry_util.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "extensions/browser/app_window/app_window.h"
13 #include "extensions/browser/app_window/app_window_registry.h"
14 #include "extensions/browser/app_window/native_app_window.h"
16 using extensions::AppWindow
;
17 using extensions::AppWindowRegistry
;
19 typedef AppWindowRegistry::AppWindowList AppWindowList
;
20 typedef AppWindowRegistry::Factory Factory
;
23 AppWindow
* AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
24 gfx::NativeWindow window
) {
25 std::vector
<Profile
*> profiles
=
26 g_browser_process
->profile_manager()->GetLoadedProfiles();
27 for (std::vector
<Profile
*>::const_iterator i
= profiles
.begin();
30 AppWindowRegistry
* registry
=
31 Factory::GetForBrowserContext(*i
, false /* create */);
35 AppWindow
* app_window
= registry
->GetAppWindowForNativeWindow(window
);
44 bool AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(
45 int window_type_mask
) {
46 std::vector
<Profile
*> profiles
=
47 g_browser_process
->profile_manager()->GetLoadedProfiles();
48 for (std::vector
<Profile
*>::const_iterator i
= profiles
.begin();
51 AppWindowRegistry
* registry
=
52 Factory::GetForBrowserContext(*i
, false /* create */);
56 const AppWindowList
& app_windows
= registry
->app_windows();
57 if (app_windows
.empty())
60 for (const AppWindow
* window
: app_windows
) {
61 if (!window
->is_hidden() &&
62 (window_type_mask
== 0 ||
63 (window
->window_type() & window_type_mask
)))
72 void AppWindowRegistryUtil::CloseAllAppWindows() {
73 std::vector
<Profile
*> profiles
=
74 g_browser_process
->profile_manager()->GetLoadedProfiles();
75 for (std::vector
<Profile
*>::const_iterator i
= profiles
.begin();
78 AppWindowRegistry
* registry
=
79 Factory::GetForBrowserContext(*i
, false /* create */);
83 while (!registry
->app_windows().empty())
84 registry
->app_windows().front()->GetBaseWindow()->Close();