OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/apps_client.h" | |
5 #include "apps/native_app_window.h" | 6 #include "apps/native_app_window.h" |
6 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
7 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/profiles/incognito_helpers.h" | 9 #include "chrome/browser/profiles/incognito_helpers.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | |
11 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
12 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
13 #include "content/public/browser/devtools_agent_host.h" | 12 #include "content/public/browser/devtools_agent_host.h" |
tapted
2013/09/04 01:08:35
nit: #include content/public/browser/browser_conte
benwells
2013/09/10 16:48:50
Done.
| |
14 #include "content/public/browser/devtools_manager.h" | 13 #include "content/public/browser/devtools_manager.h" |
15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/site_instance.h" | 16 #include "content/public/browser/site_instance.h" |
18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // Create a key that identifies a ShellWindow in a RenderViewHost across App | 21 // Create a key that identifies a ShellWindow in a RenderViewHost across App |
23 // reloads. If the window was given an id in CreateParams, the key is the | 22 // reloads. If the window was given an id in CreateParams, the key is the |
(...skipping 14 matching lines...) Expand all Loading... | |
38 std::string key = shell_window->extension()->id(); | 37 std::string key = shell_window->extension()->id(); |
39 key += ':'; | 38 key += ':'; |
40 key += shell_window->window_key(); | 39 key += shell_window->window_key(); |
41 return key; | 40 return key; |
42 } | 41 } |
43 | 42 |
44 } // namespace | 43 } // namespace |
45 | 44 |
46 namespace apps { | 45 namespace apps { |
47 | 46 |
48 ShellWindowRegistry::ShellWindowRegistry(Profile* profile) | 47 ShellWindowRegistry::ShellWindowRegistry(content::BrowserContext* context) |
49 : profile_(profile), | 48 : context_(context), |
50 devtools_callback_(base::Bind( | 49 devtools_callback_(base::Bind( |
51 &ShellWindowRegistry::OnDevToolsStateChanged, | 50 &ShellWindowRegistry::OnDevToolsStateChanged, |
52 base::Unretained(this))) { | 51 base::Unretained(this))) { |
53 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 52 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
54 devtools_callback_); | 53 devtools_callback_); |
55 } | 54 } |
56 | 55 |
57 ShellWindowRegistry::~ShellWindowRegistry() { | 56 ShellWindowRegistry::~ShellWindowRegistry() { |
58 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 57 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
59 devtools_callback_); | 58 devtools_callback_); |
60 } | 59 } |
61 | 60 |
62 // static | 61 // static |
63 ShellWindowRegistry* ShellWindowRegistry::Get(Profile* profile) { | 62 ShellWindowRegistry* ShellWindowRegistry::Get( |
64 return Factory::GetForProfile(profile, true /* create */); | 63 content::BrowserContext* context) { |
64 return Factory::GetForBrowserContext(context, true /* create */); | |
65 } | 65 } |
66 | 66 |
67 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { | 67 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { |
68 BringToFront(shell_window); | 68 BringToFront(shell_window); |
69 FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window)); | 69 FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window)); |
70 } | 70 } |
71 | 71 |
72 void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) { | 72 void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) { |
73 AddShellWindowToList(shell_window); | 73 AddShellWindowToList(shell_window); |
74 FOR_EACH_OBSERVER(Observer, observers_, | 74 FOR_EACH_OBSERVER(Observer, observers_, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 171 |
172 bool ShellWindowRegistry::HadDevToolsAttached( | 172 bool ShellWindowRegistry::HadDevToolsAttached( |
173 content::RenderViewHost* render_view_host) const { | 173 content::RenderViewHost* render_view_host) const { |
174 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); | 174 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); |
175 return key.empty() ? false : inspected_windows_.count(key) != 0; | 175 return key.empty() ? false : inspected_windows_.count(key) != 0; |
176 } | 176 } |
177 | 177 |
178 // static | 178 // static |
179 ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | 179 ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( |
180 gfx::NativeWindow window) { | 180 gfx::NativeWindow window) { |
181 std::vector<Profile*> profiles = | 181 std::vector<content::BrowserContext*> contexts = |
182 g_browser_process->profile_manager()->GetLoadedProfiles(); | 182 AppsClient::Get()->GetLoadedBrowserContexts(); |
183 for (std::vector<Profile*>::const_iterator i = profiles.begin(); | 183 for (std::vector<content::BrowserContext*>::const_iterator i = |
184 i != profiles.end(); ++i) { | 184 contexts.begin(); |
185 ShellWindowRegistry* registry = Factory::GetForProfile(*i, | 185 i != contexts.end(); ++i) { |
186 false /* create */); | 186 ShellWindowRegistry* registry = Factory::GetForBrowserContext( |
187 *i, false /* create */); | |
187 if (!registry) | 188 if (!registry) |
188 continue; | 189 continue; |
189 | 190 |
190 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(window); | 191 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(window); |
191 if (shell_window) | 192 if (shell_window) |
192 return shell_window; | 193 return shell_window; |
193 } | 194 } |
194 | 195 |
195 return NULL; | 196 return NULL; |
196 } | 197 } |
197 | 198 |
198 // static | 199 // static |
199 bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( | 200 bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( |
200 int window_type_mask) { | 201 int window_type_mask) { |
201 std::vector<Profile*> profiles = | 202 std::vector<content::BrowserContext*> contexts = |
202 g_browser_process->profile_manager()->GetLoadedProfiles(); | 203 AppsClient::Get()->GetLoadedBrowserContexts(); |
203 for (std::vector<Profile*>::const_iterator i = profiles.begin(); | 204 for (std::vector<content::BrowserContext*>::const_iterator i = |
204 i != profiles.end(); ++i) { | 205 contexts.begin(); |
205 ShellWindowRegistry* registry = Factory::GetForProfile(*i, | 206 i != contexts.end(); ++i) { |
206 false /* create */); | 207 ShellWindowRegistry* registry = Factory::GetForBrowserContext( |
208 *i, false /* create */); | |
207 if (!registry) | 209 if (!registry) |
208 continue; | 210 continue; |
209 | 211 |
210 const ShellWindowList& shell_windows = registry->shell_windows(); | 212 const ShellWindowList& shell_windows = registry->shell_windows(); |
211 if (shell_windows.empty()) | 213 if (shell_windows.empty()) |
212 continue; | 214 continue; |
213 | 215 |
214 if (window_type_mask == 0) | 216 if (window_type_mask == 0) |
215 return true; | 217 return true; |
216 | 218 |
217 for (const_iterator j = shell_windows.begin(); j != shell_windows.end(); | 219 for (const_iterator j = shell_windows.begin(); j != shell_windows.end(); |
218 ++j) { | 220 ++j) { |
219 if ((*j)->window_type() & window_type_mask) | 221 if ((*j)->window_type() & window_type_mask) |
220 return true; | 222 return true; |
221 } | 223 } |
222 } | 224 } |
223 | 225 |
224 return false; | 226 return false; |
225 } | 227 } |
226 | 228 |
227 void ShellWindowRegistry::OnDevToolsStateChanged( | 229 void ShellWindowRegistry::OnDevToolsStateChanged( |
228 content::DevToolsAgentHost* agent_host, bool attached) { | 230 content::DevToolsAgentHost* agent_host, bool attached) { |
229 content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 231 content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
230 // Ignore unrelated notifications. | 232 // Ignore unrelated notifications. |
231 if (!rvh || | 233 if (!rvh || |
232 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != profile_) | 234 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != context_) |
233 return; | 235 return; |
tapted
2013/09/04 01:08:35
nit (while you're here): blank line after early re
benwells
2013/09/10 16:48:50
Done.
| |
234 std::string key = GetWindowKeyForRenderViewHost(this, rvh); | 236 std::string key = GetWindowKeyForRenderViewHost(this, rvh); |
235 if (key.empty()) | 237 if (key.empty()) |
236 return; | 238 return; |
237 | 239 |
238 if (attached) | 240 if (attached) |
239 inspected_windows_.insert(key); | 241 inspected_windows_.insert(key); |
240 else | 242 else |
241 inspected_windows_.erase(key); | 243 inspected_windows_.erase(key); |
242 } | 244 } |
243 | 245 |
(...skipping 12 matching lines...) Expand all Loading... | |
256 shell_window); | 258 shell_window); |
257 if (it != shell_windows_.end()) | 259 if (it != shell_windows_.end()) |
258 shell_windows_.erase(it); | 260 shell_windows_.erase(it); |
259 shell_windows_.push_front(shell_window); | 261 shell_windows_.push_front(shell_window); |
260 } | 262 } |
261 | 263 |
262 /////////////////////////////////////////////////////////////////////////////// | 264 /////////////////////////////////////////////////////////////////////////////// |
263 // Factory boilerplate | 265 // Factory boilerplate |
264 | 266 |
265 // static | 267 // static |
266 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForProfile( | 268 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForBrowserContext( |
267 Profile* profile, bool create) { | 269 content::BrowserContext* context, bool create) { |
268 return static_cast<ShellWindowRegistry*>( | 270 return static_cast<ShellWindowRegistry*>( |
269 GetInstance()->GetServiceForBrowserContext(profile, create)); | 271 GetInstance()->GetServiceForBrowserContext(context, create)); |
270 } | 272 } |
271 | 273 |
272 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { | 274 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { |
273 return Singleton<ShellWindowRegistry::Factory>::get(); | 275 return Singleton<ShellWindowRegistry::Factory>::get(); |
274 } | 276 } |
275 | 277 |
276 ShellWindowRegistry::Factory::Factory() | 278 ShellWindowRegistry::Factory::Factory() |
277 : BrowserContextKeyedServiceFactory( | 279 : BrowserContextKeyedServiceFactory( |
278 "ShellWindowRegistry", | 280 "ShellWindowRegistry", |
279 BrowserContextDependencyManager::GetInstance()) { | 281 BrowserContextDependencyManager::GetInstance()) { |
280 } | 282 } |
281 | 283 |
282 ShellWindowRegistry::Factory::~Factory() { | 284 ShellWindowRegistry::Factory::~Factory() { |
283 } | 285 } |
284 | 286 |
285 BrowserContextKeyedService* | 287 BrowserContextKeyedService* |
286 ShellWindowRegistry::Factory::BuildServiceInstanceFor( | 288 ShellWindowRegistry::Factory::BuildServiceInstanceFor( |
287 content::BrowserContext* profile) const { | 289 content::BrowserContext* context) const { |
288 return new ShellWindowRegistry(static_cast<Profile*>(profile)); | 290 return new ShellWindowRegistry(context); |
289 } | 291 } |
290 | 292 |
291 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { | 293 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { |
292 return true; | 294 return true; |
293 } | 295 } |
294 | 296 |
295 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { | 297 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { |
296 return false; | 298 return false; |
297 } | 299 } |
298 | 300 |
299 content::BrowserContext* ShellWindowRegistry::Factory::GetBrowserContextToUse( | 301 content::BrowserContext* ShellWindowRegistry::Factory::GetBrowserContextToUse( |
300 content::BrowserContext* context) const { | 302 content::BrowserContext* context) const { |
301 return chrome::GetBrowserContextRedirectedInIncognito(context); | 303 return chrome::GetBrowserContextRedirectedInIncognito(context); |
302 } | 304 } |
303 | 305 |
304 } // namespace extensions | 306 } // namespace extensions |
OLD | NEW |