Chromium Code Reviews| Index: chrome/browser/ui/views/aura/panel_view_aura.cc |
| diff --git a/chrome/browser/ui/views/aura/panel_view_aura.cc b/chrome/browser/ui/views/aura/panel_view_aura.cc |
| index 9b058dd02a4e7437d64e208eea9ea9239c5bd2e4..57682946a466d69b8019119f449afa31494e6864 100644 |
| --- a/chrome/browser/ui/views/aura/panel_view_aura.cc |
| +++ b/chrome/browser/ui/views/aura/panel_view_aura.cc |
| @@ -7,6 +7,9 @@ |
| #include "ash/wm/panel_frame_view.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| +#include "chrome/browser/extensions/extension_tab_util.h" |
| +#include "chrome/browser/extensions/extension_tabs_module_constants.h" |
| +#include "chrome/browser/extensions/extension_window_wrapper.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| @@ -29,21 +32,22 @@ const int kDefaultWidth = 200; |
| const int kDefaultHeight = 300; |
| } |
| +namespace internal { |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // PanelHost |
| -namespace internal { |
| - |
| class PanelHost : public content::WebContentsDelegate, |
| public content::WebContentsObserver, |
| public ExtensionFunctionDispatcher::Delegate { |
| public: |
| - explicit PanelHost(PanelViewAura* panel_view, Profile* profile); |
| + PanelHost(PanelViewAura* panel_view, Profile* profile); |
| virtual ~PanelHost(); |
| void Init(const GURL& url); |
| content::WebContents* web_contents() const { return web_contents_.get(); } |
| + Profile* profile() const { return profile_; } |
| // ExtensionFunctionDispatcher::Delegate overrides. |
| virtual Browser* GetBrowser() OVERRIDE; |
| @@ -161,6 +165,71 @@ void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| web_contents_->GetRenderViewHost()); |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// PanelExtensionWindowWrapper |
| + |
| +class PanelExtensionWindowWrapper : public ExtensionWindowWrapper { |
| + public: |
| + PanelExtensionWindowWrapper(PanelViewAura* panel_view, PanelHost* panel_host); |
| + |
| + // Overriden from ExtensionWindowWrapper: |
| + virtual const SessionID& GetSessionId() const OVERRIDE; |
| + virtual base::DictionaryValue* CreateWindowValue( |
| + bool populate_tabs) const OVERRIDE; |
| + virtual bool CanClose(ExtensionWindowWrapper::Reason* reason) const OVERRIDE; |
| + |
| + private: |
| + PanelViewAura* panel_view_; |
| + PanelHost* panel_host_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PanelExtensionWindowWrapper); |
| +}; |
| + |
| +PanelExtensionWindowWrapper::PanelExtensionWindowWrapper( |
| + PanelViewAura* panel_view, PanelHost* panel_host) : |
|
sky
2012/02/22 21:46:25
: on next line.
stevenjb
2012/02/23 02:19:15
Done.
|
| + ExtensionWindowWrapper(panel_view, panel_host->profile()), |
| + panel_view_(panel_view), |
| + panel_host_(panel_host) { |
| +} |
| + |
| +const SessionID& PanelExtensionWindowWrapper::GetSessionId() const { |
| + return panel_view_->session_id(); |
| +} |
| + |
| +namespace keys = extension_tabs_module_constants; |
| + |
| +base::DictionaryValue* PanelExtensionWindowWrapper::CreateWindowValue( |
| + bool populate_tabs) const { |
| + DictionaryValue* result = new DictionaryValue(); |
| + result->SetInteger(keys::kIdKey, panel_view_->session_id().id()); |
| + result->SetBoolean(keys::kIncognitoKey, |
| + panel_host_->profile()->IsOffTheRecord()); |
| + result->SetBoolean(keys::kFocusedKey, false); |
| + |
| + gfx::Rect bounds = panel_view_->GetWidget()->GetRestoredBounds(); |
| + |
| + result->SetInteger(keys::kLeftKey, bounds.x()); |
| + result->SetInteger(keys::kTopKey, bounds.y()); |
| + result->SetInteger(keys::kWidthKey, bounds.width()); |
| + result->SetInteger(keys::kHeightKey, bounds.height()); |
| + result->SetString(keys::kWindowTypeKey, keys::kWindowTypeValuePanel); |
| + result->SetString(keys::kShowStateKey, keys::kShowStateValueNormal); |
| + |
| + if (populate_tabs) { |
| + ListValue* tab_list = new ListValue(); |
| + tab_list->Append(ExtensionTabUtil::CreateTabValue( |
| + panel_host_->web_contents(), NULL, 0)); |
| + result->Set(keys::kTabsKey, tab_list); |
| + } |
| + |
| + return result; |
| +} |
| + |
| +bool PanelExtensionWindowWrapper::CanClose( |
| + ExtensionWindowWrapper::Reason* reason) const { |
| + return true; |
| +} |
| + |
| } // namespace internal |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -173,6 +242,8 @@ PanelViewAura::PanelViewAura(const std::string& title) |
| } |
| PanelViewAura::~PanelViewAura() { |
| + ExtensionWindowWrapperList::GetInstance()->RemoveExtensionWindow( |
| + extension_window_wrapper_.get()); |
| } |
| views::Widget* PanelViewAura::Init(Profile* profile, |
| @@ -201,7 +272,14 @@ views::Widget* PanelViewAura::Init(Profile* profile, |
| Attach(host_->web_contents()->GetNativeView()); |
| - widget_->Show(); |
| + // Add the browser to the list of windows available to the extension API. |
| + extension_window_wrapper_.reset( |
| + new internal::PanelExtensionWindowWrapper(this, host_.get())); |
| + ExtensionWindowWrapperList::GetInstance()->AddExtensionWindow( |
| + extension_window_wrapper_.get()); |
| + |
| + // Show the window, but don't activate it by default. |
| + widget_->ShowInactive(); |
| return widget_; |
| } |
| @@ -261,3 +339,68 @@ const views::Widget* PanelViewAura::GetWidget() const { |
| views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { |
| return new ash::PanelFrameView(); |
| } |
| + |
| +// BaseWindow implementation: |
| + |
| +bool PanelViewAura::IsActive() const { |
| + return GetWidget()->IsActive(); |
| +} |
| + |
| +bool PanelViewAura::IsMaximized() const { |
| + return GetWidget()->IsMaximized(); |
| +} |
| + |
| +bool PanelViewAura::IsMinimized() const { |
| + return GetWidget()->IsMinimized(); |
| +} |
| + |
| +gfx::Rect PanelViewAura::GetRestoredBounds() const { |
| + return GetWidget()->GetRestoredBounds(); |
| +} |
| + |
| +gfx::Rect PanelViewAura::GetBounds() const { |
| + return GetWidget()->GetWindowScreenBounds(); |
| +} |
| + |
| +void PanelViewAura::Show() { |
| + GetWidget()->Show(); |
| +} |
| + |
| +void PanelViewAura::ShowInactive() { |
| + GetWidget()->ShowInactive(); |
| +} |
| + |
| +void PanelViewAura::Close() { |
| + GetWidget()->Close(); |
| +} |
| + |
| +void PanelViewAura::Activate() { |
| + GetWidget()->Activate(); |
| +} |
| + |
| +void PanelViewAura::Deactivate() { |
| + GetWidget()->Deactivate(); |
| +} |
| + |
| +void PanelViewAura::Maximize() { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void PanelViewAura::Minimize() { |
| + // TODO(stevenjb): Implement |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void PanelViewAura::Restore() { |
| + // TODO(stevenjb): Implement |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void PanelViewAura::SetBounds(const gfx::Rect& bounds) { |
| + GetWidget()->SetBounds(bounds); |
| +} |
| + |
| +void PanelViewAura::FlashFrame(bool flash) { |
| + // TODO(stevenjb): Implement |
| + NOTIMPLEMENTED(); |
| +} |