OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "apps/app_window_registry_util.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 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" |
| 15 |
| 16 using extensions::AppWindow; |
| 17 using extensions::AppWindowRegistry; |
| 18 |
| 19 typedef AppWindowRegistry::AppWindowList AppWindowList; |
| 20 typedef AppWindowRegistry::Factory Factory; |
| 21 |
| 22 namespace apps { |
| 23 |
| 24 // static |
| 25 AppWindow* AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 26 gfx::NativeWindow window) { |
| 27 std::vector<Profile*> profiles = |
| 28 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 29 for (std::vector<Profile*>::const_iterator i = profiles.begin(); |
| 30 i != profiles.end(); |
| 31 ++i) { |
| 32 AppWindowRegistry* registry = |
| 33 Factory::GetForBrowserContext(*i, false /* create */); |
| 34 if (!registry) |
| 35 continue; |
| 36 |
| 37 AppWindow* app_window = registry->GetAppWindowForNativeWindow(window); |
| 38 if (app_window) |
| 39 return app_window; |
| 40 } |
| 41 |
| 42 return NULL; |
| 43 } |
| 44 |
| 45 // static |
| 46 bool AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( |
| 47 int window_type_mask) { |
| 48 std::vector<Profile*> profiles = |
| 49 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 50 for (std::vector<Profile*>::const_iterator i = profiles.begin(); |
| 51 i != profiles.end(); |
| 52 ++i) { |
| 53 AppWindowRegistry* registry = |
| 54 Factory::GetForBrowserContext(*i, false /* create */); |
| 55 if (!registry) |
| 56 continue; |
| 57 |
| 58 const AppWindowList& app_windows = registry->app_windows(); |
| 59 if (app_windows.empty()) |
| 60 continue; |
| 61 |
| 62 if (window_type_mask == 0) |
| 63 return true; |
| 64 |
| 65 for (AppWindowList::const_iterator j = app_windows.begin(); |
| 66 j != app_windows.end(); ++j) { |
| 67 if ((*j)->window_type() & window_type_mask) |
| 68 return true; |
| 69 } |
| 70 } |
| 71 |
| 72 return false; |
| 73 } |
| 74 |
| 75 // static |
| 76 void AppWindowRegistryUtil::CloseAllAppWindows() { |
| 77 std::vector<Profile*> profiles = |
| 78 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 79 for (std::vector<Profile*>::const_iterator i = profiles.begin(); |
| 80 i != profiles.end(); |
| 81 ++i) { |
| 82 AppWindowRegistry* registry = |
| 83 Factory::GetForBrowserContext(*i, false /* create */); |
| 84 if (!registry) |
| 85 continue; |
| 86 |
| 87 while (!registry->app_windows().empty()) |
| 88 registry->app_windows().front()->GetBaseWindow()->Close(); |
| 89 } |
| 90 } |
| 91 |
| 92 } // namespace apps |
OLD | NEW |