OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/app_window/app_window_registry.h" | 5 #include "extensions/browser/app_window/app_window_registry.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/devtools_agent_host.h" | 12 #include "content/public/browser/devtools_agent_host.h" |
13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "extensions/browser/app_window/app_window.h" | 17 #include "extensions/browser/app_window/app_window.h" |
18 #include "extensions/browser/app_window/apps_client.h" | 18 #include "extensions/browser/app_window/app_window_client.h" |
19 #include "extensions/browser/app_window/native_app_window.h" | 19 #include "extensions/browser/app_window/native_app_window.h" |
20 #include "extensions/browser/extensions_browser_client.h" | 20 #include "extensions/browser/extensions_browser_client.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Create a key that identifies a AppWindow in a RenderViewHost across App | 27 // Create a key that identifies a AppWindow in a RenderViewHost across App |
28 // reloads. If the window was given an id in CreateParams, the key is the | 28 // reloads. If the window was given an id in CreateParams, the key is the |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 bool AppWindowRegistry::HadDevToolsAttached( | 201 bool AppWindowRegistry::HadDevToolsAttached( |
202 content::RenderViewHost* render_view_host) const { | 202 content::RenderViewHost* render_view_host) const { |
203 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); | 203 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); |
204 return key.empty() ? false : inspected_windows_.count(key) != 0; | 204 return key.empty() ? false : inspected_windows_.count(key) != 0; |
205 } | 205 } |
206 | 206 |
207 // static | 207 // static |
208 AppWindow* AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( | 208 AppWindow* AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( |
209 gfx::NativeWindow window) { | 209 gfx::NativeWindow window) { |
210 std::vector<content::BrowserContext*> contexts = | 210 std::vector<content::BrowserContext*> contexts = |
211 AppsClient::Get()->GetLoadedBrowserContexts(); | 211 AppWindowClient::Get()->GetLoadedBrowserContexts(); |
212 for (std::vector<content::BrowserContext*>::const_iterator i = | 212 for (std::vector<content::BrowserContext*>::const_iterator i = |
213 contexts.begin(); | 213 contexts.begin(); |
214 i != contexts.end(); | 214 i != contexts.end(); |
215 ++i) { | 215 ++i) { |
216 AppWindowRegistry* registry = | 216 AppWindowRegistry* registry = |
217 Factory::GetForBrowserContext(*i, false /* create */); | 217 Factory::GetForBrowserContext(*i, false /* create */); |
218 if (!registry) | 218 if (!registry) |
219 continue; | 219 continue; |
220 | 220 |
221 AppWindow* app_window = registry->GetAppWindowForNativeWindow(window); | 221 AppWindow* app_window = registry->GetAppWindowForNativeWindow(window); |
222 if (app_window) | 222 if (app_window) |
223 return app_window; | 223 return app_window; |
224 } | 224 } |
225 | 225 |
226 return NULL; | 226 return NULL; |
227 } | 227 } |
228 | 228 |
229 // static | 229 // static |
230 bool AppWindowRegistry::IsAppWindowRegisteredInAnyProfile( | 230 bool AppWindowRegistry::IsAppWindowRegisteredInAnyProfile( |
231 int window_type_mask) { | 231 int window_type_mask) { |
232 std::vector<content::BrowserContext*> contexts = | 232 std::vector<content::BrowserContext*> contexts = |
233 AppsClient::Get()->GetLoadedBrowserContexts(); | 233 AppWindowClient::Get()->GetLoadedBrowserContexts(); |
234 for (std::vector<content::BrowserContext*>::const_iterator i = | 234 for (std::vector<content::BrowserContext*>::const_iterator i = |
235 contexts.begin(); | 235 contexts.begin(); |
236 i != contexts.end(); | 236 i != contexts.end(); |
237 ++i) { | 237 ++i) { |
238 AppWindowRegistry* registry = | 238 AppWindowRegistry* registry = |
239 Factory::GetForBrowserContext(*i, false /* create */); | 239 Factory::GetForBrowserContext(*i, false /* create */); |
240 if (!registry) | 240 if (!registry) |
241 continue; | 241 continue; |
242 | 242 |
243 const AppWindowList& app_windows = registry->app_windows(); | 243 const AppWindowList& app_windows = registry->app_windows(); |
244 if (app_windows.empty()) | 244 if (app_windows.empty()) |
245 continue; | 245 continue; |
246 | 246 |
247 if (window_type_mask == 0) | 247 if (window_type_mask == 0) |
248 return true; | 248 return true; |
249 | 249 |
250 for (const_iterator j = app_windows.begin(); j != app_windows.end(); ++j) { | 250 for (const_iterator j = app_windows.begin(); j != app_windows.end(); ++j) { |
251 if ((*j)->window_type() & window_type_mask) | 251 if ((*j)->window_type() & window_type_mask) |
252 return true; | 252 return true; |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 return false; | 256 return false; |
257 } | 257 } |
258 | 258 |
259 // static | 259 // static |
260 void AppWindowRegistry::CloseAllAppWindows() { | 260 void AppWindowRegistry::CloseAllAppWindows() { |
261 std::vector<content::BrowserContext*> contexts = | 261 std::vector<content::BrowserContext*> contexts = |
262 AppsClient::Get()->GetLoadedBrowserContexts(); | 262 AppWindowClient::Get()->GetLoadedBrowserContexts(); |
263 for (std::vector<content::BrowserContext*>::const_iterator i = | 263 for (std::vector<content::BrowserContext*>::const_iterator i = |
264 contexts.begin(); | 264 contexts.begin(); |
265 i != contexts.end(); | 265 i != contexts.end(); |
266 ++i) { | 266 ++i) { |
267 AppWindowRegistry* registry = | 267 AppWindowRegistry* registry = |
268 Factory::GetForBrowserContext(*i, false /* create */); | 268 Factory::GetForBrowserContext(*i, false /* create */); |
269 if (!registry) | 269 if (!registry) |
270 continue; | 270 continue; |
271 | 271 |
272 while (!registry->app_windows().empty()) | 272 while (!registry->app_windows().empty()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 bool AppWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { | 343 bool AppWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { |
344 return false; | 344 return false; |
345 } | 345 } |
346 | 346 |
347 content::BrowserContext* AppWindowRegistry::Factory::GetBrowserContextToUse( | 347 content::BrowserContext* AppWindowRegistry::Factory::GetBrowserContextToUse( |
348 content::BrowserContext* context) const { | 348 content::BrowserContext* context) const { |
349 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 349 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
350 } | 350 } |
351 | 351 |
352 } // namespace extensions | 352 } // namespace extensions |
OLD | NEW |