diff --git a/ash/ash.gyp b/ash/ash.gyp index 47e6b8ae91880c..37f28da086f254 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -18,6 +18,9 @@ '../base/base.gyp:base_i18n', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../build/temp_gyp/googleurl.gyp:googleurl', + '../content/content.gyp:content', + '../content/content.gyp:content_browser', + '../ipc/ipc.gyp:ipc', '../net/net.gyp:net', '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icui18n', @@ -111,6 +114,8 @@ 'monitor/secondary_monitor_view.h', 'screen_ash.cc', 'screen_ash.h', + 'screensaver/screensaver_view.cc', + 'screensaver/screensaver_view.h', 'screenshot_delegate.h', 'shell.cc', 'shell.h', @@ -323,6 +328,8 @@ '../base/base.gyp:base', '../base/base.gyp:test_support_base', '../chrome/chrome_resources.gyp:packed_resources', + '../content/content.gyp:content_browser', + '../content/content.gyp:test_support_content', '../build/temp_gyp/googleurl.gyp:googleurl', '../skia/skia.gyp:skia', '../testing/gtest.gyp:gtest', @@ -337,6 +344,7 @@ '../ui/ui.gyp:ui_resources', '../ui/ui.gyp:ui_resources_standard', '../ui/views/views.gyp:views', + '../ui/views/views.gyp:test_support_views', 'ash', ], 'sources': [ @@ -356,6 +364,7 @@ 'launcher/launcher_unittest.cc', 'launcher/launcher_view_unittest.cc', 'monitor/multi_monitor_manager_unittest.cc', + 'screensaver/screensaver_view_unittest.cc', 'shell_unittest.cc', 'test/ash_test_base.cc', 'test/ash_test_base.h', @@ -457,6 +466,7 @@ '../ui/ui.gyp:ui_resources_standard', '../ui/views/views.gyp:views', '../ui/views/views.gyp:views_examples_lib', + '../ui/views/views.gyp:test_support_views', 'ash', ], 'sources': [ diff --git a/ash/screensaver/DEPS b/ash/screensaver/DEPS new file mode 100644 index 00000000000000..1c35d9ca694b70 --- /dev/null +++ b/ash/screensaver/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/browser", +] diff --git a/ash/screensaver/screensaver_view.cc b/ash/screensaver/screensaver_view.cc new file mode 100644 index 00000000000000..858ae9ce8452ad --- /dev/null +++ b/ash/screensaver/screensaver_view.cc @@ -0,0 +1,140 @@ +// 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 "ash/screensaver/screensaver_view.h" + +#include "ash/shell.h" +#include "ash/shell_delegate.h" +#include "base/bind.h" +#include "base/logging.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_thread.h" +#include "ui/gfx/screen.h" +#include "ui/aura/root_window.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/widget/widget.h" + +using content::BrowserThread; + +namespace { + +ash::internal::ScreensaverView* g_instance = NULL; + +} // namespace + +namespace ash { + +void ShowScreensaver(const GURL& url) { + internal::ScreensaverView::ShowScreensaver(url); +} + +void CloseScreensaver() { + internal::ScreensaverView::CloseScreensaver(); +} + +namespace internal { + +// static +void ScreensaverView::ShowScreensaver(const GURL& url) { + if (!g_instance) { + g_instance = new ScreensaverView(url); + g_instance->Show(); + } +} + +// static +void ScreensaverView::CloseScreensaver() { + if (g_instance) { + g_instance->Close(); + g_instance = NULL; + } +} + +//////////////////////////////////////////////////////////////////////////////// +// ScreensaverView, views::WidgetDelegateView implementation. +views::View* ScreensaverView::GetContentsView() { + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// ScreensaverView, content::WebContentsObserver implementation. +void ScreensaverView::RenderViewGone( + base::TerminationStatus status) { + LOG(ERROR) << "Screensaver terminated with status " << status + << ", reloading."; + // Reload the screensaver url into the webcontents. + LoadScreensaver(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ScreensaverView private methods. +ScreensaverView::ScreensaverView(const GURL& url) + : url_(url), + screensaver_webview_(NULL), + container_window_(NULL) { +} + +ScreensaverView::~ScreensaverView() { +} + +void ScreensaverView::Show() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + // Add the WebView to our view. + AddChildWebContents(); + // Show the window. + ShowWindow(); +} + +void ScreensaverView::Close() { + DCHECK(GetWidget()); + GetWidget()->Close(); +} + +void ScreensaverView::AddChildWebContents() { + content::BrowserContext* context = + Shell::GetInstance()->delegate()->GetCurrentBrowserContext(); + screensaver_webview_ = new views::WebView(context); + SetLayoutManager(new views::FillLayout); + AddChildView(screensaver_webview_); + + LoadScreensaver(); + content::WebContentsObserver::Observe( + screensaver_webview_->GetWebContents()); +} + +void ScreensaverView::LoadScreensaver() { + screensaver_webview_->GetWebContents()->GetController().LoadURL( + url_, + content::Referrer(), + content::PAGE_TRANSITION_START_PAGE, + std::string()); +} + +void ScreensaverView::ShowWindow() { + aura::RootWindow* root_window = ash::Shell::GetRootWindow(); + gfx::Rect screen_rect = + gfx::Screen::GetMonitorNearestWindow(root_window).bounds(); + + // We want to be the fullscreen topmost child of the root window. + // There should be nothing ever really that should show up on top of us. + container_window_ = new views::Widget(); + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.delegate = this; + params.parent = root_window; + container_window_->Init(params); + + container_window_->StackAtTop(); + container_window_->SetBounds(screen_rect); + container_window_->Show(); +} + +// static +ScreensaverView* ScreensaverView::GetInstance() { + return g_instance; +} + +} // namespace internal +} // namespace ash diff --git a/ash/screensaver/screensaver_view.h b/ash/screensaver/screensaver_view.h new file mode 100644 index 00000000000000..541a254147b00e --- /dev/null +++ b/ash/screensaver/screensaver_view.h @@ -0,0 +1,87 @@ +// 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 ASH_SCREENSAVER_SCREENSAVER_VIEW_H_ +#define ASH_SCREENSAVER_SCREENSAVER_VIEW_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/callback.h" +#include "content/public/browser/web_contents_observer.h" +#include "googleurl/src/gurl.h" +#include "ui/views/widget/widget_delegate.h" + +namespace content { +class BrowserContent; +} + +namespace views { +class WebView; +} + +namespace ash { + +namespace test { +class ScreensaverViewTest; +} + +ASH_EXPORT void ShowScreensaver(const GURL& url); +ASH_EXPORT void CloseScreensaver(); + +typedef + base::Callback WebViewFactory; + +namespace internal { + +// Shows a URL as a screensaver. The screensaver window is fullscreen, +// always on top of every other window and will reload the URL if the +// renderer crashes for any reason. +class ScreensaverView : public views::WidgetDelegateView, + public content::WebContentsObserver { + public: + static void ShowScreensaver(const GURL& url); + static void CloseScreensaver(); + + private: + friend class test::ScreensaverViewTest; + + explicit ScreensaverView(const GURL& url); + virtual ~ScreensaverView(); + + // views::WidgetDelegate overrides. + virtual views::View* GetContentsView() OVERRIDE; + + // content::WebContentsObserver overrides. + virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; + + void Show(); + void Close(); + + // Creates and adds web contents to our view. + void AddChildWebContents(); + // Load the screensaver in the WebView's webcontent. If the webcontents + // don't exist, they'll be created by WebView. + void LoadScreensaver(); + // Creates and shows a frameless full screen window containing our view. + void ShowWindow(); + + // For testing purposes. + static ASH_EXPORT ScreensaverView* GetInstance(); + + // URL to show in the screensaver. + GURL url_; + + // Host for the extension that implements this dialog. + views::WebView* screensaver_webview_; + + // Window that holds the screensaver webview. + views::Widget* container_window_; + + DISALLOW_COPY_AND_ASSIGN(ScreensaverView); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SCREENSAVER_SCREENSAVER_VIEW_H_ diff --git a/ash/screensaver/screensaver_view_unittest.cc b/ash/screensaver/screensaver_view_unittest.cc new file mode 100644 index 00000000000000..47a19e2e89c9ad --- /dev/null +++ b/ash/screensaver/screensaver_view_unittest.cc @@ -0,0 +1,93 @@ +// 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 "ash/screensaver/screensaver_view.h" + +#include "ash/test/ash_test_base.h" +#include "base/bind.h" +#include "content/public/browser/browser_context.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/test/test_views_delegate.h" +#include "ui/views/test/webview_test_helper.h" + +namespace ash { +namespace test { + +class ScreensaverViewTest : public ash::test::AshTestBase { + public: + ScreensaverViewTest() { + url_ = GURL("http://www.google.com"); + views_delegate_.reset(new views::TestViewsDelegate); + webview_test_helper_.reset(new views::WebViewTestHelper(message_loop())); + } + + virtual ~ScreensaverViewTest() {} + + virtual void SetUp() OVERRIDE { + AshTestBase::SetUp(); + RunAllPendingInMessageLoop(); + } + + virtual void TearDown() OVERRIDE { + AshTestBase::TearDown(); + } + + void ExpectOpenScreensaver() { + internal::ScreensaverView* screensaver = + internal::ScreensaverView::GetInstance(); + EXPECT_TRUE(screensaver != NULL); + if (!screensaver) return; + + EXPECT_TRUE(screensaver->screensaver_webview_ != NULL); + if (!screensaver->screensaver_webview_) return; + + EXPECT_TRUE(screensaver->screensaver_webview_->web_contents() != NULL); + if (!screensaver->screensaver_webview_->web_contents()) return; + + EXPECT_EQ(screensaver->screensaver_webview_->web_contents()->GetURL(), + url_); + } + + void ExpectClosedScreensaver() { + EXPECT_TRUE(internal::ScreensaverView::GetInstance() == NULL); + } + + protected: + GURL url_; + + private: + scoped_ptr views_delegate_; + scoped_ptr webview_test_helper_; + + DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest); +}; + +TEST_F(ScreensaverViewTest, ShowScreensaverAndClose) { + ash::ShowScreensaver(url_); + RunAllPendingInMessageLoop(); + ExpectOpenScreensaver(); + + ash::CloseScreensaver(); + ExpectClosedScreensaver(); +} + +TEST_F(ScreensaverViewTest, OutOfOrderMultipleShowAndClose) { + ash::CloseScreensaver(); + ExpectClosedScreensaver(); + + ash::ShowScreensaver(url_); + ExpectOpenScreensaver(); + RunAllPendingInMessageLoop(); + ash::ShowScreensaver(url_); + ExpectOpenScreensaver(); + RunAllPendingInMessageLoop(); + + ash::CloseScreensaver(); + ExpectClosedScreensaver(); + ash::CloseScreensaver(); + ExpectClosedScreensaver(); +} + +} // namespace test +} // namespace ash diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index 9cafd1e682b048..31edb6abc4a716 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -75,6 +75,10 @@ void ShellDelegateImpl::OpenCrosh() { void ShellDelegateImpl::OpenMobileSetup() { } +content::BrowserContext* ShellDelegateImpl::GetCurrentBrowserContext() { + return Shell::GetInstance()->browser_context(); +} + void ShellDelegateImpl::ToggleSpokenFeedback() { } diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h index 66f8c3618a22a8..71b65b22807fe0 100644 --- a/ash/shell/shell_delegate_impl.h +++ b/ash/shell/shell_delegate_impl.h @@ -33,6 +33,7 @@ class ShellDelegateImpl : public ash::ShellDelegate { virtual void OpenFileManager() OVERRIDE; virtual void OpenCrosh() OVERRIDE; virtual void OpenMobileSetup() OVERRIDE; + virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE; virtual void ToggleSpokenFeedback() OVERRIDE; virtual ash::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; virtual void StartPartialScreenshot( diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc index f3abad27a6fe7b..020ec0061e7573 100644 --- a/ash/shell/window_type_launcher.cc +++ b/ash/shell/window_type_launcher.cc @@ -4,6 +4,7 @@ #include "ash/shell/window_type_launcher.h" +#include "ash/screensaver/screensaver_view.h" #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" @@ -11,7 +12,10 @@ #include "ash/shell/panel_window.h" #include "ash/shell/toplevel_window.h" #include "ash/wm/shadow_types.h" +#include "base/bind.h" +#include "base/time.h" #include "base/utf_string_conversions.h" +#include "content/public/browser/browser_thread.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/gfx/canvas.h" @@ -216,7 +220,10 @@ WindowTypeLauncher::WindowTypeLauncher() this, ASCIIToUTF16("Open Views Examples Window")))), ALLOW_THIS_IN_INITIALIZER_LIST(show_hide_window_button_( new views::NativeTextButton( - this, ASCIIToUTF16("Show/Hide a Window")))) { + this, ASCIIToUTF16("Show/Hide a Window")))), + ALLOW_THIS_IN_INITIALIZER_LIST(show_screensaver_( + new views::NativeTextButton( + this, ASCIIToUTF16("Show the Screensaver [for 5 seconds]")))) { views::GridLayout* layout = new views::GridLayout(this); layout->SetInsets(5, 5, 5, 5); SetLayoutManager(layout); @@ -239,6 +246,7 @@ WindowTypeLauncher::WindowTypeLauncher() AddViewToLayout(layout, transient_button_); AddViewToLayout(layout, examples_button_); AddViewToLayout(layout, show_hide_window_button_); + AddViewToLayout(layout, show_screensaver_); #if !defined(OS_MACOSX) set_context_menu_controller(this); #endif @@ -305,6 +313,13 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView()); } else if (sender == show_hide_window_button_) { NonModalTransient::ToggleNonModalTransient(GetWidget()->GetNativeView()); + } else if (sender == show_screensaver_) { + ash::ShowScreensaver(GURL("http://www.google.com")); + content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, + FROM_HERE, + base::Bind(&ash::CloseScreensaver), + base::TimeDelta::FromSeconds(5)); + } #if !defined(OS_MACOSX) else if (sender == examples_button_) { diff --git a/ash/shell/window_type_launcher.h b/ash/shell/window_type_launcher.h index 3b9807d393575b..4dcc5ab5a1fffb 100644 --- a/ash/shell/window_type_launcher.h +++ b/ash/shell/window_type_launcher.h @@ -77,6 +77,7 @@ class WindowTypeLauncher : public views::WidgetDelegateView, views::NativeTextButton* transient_button_; views::NativeTextButton* examples_button_; views::NativeTextButton* show_hide_window_button_; + views::NativeTextButton* show_screensaver_; #if !defined(OS_MACOSX) scoped_ptr menu_runner_; #endif diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index b08b0f8c52a91b..43c15936b0353c 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -71,6 +71,9 @@ class ASH_EXPORT ShellDelegate { // Invoked when the user needs to set up mobile networking. virtual void OpenMobileSetup() = 0; + // Get the current browser context. This will get us the current profile. + virtual content::BrowserContext* GetCurrentBrowserContext() = 0; + // Invoked when the user presses a shortcut to toggle spoken feedback // for accessibility. virtual void ToggleSpokenFeedback() = 0; diff --git a/ash/test/DEPS b/ash/test/DEPS new file mode 100644 index 00000000000000..659b10548bd5a4 --- /dev/null +++ b/ash/test/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/test", +] diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index c957e484a7b07c..0dcd1676eda76f 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/test/test_launcher_delegate.h" +#include "content/test/test_browser_context.h" #include "grit/ui_resources.h" #include "ui/aura/window.h" @@ -59,6 +60,10 @@ void TestShellDelegate::OpenCrosh() { void TestShellDelegate::OpenMobileSetup() { } +content::BrowserContext* TestShellDelegate::GetCurrentBrowserContext() { + return new TestBrowserContext(); +} + void TestShellDelegate::ToggleSpokenFeedback() { } diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 039375faadadc5..1c1379450250c7 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -29,6 +29,7 @@ class TestShellDelegate : public ShellDelegate { virtual void OpenFileManager() OVERRIDE; virtual void OpenCrosh() OVERRIDE; virtual void OpenMobileSetup() OVERRIDE; + virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE; virtual void ToggleSpokenFeedback() OVERRIDE; virtual AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; virtual void StartPartialScreenshot( diff --git a/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.cc b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.cc index 9bdfb334418e32..68f725e43208de 100644 --- a/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.cc +++ b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h" +#include "ash/screensaver/screensaver_view.h" #include "base/bind.h" #include "base/callback.h" #include "base/lazy_instance.h" @@ -11,7 +12,7 @@ #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/browser/chromeos/ui/screensaver_extension_dialog.h" +#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" @@ -173,7 +174,11 @@ void KioskModeScreensaver::SetupScreensaver( chromeos::DBusThreadManager::Get()-> GetPowerManagerClient()->RequestActiveNotification(); - browser::ShowScreensaverDialog(extension); + // Add the extension to the extension service and display the screensaver. + Profile* default_profile = ProfileManager::GetDefaultProfile(); + default_profile->GetExtensionService()->AddExtension(extension); + + ash::ShowScreensaver(extension->GetFullLaunchURL()); } // NotificationObserver overrides: @@ -188,7 +193,7 @@ void KioskModeScreensaver::Observe( if (power_manager->HasObserver(this)) power_manager->RemoveObserver(this); - browser::CloseScreensaverDialog(); + ash::CloseScreensaver(); ShutdownKioskModeScreensaver(); } @@ -203,7 +208,7 @@ void KioskModeScreensaver::ActiveNotify() { } else { // Remove the screensaver so the user can at least use the underlying // login screen to be able to log in. - browser::CloseScreensaverDialog(); + ash::CloseScreensaver(); } } diff --git a/chrome/browser/chromeos/ui/screensaver_extension_dialog.cc b/chrome/browser/chromeos/ui/screensaver_extension_dialog.cc deleted file mode 100644 index c8bd9e7320c6bf..00000000000000 --- a/chrome/browser/chromeos/ui/screensaver_extension_dialog.cc +++ /dev/null @@ -1,109 +0,0 @@ -// 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/chromeos/ui/screensaver_extension_dialog.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/sessions/restore_tab_helper.h" -#include "chrome/browser/ui/views/extensions/extension_dialog.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_file_util.h" - -using content::BrowserThread; - -namespace { - -ScreensaverExtensionDialog* g_instance = NULL; - -} // namespace - -namespace browser { - -void ShowScreensaverDialog(scoped_refptr extension) { - ScreensaverExtensionDialog::ShowScreensaverDialog(extension); -} - -void CloseScreensaverDialog() { - ScreensaverExtensionDialog::CloseScreensaverDialog(); -} - -} // namespace browser - -// static -void ScreensaverExtensionDialog::ShowScreensaverDialog( - scoped_refptr extension) { - if (!g_instance) - g_instance = new ScreensaverExtensionDialog(extension); - g_instance->Show(); -} - -// static -void ScreensaverExtensionDialog::CloseScreensaverDialog() { - if (g_instance) - g_instance->Close(); -} - -ScreensaverExtensionDialog::ScreensaverExtensionDialog( - scoped_refptr extension) - : screensaver_extension_(extension) { -} - -void ScreensaverExtensionDialog::Show() { - if (!screensaver_extension_) - return; - - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Profile* default_profile = ProfileManager::GetDefaultProfile(); - default_profile->GetExtensionService()->AddExtension(screensaver_extension_); - extension_dialog_ = ExtensionDialog::ShowFullscreen( - screensaver_extension_->GetFullLaunchURL(), - default_profile, - string16(), - this); -} - -void ScreensaverExtensionDialog::Close() { - if (extension_dialog_) { - extension_dialog_->Close(); - extension_dialog_ = NULL; - } -} - -ScreensaverExtensionDialog::~ScreensaverExtensionDialog() { - if (extension_dialog_) - extension_dialog_->ObserverDestroyed(); -} - -void ScreensaverExtensionDialog::ExtensionDialogClosing( - ExtensionDialog* dialog) { - // Release our reference to the dialog to allow it to close. - extension_dialog_ = NULL; -} - -void ScreensaverExtensionDialog::ExtensionTerminated( - ExtensionDialog* dialog) { - // This needs to be run 'slightly' delayed. When we get the extension - // terminated notification, the extension isn't fully unloaded yet. There - // is no good way to get around this. The correct solution will be to - // not need to reload the extension at all - but the current wiring in - // ExtensionViewsHost makes that not possible. - MessageLoop::current()->PostTask(FROM_HERE, - base::Bind(&ScreensaverExtensionDialog::ReloadAndShow, - base::Unretained(this))); - dialog->Close(); -} - -void ScreensaverExtensionDialog::ReloadAndShow() { - ProfileManager::GetDefaultProfile()->GetExtensionService()->ReloadExtension( - screensaver_extension_->id()); - - Show(); -} diff --git a/chrome/browser/chromeos/ui/screensaver_extension_dialog.h b/chrome/browser/chromeos/ui/screensaver_extension_dialog.h deleted file mode 100644 index 6da268383301dd..00000000000000 --- a/chrome/browser/chromeos/ui/screensaver_extension_dialog.h +++ /dev/null @@ -1,58 +0,0 @@ -// 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_CHROMEOS_UI_SCREENSAVER_EXTENSION_DIALOG_H_ -#define CHROME_BROWSER_CHROMEOS_UI_SCREENSAVER_EXTENSION_DIALOG_H_ -#pragma once - -#include "base/memory/ref_counted.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" - -class Extension; -class ExtensionDialog; - -namespace browser { - -void ShowScreensaverDialog(scoped_refptr extension); -void CloseScreensaverDialog(); - -} // namespace browser - -// Shows or hides the screensaver extension in fullscreen mode on -// top of all other windows. -class ScreensaverExtensionDialog : public ExtensionDialogObserver { - public: - static void ShowScreensaverDialog(scoped_refptr extension); - static void CloseScreensaverDialog(); - - // ExtensionDialog::Observer implementation. - virtual void ExtensionDialogClosing(ExtensionDialog* dialog) OVERRIDE; - virtual void ExtensionTerminated(ExtensionDialog* dialog) OVERRIDE; - - protected: - virtual void Show(); - virtual void Close(); - - private: - friend class ScreensaverExtensionDialogBrowserTest; - friend class ScreensaverExtensionDialogTest; - - explicit ScreensaverExtensionDialog(scoped_refptr extension); - virtual ~ScreensaverExtensionDialog(); - - // Reload the screensaver extension and show another screensaver dialog. - void ReloadAndShow(); - - scoped_refptr screensaver_extension_; - // Host for the extension that implements this dialog. - scoped_refptr extension_dialog_; - - // Set while we're loading an extension; only touched from the UI thread. - bool loading_extension_; - - DISALLOW_COPY_AND_ASSIGN(ScreensaverExtensionDialog); -}; - -#endif // CHROME_BROWSER_CHROMEOS_UI_SCREENSAVER_EXTENSION_DIALOG_H_ diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc index 981db9b3fff87f..82ad589df4d76c 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc @@ -90,6 +90,12 @@ class AccessibilityViewsDelegate : public views::ViewsDelegate { } #endif + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE { + return NULL; + } + DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); }; diff --git a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc index 4cc63e4b4579d4..b8514439e94551 100644 --- a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc @@ -191,6 +191,10 @@ void ChromeShellDelegate::OpenMobileSetup() { #endif } +content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() { + return ProfileManager::GetDefaultProfile(); +} + void ChromeShellDelegate::ToggleSpokenFeedback() { #if defined(OS_CHROMEOS) content::WebUI* login_screen_web_ui = NULL; diff --git a/chrome/browser/ui/views/ash/chrome_shell_delegate.h b/chrome/browser/ui/views/ash/chrome_shell_delegate.h index 52a8fa542ccba0..4e9f2435603bba 100644 --- a/chrome/browser/ui/views/ash/chrome_shell_delegate.h +++ b/chrome/browser/ui/views/ash/chrome_shell_delegate.h @@ -42,6 +42,7 @@ class ChromeShellDelegate : public ash::ShellDelegate, virtual void OpenFileManager() OVERRIDE; virtual void OpenCrosh() OVERRIDE; virtual void OpenMobileSetup() OVERRIDE; + virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE; virtual void ToggleSpokenFeedback() OVERRIDE; virtual ash::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; virtual void StartPartialScreenshot( diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index 62465f56b362c3..cb5d34d8d4bf98 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -128,6 +128,12 @@ class ViewsDelegateImpl : public views::ViewsDelegate { } #endif + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE { + return NULL; + } + private: DISALLOW_COPY_AND_ASSIGN(ViewsDelegateImpl); }; diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index 51c573eba2210b..5b6b3e3bf58508 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -170,3 +170,9 @@ views::NativeWidgetHelperAura* ChromeViewsDelegate::CreateNativeWidgetHelper( #endif } #endif + +content::WebContents* ChromeViewsDelegate::CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) { + return NULL; +} diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h index c7e4b7c29a2e26..963150d6be4120 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.h +++ b/chrome/browser/ui/views/chrome_views_delegate.h @@ -51,6 +51,10 @@ class ChromeViewsDelegate : public views::ViewsDelegate { views::NativeWidgetAura* native_widget) OVERRIDE; #endif + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(ChromeViewsDelegate); }; diff --git a/chrome/browser/ui/views/menu_model_adapter_test.cc b/chrome/browser/ui/views/menu_model_adapter_test.cc index 740ec42336df69..98a6683829f9a9 100644 --- a/chrome/browser/ui/views/menu_model_adapter_test.cc +++ b/chrome/browser/ui/views/menu_model_adapter_test.cc @@ -95,6 +95,12 @@ class TestViewsDelegate : public views::ViewsDelegate { } #endif + content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE { + return NULL; + } + private: DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f5274a07efba82..61f394cad52451 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -845,8 +845,6 @@ 'browser/chromeos/ui/brightness_bubble.h', 'browser/chromeos/ui/idle_logout_dialog_view.cc', 'browser/chromeos/ui/idle_logout_dialog_view.h', - 'browser/chromeos/ui/screensaver_extension_dialog.cc', - 'browser/chromeos/ui/screensaver_extension_dialog.h', 'browser/chromeos/ui/setting_level_bubble.cc', 'browser/chromeos/ui/setting_level_bubble.h', 'browser/chromeos/ui/setting_level_bubble_view.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 5c9b46e2e7d434..ec44c8c357c718 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -90,6 +90,8 @@ 'test/test_browser_thread.h', 'test/test_content_client.cc', 'test/test_content_client.h', + 'test/test_content_client_initializer.cc', + 'test/test_content_client_initializer.h', 'test/test_file_error_injector.cc', 'test/test_file_error_injector.h', 'test/test_navigation_observer.cc', @@ -98,6 +100,8 @@ 'test/test_notification_tracker.h', 'test/test_renderer_host.cc', 'test/test_renderer_host.h', + 'test/test_render_view_host_factory.cc', + 'test/test_render_view_host_factory.h', 'test/test_url_fetcher_factory.cc', 'test/test_url_fetcher_factory.h', 'test/test_web_contents_view.cc', diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index 4272a9c47e5046..a81b816b2ac201 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -5,13 +5,11 @@ #include "content/test/content_test_suite.h" #include "base/logging.h" -#include "base/memory/scoped_ptr.h" #include "content/browser/mock_content_browser_client.h" -#include "content/browser/notification_service_impl.h" -#include "content/public/common/content_client.h" #include "content/public/common/content_paths.h" #include "content/public/common/url_constants.h" #include "content/test/test_content_client.h" +#include "content/test/test_content_client_initializer.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/ui_base_paths.h" @@ -20,40 +18,27 @@ #endif #include "ui/gfx/compositor/compositor_setup.h" + namespace { -class TestContentClientInitializer : public testing::EmptyTestEventListener { +class TestInitializationListener : public testing::EmptyTestEventListener { public: - TestContentClientInitializer() { + TestInitializationListener() : test_content_client_initializer_(NULL) { } virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { - notification_service_.reset(new NotificationServiceImpl()); - - DCHECK(!content::GetContentClient()); - content_client_.reset(new TestContentClient); - content::SetContentClient(content_client_.get()); - - content_browser_client_.reset(new content::MockContentBrowserClient()); - content_client_->set_browser(content_browser_client_.get()); + test_content_client_initializer_ = + new content::TestContentClientInitializer(); } virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { - notification_service_.reset(); - - DCHECK_EQ(content_client_.get(), content::GetContentClient()); - content::SetContentClient(NULL); - content_client_.reset(); - - content_browser_client_.reset(); + delete test_content_client_initializer_; } private: - scoped_ptr notification_service_; - scoped_ptr content_client_; - scoped_ptr content_browser_client_; + content::TestContentClientInitializer* test_content_client_initializer_; - DISALLOW_COPY_AND_ASSIGN(TestContentClientInitializer); + DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); }; } // namespace @@ -85,6 +70,6 @@ void ContentTestSuite::Initialize() { testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); - listeners.Append(new TestContentClientInitializer); + listeners.Append(new TestInitializationListener); } diff --git a/content/test/test_content_client_initializer.cc b/content/test/test_content_client_initializer.cc new file mode 100644 index 00000000000000..26cd3aaad5479d --- /dev/null +++ b/content/test/test_content_client_initializer.cc @@ -0,0 +1,35 @@ +// 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 "content/test/test_content_client_initializer.h" + +#include "content/browser/mock_content_browser_client.h" +#include "content/browser/notification_service_impl.h" +#include "content/public/common/content_client.h" +#include "content/test/test_content_client.h" + +namespace content { + +TestContentClientInitializer::TestContentClientInitializer() { + notification_service_.reset(new NotificationServiceImpl()); + + DCHECK(!content::GetContentClient()); + content_client_.reset(new TestContentClient); + content::SetContentClient(content_client_.get()); + + content_browser_client_.reset(new content::MockContentBrowserClient()); + content_client_->set_browser(content_browser_client_.get()); +} + +TestContentClientInitializer::~TestContentClientInitializer() { + notification_service_.reset(); + + DCHECK_EQ(content_client_.get(), content::GetContentClient()); + content::SetContentClient(NULL); + content_client_.reset(); + + content_browser_client_.reset(); +} + +} // namespace content diff --git a/content/test/test_content_client_initializer.h b/content/test/test_content_client_initializer.h new file mode 100644 index 00000000000000..fbbdd80b7b6204 --- /dev/null +++ b/content/test/test_content_client_initializer.h @@ -0,0 +1,37 @@ +// 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 CONTENT_TEST_TEST_CONTENT_CLIENT_INITIALIZER_ +#define CONTENT_TEST_TEST_CONTENT_CLIENT_INITIALIZER_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" + +class NotificationServiceImpl; + +namespace content { + +class ContentClient; +class ContentBrowserClient; + +// Initializes various objects needed to run unit tests that use content:: +// objects. Currently this includes setting up the notification service, +// creating and setting the content client and the content browser client. +class TestContentClientInitializer { + public: + TestContentClientInitializer(); + ~TestContentClientInitializer(); + + private: + scoped_ptr notification_service_; + scoped_ptr content_client_; + scoped_ptr content_browser_client_; + + DISALLOW_COPY_AND_ASSIGN(TestContentClientInitializer); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_CONTENT_CLIENT_INITIALIZER_ diff --git a/content/test/test_render_view_host_factory.cc b/content/test/test_render_view_host_factory.cc new file mode 100644 index 00000000000000..9173dcbdc35a40 --- /dev/null +++ b/content/test/test_render_view_host_factory.cc @@ -0,0 +1,40 @@ +// 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 "content/test/test_render_view_host_factory.h" + +#include "content/browser/renderer_host/test_render_view_host.h" +#include "content/browser/site_instance_impl.h" +#include "content/public/browser/render_process_host_factory.h" + +namespace content { + +TestRenderViewHostFactory::TestRenderViewHostFactory( + content::RenderProcessHostFactory* rph_factory) + : render_process_host_factory_(rph_factory) { + RenderViewHostFactory::RegisterFactory(this); +} + +TestRenderViewHostFactory::~TestRenderViewHostFactory() { + RenderViewHostFactory::UnregisterFactory(); +} + +void TestRenderViewHostFactory::set_render_process_host_factory( + content::RenderProcessHostFactory* rph_factory) { + render_process_host_factory_ = rph_factory; +} + +content::RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost( + SiteInstance* instance, + RenderViewHostDelegate* delegate, + int routing_id, + bool swapped_out, + SessionStorageNamespace* session_storage) { + // See declaration of render_process_host_factory_ below. + static_cast(instance)-> + set_render_process_host_factory(render_process_host_factory_); + return new TestRenderViewHost(instance, delegate, routing_id, swapped_out); +} + +} // namespace content diff --git a/content/test/test_render_view_host_factory.h b/content/test/test_render_view_host_factory.h new file mode 100644 index 00000000000000..c7f05e26e0c6e5 --- /dev/null +++ b/content/test/test_render_view_host_factory.h @@ -0,0 +1,54 @@ +// 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 CONTENT_TEST_TEST_RENDER_VIEW_HOST_FACTORY_H_ +#define CONTENT_TEST_TEST_RENDER_VIEW_HOST_FACTORY_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/browser/renderer_host/render_view_host_factory.h" + +namespace content { + +class SiteInstance; +class RenderViewHostDelegate; +class RenderProcessHostFactory; +class SessionStorageNamespace; + +// Manages creation of the RenderViewHosts using our special subclass. This +// automatically registers itself when it goes in scope, and unregisters itself +// when it goes out of scope. Since you can't have more than one factory +// registered at a time, you can only have one of these objects at a time. +class TestRenderViewHostFactory : public RenderViewHostFactory { + public: + explicit TestRenderViewHostFactory( + content::RenderProcessHostFactory* rph_factory); + virtual ~TestRenderViewHostFactory(); + + virtual void set_render_process_host_factory( + content::RenderProcessHostFactory* rph_factory); + virtual content::RenderViewHost* CreateRenderViewHost( + content::SiteInstance* instance, + content::RenderViewHostDelegate* delegate, + int routing_id, + bool swapped_out, + content::SessionStorageNamespace* session_storage) OVERRIDE; + + private: + // This is a bit of a hack. With the current design of the site instances / + // browsing instances, it's difficult to pass a RenderProcessHostFactory + // around properly. + // + // Instead, we set it right before we create a new RenderViewHost, which + // happens before the RenderProcessHost is created. This way, the instance + // has the correct factory and creates our special RenderProcessHosts. + content::RenderProcessHostFactory* render_process_host_factory_; + + DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_RENDER_VIEW_HOST_FACTORY_H_ diff --git a/content/test/test_renderer_host.cc b/content/test/test_renderer_host.cc index 58d3ac944c2838..0921774ed9ae93 100644 --- a/content/test/test_renderer_host.cc +++ b/content/test/test_renderer_host.cc @@ -12,6 +12,7 @@ #include "content/public/browser/web_contents.h" #include "content/test/mock_render_process_host.h" #include "content/test/test_browser_context.h" +#include "content/test/test_render_view_host_factory.h" #if defined(USE_AURA) #include "ui/aura/env.h" @@ -25,68 +26,6 @@ namespace content { -// Manages creation of the RenderViewHosts using our special subclass. This -// automatically registers itself when it goes in scope, and unregisters itself -// when it goes out of scope. Since you can't have more than one factory -// registered at a time, you can only have one of these objects at a time. -// -// This is an implementation detail of this file and used only via -// RenderViewHostTestEnabler. -class TestRenderViewHostFactory : public RenderViewHostFactory { - public: - explicit TestRenderViewHostFactory( - content::RenderProcessHostFactory* rph_factory); - virtual ~TestRenderViewHostFactory(); - - virtual void set_render_process_host_factory( - content::RenderProcessHostFactory* rph_factory); - virtual content::RenderViewHost* CreateRenderViewHost( - content::SiteInstance* instance, - content::RenderViewHostDelegate* delegate, - int routing_id, - bool swapped_out, - content::SessionStorageNamespace* session_storage) OVERRIDE; - - private: - // This is a bit of a hack. With the current design of the site instances / - // browsing instances, it's difficult to pass a RenderProcessHostFactory - // around properly. - // - // Instead, we set it right before we create a new RenderViewHost, which - // happens before the RenderProcessHost is created. This way, the instance - // has the correct factory and creates our special RenderProcessHosts. - content::RenderProcessHostFactory* render_process_host_factory_; - - DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); -}; - -TestRenderViewHostFactory::TestRenderViewHostFactory( - content::RenderProcessHostFactory* rph_factory) - : render_process_host_factory_(rph_factory) { - RenderViewHostFactory::RegisterFactory(this); -} - -TestRenderViewHostFactory::~TestRenderViewHostFactory() { - RenderViewHostFactory::UnregisterFactory(); -} - -void TestRenderViewHostFactory::set_render_process_host_factory( - content::RenderProcessHostFactory* rph_factory) { - render_process_host_factory_ = rph_factory; -} - -content::RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost( - SiteInstance* instance, - RenderViewHostDelegate* delegate, - int routing_id, - bool swapped_out, - SessionStorageNamespace* session_storage) { - // See declaration of render_process_host_factory_ below. - static_cast(instance)-> - set_render_process_host_factory(render_process_host_factory_); - return new TestRenderViewHost(instance, delegate, routing_id, swapped_out); -} - // static RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { return static_cast(host); diff --git a/ui/views/controls/webview/webview.cc b/ui/views/controls/webview/webview.cc index eb7846ba6c99d3..b6825d15159fd1 100644 --- a/ui/views/controls/webview/webview.cc +++ b/ui/views/controls/webview/webview.cc @@ -17,6 +17,7 @@ #include "ui/base/accessibility/accessibility_types.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/focus/focus_manager.h" +#include "ui/views/views_delegate.h" namespace views { @@ -46,11 +47,7 @@ content::WebContents* WebView::GetWebContents() { void WebView::CreateWebContentsWithSiteInstance( content::SiteInstance* site_instance) { if (!web_contents_) { - wc_owner_.reset(content::WebContents::Create(browser_context_, - site_instance, - MSG_ROUTING_NONE, - NULL, - NULL)); + wc_owner_.reset(CreateWebContents(browser_context_, site_instance)); web_contents_ = wc_owner_.get(); web_contents_->SetDelegate(this); AttachWebContents(); @@ -228,4 +225,24 @@ void WebView::WebContentsDestroyed(content::WebContents* web_contents) { SetWebContents(NULL); } +content::WebContents* WebView::CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) { + content::WebContents* contents = NULL; + if (ViewsDelegate::views_delegate) { + contents = ViewsDelegate::views_delegate->CreateWebContents( + browser_context, site_instance); + } + + if (!contents) { + return content::WebContents::Create(browser_context, + site_instance, + MSG_ROUTING_NONE, + NULL, + NULL); + } + + return contents; +} + } // namespace views diff --git a/ui/views/controls/webview/webview.h b/ui/views/controls/webview/webview.h index 5a73dc967f1677..de6fa7c418ef69 100644 --- a/ui/views/controls/webview/webview.h +++ b/ui/views/controls/webview/webview.h @@ -102,6 +102,13 @@ class VIEWS_EXPORT WebView : public View, content::RenderViewHost* new_host); void WebContentsDestroyed(content::WebContents* web_contents); + // Create a regular or test web contents (based on whether we're running + // in a unit test or not). + content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance); + + NativeViewHost* wcv_holder_; scoped_ptr wc_owner_; content::WebContents* web_contents_; @@ -114,4 +121,4 @@ class VIEWS_EXPORT WebView : public View, } // namespace views -#endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ \ No newline at end of file +#endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ diff --git a/ui/views/test/DEPS b/ui/views/test/DEPS new file mode 100644 index 00000000000000..659b10548bd5a4 --- /dev/null +++ b/ui/views/test/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/test", +] diff --git a/ui/views/test/test_views_delegate.cc b/ui/views/test/test_views_delegate.cc index a8fe51177da391..21ae8ae1105c1e 100644 --- a/ui/views/test/test_views_delegate.cc +++ b/ui/views/test/test_views_delegate.cc @@ -5,6 +5,7 @@ #include "ui/views/test/test_views_delegate.h" #include "base/logging.h" +#include "content/test/web_contents_tester.h" #include "ui/base/clipboard/clipboard.h" namespace views { @@ -64,4 +65,11 @@ views::NativeWidgetHelperAura* TestViewsDelegate::CreateNativeWidgetHelper( } #endif +content::WebContents* TestViewsDelegate::CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) { + return content::WebContentsTester::CreateTestWebContents(browser_context, + site_instance); +} + } // namespace views diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h index 1ea5cdfdc69e35..54ae0be3586b05 100644 --- a/ui/views/test/test_views_delegate.h +++ b/ui/views/test/test_views_delegate.h @@ -64,6 +64,10 @@ class TestViewsDelegate : public ViewsDelegate { views::NativeWidgetAura* native_widget) OVERRIDE; #endif + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE; + private: mutable scoped_ptr clipboard_; bool use_transparent_windows_; diff --git a/ui/views/test/webview_test_helper.cc b/ui/views/test/webview_test_helper.cc new file mode 100644 index 00000000000000..6ff392575863d4 --- /dev/null +++ b/ui/views/test/webview_test_helper.cc @@ -0,0 +1,34 @@ +// 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 "ui/views/test/webview_test_helper.h" + +#include "base/message_loop.h" +#include "content/test/mock_render_process_host.h" +#include "content/test/test_browser_thread.h" +#include "content/test/test_content_client_initializer.h" +#include "content/test/test_render_view_host_factory.h" +#include "ui/views/controls/webview/webview.h" + +namespace views { + +WebViewTestHelper::WebViewTestHelper(MessageLoopForUI* ui_loop) { + test_content_client_initializer_.reset( + new content::TestContentClientInitializer); + + // Setup to register a new RenderViewHost factory which manufactures + // mock render process hosts. This ensures that we never create a 'real' + // render view host since support for it doesn't exist in unit tests. + rph_factory_.reset(new content::MockRenderProcessHostFactory()); + rvh_factory_.reset( + new content::TestRenderViewHostFactory(rph_factory_.get())); + + ui_thread_.reset( + new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); +} + +WebViewTestHelper::~WebViewTestHelper() { +} + +} // namespace views diff --git a/ui/views/test/webview_test_helper.h b/ui/views/test/webview_test_helper.h new file mode 100644 index 00000000000000..9868bcc252f5a7 --- /dev/null +++ b/ui/views/test/webview_test_helper.h @@ -0,0 +1,41 @@ +// 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 UI_VIEWS_TEST_WEB_VIEW_TEST_HELPER_H_ +#define UI_VIEWS_TEST_WEB_VIEW_TEST_HELPER_H_ +#pragma once + +#include "base/memory/scoped_ptr.h" + +class MessageLoopForUI; + +namespace content { +class TestContentClientInitializer; +class TestBrowserThread; +class MockRenderProcessHostFactory; +class TestRenderViewHostFactory; +} // namespace content + +namespace views { + +class WebViewTestHelper { + public: + explicit WebViewTestHelper(MessageLoopForUI* ui_loop); + virtual ~WebViewTestHelper(); + + private: + scoped_ptr + test_content_client_initializer_; + + scoped_ptr ui_thread_; + + scoped_ptr rph_factory_; + scoped_ptr rvh_factory_; + + DISALLOW_COPY_AND_ASSIGN(WebViewTestHelper); +}; + +} // namespace views + +#endif // UI_VIEWS_TEST_WEB_VIEW_TEST_HELPER_H_ diff --git a/ui/views/views.gyp b/ui/views/views.gyp index 7919b8e3625674..e83e467bae8d0a 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -450,6 +450,32 @@ }], ], }, # target_name: views + { + 'target_name': 'test_support_views', + 'type': 'static_library', + 'dependencies': [ + '../../base/base.gyp:base', + '../../content/content.gyp:test_support_content', + '../../ipc/ipc.gyp:test_support_ipc', + '../../net/net.gyp:net_test_support', + '../../skia/skia.gyp:skia', + '../../testing/gtest.gyp:gtest', + '../ui.gyp:ui', + 'views', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'test/test_tooltip_client.h', + 'test/test_views_delegate.cc', + 'test/test_views_delegate.h', + 'test/views_test_base.cc', + 'test/views_test_base.h', + 'test/webview_test_helper.cc', + 'test/webview_test_helper.h', + ], + }, # target_name: test_support_views { 'target_name': 'views_unittests', 'type': 'executable', @@ -473,6 +499,7 @@ '../ui.gyp:ui', '../ui.gyp:ui_resources', '../ui.gyp:ui_resources_standard', + 'test_support_views', 'views', ], 'include_dirs': [ @@ -504,11 +531,6 @@ 'focus/focus_traversal_unittest.cc', 'layout/box_layout_unittest.cc', 'layout/grid_layout_unittest.cc', - 'test/test_tooltip_client.h', - 'test/test_views_delegate.cc', - 'test/test_views_delegate.h', - 'test/views_test_base.cc', - 'test/views_test_base.h', 'view_model_unittest.cc', 'view_model_utils_unittest.cc', 'view_unittest.cc', @@ -655,6 +677,7 @@ '../../chrome/chrome_resources.gyp:packed_resources', '../../content/content.gyp:content_shell_lib', '../../content/content.gyp:content', + '../../content/content.gyp:test_support_content', '../../skia/skia.gyp:skia', '../../third_party/icu/icu.gyp:icui18n', '../../third_party/icu/icu.gyp:icuuc', diff --git a/ui/views/views_delegate.h b/ui/views/views_delegate.h index d1fc739e3c791b..11e38f5ed968c9 100644 --- a/ui/views/views_delegate.h +++ b/ui/views/views_delegate.h @@ -17,6 +17,12 @@ #include "ui/base/ui_base_types.h" #include "ui/views/views_export.h" +namespace content { +class WebContents; +class BrowserContext; +class SiteInstance; +} + namespace gfx { class Rect; } @@ -108,6 +114,11 @@ class VIEWS_EXPORT ViewsDelegate { virtual NativeWidgetHelperAura* CreateNativeWidgetHelper( NativeWidgetAura* native_widget) = 0; #endif + + // Creates a web contents. This will return NULL unless overriden. + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) = 0; }; } // namespace views