diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-23 10:50:40 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-23 10:50:40 +0000 |
commit | fc1b688e0dcbfd01aff21d71cf909c1913fda2f8 (patch) | |
tree | fb93027ca5bd1e6fb2eaf8834b85210fe6aec94d /ui/views/examples | |
parent | b3931d5179f58be502f057f115806a934c02f96f (diff) | |
download | chromium_src-fc1b688e0dcbfd01aff21d71cf909c1913fda2f8.zip chromium_src-fc1b688e0dcbfd01aff21d71cf909c1913fda2f8.tar.gz chromium_src-fc1b688e0dcbfd01aff21d71cf909c1913fda2f8.tar.bz2 |
Repurpose views+content example into a generic multiprocess views runtime
This is to facilitate the addition of an app launcher example/demo app,
separate from the browser, and to assist testing of the out-of-process
compositor on mac.
The change splits out from the current views_examples_with_content_exe
target a new views_content_client target placed in
ui/views_content_client. views_examples_with_content_exe is updated to
use it.
This will allow the app launcher to have its own example app, while
reusing the logic to set up the multiprocess runtime environment for
using views and content.
Follow-up patches for the views_content_client runtime will: isolate
aura dependencies, introduce the gpu_process UI compositor, and
implement the runtime environment for mac.
BUG=365977
Review URL: https://codereview.chromium.org/284113011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/examples')
11 files changed, 52 insertions, 435 deletions
diff --git a/ui/views/examples/DEPS b/ui/views/examples/DEPS index 44d965d..06e440bb 100644 --- a/ui/views/examples/DEPS +++ b/ui/views/examples/DEPS @@ -3,4 +3,5 @@ include_rules = [ "+content/shell", "+sandbox", "+ui/gl/gl_surface.h", # To initialize GL bindings. + "+ui/views_content_client", ] diff --git a/ui/views/examples/content_client/DEPS b/ui/views/examples/content_client/DEPS deleted file mode 100644 index f71262e..0000000 --- a/ui/views/examples/content_client/DEPS +++ /dev/null @@ -1,4 +0,0 @@ -include_rules = [ - "+content/public", - "+content/shell", -] diff --git a/ui/views/examples/content_client/examples_browser_main_parts.cc b/ui/views/examples/content_client/examples_browser_main_parts.cc deleted file mode 100644 index 159b931..0000000 --- a/ui/views/examples/content_client/examples_browser_main_parts.cc +++ /dev/null @@ -1,91 +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 "ui/views/examples/content_client/examples_browser_main_parts.h" - -#include "base/bind.h" -#include "base/command_line.h" -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "base/strings/string_number_conversions.h" -#include "base/threading/thread.h" -#include "base/threading/thread_restrictions.h" -#include "content/public/browser/context_factory.h" -#include "content/public/common/content_switches.h" -#include "content/shell/browser/shell_browser_context.h" -#include "ui/aura/env.h" -#include "ui/base/ime/input_method_initializer.h" -#include "ui/gfx/screen.h" -#include "ui/views/examples/examples_window_with_content.h" -#include "ui/views/test/desktop_test_views_delegate.h" -#include "ui/views/widget/native_widget_aura.h" -#include "ui/wm/core/wm_state.h" -#include "url/gurl.h" - -#if defined(OS_CHROMEOS) -#include "ui/aura/test/test_screen.h" -#include "ui/aura/window.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/wm/test/wm_test_helper.h" -#else // !defined(OS_CHROMEOS) -#include "ui/views/widget/desktop_aura/desktop_screen.h" -#endif - -namespace views { -namespace examples { - -ExamplesBrowserMainParts::ExamplesBrowserMainParts( - const content::MainFunctionParams& parameters) { -} - -ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { -} - -void ExamplesBrowserMainParts::ToolkitInitialized() { - wm_state_.reset(new wm::WMState); -} - -void ExamplesBrowserMainParts::PreMainMessageLoopRun() { - ui::InitializeInputMethodForTesting(); - browser_context_.reset(new content::ShellBrowserContext(false, NULL)); - - gfx::NativeView window_context = NULL; -#if defined(OS_CHROMEOS) - gfx::Screen::SetScreenInstance( - gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); - // Set up basic pieces of views::corewm. - wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600), - content::GetContextFactory())); - // Ensure the X window gets mapped. - wm_test_helper_->host()->Show(); - // Ensure Aura knows where to open new windows. - window_context = wm_test_helper_->host()->window(); -#else - aura::Env::CreateInstance(true); - gfx::Screen::SetScreenInstance( - gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen()); -#endif - views_delegate_.reset(new DesktopTestViewsDelegate); - - ShowExamplesWindowWithContent( - QUIT_ON_CLOSE, browser_context_.get(), window_context); -} - -void ExamplesBrowserMainParts::PostMainMessageLoopRun() { - browser_context_.reset(); -#if defined(OS_CHROMEOS) - wm_test_helper_.reset(); -#endif - views_delegate_.reset(); - aura::Env::DeleteInstance(); -} - -bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { - base::RunLoop run_loop; - run_loop.Run(); - return true; -} - -} // namespace examples -} // namespace views diff --git a/ui/views/examples/content_client/examples_browser_main_parts.h b/ui/views/examples/content_client/examples_browser_main_parts.h deleted file mode 100644 index 85ec1c6..0000000 --- a/ui/views/examples/content_client/examples_browser_main_parts.h +++ /dev/null @@ -1,61 +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 UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_ -#define UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_ - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/browser/browser_main_parts.h" - -namespace content { -class ShellBrowserContext; -struct MainFunctionParams; -} - -namespace wm { -class WMState; -class WMTestHelper; -} - -namespace views { -class ViewsDelegate; - -namespace examples { - -class ExamplesBrowserMainParts : public content::BrowserMainParts { - public: - explicit ExamplesBrowserMainParts( - const content::MainFunctionParams& parameters); - virtual ~ExamplesBrowserMainParts(); - - // content::BrowserMainParts: - virtual void ToolkitInitialized() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE; - - content::ShellBrowserContext* browser_context() { - return browser_context_.get(); - } - - private: - scoped_ptr<content::ShellBrowserContext> browser_context_; - - scoped_ptr<ViewsDelegate> views_delegate_; - -#if defined(OS_CHROMEOS) - // Enable a minimal set of views::corewm to be initialized. - scoped_ptr<wm::WMTestHelper> wm_test_helper_; -#endif - - scoped_ptr<wm::WMState> wm_state_; - - DISALLOW_COPY_AND_ASSIGN(ExamplesBrowserMainParts); -}; - -} // namespace examples -} // namespace views - -#endif // UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_ diff --git a/ui/views/examples/content_client/examples_content_browser_client.cc b/ui/views/examples/content_client/examples_content_browser_client.cc deleted file mode 100644 index 6b3b910..0000000 --- a/ui/views/examples/content_client/examples_content_browser_client.cc +++ /dev/null @@ -1,38 +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 "ui/views/examples/content_client/examples_content_browser_client.h" - -#include "content/shell/browser/shell_browser_context.h" -#include "ui/views/examples/content_client/examples_browser_main_parts.h" - -namespace views { -namespace examples { - -ExamplesContentBrowserClient::ExamplesContentBrowserClient() - : examples_browser_main_parts_(NULL) { -} - -ExamplesContentBrowserClient::~ExamplesContentBrowserClient() { -} - -content::BrowserMainParts* ExamplesContentBrowserClient::CreateBrowserMainParts( - const content::MainFunctionParams& parameters) { - examples_browser_main_parts_ = new ExamplesBrowserMainParts(parameters); - return examples_browser_main_parts_; -} - -net::URLRequestContextGetter* -ExamplesContentBrowserClient::CreateRequestContext( - content::BrowserContext* content_browser_context, - content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) { - content::ShellBrowserContext* shell_context = - examples_browser_main_parts_->browser_context(); - return shell_context->CreateRequestContext(protocol_handlers, - protocol_interceptors.Pass()); -} - -} // namespace examples -} // namespace views diff --git a/ui/views/examples/content_client/examples_content_browser_client.h b/ui/views/examples/content_client/examples_content_browser_client.h deleted file mode 100644 index db8824b..0000000 --- a/ui/views/examples/content_client/examples_content_browser_client.h +++ /dev/null @@ -1,42 +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 UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_CONTENT_BROWSER_CLIENT_H_ -#define UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_CONTENT_BROWSER_CLIENT_H_ - -#include "base/macros.h" -#include "content/public/browser/content_browser_client.h" - -namespace content { -class ShellBrowserContext; -} - -namespace views { -namespace examples { - -class ExamplesBrowserMainParts; - -class ExamplesContentBrowserClient : public content::ContentBrowserClient { - public: - ExamplesContentBrowserClient(); - virtual ~ExamplesContentBrowserClient(); - - // content::ContentBrowserClient: - virtual content::BrowserMainParts* CreateBrowserMainParts( - const content::MainFunctionParams& parameters) OVERRIDE; - virtual net::URLRequestContextGetter* CreateRequestContext( - content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE; - - private: - ExamplesBrowserMainParts* examples_browser_main_parts_; - - DISALLOW_COPY_AND_ASSIGN(ExamplesContentBrowserClient); -}; - -} // namespace examples -} // namespace views - -#endif // UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_CONTENT_BROWSER_CLIENT_H_ diff --git a/ui/views/examples/content_client/examples_main.cc b/ui/views/examples/content_client/examples_main.cc deleted file mode 100644 index 5598387..0000000 --- a/ui/views/examples/content_client/examples_main.cc +++ /dev/null @@ -1,32 +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 "content/public/app/content_main.h" -#include "ui/views/examples/content_client/examples_main_delegate.h" - -#if defined(OS_WIN) -#include "content/public/app/startup_helper_win.h" -#include "sandbox/win/src/sandbox_types.h" -#endif - -#if defined(OS_WIN) -int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { -#else -int main(int argc, const char** argv) { -#endif - views::examples::ExamplesMainDelegate delegate; - content::ContentMainParams params(&delegate); - -#if defined(OS_WIN) - sandbox::SandboxInterfaceInfo sandbox_info = {0}; - content::InitializeSandboxInfo(&sandbox_info); - params.instance = instance; - params.sandbox_info = &sandbox_info; -#else - params.argc = argc; - params.argv = argv; -#endif - - return content::ContentMain(params); -} diff --git a/ui/views/examples/content_client/examples_main_delegate.cc b/ui/views/examples/content_client/examples_main_delegate.cc deleted file mode 100644 index 5680ea3..0000000 --- a/ui/views/examples/content_client/examples_main_delegate.cc +++ /dev/null @@ -1,72 +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 "ui/views/examples/content_client/examples_main_delegate.h" - -#include <string> - -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/path_service.h" -#include "content/public/common/content_switches.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/ui_base_paths.h" -#include "ui/views/examples/content_client/examples_content_browser_client.h" - -#if defined(OS_WIN) -#include "base/logging_win.h" -#endif - -namespace views { -namespace examples { -namespace { - -#if defined(OS_WIN) -// {83FAC8EE-7A0E-4dbb-A3F6-6F500D7CAB1A} -const GUID kViewsExamplesProviderName = - { 0x83fac8ee, 0x7a0e, 0x4dbb, - { 0xa3, 0xf6, 0x6f, 0x50, 0xd, 0x7c, 0xab, 0x1a } }; -#endif - -} // namespace - -ExamplesMainDelegate::ExamplesMainDelegate() { -} - -ExamplesMainDelegate::~ExamplesMainDelegate() { -} - -bool ExamplesMainDelegate::BasicStartupComplete(int* exit_code) { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - std::string process_type = - command_line.GetSwitchValueASCII(switches::kProcessType); - - content::SetContentClient(&content_client_); - - logging::LoggingSettings settings; - settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; - bool success = logging::InitLogging(settings); - CHECK(success); -#if defined(OS_WIN) - logging::LogEventProvider::Initialize(kViewsExamplesProviderName); -#endif - - return false; -} - -void ExamplesMainDelegate::PreSandboxStartup() { - base::FilePath ui_test_pak_path; - DCHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); - ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); -} - -content::ContentBrowserClient* - ExamplesMainDelegate::CreateContentBrowserClient() { - browser_client_.reset(new ExamplesContentBrowserClient); - return browser_client_.get(); -} - -} // namespace examples -} // namespace views diff --git a/ui/views/examples/content_client/examples_main_delegate.h b/ui/views/examples/content_client/examples_main_delegate.h deleted file mode 100644 index 1bfd5c3..0000000 --- a/ui/views/examples/content_client/examples_main_delegate.h +++ /dev/null @@ -1,40 +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 UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_MAIN_DELEGATE_H_ -#define UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_MAIN_DELEGATE_H_ - -#include <string> - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/app/content_main_delegate.h" -#include "content/shell/common/shell_content_client.h" - -namespace views { -namespace examples { - -class ExamplesContentBrowserClient; - -class ExamplesMainDelegate : public content::ContentMainDelegate { - public: - ExamplesMainDelegate(); - virtual ~ExamplesMainDelegate(); - - // content::ContentMainDelegate implementation - virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; - virtual void PreSandboxStartup() OVERRIDE; - virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; - - private: - scoped_ptr<ExamplesContentBrowserClient> browser_client_; - content::ShellContentClient content_client_; - - DISALLOW_COPY_AND_ASSIGN(ExamplesMainDelegate); -}; - -} // namespace examples -} // namespace views - -#endif // UI_VIEWS_EXAMPLES_CONTENT_CLIENT_EXAMPLES_MAIN_DELEGATE_H_ diff --git a/ui/views/examples/examples.gyp b/ui/views/examples/examples.gyp index 100d8b9..aa41cd0 100644 --- a/ui/views/examples/examples.gyp +++ b/ui/views/examples/examples.gyp @@ -117,26 +117,14 @@ 'type': '<(component)', 'dependencies': [ '../../../base/base.gyp:base', - '../../../base/base.gyp:base_i18n', '../../../content/content.gyp:content', '../../../skia/skia.gyp:skia', - '../../../third_party/icu/icu.gyp:icui18n', - '../../../third_party/icu/icu.gyp:icuuc', '../../../url/url.gyp:url_lib', - '../../aura/aura.gyp:aura', - '../../base/ui_base.gyp:ui_base', '../../events/events.gyp:events', - '../../gfx/gfx.gyp:gfx', - '../../gfx/gfx.gyp:gfx_geometry', - '../../resources/ui_resources.gyp:ui_resources', - '../../resources/ui_resources.gyp:ui_test_pak', '../controls/webview/webview.gyp:webview', '../views.gyp:views', 'views_examples_lib', ], - 'include_dirs': [ - '../../..', - ], 'defines': [ 'VIEWS_EXAMPLES_WITH_CONTENT_IMPLEMENTATION', ], @@ -147,53 +135,19 @@ 'webview_example.cc', 'webview_example.h', ], - 'conditions': [ - ['OS=="win"', { - 'include_dirs': [ - '../../../third_party/wtl/include', - ], - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - 'msvs_disabled_warnings': [ 4267, ], - }], - ], }, # target_name: views_examples_with_content_lib { 'target_name': 'views_examples_with_content_exe', 'type': 'executable', 'dependencies': [ '../../../base/base.gyp:base', - '../../../base/base.gyp:base_i18n', '../../../content/content.gyp:content', - '../../../content/content_shell_and_tests.gyp:content_shell_lib', - '../../../content/content_shell_and_tests.gyp:test_support_content', - '../../../skia/skia.gyp:skia', - '../../../third_party/icu/icu.gyp:icui18n', - '../../../third_party/icu/icu.gyp:icuuc', - '../../aura/aura.gyp:aura', - '../../base/ui_base.gyp:ui_base', - '../../compositor/compositor.gyp:compositor', - '../../events/events.gyp:events', - '../../gfx/gfx.gyp:gfx', - '../../gfx/gfx.gyp:gfx_geometry', - '../../resources/ui_resources.gyp:ui_resources', - '../../resources/ui_resources.gyp:ui_test_pak', - '../../wm/wm.gyp:wm_test_support', - '../views.gyp:views', - '../views.gyp:views_test_support', + '../../views_content_client/views_content_client.gyp:views_content_client', 'views_examples_with_content_lib', ], - 'include_dirs': [ - '../../..', - ], 'sources': [ '../../../content/app/startup_helper_win.cc', - 'content_client/examples_browser_main_parts.cc', - 'content_client/examples_browser_main_parts.h', - 'content_client/examples_content_browser_client.cc', - 'content_client/examples_content_browser_client.h', - 'content_client/examples_main_delegate.cc', - 'content_client/examples_main_delegate.h', - 'content_client/examples_main.cc', + 'examples_with_content_main_exe.cc', ], 'conditions': [ ['OS=="win"', { @@ -217,13 +171,6 @@ '../../../sandbox/sandbox.gyp:sandbox', ], }], - ['OS=="win"', { - 'sources/': [ - # This is needed because the aura rule strips it from the default - # sources list. - ['include', '^../../../content/app/startup_helper_win.cc'], - ], - }], ], }, # target_name: views_examples_with_content_exe ], diff --git a/ui/views/examples/examples_with_content_main_exe.cc b/ui/views/examples/examples_with_content_main_exe.cc new file mode 100644 index 0000000..8df1dec --- /dev/null +++ b/ui/views/examples/examples_with_content_main_exe.cc @@ -0,0 +1,49 @@ +// 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 "base/bind.h" +#include "content/public/browser/browser_context.h" +#include "ui/views/examples/examples_window_with_content.h" +#include "ui/views_content_client/views_content_client.h" + +#if defined(OS_WIN) +#include "content/public/app/startup_helper_win.h" +#include "sandbox/win/src/sandbox_types.h" +#endif + +namespace { + +void ShowContentExampleWindow(content::BrowserContext* browser_context, + gfx::NativeView window_context) { + views::examples::ShowExamplesWindowWithContent(views::examples::QUIT_ON_CLOSE, + browser_context, + window_context); + + // These lines serve no purpose other than to introduce an explicit content + // dependency. If the main executable doesn't have this dependency, the linker + // has more flexibility to reorder library dependencies in a shared component + // build. On linux, this can cause libc to appear before libcontent in the + // dlsym search path, which breaks (usually valid) assumptions made in + // sandbox::InitLibcUrandomOverrides(). See http://crbug.com/374712. + if (!browser_context) { + content::BrowserContext::SaveSessionState(NULL); + NOTREACHED(); + } +} + +} // namespace + +#if defined(OS_WIN) +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + content::InitializeSandboxInfo(&sandbox_info); + ui::ViewsContentClient views_content_client(instance, &sandbox_info); +#else +int main(int argc, const char** argv) { + ui::ViewsContentClient views_content_client(argc, argv); +#endif + + views_content_client.set_task(base::Bind(&ShowContentExampleWindow)); + return views_content_client.RunMain(); +} |