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

Unified Diff: chrome/browser/ui/panels/panel.cc

Issue 10790062: [Panels refactor] Track Panels in TaskManager now that they are not under the tab contents umbrella. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 5 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/ui/panels/panel.cc
diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc
index 90f4ded2cef105fd4aa850791d8110303d52c14d..1f744530260b8e345b851b0e1cdc81b5e67bca7f 100644
--- a/chrome/browser/ui/panels/panel.cc
+++ b/chrome/browser/ui/panels/panel.cc
@@ -31,6 +31,13 @@
using content::RenderViewHost;
using content::UserMetricsAction;
+namespace {
+
+static base::LazyInstance<base::PropertyAccessor<Panel*> >
+ g_panel_property_accessor = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
namespace panel_internal {
class PanelExtensionWindowController : public ExtensionWindowController {
@@ -113,6 +120,17 @@ Panel::~Panel() {
browser::EndKeepAlive();
}
+// static
+base::PropertyAccessor<Panel*>* Panel::property_accessor() {
+ return g_panel_property_accessor.Pointer();
+}
+
+// static
+Panel* Panel::FromWebContents(content::WebContents* contents) {
+ Panel** panel = property_accessor()->GetProperty(contents->GetPropertyBag());
Dmitry Titov 2012/07/18 22:52:15 Seems a loop through PanelManager will be easier t
+ return panel ? *panel : NULL;
+}
+
void Panel::Initialize(const gfx::Rect& bounds, Browser* browser) {
DCHECK(!initialized_);
DCHECK(!panel_strip_); // Cannot be added to a strip until fully created.
@@ -141,7 +159,14 @@ void Panel::Initialize(Profile* profile, const GURL& url,
// Set up hosting for web contents.
panel_host_.reset(new PanelHost(this, profile));
panel_host_->Init(url);
- native_panel_->AttachWebContents(GetWebContents());
+
+ // Stash this panel in the property bag so it can be retrieved without
+ // having to iterate through all panel manager.
+ content::WebContents* contents = GetWebContents();
+ if (contents) {
Dmitry Titov 2012/07/18 22:52:15 can it be NULL? When?
+ property_accessor()->SetProperty(contents->GetPropertyBag(), this);
+ native_panel_->AttachWebContents(contents);
+ }
// Close when the extension is unloaded or the browser is exiting.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,

Powered by Google App Engine
This is Rietveld 408576698