Chromium Code Reviews| 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, |