Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ui/panels/panel.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 30 | 30 |
| 31 using content::RenderViewHost; | 31 using content::RenderViewHost; |
| 32 using content::UserMetricsAction; | 32 using content::UserMetricsAction; |
| 33 | 33 |
| 34 namespace { | |
| 35 | |
| 36 static base::LazyInstance<base::PropertyAccessor<Panel*> > | |
| 37 g_panel_property_accessor = LAZY_INSTANCE_INITIALIZER; | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 34 namespace panel_internal { | 41 namespace panel_internal { |
| 35 | 42 |
| 36 class PanelExtensionWindowController : public ExtensionWindowController { | 43 class PanelExtensionWindowController : public ExtensionWindowController { |
| 37 public: | 44 public: |
| 38 PanelExtensionWindowController(Panel* panel, Profile* profile); | 45 PanelExtensionWindowController(Panel* panel, Profile* profile); |
| 39 | 46 |
| 40 // Overridden from ExtensionWindowController. | 47 // Overridden from ExtensionWindowController. |
| 41 virtual int GetWindowId() const OVERRIDE; | 48 virtual int GetWindowId() const OVERRIDE; |
| 42 virtual std::string GetWindowTypeText() const OVERRIDE; | 49 virtual std::string GetWindowTypeText() const OVERRIDE; |
| 43 virtual base::DictionaryValue* CreateWindowValueWithTabs() const OVERRIDE; | 50 virtual base::DictionaryValue* CreateWindowValueWithTabs() const OVERRIDE; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 113 |
| 107 Panel::~Panel() { | 114 Panel::~Panel() { |
| 108 // Invoked by native panel destructor. Do not access native_panel_ here. | 115 // Invoked by native panel destructor. Do not access native_panel_ here. |
| 109 | 116 |
| 110 // Remove shutdown prevention. | 117 // Remove shutdown prevention. |
| 111 // TODO(jennb): remove guard after refactor | 118 // TODO(jennb): remove guard after refactor |
| 112 if (extension_window_controller_.get()) | 119 if (extension_window_controller_.get()) |
| 113 browser::EndKeepAlive(); | 120 browser::EndKeepAlive(); |
| 114 } | 121 } |
| 115 | 122 |
| 123 // static | |
| 124 base::PropertyAccessor<Panel*>* Panel::property_accessor() { | |
| 125 return g_panel_property_accessor.Pointer(); | |
| 126 } | |
| 127 | |
| 128 // static | |
| 129 Panel* Panel::FromWebContents(content::WebContents* contents) { | |
| 130 Panel** panel = property_accessor()->GetProperty(contents->GetPropertyBag()); | |
|
Dmitry Titov
2012/07/18 22:52:15
Seems a loop through PanelManager will be easier t
| |
| 131 return panel ? *panel : NULL; | |
| 132 } | |
| 133 | |
| 116 void Panel::Initialize(const gfx::Rect& bounds, Browser* browser) { | 134 void Panel::Initialize(const gfx::Rect& bounds, Browser* browser) { |
| 117 DCHECK(!initialized_); | 135 DCHECK(!initialized_); |
| 118 DCHECK(!panel_strip_); // Cannot be added to a strip until fully created. | 136 DCHECK(!panel_strip_); // Cannot be added to a strip until fully created. |
| 119 DCHECK_EQ(EXPANDED, expansion_state_); | 137 DCHECK_EQ(EXPANDED, expansion_state_); |
| 120 DCHECK(!bounds.IsEmpty()); | 138 DCHECK(!bounds.IsEmpty()); |
| 121 initialized_ = true; | 139 initialized_ = true; |
| 122 full_size_ = bounds.size(); | 140 full_size_ = bounds.size(); |
| 123 native_panel_ = CreateNativePanel(browser, this, bounds); | 141 native_panel_ = CreateNativePanel(browser, this, bounds); |
| 124 } | 142 } |
| 125 | 143 |
| 126 void Panel::Initialize(Profile* profile, const GURL& url, | 144 void Panel::Initialize(Profile* profile, const GURL& url, |
| 127 const gfx::Rect& bounds) { | 145 const gfx::Rect& bounds) { |
| 128 DCHECK(!initialized_); | 146 DCHECK(!initialized_); |
| 129 DCHECK(!panel_strip_); // Cannot be added to a strip until fully created. | 147 DCHECK(!panel_strip_); // Cannot be added to a strip until fully created. |
| 130 DCHECK_EQ(EXPANDED, expansion_state_); | 148 DCHECK_EQ(EXPANDED, expansion_state_); |
| 131 DCHECK(!bounds.IsEmpty()); | 149 DCHECK(!bounds.IsEmpty()); |
| 132 initialized_ = true; | 150 initialized_ = true; |
| 133 full_size_ = bounds.size(); | 151 full_size_ = bounds.size(); |
| 134 native_panel_ = CreateNativePanel(this, bounds); | 152 native_panel_ = CreateNativePanel(this, bounds); |
| 135 | 153 |
| 136 extension_window_controller_.reset( | 154 extension_window_controller_.reset( |
| 137 new panel_internal::PanelExtensionWindowController(this, profile)); | 155 new panel_internal::PanelExtensionWindowController(this, profile)); |
| 138 | 156 |
| 139 InitCommandState(); | 157 InitCommandState(); |
| 140 | 158 |
| 141 // Set up hosting for web contents. | 159 // Set up hosting for web contents. |
| 142 panel_host_.reset(new PanelHost(this, profile)); | 160 panel_host_.reset(new PanelHost(this, profile)); |
| 143 panel_host_->Init(url); | 161 panel_host_->Init(url); |
| 144 native_panel_->AttachWebContents(GetWebContents()); | 162 |
| 163 // Stash this panel in the property bag so it can be retrieved without | |
| 164 // having to iterate through all panel manager. | |
| 165 content::WebContents* contents = GetWebContents(); | |
| 166 if (contents) { | |
|
Dmitry Titov
2012/07/18 22:52:15
can it be NULL? When?
| |
| 167 property_accessor()->SetProperty(contents->GetPropertyBag(), this); | |
| 168 native_panel_->AttachWebContents(contents); | |
| 169 } | |
| 145 | 170 |
| 146 // Close when the extension is unloaded or the browser is exiting. | 171 // Close when the extension is unloaded or the browser is exiting. |
| 147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 172 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 148 content::Source<Profile>(profile)); | 173 content::Source<Profile>(profile)); |
| 149 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 174 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 150 content::NotificationService::AllSources()); | 175 content::NotificationService::AllSources()); |
| 151 | 176 |
| 152 // Prevent the browser process from shutting down while this window is open. | 177 // Prevent the browser process from shutting down while this window is open. |
| 153 browser::StartKeepAlive(); | 178 browser::StartKeepAlive(); |
| 154 } | 179 } |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 | 743 |
| 719 void Panel::UpdateTitleBar() { | 744 void Panel::UpdateTitleBar() { |
| 720 native_panel_->UpdatePanelTitleBar(); | 745 native_panel_->UpdatePanelTitleBar(); |
| 721 } | 746 } |
| 722 | 747 |
| 723 void Panel::LoadingStateChanged(bool is_loading) { | 748 void Panel::LoadingStateChanged(bool is_loading) { |
| 724 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 749 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 725 native_panel_->UpdatePanelLoadingAnimations(is_loading); | 750 native_panel_->UpdatePanelLoadingAnimations(is_loading); |
| 726 UpdateTitleBar(); | 751 UpdateTitleBar(); |
| 727 } | 752 } |
| OLD | NEW |