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::IsAppWindowRegisteredInAnyProfile(
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 if (window_type_mask
== 0)
63 for (AppWindowList::const_iterator j
= app_windows
.begin();
64 j
!= app_windows
.end(); ++j
) {
65 if ((*j
)->window_type() & window_type_mask
)
74 void AppWindowRegistryUtil::CloseAllAppWindows() {
75 std::vector
<Profile
*> profiles
=
76 g_browser_process
->profile_manager()->GetLoadedProfiles();
77 for (std::vector
<Profile
*>::const_iterator i
= profiles
.begin();
80 AppWindowRegistry
* registry
=
81 Factory::GetForBrowserContext(*i
, false /* create */);
85 while (!registry
->app_windows().empty())
86 registry
->app_windows().front()->GetBaseWindow()->Close();