summaryrefslogtreecommitdiffstats
path: root/ui/views
diff options
context:
space:
mode:
authorrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 17:20:18 +0000
committerrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 17:20:18 +0000
commitd54f8a4a7b186b3fdcfcee666b8fadd16f575576 (patch)
tree4181b434ebcdd7749b4895fabf913c50c48806d3 /ui/views
parentfcec95ae1cd54e26944bc8821d8356642662e64e (diff)
downloadchromium_src-d54f8a4a7b186b3fdcfcee666b8fadd16f575576.zip
chromium_src-d54f8a4a7b186b3fdcfcee666b8fadd16f575576.tar.gz
chromium_src-d54f8a4a7b186b3fdcfcee666b8fadd16f575576.tar.bz2
Re-implement the screensaver to use WebView instead of ExtensionDialogHost.
Use WebView to render the screensaver extension instead of ExtensionDialogHost. Using the RenderViewGone override to detect termination of the renderer process to restart it. Added browser tests. R=ben@chromium.org,sky@chromium.org BUG=chromium-os:28211 TEST=Tested that the screensaver comes up; tested the reload via crashing the extension renderer with SIG_ABRT; also ran browser tests. Review URL: https://chromiumcodereview.appspot.com/10191010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r--ui/views/controls/webview/webview.cc27
-rw-r--r--ui/views/controls/webview/webview.h9
-rw-r--r--ui/views/test/DEPS3
-rw-r--r--ui/views/test/test_views_delegate.cc8
-rw-r--r--ui/views/test/test_views_delegate.h4
-rw-r--r--ui/views/test/webview_test_helper.cc34
-rw-r--r--ui/views/test/webview_test_helper.h41
-rw-r--r--ui/views/views.gyp33
-rw-r--r--ui/views/views_delegate.h11
9 files changed, 159 insertions, 11 deletions
diff --git a/ui/views/controls/webview/webview.cc b/ui/views/controls/webview/webview.cc
index eb7846b..b6825d1 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 5a73dc9..de6fa7c 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<content::WebContents> 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 0000000..659b105
--- /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 a8fe511..21ae8ae 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 1ea5cdf..54ae0be 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<ui::Clipboard> 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 0000000..6ff3925
--- /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 0000000..9868bcc
--- /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<content::TestContentClientInitializer>
+ test_content_client_initializer_;
+
+ scoped_ptr<content::TestBrowserThread> ui_thread_;
+
+ scoped_ptr<content::MockRenderProcessHostFactory> rph_factory_;
+ scoped_ptr<content::TestRenderViewHostFactory> 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 7919b8e..e83e467 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -451,6 +451,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',
'dependencies': [
@@ -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 d1fc739..11e38f5 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