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

Unified 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: before unit test 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/shell_window_registry.cc
diff --git a/chrome/browser/extensions/shell_window_registry.cc b/chrome/browser/extensions/shell_window_registry.cc
index a25bd3d3a00c4a6e0203ec60875118dcc1e10848..46f6e4a27962a8785ab6d92c0f12d16e05be64f0 100644
--- a/chrome/browser/extensions/shell_window_registry.cc
+++ b/chrome/browser/extensions/shell_window_registry.cc
@@ -6,12 +6,35 @@
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
+namespace {
benwells 2012/10/23 06:18:48 Nit: blank line after namespace
tapted 2012/10/23 07:04:23 Done.
+std::string GetWindowKeyForRenderViewHost(
+ const extensions::ShellWindowRegistry* registry,
+ content::RenderViewHost* render_view_host) {
+ ShellWindow* shell_window =
+ registry->GetShellWindowForRenderViewHost(render_view_host);
+ if (!shell_window)
+ return std::string(); // Not a ShellWindow.
benwells 2012/10/23 06:18:48 Blank line after early return.
tapted 2012/10/23 07:04:23 Done.
+ if (shell_window->window_key().empty())
+ return std::string(); // Not created with an |id| in CreateParams.
+
+ std::string key = shell_window->extension()->id();
benwells 2012/10/23 06:18:48 Please put a comment in describing the key format.
tapted 2012/10/23 07:04:23 Done.
+ key += shell_window->window_key();
+ return key;
+}
benwells 2012/10/23 06:18:48 Nit: blank line between }'s
tapted 2012/10/23 07:04:23 Done.
+}
+
namespace extensions {
-ShellWindowRegistry::ShellWindowRegistry() {}
+ShellWindowRegistry::ShellWindowRegistry(Profile* profile) {
+ registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED,
+ content::Source<content::BrowserContext>(profile));
+ registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED,
+ content::Source<content::BrowserContext>(profile));
+}
ShellWindowRegistry::~ShellWindowRegistry() {}
@@ -85,6 +108,28 @@ ShellWindow* ShellWindowRegistry::GetCurrentShellWindowForApp(
return result;
}
+bool ShellWindowRegistry::HadDevToolsAttached(
+ content::RenderViewHost* render_view_host) const {
+ std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
+ return key.empty() ? false : inspected_windows_.count(key);
+}
+
+void ShellWindowRegistry::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ content::RenderViewHost* render_view_host =
+ content::Details<content::RenderViewHost>(details).ptr();
+ std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
+ if (key.empty())
+ return;
+
+ if (type == content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED) {
benwells 2012/10/23 06:18:48 Use switch here and put NOT_REACHED for default ca
tapted 2012/10/23 07:04:23 Done.
+ inspected_windows_.insert(key);
+ } else if (type == content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED) {
+ inspected_windows_.erase(key);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
// Factory boilerplate
@@ -109,7 +154,7 @@ ShellWindowRegistry::Factory::~Factory() {
ProfileKeyedService* ShellWindowRegistry::Factory::BuildServiceInstanceFor(
Profile* profile) const {
- return new ShellWindowRegistry();
+ return new ShellWindowRegistry(profile);
}
bool ShellWindowRegistry::Factory::ServiceHasOwnInstanceInIncognito() const {

Powered by Google App Engine
This is Rietveld 408576698