summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 19:32:51 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 19:32:51 +0000
commitbafda13fc1c1f1a28ef15fd8703370dda0d1a5f3 (patch)
tree8a76684a0383ff568d3269b0d53ae32097a13356 /chrome/browser/ui
parent9032a08cf5482654c03d283f46bd21886e1b3e96 (diff)
downloadchromium_src-bafda13fc1c1f1a28ef15fd8703370dda0d1a5f3.zip
chromium_src-bafda13fc1c1f1a28ef15fd8703370dda0d1a5f3.tar.gz
chromium_src-bafda13fc1c1f1a28ef15fd8703370dda0d1a5f3.tar.bz2
Launch panels in Aura (through chrome.windows.create()) with a new panel view.
BUG=112198 TEST=Run an aura build with --aura-panels. Use an extension to open a panel with chrome.windows.create (e.g. see extension attached to issue, comment #38). Panel should open as a new Aura panel. Review URL: http://codereview.chromium.org/9392019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser.cc31
-rw-r--r--chrome/browser/ui/browser.h8
-rw-r--r--chrome/browser/ui/views/aura/panel_view_aura.cc263
-rw-r--r--chrome/browser/ui/views/aura/panel_view_aura.h77
4 files changed, 378 insertions, 1 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 7afd5e5..e5b7a3a 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -207,7 +207,9 @@
#endif
#if defined(USE_AURA)
+#include "ash/ash_switches.h"
#include "ash/shell.h"
+#include "chrome/browser/ui/views/aura/panel_view_aura.h"
#endif
#if !defined(OS_CHROMEOS) || defined(USE_AURA)
@@ -698,8 +700,17 @@ WebContents* Browser::OpenApplication(
tab = shell_window->web_contents();
break;
}
- case extension_misc::LAUNCH_WINDOW:
case extension_misc::LAUNCH_PANEL:
+#if defined(USE_AURA)
+ if (extension &&
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAuraPanelManager)) {
+ tab = OpenApplicationPanel(profile, extension, override_url);
+ break;
+ }
+ // else fall through to LAUNCH_WINDOW
+#endif
+ case extension_misc::LAUNCH_WINDOW:
tab = Browser::OpenApplicationWindow(profile, extension, container,
override_url, NULL);
break;
@@ -715,6 +726,24 @@ WebContents* Browser::OpenApplication(
return tab;
}
+#if defined(USE_AURA)
+// static
+WebContents* Browser::OpenApplicationPanel(
+ Profile* profile,
+ const Extension* extension,
+ const GURL& url_input) {
+ GURL url = UrlForExtension(extension, url_input);
+ std::string app_name =
+ web_app::GenerateApplicationNameFromExtensionId(extension->id());
+ gfx::Rect panel_bounds;
+ panel_bounds.set_width(extension->launch_width());
+ panel_bounds.set_height(extension->launch_height());
+ PanelViewAura* panel_view = new PanelViewAura(app_name);
+ panel_view->Init(profile, url, panel_bounds);
+ return panel_view->WebContents();
+}
+#endif
+
// static
WebContents* Browser::OpenApplicationWindow(
Profile* profile,
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index d4a975c..96bd1ee 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -277,6 +277,14 @@ class Browser : public TabHandlerDelegate,
const GURL& override_url,
WindowOpenDisposition disposition);
+#if defined(USE_AURA)
+ // Opens |url| in a new application panel window for the specified url.
+ static content::WebContents* OpenApplicationPanel(
+ Profile* profile,
+ const Extension* extension,
+ const GURL& url);
+#endif
+
// Opens a new application window for the specified url. If |as_panel|
// is true, the application will be opened as a Browser::Type::APP_PANEL in
// app panel window, otherwise it will be opened as as either
diff --git a/chrome/browser/ui/views/aura/panel_view_aura.cc b/chrome/browser/ui/views/aura/panel_view_aura.cc
new file mode 100644
index 0000000..9b058dd
--- /dev/null
+++ b/chrome/browser/ui/views/aura/panel_view_aura.cc
@@ -0,0 +1,263 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/aura/panel_view_aura.h"
+
+#include "ash/wm/panel_frame_view.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/common/chrome_view_type.h"
+#include "chrome/common/extensions/extension_messages.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "googleurl/src/gurl.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_macros.h"
+#include "ui/aura/window.h"
+#include "ui/views/widget/widget.h"
+
+namespace {
+const int kMinWidth = 100;
+const int kMinHeight = 100;
+const int kDefaultWidth = 200;
+const int kDefaultHeight = 300;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PanelHost
+
+namespace internal {
+
+class PanelHost : public content::WebContentsDelegate,
+ public content::WebContentsObserver,
+ public ExtensionFunctionDispatcher::Delegate {
+ public:
+ explicit PanelHost(PanelViewAura* panel_view, Profile* profile);
+ virtual ~PanelHost();
+
+ void Init(const GURL& url);
+
+ content::WebContents* web_contents() const { return web_contents_.get(); }
+
+ // ExtensionFunctionDispatcher::Delegate overrides.
+ virtual Browser* GetBrowser() OVERRIDE;
+ virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
+
+ // content::WebContentsDelegate implementation:
+ virtual void CloseContents(content::WebContents* source) OVERRIDE;
+ virtual void HandleMouseDown() OVERRIDE;
+ virtual void UpdatePreferredSize(content::WebContents* source,
+ const gfx::Size& pref_size) OVERRIDE;
+ virtual void AddNewContents(content::WebContents* source,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture) OVERRIDE;
+
+ // content::WebContentsObserver implementation:
+ virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
+ virtual void RenderViewReady() OVERRIDE;
+ virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ protected:
+ // Message handlers
+ void OnRequest(const ExtensionHostMsg_Request_Params& params);
+
+ private:
+ PanelViewAura* panel_view_;
+ Profile* profile_;
+ ExtensionFunctionDispatcher extension_function_dispatcher_;
+ scoped_ptr<content::WebContents> web_contents_;
+ // Site instance to be used for opening new links.
+ scoped_refptr<content::SiteInstance> site_instance_;
+};
+
+PanelHost::PanelHost(PanelViewAura* panel_view, Profile* profile)
+ : panel_view_(panel_view),
+ profile_(profile),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ extension_function_dispatcher_(profile, this)) {
+}
+
+PanelHost::~PanelHost() {
+}
+
+void PanelHost::Init(const GURL& url) {
+ site_instance_ = content::SiteInstance::CreateForURL(profile_, url);
+
+ web_contents_.reset(content::WebContents::Create(
+ profile_, site_instance_.get(), MSG_ROUTING_NONE, NULL, NULL));
+ web_contents_->SetViewType(chrome::VIEW_TYPE_PANEL);
+ web_contents_->SetDelegate(this);
+ Observe(web_contents_.get());
+
+ web_contents_->GetController().LoadURL(
+ url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
+}
+
+Browser* PanelHost::GetBrowser() {
+ return NULL;
+}
+
+content::WebContents* PanelHost::GetAssociatedWebContents() const {
+ return web_contents_.get();
+}
+
+void PanelHost::CloseContents(content::WebContents* source) {
+ panel_view_->CloseView();
+}
+
+void PanelHost::HandleMouseDown() {
+}
+
+void PanelHost::UpdatePreferredSize(content::WebContents* source,
+ const gfx::Size& pref_size) {
+ panel_view_->SetContentPreferredSize(pref_size);
+}
+
+// This handles launching a new page from within the panel.
+// TODO(stevenjb): Determine whether or not this is the desired/expected
+// behavior for panels.
+void PanelHost::AddNewContents(content::WebContents* source,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture) {
+ Browser* browser = BrowserList::GetLastActiveWithProfile(
+ Profile::FromBrowserContext(new_contents->GetBrowserContext()));
+ if (!browser)
+ return;
+ browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture);
+}
+
+void PanelHost::RenderViewCreated(RenderViewHost* render_view_host) {
+}
+
+void PanelHost::RenderViewReady() {
+}
+
+void PanelHost::RenderViewGone(base::TerminationStatus status) {
+ CloseContents(web_contents_.get());
+}
+
+bool PanelHost::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PanelHost, message)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
+ extension_function_dispatcher_.Dispatch(params,
+ web_contents_->GetRenderViewHost());
+}
+
+} // namespace internal
+
+////////////////////////////////////////////////////////////////////////////////
+// PanelViewAura
+
+PanelViewAura::PanelViewAura(const std::string& title)
+ : title_(title),
+ preferred_size_(kMinWidth, kMinHeight),
+ widget_(NULL) {
+}
+
+PanelViewAura::~PanelViewAura() {
+}
+
+views::Widget* PanelViewAura::Init(Profile* profile,
+ const GURL& url,
+ const gfx::Rect& bounds) {
+ widget_ = new views::Widget;
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL);
+ params.delegate = this;
+
+ params.bounds = bounds;
+ if (params.bounds.width() == 0)
+ params.bounds.set_width(kDefaultWidth);
+ else if (params.bounds.width() < kMinWidth)
+ params.bounds.set_width(kMinWidth);
+
+ if (params.bounds.height() == 0)
+ params.bounds.set_height(kDefaultHeight);
+ else if (params.bounds.height() < kMinHeight)
+ params.bounds.set_height(kMinHeight);
+
+ widget_->Init(params);
+ widget_->GetNativeView()->SetName(title_);
+
+ host_.reset(new internal::PanelHost(this, profile));
+ host_->Init(url);
+
+ Attach(host_->web_contents()->GetNativeView());
+
+ widget_->Show();
+
+ return widget_;
+}
+
+content::WebContents* PanelViewAura::WebContents() {
+ return host_->web_contents();
+}
+
+void PanelViewAura::CloseView() {
+ widget_->CloseNow();
+}
+
+void PanelViewAura::SetContentPreferredSize(const gfx::Size& size) {
+ if (size.width() > kMinWidth)
+ preferred_size_.set_width(size.width());
+ if (size.height() > kMinHeight)
+ preferred_size_.set_height(size.height());
+}
+
+// views::View implementation:
+
+gfx::Size PanelViewAura::GetPreferredSize() {
+ return preferred_size_;
+}
+
+// views::WidgetDelegate implementation:
+
+bool PanelViewAura::CanResize() const {
+ // TODO(stevenjb): Can/should panels be able to prevent resizing?
+ return true;
+}
+
+string16 PanelViewAura::GetWindowTitle() const {
+ return UTF8ToUTF16(title_);
+}
+
+views::View* PanelViewAura::GetContentsView() {
+ return this;
+}
+
+views::View* PanelViewAura::GetInitiallyFocusedView() {
+ return this;
+}
+
+bool PanelViewAura::ShouldShowWindowTitle() const {
+ return true;
+}
+
+views::Widget* PanelViewAura::GetWidget() {
+ return View::GetWidget();
+}
+
+const views::Widget* PanelViewAura::GetWidget() const {
+ return View::GetWidget();
+}
+
+views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() {
+ return new ash::PanelFrameView();
+}
diff --git a/chrome/browser/ui/views/aura/panel_view_aura.h b/chrome/browser/ui/views/aura/panel_view_aura.h
new file mode 100644
index 0000000..66d2191
--- /dev/null
+++ b/chrome/browser/ui/views/aura/panel_view_aura.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_AURA_PANEL_VIEW_AURA_H_
+#define CHROME_BROWSER_UI_VIEWS_AURA_PANEL_VIEW_AURA_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "ui/gfx/size.h"
+#include "ui/views/controls/native/native_view_host.h"
+#include "ui/views/widget/widget_delegate.h"
+
+class GURL;
+class Profile;
+
+namespace content {
+class WebContents;
+}
+
+namespace views {
+class Widget;
+}
+
+namespace internal {
+class PanelHost;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// PanelViewAura is used to display HTML in a Panel window.
+//
+class PanelViewAura : public views::NativeViewHost,
+ public views::WidgetDelegate {
+ public:
+ explicit PanelViewAura(const std::string& title);
+ virtual ~PanelViewAura();
+
+ views::Widget* Init(Profile* profile,
+ const GURL& url,
+ const gfx::Rect& bounds);
+
+ // Returns the WebContents associated with this panel.
+ content::WebContents* WebContents();
+
+ // Close the panel window.
+ void CloseView();
+
+ // Set the preferred size of the contents.
+ void SetContentPreferredSize(const gfx::Size& size);
+
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+
+ // Overridden from views::WidgetDelegate:
+ virtual bool CanResize() const OVERRIDE;
+ virtual string16 GetWindowTitle() const OVERRIDE;
+ virtual views::View* GetContentsView() OVERRIDE;
+ virtual views::View* GetInitiallyFocusedView() OVERRIDE;
+ virtual bool ShouldShowWindowTitle() const OVERRIDE;
+ virtual views::Widget* GetWidget() OVERRIDE;
+ virtual const views::Widget* GetWidget() const OVERRIDE;
+ virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
+
+ private:
+ std::string title_;
+ gfx::Size preferred_size_;
+ // Owned internal host class implementing WebContents and Extension Delegates.
+ scoped_ptr<internal::PanelHost> host_;
+ // Unowned pointer to the widget.
+ views::Widget* widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(PanelViewAura);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_AURA_PANEL_VIEW_AURA_H_