summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/apps.gypi4
-rw-r--r--apps/shell/browser/shell_browser_main_parts.cc85
-rw-r--r--apps/shell/browser/shell_browser_main_parts.h27
-rw-r--r--apps/shell/browser/shell_desktop_controller.cc121
-rw-r--r--apps/shell/browser/shell_desktop_controller.h74
-rw-r--r--apps/shell/browser/web_view_window.cc88
-rw-r--r--apps/shell/browser/web_view_window.h28
-rw-r--r--ui/display/chromeos/output_configurator.cc2
8 files changed, 209 insertions, 220 deletions
diff --git a/apps/apps.gypi b/apps/apps.gypi
index ddbec1b..521bb5a 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -189,6 +189,8 @@
'shell/browser/shell_browser_main_parts.h',
'shell/browser/shell_content_browser_client.cc',
'shell/browser/shell_content_browser_client.h',
+ 'shell/browser/shell_desktop_controller.cc',
+ 'shell/browser/shell_desktop_controller.h',
'shell/browser/shell_extension_system.cc',
'shell/browser/shell_extension_system.h',
'shell/browser/shell_extension_system_factory.cc',
@@ -197,8 +199,6 @@
'shell/browser/shell_extension_web_contents_observer.h',
'shell/browser/shell_extensions_browser_client.cc',
'shell/browser/shell_extensions_browser_client.h',
- 'shell/browser/web_view_window.cc',
- 'shell/browser/web_view_window.cc',
'shell/common/shell_content_client.cc',
'shell/common/shell_content_client.h',
'shell/common/shell_extensions_client.cc',
diff --git a/apps/shell/browser/shell_browser_main_parts.cc b/apps/shell/browser/shell_browser_main_parts.cc
index fefaf0c..2700cb4 100644
--- a/apps/shell/browser/shell_browser_main_parts.cc
+++ b/apps/shell/browser/shell_browser_main_parts.cc
@@ -7,10 +7,10 @@
#include "apps/browser_context_keyed_service_factories.h"
#include "apps/shell/browser/shell_apps_client.h"
#include "apps/shell/browser/shell_browser_context.h"
+#include "apps/shell/browser/shell_desktop_controller.h"
#include "apps/shell/browser/shell_extension_system.h"
#include "apps/shell/browser/shell_extension_system_factory.h"
#include "apps/shell/browser/shell_extensions_browser_client.h"
-#include "apps/shell/browser/web_view_window.h"
#include "apps/shell/common/shell_extensions_client.h"
#include "base/command_line.h"
#include "base/file_util.h"
@@ -22,17 +22,9 @@
#include "content/shell/browser/shell_net_log.h"
#include "extensions/browser/browser_context_keyed_service_factories.h"
#include "extensions/browser/extension_system.h"
-#include "ui/aura/env.h"
-#include "ui/aura/test/test_screen.h"
-#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
-#include "ui/base/ime/input_method_initializer.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/screen.h"
-#include "ui/views/test/test_views_delegate.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
-#include "ui/wm/test/wm_test_helper.h"
using content::BrowserContext;
using extensions::Extension;
@@ -49,27 +41,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::ShellExtensionSystemFactory::GetInstance();
}
-// A ViewsDelegate to attach new unparented windows to app_shell's root window.
-class ShellViewsDelegate : public views::TestViewsDelegate {
- public:
- explicit ShellViewsDelegate(aura::Window* root_window)
- : root_window_(root_window) {}
- virtual ~ShellViewsDelegate() {}
-
- // views::ViewsDelegate implementation.
- virtual void OnBeforeWidgetInit(
- views::Widget::InitParams* params,
- views::internal::NativeWidgetDelegate* delegate) OVERRIDE {
- if (!params->parent)
- params->parent = root_window_;
- }
-
- private:
- aura::Window* root_window_;
-
- DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
-};
-
} // namespace
namespace apps {
@@ -99,10 +70,11 @@ int ShellBrowserMainParts::PreCreateThreads() {
}
void ShellBrowserMainParts::PreMainMessageLoopRun() {
- // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc
+ desktop_controller_.reset(new ShellDesktopController);
+ desktop_controller_->GetWindowTreeHost()->AddObserver(this);
+ // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc
// TODO(jamescook): Initialize chromeos::UserManager.
-
net_log_.reset(new content::ShellNetLog("app_shell"));
// Initialize our "profile" equivalent.
@@ -139,9 +111,6 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
return;
}
- CreateRootWindow();
- CreateViewsDelegate();
-
const std::string kAppSwitch = "app";
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(kAppSwitch)) {
@@ -149,11 +118,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir);
extension_system_->LoadAndLaunchApp(app_absolute_dir);
} else {
- // TODO(jamescook): For demo purposes create a window with a WebView just
- // to ensure that the content module is properly initialized.
- webview_window_.reset(CreateWebViewWindow(browser_context_.get(),
- wm_test_helper_->host()->window()));
- webview_window_->Show();
+ LOG(ERROR) << "--" << kAppSwitch << " unset; boredom is in your future";
}
}
@@ -165,15 +130,15 @@ bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
}
void ShellBrowserMainParts::PostMainMessageLoopRun() {
- DestroyViewsDelegate();
- DestroyRootWindow();
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
browser_context_.get());
extension_system_ = NULL;
extensions::ExtensionsBrowserClient::Set(NULL);
extensions_browser_client_.reset();
browser_context_.reset();
- aura::Env::DeleteInstance();
+
+ desktop_controller_->GetWindowTreeHost()->RemoveObserver(this);
+ desktop_controller_.reset();
}
void ShellBrowserMainParts::OnHostCloseRequested(
@@ -183,40 +148,6 @@ void ShellBrowserMainParts::OnHostCloseRequested(
base::MessageLoop::QuitClosure());
}
-void ShellBrowserMainParts::CreateRootWindow() {
- test_screen_.reset(aura::TestScreen::Create());
- // TODO(jamescook): Replace this with a real Screen implementation.
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
- // TODO(jamescook): Initialize a real input method.
- ui::InitializeInputMethodForTesting();
- // Set up basic pieces of views::corewm.
- wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600)));
- // Ensure the X window gets mapped.
- wm_test_helper_->host()->Show();
- // Watch for the user clicking the close box.
- wm_test_helper_->host()->AddObserver(this);
-}
-
-void ShellBrowserMainParts::DestroyRootWindow() {
- // We should close widget before destroying root window.
- webview_window_.reset();
- devtools_delegate_->Stop();
- wm_test_helper_->host()->RemoveObserver(this);
- wm_test_helper_.reset();
- ui::ShutdownInputMethodForTesting();
-}
-
-void ShellBrowserMainParts::CreateViewsDelegate() {
- DCHECK(!views::ViewsDelegate::views_delegate);
- views::ViewsDelegate::views_delegate =
- new ShellViewsDelegate(wm_test_helper_->host()->window());
-}
-
-void ShellBrowserMainParts::DestroyViewsDelegate() {
- delete views::ViewsDelegate::views_delegate;
- views::ViewsDelegate::views_delegate = NULL;
-}
-
void ShellBrowserMainParts::CreateExtensionSystem() {
DCHECK(browser_context_);
extension_system_ = static_cast<ShellExtensionSystem*>(
diff --git a/apps/shell/browser/shell_browser_main_parts.h b/apps/shell/browser/shell_browser_main_parts.h
index 8d559bc..e29140d 100644
--- a/apps/shell/browser/shell_browser_main_parts.h
+++ b/apps/shell/browser/shell_browser_main_parts.h
@@ -12,10 +12,6 @@
#include "content/public/common/main_function_params.h"
#include "ui/aura/window_tree_host_observer.h"
-namespace aura {
-class TestScreen;
-}
-
namespace content {
class ShellBrowserContext;
class ShellDevToolsDelegate;
@@ -35,14 +31,11 @@ namespace net {
class NetLog;
}
-namespace wm {
-class WMTestHelper;
-}
-
namespace apps {
class ShellAppsClient;
class ShellBrowserContext;
+class ShellDesktopController;
class ShellExtensionsClient;
// Handles initialization of AppShell.
@@ -74,19 +67,10 @@ class ShellBrowserMainParts : public content::BrowserMainParts,
virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
private:
- // Creates the window that hosts the apps.
- void CreateRootWindow();
-
- // Closes and destroys the root window hosting the app.
- void DestroyRootWindow();
-
- // Window placement is controlled by a ViewsDelegate.
- void CreateViewsDelegate();
- void DestroyViewsDelegate();
-
// Creates and initializes the ExtensionSystem.
void CreateExtensionSystem();
+ scoped_ptr<ShellDesktopController> desktop_controller_;
scoped_ptr<ShellBrowserContext> browser_context_;
scoped_ptr<ShellExtensionsClient> extensions_client_;
scoped_ptr<extensions::ShellExtensionsBrowserClient>
@@ -94,13 +78,6 @@ class ShellBrowserMainParts : public content::BrowserMainParts,
scoped_ptr<ShellAppsClient> apps_client_;
scoped_ptr<net::NetLog> net_log_;
- // Enable a minimal set of views::corewm to be initialized.
- scoped_ptr<wm::WMTestHelper> wm_test_helper_;
-
- scoped_ptr<aura::TestScreen> test_screen_;
-
- scoped_ptr<views::Widget> webview_window_;
-
scoped_ptr<content::ShellDevToolsDelegate> devtools_delegate_;
// Owned by the KeyedService system.
diff --git a/apps/shell/browser/shell_desktop_controller.cc b/apps/shell/browser/shell_desktop_controller.cc
new file mode 100644
index 0000000..0aa4b11
--- /dev/null
+++ b/apps/shell/browser/shell_desktop_controller.cc
@@ -0,0 +1,121 @@
+// Copyright 2014 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 "apps/shell/browser/shell_desktop_controller.h"
+
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/aura/env.h"
+#include "ui/aura/test/test_screen.h"
+#include "ui/aura/window_event_dispatcher.h"
+#include "ui/base/ime/input_method_initializer.h"
+#include "ui/gfx/screen.h"
+#include "ui/views/test/test_views_delegate.h"
+#include "ui/views/views_delegate.h"
+#include "ui/views/widget/widget.h"
+#include "ui/wm/test/wm_test_helper.h"
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+#include "ui/display/chromeos/display_mode.h"
+#include "ui/display/chromeos/display_snapshot.h"
+#endif
+
+namespace apps {
+namespace {
+
+const SkColor kBackgroundColor = SK_ColorBLACK;
+
+// A ViewsDelegate to attach new unparented windows to app_shell's root window.
+class ShellViewsDelegate : public views::TestViewsDelegate {
+ public:
+ explicit ShellViewsDelegate(aura::Window* root_window)
+ : root_window_(root_window) {}
+ virtual ~ShellViewsDelegate() {}
+
+ // views::ViewsDelegate implementation.
+ virtual void OnBeforeWidgetInit(
+ views::Widget::InitParams* params,
+ views::internal::NativeWidgetDelegate* delegate) OVERRIDE {
+ if (!params->parent)
+ params->parent = root_window_;
+ }
+
+ private:
+ aura::Window* root_window_; // Not owned.
+
+ DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
+};
+
+} // namespace
+
+ShellDesktopController::ShellDesktopController() {
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+ output_configurator_.reset(new ui::OutputConfigurator);
+ output_configurator_->Init(false);
+ output_configurator_->ForceInitialConfigure(0);
+ output_configurator_->AddObserver(this);
+#endif
+ CreateRootWindow();
+
+ DCHECK(!views::ViewsDelegate::views_delegate);
+ views::ViewsDelegate::views_delegate =
+ new ShellViewsDelegate(wm_test_helper_->host()->window());
+}
+
+ShellDesktopController::~ShellDesktopController() {
+ delete views::ViewsDelegate::views_delegate;
+ views::ViewsDelegate::views_delegate = NULL;
+ DestroyRootWindow();
+ aura::Env::DeleteInstance();
+}
+
+aura::WindowTreeHost* ShellDesktopController::GetWindowTreeHost() {
+ return wm_test_helper_->host();
+}
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+void ShellDesktopController::OnDisplayModeChanged(
+ const std::vector<ui::OutputConfigurator::DisplayState>& outputs) OVERRIDE {
+ gfx::Size size = GetPrimaryDisplaySize();
+ if (!size.IsEmpty())
+ wm_test_helper_->host()->UpdateRootWindowSize(size);
+}
+#endif
+
+void ShellDesktopController::CreateRootWindow() {
+ test_screen_.reset(aura::TestScreen::Create());
+ // TODO(jamescook): Replace this with a real Screen implementation.
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
+ // TODO(jamescook): Initialize a real input method.
+ ui::InitializeInputMethodForTesting();
+
+ // Set up basic pieces of views::corewm.
+ gfx::Size size = GetPrimaryDisplaySize();
+ if (size.IsEmpty())
+ size = gfx::Size(800, 600);
+ wm_test_helper_.reset(new wm::WMTestHelper(size));
+ wm_test_helper_->host()->compositor()->SetBackgroundColor(kBackgroundColor);
+
+ // Ensure the X window gets mapped.
+ wm_test_helper_->host()->Show();
+}
+
+void ShellDesktopController::DestroyRootWindow() {
+ wm_test_helper_.reset();
+ ui::ShutdownInputMethodForTesting();
+}
+
+gfx::Size ShellDesktopController::GetPrimaryDisplaySize() {
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+ const std::vector<ui::OutputConfigurator::DisplayState>& states =
+ output_configurator_->cached_outputs();
+ if (states.empty())
+ return gfx::Size();
+ const ui::DisplayMode* mode = states[0].display->current_mode();
+ return mode ? mode->size() : gfx::Size();
+#else
+ return gfx::Size();
+#endif
+}
+
+} // namespace apps
diff --git a/apps/shell/browser/shell_desktop_controller.h b/apps/shell/browser/shell_desktop_controller.h
new file mode 100644
index 0000000..d1c1484
--- /dev/null
+++ b/apps/shell/browser/shell_desktop_controller.h
@@ -0,0 +1,74 @@
+// Copyright 2014 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 APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
+#define APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/window_tree_host_observer.h"
+#include "ui/gfx/geometry/size.h"
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+#include "ui/display/chromeos/output_configurator.h"
+#endif
+
+namespace aura {
+class TestScreen;
+class WindowTreeHost;
+}
+
+namespace wm {
+class WMTestHelper;
+}
+
+namespace apps {
+
+// Handles desktop-related tasks for app_shell.
+class ShellDesktopController
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+ : public ui::OutputConfigurator::Observer
+#endif
+ {
+ public:
+ ShellDesktopController();
+ virtual ~ShellDesktopController();
+
+ // Returns the host for the Aura window tree.
+ aura::WindowTreeHost* GetWindowTreeHost();
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+ // ui::OutputConfigurator::Observer overrides.
+ virtual void OnDisplayModeChanged(
+ const std::vector<ui::OutputConfigurator::DisplayState>& outputs)
+ OVERRIDE;
+#endif
+
+ private:
+ // Creates the window that hosts the app.
+ void CreateRootWindow();
+
+ // Closes and destroys the root window hosting the app.
+ void DestroyRootWindow();
+
+ // Returns the dimensions (in pixels) of the primary display, or an empty size
+ // if the dimensions can't be determined or no display is connected.
+ gfx::Size GetPrimaryDisplaySize();
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+ scoped_ptr<ui::OutputConfigurator> output_configurator_;
+#endif
+
+ // Enable a minimal set of views::corewm to be initialized.
+ scoped_ptr<wm::WMTestHelper> wm_test_helper_;
+
+ scoped_ptr<aura::TestScreen> test_screen_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellDesktopController);
+};
+
+} // namespace apps
+
+#endif // APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
diff --git a/apps/shell/browser/web_view_window.cc b/apps/shell/browser/web_view_window.cc
deleted file mode 100644
index 88b24ce..0000000
--- a/apps/shell/browser/web_view_window.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2013 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 "apps/shell/browser/web_view_window.h"
-
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "ui/aura/window.h"
-#include "ui/views/controls/webview/webview.h"
-#include "ui/views/layout/fill_layout.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_delegate.h"
-
-namespace {
-
-// A simple window containing a single web view.
-class WebViewWindowContents : public views::WidgetDelegateView {
- public:
- explicit WebViewWindowContents(content::BrowserContext* browser_context)
- : browser_context_(browser_context) {}
- virtual ~WebViewWindowContents() {}
-
- // views::WidgetDelegateView overrides:
- virtual views::View* GetContentsView() OVERRIDE;
- virtual void WindowClosing() OVERRIDE;
-
- // views::View overrides:
- virtual void ViewHierarchyChanged(
- const ViewHierarchyChangedDetails& details) OVERRIDE;
-
- private:
- // Initialize this view's children.
- void InitChildViews();
-
- content::BrowserContext* browser_context_;
-
- DISALLOW_COPY_AND_ASSIGN(WebViewWindowContents);
-};
-
-views::View* WebViewWindowContents::GetContentsView() {
- return this;
-}
-
-void WebViewWindowContents::WindowClosing() {
- // Close the app when the window is closed.
- if (base::MessageLoopForUI::current()->is_running())
- base::MessageLoopForUI::current()->Quit();
-}
-
-void WebViewWindowContents::ViewHierarchyChanged(
- const ViewHierarchyChangedDetails& details) {
- // Initialize child views when this view is attached.
- if (details.is_add && details.child == this)
- InitChildViews();
-}
-
-void WebViewWindowContents::InitChildViews() {
- // Create a WebView that fills the window.
- SetLayoutManager(new views::FillLayout);
- views::WebView* web_view = new views::WebView(browser_context_);
- AddChildView(web_view);
-
- web_view->LoadInitialURL(GURL("http://www.google.com/"));
- web_view->web_contents()->GetView()->Focus();
-}
-
-} // namespace
-
-namespace apps {
-
-views::Widget* CreateWebViewWindow(content::BrowserContext* browser_context,
- aura::Window* window_context) {
- views::Widget* widget = new views::Widget;
- views::Widget::InitParams params;
- params.delegate = new WebViewWindowContents(browser_context);
- params.context = window_context;
- // Make widget owns the native_widget, so that the pointer of widget is still
- // valid after user click the close button of the widget inside root window.
- // app_shell client controls the widget lifetime.
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = window_context->bounds();
- params.top_level = true;
- widget->Init(params);
- return widget;
-}
-
-} // namespace apps
diff --git a/apps/shell/browser/web_view_window.h b/apps/shell/browser/web_view_window.h
deleted file mode 100644
index e3d53f7..0000000
--- a/apps/shell/browser/web_view_window.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2013 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 APPS_SHELL_BROWSER_WEB_VIEW_WINDOW_H_
-#define APPS_SHELL_BROWSER_WEB_VIEW_WINDOW_H_
-
-namespace aura {
-class Window;
-}
-
-namespace content {
-class BrowserContext;
-}
-
-namespace views {
-class Widget;
-}
-
-namespace apps {
-
-// Create an example window containing a WebView.
-views::Widget* CreateWebViewWindow(content::BrowserContext* browser_context,
- aura::Window* window_context);
-
-} // namespace apps
-
-#endif // APPS_SHELL_BROWSER_WEB_VIEW_WINDOW_H_
diff --git a/ui/display/chromeos/output_configurator.cc b/ui/display/chromeos/output_configurator.cc
index cd95866..e840413 100644
--- a/ui/display/chromeos/output_configurator.cc
+++ b/ui/display/chromeos/output_configurator.cc
@@ -912,6 +912,8 @@ OutputState OutputConfigurator::ChooseOutputState(
// state so that its native mode will be used.
return OUTPUT_STATE_SINGLE;
} else {
+ if (!state_controller_)
+ return OUTPUT_STATE_DUAL_EXTENDED;
// With either both outputs on or both outputs off, use one of the
// dual modes.
std::vector<int64> display_ids;