| 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/app_window_client.h" | |
| 19 #include "extensions/browser/app_window/native_app_window.h" | 18 #include "extensions/browser/app_window/native_app_window.h" |
| 20 #include "extensions/browser/extensions_browser_client.h" | 19 #include "extensions/browser/extensions_browser_client.h" |
| 21 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 22 | 21 |
| 23 namespace extensions { | 22 namespace extensions { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 // Create a key that identifies a AppWindow in a RenderViewHost across App | 26 // 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 | 27 // reloads. If the window was given an id in CreateParams, the key is the |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 196 } |
| 198 return result; | 197 return result; |
| 199 } | 198 } |
| 200 | 199 |
| 201 bool AppWindowRegistry::HadDevToolsAttached( | 200 bool AppWindowRegistry::HadDevToolsAttached( |
| 202 content::RenderViewHost* render_view_host) const { | 201 content::RenderViewHost* render_view_host) const { |
| 203 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); | 202 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); |
| 204 return key.empty() ? false : inspected_windows_.count(key) != 0; | 203 return key.empty() ? false : inspected_windows_.count(key) != 0; |
| 205 } | 204 } |
| 206 | 205 |
| 207 // static | |
| 208 AppWindow* AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( | |
| 209 gfx::NativeWindow window) { | |
| 210 std::vector<content::BrowserContext*> contexts = | |
| 211 AppWindowClient::Get()->GetLoadedBrowserContexts(); | |
| 212 for (std::vector<content::BrowserContext*>::const_iterator i = | |
| 213 contexts.begin(); | |
| 214 i != contexts.end(); | |
| 215 ++i) { | |
| 216 AppWindowRegistry* registry = | |
| 217 Factory::GetForBrowserContext(*i, false /* create */); | |
| 218 if (!registry) | |
| 219 continue; | |
| 220 | |
| 221 AppWindow* app_window = registry->GetAppWindowForNativeWindow(window); | |
| 222 if (app_window) | |
| 223 return app_window; | |
| 224 } | |
| 225 | |
| 226 return NULL; | |
| 227 } | |
| 228 | |
| 229 // static | |
| 230 bool AppWindowRegistry::IsAppWindowRegisteredInAnyProfile( | |
| 231 int window_type_mask) { | |
| 232 std::vector<content::BrowserContext*> contexts = | |
| 233 AppWindowClient::Get()->GetLoadedBrowserContexts(); | |
| 234 for (std::vector<content::BrowserContext*>::const_iterator i = | |
| 235 contexts.begin(); | |
| 236 i != contexts.end(); | |
| 237 ++i) { | |
| 238 AppWindowRegistry* registry = | |
| 239 Factory::GetForBrowserContext(*i, false /* create */); | |
| 240 if (!registry) | |
| 241 continue; | |
| 242 | |
| 243 const AppWindowList& app_windows = registry->app_windows(); | |
| 244 if (app_windows.empty()) | |
| 245 continue; | |
| 246 | |
| 247 if (window_type_mask == 0) | |
| 248 return true; | |
| 249 | |
| 250 for (const_iterator j = app_windows.begin(); j != app_windows.end(); ++j) { | |
| 251 if ((*j)->window_type() & window_type_mask) | |
| 252 return true; | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 return false; | |
| 257 } | |
| 258 | |
| 259 // static | |
| 260 void AppWindowRegistry::CloseAllAppWindows() { | |
| 261 std::vector<content::BrowserContext*> contexts = | |
| 262 AppWindowClient::Get()->GetLoadedBrowserContexts(); | |
| 263 for (std::vector<content::BrowserContext*>::const_iterator i = | |
| 264 contexts.begin(); | |
| 265 i != contexts.end(); | |
| 266 ++i) { | |
| 267 AppWindowRegistry* registry = | |
| 268 Factory::GetForBrowserContext(*i, false /* create */); | |
| 269 if (!registry) | |
| 270 continue; | |
| 271 | |
| 272 while (!registry->app_windows().empty()) | |
| 273 registry->app_windows().front()->GetBaseWindow()->Close(); | |
| 274 } | |
| 275 } | |
| 276 | |
| 277 void AppWindowRegistry::OnDevToolsStateChanged( | 206 void AppWindowRegistry::OnDevToolsStateChanged( |
| 278 content::DevToolsAgentHost* agent_host, | 207 content::DevToolsAgentHost* agent_host, |
| 279 bool attached) { | 208 bool attached) { |
| 280 content::WebContents* web_contents = agent_host->GetWebContents(); | 209 content::WebContents* web_contents = agent_host->GetWebContents(); |
| 281 // Ignore unrelated notifications. | 210 // Ignore unrelated notifications. |
| 282 if (!web_contents || web_contents->GetBrowserContext() != context_) | 211 if (!web_contents || web_contents->GetBrowserContext() != context_) |
| 283 return; | 212 return; |
| 284 | 213 |
| 285 std::string key = | 214 std::string key = |
| 286 GetWindowKeyForRenderViewHost(this, web_contents->GetRenderViewHost()); | 215 GetWindowKeyForRenderViewHost(this, web_contents->GetRenderViewHost()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 bool AppWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { | 272 bool AppWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { |
| 344 return false; | 273 return false; |
| 345 } | 274 } |
| 346 | 275 |
| 347 content::BrowserContext* AppWindowRegistry::Factory::GetBrowserContextToUse( | 276 content::BrowserContext* AppWindowRegistry::Factory::GetBrowserContextToUse( |
| 348 content::BrowserContext* context) const { | 277 content::BrowserContext* context) const { |
| 349 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 278 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
| 350 } | 279 } |
| 351 | 280 |
| 352 } // namespace extensions | 281 } // namespace extensions |
| OLD | NEW |