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..7fc67d49ae3099989e7c881056095a9482bc3b6e 100644 |
| --- a/chrome/browser/ui/views/aura/panel_view_aura.cc |
| +++ b/chrome/browser/ui/views/aura/panel_view_aura.cc |
| @@ -7,6 +7,10 @@ |
| #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_controller.h" |
| +#include "chrome/browser/extensions/extension_window_list.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| @@ -29,21 +33,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 +166,83 @@ void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| web_contents_->GetRenderViewHost()); |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// PanelExtensionWindowController |
| + |
| +class PanelExtensionWindowController : public ExtensionWindowController { |
| + public: |
| + PanelExtensionWindowController(PanelViewAura* panel_view, |
| + PanelHost* panel_host); |
| + |
| + // Overriden from ExtensionWindowController: |
| + virtual const SessionID& GetSessionId() const OVERRIDE; |
| + virtual base::DictionaryValue* CreateWindowValue() const OVERRIDE; |
| + virtual base::DictionaryValue* CreateWindowValueWithTabs() const OVERRIDE; |
| + virtual bool CanClose( |
| + ExtensionWindowController::Reason* reason) const OVERRIDE; |
| + virtual void SetFullscreenMode(bool is_fullscreen, |
| + const GURL& extension_url) const OVERRIDE; |
| + |
| + private: |
| + PanelViewAura* panel_view_; |
| + PanelHost* panel_host_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PanelExtensionWindowController); |
| +}; |
| + |
| +PanelExtensionWindowController::PanelExtensionWindowController( |
| + PanelViewAura* panel_view, |
| + PanelHost* panel_host) |
| + : ExtensionWindowController(panel_view, panel_host->profile()), |
| + panel_view_(panel_view), |
| + panel_host_(panel_host) { |
| +} |
| + |
| +const SessionID& PanelExtensionWindowController::GetSessionId() const { |
| + return panel_view_->session_id(); |
| +} |
| + |
| +namespace keys = extension_tabs_module_constants; |
| + |
| +base::DictionaryValue* |
| +PanelExtensionWindowController::CreateWindowValue() 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); |
| + |
| + return result; |
| +} |
| + |
| +base::DictionaryValue* |
| +PanelExtensionWindowController::CreateWindowValueWithTabs() const { |
| + DictionaryValue* result = CreateWindowValue(); |
| + 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 PanelExtensionWindowController::CanClose( |
| + ExtensionWindowController::Reason* reason) const { |
| + return true; |
| +} |
| + |
| +void PanelExtensionWindowController::SetFullscreenMode( |
| + bool is_fullscreen, const GURL& extension_url) const { |
| +} |
| + |
| } // namespace internal |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -173,6 +255,8 @@ PanelViewAura::PanelViewAura(const std::string& title) |
| } |
| PanelViewAura::~PanelViewAura() { |
| + ExtensionWindowList::GetInstance()->RemoveExtensionWindow( |
|
Mihai Parparita -not on Chrome
2012/02/23 02:35:36
Why not do the registration/deregistration in the
stevenjb
2012/02/23 19:57:51
Good suggestion, I can do that now. (The registrat
|
| + extension_window_controller_.get()); |
| } |
| views::Widget* PanelViewAura::Init(Profile* profile, |
| @@ -201,7 +285,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_controller_.reset( |
| + new internal::PanelExtensionWindowController(this, host_.get())); |
| + ExtensionWindowList::GetInstance()->AddExtensionWindow( |
| + extension_window_controller_.get()); |
| + |
| + // Show the window, but don't activate it by default. |
| + widget_->ShowInactive(); |
| return widget_; |
| } |
| @@ -261,3 +352,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(); |
| +} |