Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/extensions/shell_window_registry.cc

Issue 11238055: Re-open DevTools windows for PackagedApps if they are reloaded with DevTools open. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: reviewer comments, use MAYBE_ Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/shell_window_registry.h" 5 #include "chrome/browser/extensions/shell_window_registry.h"
6 #include "chrome/browser/profiles/profile_dependency_manager.h" 6 #include "chrome/browser/profiles/profile_dependency_manager.h"
7 #include "chrome/browser/ui/extensions/shell_window.h" 7 #include "chrome/browser/ui/extensions/shell_window.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "content/public/browser/notification_types.h"
9 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 12
13 namespace {
14
15 // Create a key that identifies a ShellWindow in a RenderViewHost across App
16 // reloads. Current format concatenates the extension ID (fixed length string)
17 // a colon separator, and the ShellWindow's |id| (passed to create). If the
18 // RenderViewHost is not for a ShellWindow, or if the window was not created
19 // with an |id|, return an empty string.
20 std::string GetWindowKeyForRenderViewHost(
21 const extensions::ShellWindowRegistry* registry,
22 content::RenderViewHost* render_view_host) {
23 ShellWindow* shell_window =
24 registry->GetShellWindowForRenderViewHost(render_view_host);
25 if (!shell_window)
26 return std::string(); // Not a ShellWindow.
27
28 if (shell_window->window_key().empty())
29 return std::string(); // Not created with an |id| in CreateParams.
30
31 std::string key = shell_window->extension()->id();
32 key += ':';
33 key += shell_window->window_key();
34 return key;
35 }
36
37 }
38
12 namespace extensions { 39 namespace extensions {
13 40
14 ShellWindowRegistry::ShellWindowRegistry() {} 41 ShellWindowRegistry::ShellWindowRegistry(Profile* profile) {
42 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED,
43 content::Source<content::BrowserContext>(profile));
44 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED,
45 content::Source<content::BrowserContext>(profile));
46 }
15 47
16 ShellWindowRegistry::~ShellWindowRegistry() {} 48 ShellWindowRegistry::~ShellWindowRegistry() {}
17 49
18 // static 50 // static
19 ShellWindowRegistry* ShellWindowRegistry::Get(Profile* profile) { 51 ShellWindowRegistry* ShellWindowRegistry::Get(Profile* profile) {
20 return Factory::GetForProfile(profile); 52 return Factory::GetForProfile(profile);
21 } 53 }
22 54
23 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { 55 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) {
24 shell_windows_.insert(shell_window); 56 shell_windows_.insert(shell_window);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 i != shell_windows_.end(); ++i) { 110 i != shell_windows_.end(); ++i) {
79 if ((*i)->extension()->id() == app_id) 111 if ((*i)->extension()->id() == app_id)
80 result = *i; 112 result = *i;
81 if (result->GetBaseWindow()->IsActive()) 113 if (result->GetBaseWindow()->IsActive())
82 return result; 114 return result;
83 } 115 }
84 116
85 return result; 117 return result;
86 } 118 }
87 119
120 bool ShellWindowRegistry::HadDevToolsAttached(
121 content::RenderViewHost* render_view_host) const {
122 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
123 return key.empty() ? false : inspected_windows_.count(key) != 0;
124 }
125
126 void ShellWindowRegistry::Observe(int type,
127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) {
129 content::RenderViewHost* render_view_host =
130 content::Details<content::RenderViewHost>(details).ptr();
131 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
132 if (key.empty())
133 return;
134
135 switch (type) {
136 case content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED:
137 inspected_windows_.insert(key);
138 break;
139 case content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED:
140 inspected_windows_.erase(key);
141 break;
142 default:
143 NOTREACHED();
144 }
145 }
146
88 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
89 // Factory boilerplate 148 // Factory boilerplate
90 149
91 // static 150 // static
92 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForProfile( 151 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForProfile(
93 Profile* profile) { 152 Profile* profile) {
94 return static_cast<ShellWindowRegistry*>( 153 return static_cast<ShellWindowRegistry*>(
95 GetInstance()->GetServiceForProfile(profile, true)); 154 GetInstance()->GetServiceForProfile(profile, true));
96 } 155 }
97 156
98 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { 157 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() {
99 return Singleton<ShellWindowRegistry::Factory>::get(); 158 return Singleton<ShellWindowRegistry::Factory>::get();
100 } 159 }
101 160
102 ShellWindowRegistry::Factory::Factory() 161 ShellWindowRegistry::Factory::Factory()
103 : ProfileKeyedServiceFactory("ShellWindowRegistry", 162 : ProfileKeyedServiceFactory("ShellWindowRegistry",
104 ProfileDependencyManager::GetInstance()) { 163 ProfileDependencyManager::GetInstance()) {
105 } 164 }
106 165
107 ShellWindowRegistry::Factory::~Factory() { 166 ShellWindowRegistry::Factory::~Factory() {
108 } 167 }
109 168
110 ProfileKeyedService* ShellWindowRegistry::Factory::BuildServiceInstanceFor( 169 ProfileKeyedService* ShellWindowRegistry::Factory::BuildServiceInstanceFor(
111 Profile* profile) const { 170 Profile* profile) const {
112 return new ShellWindowRegistry(); 171 return new ShellWindowRegistry(profile);
113 } 172 }
114 173
115 bool ShellWindowRegistry::Factory::ServiceHasOwnInstanceInIncognito() const { 174 bool ShellWindowRegistry::Factory::ServiceHasOwnInstanceInIncognito() const {
116 return true; 175 return true;
117 } 176 }
118 177
119 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithProfile() const { 178 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithProfile() const {
120 return true; 179 return true;
121 } 180 }
122 181
123 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { 182 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const {
124 return false; 183 return false;
125 } 184 }
126 185
127 } // namespace extensions 186 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/shell_window_registry.h ('k') | chrome/test/data/extensions/platform_apps/minimal_id/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698