diff options
author | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-27 19:32:26 +0000 |
---|---|---|
committer | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-27 19:32:26 +0000 |
commit | a659114b2a7b20b097e4046f79a07622eb3f7cd3 (patch) | |
tree | db971bfe360fd805480840523ad83a28fc64a8af | |
parent | abc501eda14b3f1049195e0ccee0dac13d9b7a80 (diff) | |
download | chromium_src-a659114b2a7b20b097e4046f79a07622eb3f7cd3.zip chromium_src-a659114b2a7b20b097e4046f79a07622eb3f7cd3.tar.gz chromium_src-a659114b2a7b20b097e4046f79a07622eb3f7cd3.tar.bz2 |
Re-land r246921: "Allow running content-shell headless with --dump-render-tree."
This change reverts r247148 and re-lands r246921. It's unclear if there
really is something wrong with this patch, and the crashes in
run-webkit-tests were addressed in Blink r165816.
TBR=jochen@chromium.org, sadrul@chromium.org
BUG=316712
Review URL: https://codereview.chromium.org/132903012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247278 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/content_shell.gypi | 2 | ||||
-rw-r--r-- | content/shell/browser/shell.cc | 4 | ||||
-rw-r--r-- | content/shell/browser/shell.h | 7 | ||||
-rw-r--r-- | content/shell/browser/shell_aura.cc | 152 | ||||
-rw-r--r-- | content/shell/browser/shell_platform_data_aura.cc | 156 | ||||
-rw-r--r-- | content/shell/browser/shell_platform_data_aura.h (renamed from content/shell/browser/shell_aura.h) | 21 | ||||
-rw-r--r-- | content/shell/browser/shell_views.cc | 51 |
7 files changed, 228 insertions, 165 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index d3373ad..214e03a 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -127,6 +127,8 @@ 'shell/browser/shell_net_log.h', 'shell/browser/shell_network_delegate.cc', 'shell/browser/shell_network_delegate.h', + 'shell/browser/shell_platform_data_aura.cc', + 'shell/browser/shell_platform_data_aura.h', 'shell/browser/shell_plugin_service_filter.cc', 'shell/browser/shell_plugin_service_filter.h', 'shell/browser/shell_quota_permission_context.cc', diff --git a/content/shell/browser/shell.cc b/content/shell/browser/shell.cc index 28708fb..b6b5a43 100644 --- a/content/shell/browser/shell.cc +++ b/content/shell/browser/shell.cc @@ -29,10 +29,6 @@ #include "content/shell/common/shell_messages.h" #include "content/shell/common/shell_switches.h" -#if defined(USE_AURA) && !defined(TOOLKIT_VIEWS) -#include "content/shell/browser/shell_aura.h" -#endif - namespace content { const int Shell::kDefaultTestWindowWidthDip = 800; diff --git a/content/shell/browser/shell.h b/content/shell/browser/shell.h index edd59ce..92cd7b5 100644 --- a/content/shell/browser/shell.h +++ b/content/shell/browser/shell.h @@ -41,7 +41,7 @@ class GURL; namespace content { #if defined(USE_AURA) -class ShellAuraPlatformData; +class ShellPlatformDataAura; #endif class BrowserContext; @@ -259,10 +259,9 @@ class Shell : public WebContentsDelegate, static views::ViewsDelegate* views_delegate_; views::Widget* window_widget_; -#else // defined(TOOLKIT_VIEWS) - static ShellAuraPlatformData* platform_; #endif // defined(TOOLKIT_VIEWS) -#endif + static ShellPlatformDataAura* platform_; +#endif // defined(USE_AURA) bool headless_; diff --git a/content/shell/browser/shell_aura.cc b/content/shell/browser/shell_aura.cc index 725055d..61bc807 100644 --- a/content/shell/browser/shell_aura.cc +++ b/content/shell/browser/shell_aura.cc @@ -6,155 +6,20 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" -#include "content/shell/browser/shell_aura.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/client/default_activation_client.h" -#include "ui/aura/client/default_capture_client.h" +#include "content/shell/browser/shell_platform_data_aura.h" #include "ui/aura/env.h" -#include "ui/aura/layout_manager.h" #include "ui/aura/root_window.h" -#include "ui/aura/test/test_focus_client.h" #include "ui/aura/test/test_screen.h" -#include "ui/aura/test/test_window_tree_client.h" #include "ui/aura/window.h" -#include "ui/base/ime/input_method.h" -#include "ui/base/ime/input_method_delegate.h" -#include "ui/base/ime/input_method_factory.h" -#include "ui/gfx/screen.h" namespace content { -namespace { - -class FillLayout : public aura::LayoutManager { - public: - explicit FillLayout(aura::RootWindow* root) - : root_(root) { - } - - virtual ~FillLayout() {} - - private: - // aura::LayoutManager: - virtual void OnWindowResized() OVERRIDE { - } - - virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { - child->SetBounds(root_->window()->bounds()); - } - - virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { - } - - virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { - } - - virtual void OnChildWindowVisibilityChanged(aura::Window* child, - bool visible) OVERRIDE { - } - - virtual void SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) OVERRIDE { - SetChildBoundsDirect(child, requested_bounds); - } - - aura::RootWindow* root_; - - DISALLOW_COPY_AND_ASSIGN(FillLayout); -}; - -class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, - public ui::EventHandler { - public: - explicit MinimalInputEventFilter(aura::RootWindow* root) - : root_(root), - input_method_(ui::CreateInputMethod(this, - gfx::kNullAcceleratedWidget)) { - input_method_->Init(true); - root_->window()->AddPreTargetHandler(this); - root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, - input_method_.get()); - } - - virtual ~MinimalInputEventFilter() { - root_->window()->RemovePreTargetHandler(this); - root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, - static_cast<ui::InputMethod*>(NULL)); - } - - private: - // ui::EventHandler: - virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { - const ui::EventType type = event->type(); - if (type == ui::ET_TRANSLATED_KEY_PRESS || - type == ui::ET_TRANSLATED_KEY_RELEASE) { - // The |event| is already handled by this object, change the type of the - // event to ui::ET_KEY_* and pass it to the next filter. - static_cast<ui::TranslatedKeyEvent*>(event)->ConvertToKeyEvent(); - } else { - if (input_method_->DispatchKeyEvent(*event)) - event->StopPropagation(); - } - } - - // ui::InputMethodDelegate: - virtual bool DispatchKeyEventPostIME( - const base::NativeEvent& event) OVERRIDE { - ui::TranslatedKeyEvent aura_event(event, false /* is_char */); - return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent( - &aura_event); - } - - virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type, - ui::KeyboardCode key_code, - int flags) OVERRIDE { - ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code, - flags); - return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent( - &aura_event); - } - - aura::RootWindow* root_; - scoped_ptr<ui::InputMethod> input_method_; - - DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter); -}; - -} - -ShellAuraPlatformData* Shell::platform_ = NULL; - -ShellAuraPlatformData::ShellAuraPlatformData() { - aura::TestScreen* screen = aura::TestScreen::Create(); - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); - root_window_.reset(screen->CreateRootWindowForPrimaryDisplay()); - root_window_->host()->Show(); - root_window_->window()->SetLayoutManager(new FillLayout(root_window_.get())); - - focus_client_.reset(new aura::test::TestFocusClient()); - aura::client::SetFocusClient(root_window_->window(), focus_client_.get()); - - activation_client_.reset( - new aura::client::DefaultActivationClient(root_window_->window())); - capture_client_.reset( - new aura::client::DefaultCaptureClient(root_window_->window())); - window_tree_client_.reset( - new aura::test::TestWindowTreeClient(root_window_->window())); - ime_filter_.reset(new MinimalInputEventFilter(root_window_.get())); -} - -ShellAuraPlatformData::~ShellAuraPlatformData() { -} - -void ShellAuraPlatformData::ResizeWindow(int width, int height) { - root_window_->host()->SetBounds(gfx::Rect(width, height)); -} - // static void Shell::PlatformInitialize(const gfx::Size& default_window_size) { CHECK(!platform_); - aura::Env::CreateInstance(); - platform_ = new ShellAuraPlatformData(); + aura::TestScreen* screen = aura::TestScreen::Create(); + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); + platform_ = new ShellPlatformDataAura(default_window_size); } void Shell::PlatformExit() { @@ -178,7 +43,9 @@ void Shell::PlatformSetIsLoading(bool loading) { void Shell::PlatformCreateWindow(int width, int height) { CHECK(platform_); - platform_->ResizeWindow(width, height); + if (!headless_) + platform_->ShowWindow(); + platform_->ResizeWindow(gfx::Size(width, height)); } void Shell::PlatformSetContents() { @@ -195,7 +62,10 @@ void Shell::PlatformResizeSubViews() { } void Shell::Close() { - web_contents_.reset(); + if (headless_) + delete this; + else + web_contents_.reset(); } void Shell::PlatformSetTitle(const base::string16& title) { diff --git a/content/shell/browser/shell_platform_data_aura.cc b/content/shell/browser/shell_platform_data_aura.cc new file mode 100644 index 0000000..e7a1290 --- /dev/null +++ b/content/shell/browser/shell_platform_data_aura.cc @@ -0,0 +1,156 @@ +// 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 "content/shell/browser/shell_platform_data_aura.h" + +#include "content/shell/browser/shell.h" +#include "ui/aura/client/aura_constants.h" +#include "ui/aura/client/default_activation_client.h" +#include "ui/aura/client/default_capture_client.h" +#include "ui/aura/env.h" +#include "ui/aura/layout_manager.h" +#include "ui/aura/root_window.h" +#include "ui/aura/test/test_focus_client.h" +#include "ui/aura/test/test_window_tree_client.h" +#include "ui/aura/window.h" +#include "ui/base/ime/input_method.h" +#include "ui/base/ime/input_method_delegate.h" +#include "ui/base/ime/input_method_factory.h" +#include "ui/gfx/screen.h" + +namespace content { + +namespace { + +class FillLayout : public aura::LayoutManager { + public: + explicit FillLayout(aura::RootWindow* root) + : root_(root) { + } + + virtual ~FillLayout() {} + + private: + // aura::LayoutManager: + virtual void OnWindowResized() OVERRIDE { + } + + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { + child->SetBounds(root_->window()->bounds()); + } + + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { + } + + virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { + } + + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) OVERRIDE { + } + + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE { + SetChildBoundsDirect(child, requested_bounds); + } + + aura::RootWindow* root_; + + DISALLOW_COPY_AND_ASSIGN(FillLayout); +}; + +class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, + public ui::EventHandler { + public: + explicit MinimalInputEventFilter(aura::RootWindow* root) + : root_(root), + input_method_(ui::CreateInputMethod(this, + gfx::kNullAcceleratedWidget)) { + input_method_->Init(true); + root_->window()->AddPreTargetHandler(this); + root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, + input_method_.get()); + } + + virtual ~MinimalInputEventFilter() { + root_->window()->RemovePreTargetHandler(this); + root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, + static_cast<ui::InputMethod*>(NULL)); + } + + private: + // ui::EventHandler: + virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { + const ui::EventType type = event->type(); + if (type == ui::ET_TRANSLATED_KEY_PRESS || + type == ui::ET_TRANSLATED_KEY_RELEASE) { + // The |event| is already handled by this object, change the type of the + // event to ui::ET_KEY_* and pass it to the next filter. + static_cast<ui::TranslatedKeyEvent*>(event)->ConvertToKeyEvent(); + } else { + if (input_method_->DispatchKeyEvent(*event)) + event->StopPropagation(); + } + } + + // ui::InputMethodDelegate: + virtual bool DispatchKeyEventPostIME( + const base::NativeEvent& event) OVERRIDE { + ui::TranslatedKeyEvent aura_event(event, false /* is_char */); + return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent( + &aura_event); + } + + virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type, + ui::KeyboardCode key_code, + int flags) OVERRIDE { + ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code, + flags); + return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent( + &aura_event); + } + + aura::RootWindow* root_; + scoped_ptr<ui::InputMethod> input_method_; + + DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter); +}; + +} + +ShellPlatformDataAura* Shell::platform_ = NULL; + +ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { + aura::Env::CreateInstance(); + root_window_.reset(new aura::RootWindow( + aura::RootWindow::CreateParams(gfx::Rect(initial_size)))); + root_window_->Init(); + root_window_->window()->SetLayoutManager(new FillLayout(root_window_.get())); + + focus_client_.reset(new aura::test::TestFocusClient()); + aura::client::SetFocusClient(root_window_->window(), focus_client_.get()); + + activation_client_.reset( + new aura::client::DefaultActivationClient(root_window_->window())); + capture_client_.reset( + new aura::client::DefaultCaptureClient(root_window_->window())); + window_tree_client_.reset( + new aura::test::TestWindowTreeClient(root_window_->window())); + ime_filter_.reset(new MinimalInputEventFilter(root_window_.get())); +} + +ShellPlatformDataAura::~ShellPlatformDataAura() { +} + +void ShellPlatformDataAura::ShowWindow() { + root_window_->host()->Show(); +} + +void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) { + root_window_->host()->SetBounds(gfx::Rect(size)); +} + + + +} // namespace content diff --git a/content/shell/browser/shell_aura.h b/content/shell/browser/shell_platform_data_aura.h index edf9513..9b7ea2b 100644 --- a/content/shell/browser/shell_aura.h +++ b/content/shell/browser/shell_platform_data_aura.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_SHELL_BROWSER_SHELL_AURA_H_ -#define CONTENT_SHELL_BROWSER_SHELL_AURA_H_ +#ifndef CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DATA_AURA_H_ +#define CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DATA_AURA_H_ #include "base/memory/scoped_ptr.h" @@ -17,18 +17,23 @@ class WindowTreeClient; class RootWindow; } +namespace gfx { +class Size; +} + namespace ui { class EventHandler; } namespace content { -class ShellAuraPlatformData { +class ShellPlatformDataAura { public: - ShellAuraPlatformData(); - ~ShellAuraPlatformData(); + explicit ShellPlatformDataAura(const gfx::Size& initial_size); + ~ShellPlatformDataAura(); - void ResizeWindow(int width, int height); + void ShowWindow(); + void ResizeWindow(const gfx::Size& size); aura::RootWindow* window() { return root_window_.get(); } @@ -40,9 +45,9 @@ class ShellAuraPlatformData { scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; scoped_ptr<ui::EventHandler> ime_filter_; - DISALLOW_COPY_AND_ASSIGN(ShellAuraPlatformData); + DISALLOW_COPY_AND_ASSIGN(ShellPlatformDataAura); }; } // namespace content -#endif // CONTENT_SHELL_BROWSER_SHELL_AURA_H_ +#endif // CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DATA_AURA_H_ diff --git a/content/shell/browser/shell_views.cc b/content/shell/browser/shell_views.cc index c6b09e4..3086237 100644 --- a/content/shell/browser/shell_views.cc +++ b/content/shell/browser/shell_views.cc @@ -6,8 +6,10 @@ #include "base/command_line.h" #include "base/strings/utf_string_conversions.h" +#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" +#include "content/shell/browser/shell_platform_data_aura.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" @@ -343,11 +345,12 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) { void Shell::PlatformExit() { #if defined(OS_CHROMEOS) - if (wm_test_helper_) - delete wm_test_helper_; + delete wm_test_helper_; #endif - if (views_delegate_) - delete views_delegate_; + delete views_delegate_; + views_delegate_ = NULL; + delete platform_; + platform_ = NULL; #if defined(OS_CHROMEOS) chromeos::DBusThreadManager::Shutdown(); #endif @@ -358,6 +361,8 @@ void Shell::PlatformCleanUp() { } void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { + if (headless_) + return; ShellWindowDelegateView* delegate_view = static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); if (control == BACK_BUTTON) { @@ -373,6 +378,8 @@ void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { } void Shell::PlatformSetAddressBarURL(const GURL& url) { + if (headless_) + return; ShellWindowDelegateView* delegate_view = static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); delegate_view->SetAddressBarURL(url); @@ -382,6 +389,14 @@ void Shell::PlatformSetIsLoading(bool loading) { } void Shell::PlatformCreateWindow(int width, int height) { + if (headless_) { + content_size_ = gfx::Size(width, height); + if (!platform_) + platform_ = new ShellPlatformDataAura(content_size_); + else + platform_->ResizeWindow(content_size_); + return; + } #if defined(OS_CHROMEOS) window_widget_ = views::Widget::CreateWindowWithContextAndBounds( new ShellWindowDelegateView(this), @@ -402,19 +417,39 @@ void Shell::PlatformCreateWindow(int width, int height) { } void Shell::PlatformSetContents() { - ShellWindowDelegateView* delegate_view = - static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); - delegate_view->SetWebContents(web_contents_.get(), content_size_); + if (headless_) { + CHECK(platform_); + aura::Window* content = web_contents_->GetView()->GetNativeView(); + aura::Window* parent = platform_->window()->window(); + if (!parent->Contains(content)) { + parent->AddChild(content); + content->Show(); + } + content->SetBounds(gfx::Rect(content_size_)); + RenderWidgetHostView* host_view = web_contents_->GetRenderWidgetHostView(); + if (host_view) + host_view->SetSize(content_size_); + } else { + views::WidgetDelegate* widget_delegate = window_widget_->widget_delegate(); + ShellWindowDelegateView* delegate_view = + static_cast<ShellWindowDelegateView*>(widget_delegate); + delegate_view->SetWebContents(web_contents_.get(), content_size_); + } } void Shell::PlatformResizeSubViews() { } void Shell::Close() { - window_widget_->CloseNow(); + if (headless_) + delete this; + else + window_widget_->CloseNow(); } void Shell::PlatformSetTitle(const base::string16& title) { + if (headless_) + return; ShellWindowDelegateView* delegate_view = static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); delegate_view->SetWindowTitle(title); |