diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 22:51:10 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 22:51:10 +0000 |
commit | b0adde16dd13f214d0c718da0fc41c93515596d8 (patch) | |
tree | f27c5b74cf77b1fb77ab5273bb5c8f77ffc09e3f /ui/views/examples | |
parent | 703e4d5ee994674dfcfaec60183879565bdf1011 (diff) | |
download | chromium_src-b0adde16dd13f214d0c718da0fc41c93515596d8.zip chromium_src-b0adde16dd13f214d0c718da0fc41c93515596d8.tar.gz chromium_src-b0adde16dd13f214d0c718da0fc41c93515596d8.tar.bz2 |
Beginnings of a WebView.
http://crbug.com/105557
TEST=none
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=131837
Review URL: https://chromiumcodereview.appspot.com/10024081
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/examples')
-rw-r--r-- | ui/views/examples/DEPS | 4 | ||||
-rw-r--r-- | ui/views/examples/content_client/DEPS | 3 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_browser_main_parts.cc | 123 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_browser_main_parts.h | 75 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_content_browser_client.cc | 373 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_content_browser_client.h | 210 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_main_delegate.cc | 108 | ||||
-rw-r--r-- | ui/views/examples/content_client/examples_main_delegate.h | 64 | ||||
-rw-r--r-- | ui/views/examples/examples_main.cc | 110 | ||||
-rw-r--r-- | ui/views/examples/examples_window.cc | 16 | ||||
-rw-r--r-- | ui/views/examples/examples_window.h | 7 | ||||
-rw-r--r-- | ui/views/examples/webview_example.cc | 41 | ||||
-rw-r--r-- | ui/views/examples/webview_example.h | 40 |
13 files changed, 1072 insertions, 102 deletions
diff --git a/ui/views/examples/DEPS b/ui/views/examples/DEPS new file mode 100644 index 0000000..29f46d3 --- /dev/null +++ b/ui/views/examples/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+content", + "+sandbox", +] diff --git a/ui/views/examples/content_client/DEPS b/ui/views/examples/content_client/DEPS new file mode 100644 index 0000000..60dbcf4 --- /dev/null +++ b/ui/views/examples/content_client/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content", +] diff --git a/ui/views/examples/content_client/examples_browser_main_parts.cc b/ui/views/examples/content_client/examples_browser_main_parts.cc new file mode 100644 index 0000000..62d3686 --- /dev/null +++ b/ui/views/examples/content_client/examples_browser_main_parts.cc @@ -0,0 +1,123 @@ +// 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.h" +#include "base/string_number_conversions.h" +#include "base/threading/thread.h" +#include "base/threading/thread_restrictions.h" +#include "content/public/common/content_switches.h" +#include "content/shell/shell.h" +#include "content/shell/shell_browser_context.h" +#include "content/shell/shell_devtools_delegate.h" +#include "content/shell/shell_switches.h" +#include "googleurl/src/gurl.h" +#include "net/base/net_module.h" +#include "ui/base/clipboard/clipboard.h" +#include "ui/views/examples/examples_window.h" +#include "ui/views/test/test_views_delegate.h" +#include "ui/views/focus/accelerator_handler.h" + +#if defined(USE_AURA) +#include "ui/aura/client/stacking_client.h" +#include "ui/aura/env.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/gfx/compositor/compositor.h" +#include "ui/gfx/compositor/test/compositor_test_support.h" +#include "ui/views/widget/native_widget_aura.h" +#endif + +namespace views { +namespace examples { +namespace { +#if defined(USE_AURA) +class RootWindowStackingClient : public aura::client::StackingClient { + public: + explicit RootWindowStackingClient() { + aura::client::SetStackingClient(this); + } + + virtual ~RootWindowStackingClient() { + aura::client::SetStackingClient(NULL); + } + + // Overridden from aura::client::StackingClient: + virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE { + return window->GetRootWindow(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(RootWindowStackingClient); +}; +#endif +} + +ExamplesBrowserMainParts::ExamplesBrowserMainParts( + const content::MainFunctionParams& parameters) + : BrowserMainParts(), + devtools_delegate_(NULL) { +} + +ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { +} + +#if !defined(OS_MACOSX) +void ExamplesBrowserMainParts::PreMainMessageLoopStart() { +} +#endif + +int ExamplesBrowserMainParts::PreCreateThreads() { + return 0; +} + +void ExamplesBrowserMainParts::PreMainMessageLoopRun() { + browser_context_.reset(new content::ShellBrowserContext); + +#if defined(USE_AURA) + // TURN ON THE HAX. + views::NativeWidgetAura::set_aura_desktop_hax(); + ui::CompositorTestSupport::Initialize(); + root_window_stacking_client_.reset(new RootWindowStackingClient); +#endif + views_delegate_.reset(new views::TestViewsDelegate); + + views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE, + browser_context_.get()); +} + +void ExamplesBrowserMainParts::PostMainMessageLoopRun() { + if (devtools_delegate_) + devtools_delegate_->Stop(); + browser_context_.reset(); + views_delegate_.reset(); +#if defined(USE_AURA) + root_window_stacking_client_.reset(); + aura::Env::DeleteInstance(); + ui::CompositorTestSupport::Terminate(); +#endif +} + +bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { + // xxx: Hax here because this kills event handling. +#if !defined(USE_AURA) + views::AcceleratorHandler accelerator_handler; + MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); +#else + MessageLoopForUI::current()->Run(); +#endif + return true; +} + +ui::Clipboard* ExamplesBrowserMainParts::GetClipboard() { + if (!clipboard_.get()) + clipboard_.reset(new ui::Clipboard()); + return clipboard_.get(); +} + +} // 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 new file mode 100644 index 0000000..bdbcbc9 --- /dev/null +++ b/ui/views/examples/content_client/examples_browser_main_parts.h @@ -0,0 +1,75 @@ +// 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_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_main_parts.h" + +namespace base { +class Thread; +} + +namespace ui { +class Clipboard; +} + +namespace content { + +class ShellBrowserContext; +class ShellDevToolsDelegate; +struct MainFunctionParams; +} + +namespace views { +class ViewsDelegate; +namespace examples { + +class ExamplesBrowserMainParts : public content::BrowserMainParts { + public: + explicit ExamplesBrowserMainParts( + const content::MainFunctionParams& parameters); + virtual ~ExamplesBrowserMainParts(); + + // Overridden from content::BrowserMainParts: + virtual void PreEarlyInitialization() OVERRIDE {} + virtual void PostEarlyInitialization() OVERRIDE {} + virtual void PreMainMessageLoopStart() OVERRIDE; + virtual void PostMainMessageLoopStart() OVERRIDE {} + virtual void ToolkitInitialized() OVERRIDE {} + virtual int PreCreateThreads() OVERRIDE; + virtual void PreMainMessageLoopRun() OVERRIDE; + virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; + virtual void PostMainMessageLoopRun() OVERRIDE; + virtual void PostDestroyThreads() OVERRIDE {} + + ui::Clipboard* GetClipboard(); + content::ShellDevToolsDelegate* devtools_delegate() { + return devtools_delegate_; + } + + content::ShellBrowserContext* browser_context() { + return browser_context_.get(); + } + + private: + scoped_ptr<content::ShellBrowserContext> browser_context_; + + scoped_ptr<ui::Clipboard> clipboard_; + content::ShellDevToolsDelegate* devtools_delegate_; + scoped_ptr<views::ViewsDelegate> views_delegate_; +#if defined(USE_AURA) + scoped_ptr<aura::client::StackingClient> root_window_stacking_client_; +#endif + + 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 new file mode 100644 index 0000000..3dabb91 --- /dev/null +++ b/ui/views/examples/content_client/examples_content_browser_client.cc @@ -0,0 +1,373 @@ +// 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 "base/command_line.h" +#include "base/file_path.h" +#include "content/public/browser/resource_dispatcher_host.h" +#include "content/shell/shell.h" +#include "content/shell/shell_devtools_delegate.h" +#include "content/shell/shell_render_view_host_observer.h" +#include "content/shell/shell_resource_dispatcher_host_delegate.h" +#include "content/shell/shell_switches.h" +#include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkBitmap.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_; +} + +content::WebContentsView* + ExamplesContentBrowserClient::OverrideCreateWebContentsView( + content::WebContents* web_contents) { + return NULL; +} + +content::WebContentsViewDelegate* + ExamplesContentBrowserClient::GetWebContentsViewDelegate( + content::WebContents* web_contents) { + return NULL; +} + +void ExamplesContentBrowserClient::RenderViewHostCreated( + content::RenderViewHost* render_view_host) { + new content::ShellRenderViewHostObserver(render_view_host); +} + +void ExamplesContentBrowserClient::RenderProcessHostCreated( + content::RenderProcessHost* host) { +} + +content::WebUIControllerFactory* + ExamplesContentBrowserClient::GetWebUIControllerFactory() { + return NULL; +} + +GURL ExamplesContentBrowserClient::GetEffectiveURL( + content::BrowserContext* browser_context, const GURL& url) { + return GURL(); +} + +bool ExamplesContentBrowserClient::ShouldUseProcessPerSite( + content::BrowserContext* browser_context, const GURL& effective_url) { + return false; +} + +bool ExamplesContentBrowserClient::IsHandledURL(const GURL& url) { + return false; +} + +bool ExamplesContentBrowserClient::IsSuitableHost( + content::RenderProcessHost* process_host, + const GURL& site_url) { + return true; +} + +bool ExamplesContentBrowserClient::ShouldTryToUseExistingProcessHost( + content::BrowserContext* browser_context, const GURL& url) { + return false; +} + +void ExamplesContentBrowserClient::SiteInstanceGotProcess( + content::SiteInstance* site_instance) { +} + +void ExamplesContentBrowserClient::SiteInstanceDeleting( + content::SiteInstance* site_instance) { +} + +bool ExamplesContentBrowserClient::ShouldSwapProcessesForNavigation( + const GURL& current_url, + const GURL& new_url) { + return false; +} + +std::string ExamplesContentBrowserClient::GetCanonicalEncodingNameByAliasName( + const std::string& alias_name) { + return std::string(); +} + +void ExamplesContentBrowserClient::AppendExtraCommandLineSwitches( + CommandLine* command_line, int child_process_id) { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + command_line->AppendSwitch(switches::kDumpRenderTree); +} + +std::string ExamplesContentBrowserClient::GetApplicationLocale() { + return std::string(); +} + +std::string ExamplesContentBrowserClient::GetAcceptLangs( + content::BrowserContext* context) { + return std::string(); +} + +SkBitmap* ExamplesContentBrowserClient::GetDefaultFavicon() { + static SkBitmap empty; + return ∅ +} + +bool ExamplesContentBrowserClient::AllowAppCache( + const GURL& manifest_url, + const GURL& first_party, + content::ResourceContext* context) { + return true; +} + +bool ExamplesContentBrowserClient::AllowGetCookie( + const GURL& url, + const GURL& first_party, + const net::CookieList& cookie_list, + content::ResourceContext* context, + int render_process_id, + int render_view_id) { + return true; +} + +bool ExamplesContentBrowserClient::AllowSetCookie( + const GURL& url, + const GURL& first_party, + const std::string& cookie_line, + content::ResourceContext* context, + int render_process_id, + int render_view_id, + net::CookieOptions* options) { + return true; +} + +bool ExamplesContentBrowserClient::AllowSaveLocalState( + content::ResourceContext* context) { + return true; +} + +bool ExamplesContentBrowserClient::AllowWorkerDatabase( + const GURL& url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) { + return true; +} + +bool ExamplesContentBrowserClient::AllowWorkerFileSystem( + const GURL& url, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) { + return true; +} + +bool ExamplesContentBrowserClient::AllowWorkerIndexedDB( + const GURL& url, + const string16& name, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) { + return true; +} + +content::QuotaPermissionContext* + ExamplesContentBrowserClient::CreateQuotaPermissionContext() { + return NULL; +} + +net::URLRequestContext* + ExamplesContentBrowserClient::OverrideRequestContextForURL( + const GURL& url, content::ResourceContext* context) { + return NULL; +} + +void ExamplesContentBrowserClient::OpenItem(const FilePath& path) { +} + +void ExamplesContentBrowserClient::ShowItemInFolder(const FilePath& path) { +} + +void ExamplesContentBrowserClient::AllowCertificateError( + int render_process_id, + int render_view_id, + int cert_error, + const net::SSLInfo& ssl_info, + const GURL& request_url, + bool overridable, + const base::Callback<void(bool)>& callback, + bool* cancel_request) { +} + +void ExamplesContentBrowserClient::SelectClientCertificate( + int render_process_id, + int render_view_id, + const net::HttpNetworkSession* network_session, + net::SSLCertRequestInfo* cert_request_info, + const base::Callback<void(net::X509Certificate*)>& callback) { +} + +void ExamplesContentBrowserClient::AddNewCertificate( + net::URLRequest* request, + net::X509Certificate* cert, + int render_process_id, + int render_view_id) { +} + +void ExamplesContentBrowserClient::RequestMediaAccessPermission( + const content::MediaStreamRequest* request, + const content::MediaResponseCallback& callback) { +} + +content::MediaObserver* ExamplesContentBrowserClient::GetMediaObserver() { + return NULL; +} + +void ExamplesContentBrowserClient::RequestDesktopNotificationPermission( + const GURL& source_origin, + int callback_context, + int render_process_id, + int render_view_id) { +} + +WebKit::WebNotificationPresenter::Permission + ExamplesContentBrowserClient::CheckDesktopNotificationPermission( + const GURL& source_origin, + content::ResourceContext* context, + int render_process_id) { + return WebKit::WebNotificationPresenter::PermissionAllowed; +} + +void ExamplesContentBrowserClient::ShowDesktopNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id, + bool worker) { +} + +void ExamplesContentBrowserClient::CancelDesktopNotification( + int render_process_id, + int render_view_id, + int notification_id) { +} + +bool ExamplesContentBrowserClient::CanCreateWindow( + const GURL& opener_url, + const GURL& origin, + WindowContainerType container_type, + content::ResourceContext* context, + int render_process_id, + bool* no_javascript_access) { + *no_javascript_access = false; + return true; +} + +std::string ExamplesContentBrowserClient::GetWorkerProcessTitle( + const GURL& url, content::ResourceContext* context) { + return std::string(); +} + +void ExamplesContentBrowserClient::ResourceDispatcherHostCreated() { + resource_dispatcher_host_delegate_.reset( + new content::ShellResourceDispatcherHostDelegate); + content::ResourceDispatcherHost::Get()->SetDelegate( + resource_dispatcher_host_delegate_.get()); +} + +content::SpeechRecognitionManagerDelegate* + ExamplesContentBrowserClient::GetSpeechRecognitionManagerDelegate() { + return NULL; +} + +ui::Clipboard* ExamplesContentBrowserClient::GetClipboard() { + return examples_browser_main_parts_->GetClipboard(); +} + +net::NetLog* ExamplesContentBrowserClient::GetNetLog() { + return NULL; +} + +content::AccessTokenStore* + ExamplesContentBrowserClient::CreateAccessTokenStore() { + return NULL; +} + +bool ExamplesContentBrowserClient::IsFastShutdownPossible() { + return true; +} + +void ExamplesContentBrowserClient::OverrideWebkitPrefs( + content::RenderViewHost* rvh, + const GURL& url, + WebPreferences* prefs) { +} + +void ExamplesContentBrowserClient::UpdateInspectorSetting( + content::RenderViewHost* rvh, + const std::string& key, + const std::string& value) { +} + +void ExamplesContentBrowserClient::ClearInspectorSettings( + content::RenderViewHost* rvh) { +} + +void ExamplesContentBrowserClient::BrowserURLHandlerCreated( + content::BrowserURLHandler* handler) { +} + +void ExamplesContentBrowserClient::ClearCache(content::RenderViewHost* rvh) { +} + +void ExamplesContentBrowserClient::ClearCookies(content::RenderViewHost* rvh) { +} + +FilePath ExamplesContentBrowserClient::GetDefaultDownloadDirectory() { + return FilePath(); +} + +std::string ExamplesContentBrowserClient::GetDefaultDownloadName() { + return "download"; +} + +bool ExamplesContentBrowserClient::AllowSocketAPI( + content::BrowserContext* browser_context, + const GURL& url) { + return false; +} + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +int ExamplesContentBrowserClient::GetCrashSignalFD( + const CommandLine& command_line) { + return -1; +} +#endif + +#if defined(OS_WIN) +const wchar_t* ExamplesContentBrowserClient::GetResourceDllName() { + return NULL; +} +#endif + +#if defined(USE_NSS) +crypto::CryptoModuleBlockingPasswordDelegate* + ExamplesContentBrowserClient::GetCryptoPasswordDelegate(const GURL& url) { + return NULL; +} +#endif + +content::ShellBrowserContext* ExamplesContentBrowserClient::browser_context() { + return examples_browser_main_parts_->browser_context(); +} + +} // 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 new file mode 100644 index 0000000..6addff2 --- /dev/null +++ b/ui/views/examples/content_client/examples_content_browser_client.h @@ -0,0 +1,210 @@ +// 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_ +#pragma once + +#include <string> + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/content_browser_client.h" + +namespace content { +class ShellBrowserContext; +class ShellBrowserMainParts; +class ShellResourceDispatcherHostDelegate; +} + +namespace views { +namespace examples { + +class ExamplesBrowserMainParts; + +class ExamplesContentBrowserClient : public content::ContentBrowserClient { + public: + ExamplesContentBrowserClient(); + virtual ~ExamplesContentBrowserClient(); + + // Overridden from content::ContentBrowserClient: + virtual content::BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams& parameters) OVERRIDE; + virtual content::WebContentsView* OverrideCreateWebContentsView( + content::WebContents* web_contents) OVERRIDE; + virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( + content::WebContents* web_contents) OVERRIDE; + virtual void RenderViewHostCreated( + content::RenderViewHost* render_view_host) OVERRIDE; + virtual void RenderProcessHostCreated( + content::RenderProcessHost* host) OVERRIDE; + virtual content::WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE; + virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, + const GURL& url) OVERRIDE; + virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, + const GURL& effective_url) OVERRIDE; + virtual bool IsHandledURL(const GURL& url) OVERRIDE; + virtual bool IsSuitableHost(content::RenderProcessHost* process_host, + const GURL& site_url) OVERRIDE; + virtual bool ShouldTryToUseExistingProcessHost( + content::BrowserContext* browser_context, const GURL& url) OVERRIDE; + virtual void SiteInstanceGotProcess( + content::SiteInstance* site_instance) OVERRIDE; + virtual void SiteInstanceDeleting( + content::SiteInstance* site_instance) OVERRIDE; + virtual bool ShouldSwapProcessesForNavigation(const GURL& current_url, + const GURL& new_url) OVERRIDE; + + virtual std::string GetCanonicalEncodingNameByAliasName( + const std::string& alias_name) OVERRIDE; + virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, + int child_process_id) OVERRIDE; + virtual std::string GetApplicationLocale() OVERRIDE; + virtual std::string GetAcceptLangs( + content::BrowserContext* context) OVERRIDE; + virtual SkBitmap* GetDefaultFavicon() OVERRIDE; + virtual bool AllowAppCache(const GURL& manifest_url, + const GURL& first_party, + content::ResourceContext* context) OVERRIDE; + virtual bool AllowGetCookie(const GURL& url, + const GURL& first_party, + const net::CookieList& cookie_list, + content::ResourceContext* context, + int render_process_id, + int render_view_id) OVERRIDE; + virtual bool AllowSetCookie(const GURL& url, + const GURL& first_party, + const std::string& cookie_line, + content::ResourceContext* context, + int render_process_id, + int render_view_id, + net::CookieOptions* options) OVERRIDE; + virtual bool AllowSaveLocalState( + content::ResourceContext* context) OVERRIDE; + virtual bool AllowWorkerDatabase( + const GURL& url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) OVERRIDE; + virtual bool AllowWorkerFileSystem( + const GURL& url, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) OVERRIDE; + virtual bool AllowWorkerIndexedDB( + const GURL& url, + const string16& name, + content::ResourceContext* context, + const std::vector<std::pair<int, int> >& render_views) OVERRIDE; + virtual net::URLRequestContext* OverrideRequestContextForURL( + const GURL& url, content::ResourceContext* context) OVERRIDE; + virtual content::QuotaPermissionContext* + CreateQuotaPermissionContext() OVERRIDE; + virtual void OpenItem(const FilePath& path) OVERRIDE; + virtual void ShowItemInFolder(const FilePath& path) OVERRIDE; + virtual void AllowCertificateError( + int render_process_id, + int render_view_id, + int cert_error, + const net::SSLInfo& ssl_info, + const GURL& request_url, + bool overridable, + const base::Callback<void(bool)>& callback, + bool* cancel_request) OVERRIDE; + virtual void SelectClientCertificate( + int render_process_id, + int render_view_id, + const net::HttpNetworkSession* network_session, + net::SSLCertRequestInfo* cert_request_info, + const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE; + virtual void AddNewCertificate( + net::URLRequest* request, + net::X509Certificate* cert, + int render_process_id, + int render_view_id) OVERRIDE; + virtual void RequestMediaAccessPermission( + const content::MediaStreamRequest* request, + const content::MediaResponseCallback& callback) OVERRIDE; + virtual content::MediaObserver* GetMediaObserver() OVERRIDE; + virtual void RequestDesktopNotificationPermission( + const GURL& source_origin, + int callback_context, + int render_process_id, + int render_view_id) OVERRIDE; + virtual WebKit::WebNotificationPresenter::Permission + CheckDesktopNotificationPermission( + const GURL& origin, + content::ResourceContext* context, + int render_process_id) OVERRIDE; + virtual void ShowDesktopNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id, + bool worker) OVERRIDE; + virtual void CancelDesktopNotification( + int render_process_id, + int render_view_id, + int notification_id) OVERRIDE; + virtual bool CanCreateWindow( + const GURL& opener_url, + const GURL& origin, + WindowContainerType container_type, + content::ResourceContext* context, + int render_process_id, + bool* no_javascript_access) OVERRIDE; + virtual std::string GetWorkerProcessTitle( + const GURL& url, content::ResourceContext* context) OVERRIDE; + virtual void ResourceDispatcherHostCreated() OVERRIDE; + virtual content::SpeechRecognitionManagerDelegate* + GetSpeechRecognitionManagerDelegate() OVERRIDE; + virtual ui::Clipboard* GetClipboard() OVERRIDE; + virtual net::NetLog* GetNetLog() OVERRIDE; + virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE; + virtual bool IsFastShutdownPossible() OVERRIDE; + virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh, + const GURL& url, + WebPreferences* prefs) OVERRIDE; + virtual void UpdateInspectorSetting(content::RenderViewHost* rvh, + const std::string& key, + const std::string& value) OVERRIDE; + virtual void ClearInspectorSettings(content::RenderViewHost* rvh) OVERRIDE; + virtual void BrowserURLHandlerCreated( + content::BrowserURLHandler* handler) OVERRIDE; + virtual void ClearCache(content::RenderViewHost* rvh) OVERRIDE; + virtual void ClearCookies(content::RenderViewHost* rvh) OVERRIDE; + virtual FilePath GetDefaultDownloadDirectory() OVERRIDE; + virtual std::string GetDefaultDownloadName() OVERRIDE; + virtual bool AllowSocketAPI(content::BrowserContext* browser_context, + const GURL& url) OVERRIDE; + +#if defined(OS_POSIX) && !defined(OS_MACOSX) + virtual int GetCrashSignalFD(const CommandLine& command_line) OVERRIDE; +#endif + +#if defined(OS_WIN) + virtual const wchar_t* GetResourceDllName() OVERRIDE; +#endif + +#if defined(USE_NSS) + virtual + crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( + const GURL& url) OVERRIDE; +#endif + + content::ShellBrowserContext* browser_context(); + + private: + scoped_ptr<content::ShellResourceDispatcherHostDelegate> + resource_dispatcher_host_delegate_; + + 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_delegate.cc b/ui/views/examples/content_client/examples_main_delegate.cc new file mode 100644 index 0000000..4e84e67 --- /dev/null +++ b/ui/views/examples/content_client/examples_main_delegate.cc @@ -0,0 +1,108 @@ +// 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 "base/command_line.h" +#include "base/file_path.h" +#include "base/path_service.h" +#include "content/public/browser/browser_main_runner.h" +#include "content/public/common/content_switches.h" +#include "content/shell/shell_content_plugin_client.h" +#include "content/shell/shell_content_renderer_client.h" +#include "content/shell/shell_content_utility_client.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" + +namespace views { +namespace examples { +namespace { + +int ExamplesBrowserMain( + const content::MainFunctionParams& main_function_params) { + scoped_ptr<content::BrowserMainRunner> main_runner( + content::BrowserMainRunner::Create()); + int exit_code = main_runner->Initialize(main_function_params); + if (exit_code >= 0) + return exit_code; + exit_code = main_runner->Run(); + main_runner->Shutdown(); + return exit_code; +} + +} + +ExamplesMainDelegate::ExamplesMainDelegate() { +} + +ExamplesMainDelegate::~ExamplesMainDelegate() { +} + +bool ExamplesMainDelegate::BasicStartupComplete(int* exit_code) { + return false; +} + +void ExamplesMainDelegate::PreSandboxStartup() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + std::string process_type = + command_line.GetSwitchValueASCII(switches::kProcessType); + + content::SetContentClient(&content_client_); + InitializeShellContentClient(process_type); + + InitializeResourceBundle(); +} + +void ExamplesMainDelegate::SandboxInitialized(const std::string& process_type) { +} + +int ExamplesMainDelegate::RunProcess( + const std::string& process_type, + const content::MainFunctionParams& main_function_params) { + if (process_type != "") + return -1; + + return ExamplesBrowserMain(main_function_params); +} + +void ExamplesMainDelegate::ProcessExiting(const std::string& process_type) { +} + +#if defined(OS_POSIX) +content::ZygoteForkDelegate* ExamplesMainDelegate::ZygoteStarting() { + return NULL; +} + +void ExamplesMainDelegate::ZygoteForked() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + std::string process_type = + command_line.GetSwitchValueASCII(switches::kProcessType); + InitializeShellContentClient(process_type); +} +#endif + +void ExamplesMainDelegate::InitializeShellContentClient( + const std::string& process_type) { + if (process_type.empty()) { + browser_client_.reset(new ExamplesContentBrowserClient); + content::GetContentClient()->set_browser(browser_client_.get()); + } else if (process_type == switches::kRendererProcess) { + renderer_client_.reset(new content::ShellContentRendererClient); + content::GetContentClient()->set_renderer(renderer_client_.get()); + } else if (process_type == switches::kPluginProcess) { + plugin_client_.reset(new content::ShellContentPluginClient); + content::GetContentClient()->set_plugin(plugin_client_.get()); + } else if (process_type == switches::kUtilityProcess) { + utility_client_.reset(new content::ShellContentUtilityClient); + content::GetContentClient()->set_utility(utility_client_.get()); + } +} + +void ExamplesMainDelegate::InitializeResourceBundle() { + ui::ResourceBundle::InitSharedInstanceWithLocale("en-US"); +} + +} // 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 new file mode 100644 index 0000000..7945223 --- /dev/null +++ b/ui/views/examples/content_client/examples_main_delegate.h @@ -0,0 +1,64 @@ +// 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_ +#pragma once + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "content/shell/shell_content_client.h" +#include "content/public/app/content_main_delegate.h" + +namespace content { +class ShellContentRendererClient; +class ShellContentPluginClient; +class ShellContentUtilityClient; +} + +namespace views { +namespace examples { + +class ExamplesContentBrowserClient; + +class ExamplesMainDelegate : public content::ContentMainDelegate { + public: + ExamplesMainDelegate(); + virtual ~ExamplesMainDelegate(); + + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; + virtual void PreSandboxStartup() OVERRIDE; + virtual void SandboxInitialized(const std::string& process_type) OVERRIDE; + virtual int RunProcess( + const std::string& process_type, + const content::MainFunctionParams& main_function_params) OVERRIDE; + virtual void ProcessExiting(const std::string& process_type) OVERRIDE; +#if defined(OS_MACOSX) + virtual bool ProcessRegistersWithSystemProcess( + const std::string& process_type) OVERRIDE; + virtual bool ShouldSendMachPort(const std::string& process_type) OVERRIDE; + virtual bool DelaySandboxInitialization( + const std::string& process_type) OVERRIDE; +#elif defined(OS_POSIX) + virtual content::ZygoteForkDelegate* ZygoteStarting() OVERRIDE; + virtual void ZygoteForked() OVERRIDE; +#endif // OS_MACOSX + + private: + void InitializeShellContentClient(const std::string& process_type); + void InitializeResourceBundle(); + + scoped_ptr<ExamplesContentBrowserClient> browser_client_; + scoped_ptr<content::ShellContentRendererClient> renderer_client_; + scoped_ptr<content::ShellContentPluginClient> plugin_client_; + scoped_ptr<content::ShellContentUtilityClient> utility_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_main.cc b/ui/views/examples/examples_main.cc index 699f26f..bd2fbf3 100644 --- a/ui/views/examples/examples_main.cc +++ b/ui/views/examples/examples_main.cc @@ -2,107 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/at_exit.h" -#include "base/command_line.h" -#include "base/i18n/icu_util.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/process_util.h" -#include "base/stl_util.h" -#include "base/utf_string_conversions.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/ui_base_paths.h" -#include "ui/views/examples/examples_window.h" -#include "ui/views/focus/accelerator_handler.h" -#include "ui/views/test/test_views_delegate.h" -#include "ui/views/widget/widget.h" +#include "content/public/app/content_main.h" +#include "sandbox/src/sandbox_types.h" +#include "ui/views/examples/content_client/examples_main_delegate.h" #if defined(OS_WIN) -#include "ui/base/win/scoped_ole_initializer.h" +#include "content/public/app/startup_helper_win.h" #endif -#if defined(USE_AURA) -#include "ui/aura/client/stacking_client.h" -#include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/gfx/compositor/compositor.h" -#include "ui/gfx/compositor/test/compositor_test_support.h" -#include "ui/views/widget/native_widget_aura.h" -#endif - -#if defined(USE_AURA) -class RootWindowStackingClient : public aura::client::StackingClient { - public: - explicit RootWindowStackingClient() { - aura::client::SetStackingClient(this); - } - - virtual ~RootWindowStackingClient() { - aura::client::SetStackingClient(NULL); - } - - // Overridden from aura::client::StackingClient: - virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE { - return window->GetRootWindow(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(RootWindowStackingClient); -}; -#endif - -int main(int argc, char** argv) { #if defined(OS_WIN) - ui::ScopedOleInitializer ole_initializer; -#endif - CommandLine::Init(argc, argv); - - logging::InitLogging(NULL, - logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, - logging::LOCK_LOG_FILE, - logging::DELETE_OLD_LOG_FILE, - logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); - - base::EnableTerminationOnHeapCorruption(); - - // The exit manager is in charge of calling the dtors of singleton objects. - base::AtExitManager exit_manager; - - ui::RegisterPathProvider(); - bool icu_result = icu_util::Initialize(); - CHECK(icu_result); - ui::ResourceBundle::InitSharedInstanceWithLocale("en-US"); - - MessageLoop main_message_loop(MessageLoop::TYPE_UI); -#if defined(USE_AURA) - - // TURN ON THE HAX. - views::NativeWidgetAura::set_aura_desktop_hax(); - - ui::CompositorTestSupport::Initialize(); - - { - RootWindowStackingClient root_window_stacking_client; -#endif - - views::TestViewsDelegate delegate; - - views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE); - - // xxx: Hax here because this kills event handling. -#if !defined(USE_AURA) - views::AcceleratorHandler accelerator_handler; - MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + content::InitializeSandboxInfo(&sandbox_info); + views::examples::ExamplesMainDelegate delegate; + return content::ContentMain(instance, &sandbox_info, &delegate); +} #else - MessageLoopForUI::current()->Run(); -#endif - -#if defined(USE_AURA) - } - aura::Env::DeleteInstance(); - ui::CompositorTestSupport::Terminate(); +int main(int argc, const char** argv) { + views::examples::ExamplesMainDelegate delegate; + return content::ContentMain(argc, argv, &delegate); #endif - - return 0; -} diff --git a/ui/views/examples/examples_window.cc b/ui/views/examples/examples_window.cc index 4d763e6..b78bdd0 100644 --- a/ui/views/examples/examples_window.cc +++ b/ui/views/examples/examples_window.cc @@ -11,6 +11,7 @@ #include "base/process_util.h" #include "base/stl_util.h" #include "base/utf_string_conversions.h" +#include "content/public/browser/browser_context.h" #include "ui/base/models/combobox_model.h" #include "ui/base/ui_base_paths.h" #include "ui/views/controls/button/text_button.h" @@ -37,6 +38,7 @@ #include "ui/views/examples/textfield_example.h" #include "ui/views/examples/throbber_example.h" #include "ui/views/examples/tree_view_example.h" +#include "ui/views/examples/webview_example.h" #include "ui/views/examples/widget_example.h" #include "ui/views/focus/accelerator_handler.h" #include "ui/views/layout/fill_layout.h" @@ -76,11 +78,13 @@ class ComboboxModelExampleList : public ui::ComboboxModel { class ExamplesWindowContents : public WidgetDelegateView, public ComboboxListener { public: - explicit ExamplesWindowContents(Operation operation) +ExamplesWindowContents(Operation operation, + content::BrowserContext* browser_context) : combobox_(new Combobox(&combobox_model_)), example_shown_(new View), status_label_(new Label), - operation_(operation) { + operation_(operation), + browser_context_(browser_context) { instance_ = this; combobox_->set_listener(this); } @@ -178,6 +182,7 @@ class ExamplesWindowContents : public WidgetDelegateView, combobox_model_.AddExample(new TextfieldExample); combobox_model_.AddExample(new ThrobberExample); combobox_model_.AddExample(new TreeViewExample); + combobox_model_.AddExample(new WebViewExample(browser_context_)); combobox_model_.AddExample(new WidgetExample); } @@ -187,6 +192,7 @@ class ExamplesWindowContents : public WidgetDelegateView, View* example_shown_; Label* status_label_; const Operation operation_; + content::BrowserContext* browser_context_; DISALLOW_COPY_AND_ASSIGN(ExamplesWindowContents); }; @@ -194,11 +200,13 @@ class ExamplesWindowContents : public WidgetDelegateView, // static ExamplesWindowContents* ExamplesWindowContents::instance_ = NULL; -void ShowExamplesWindow(Operation operation) { +void ShowExamplesWindow(Operation operation, + content::BrowserContext* browser_context) { if (ExamplesWindowContents::instance()) { ExamplesWindowContents::instance()->GetWidget()->Activate(); } else { - Widget::CreateWindowWithBounds(new ExamplesWindowContents(operation), + Widget::CreateWindowWithBounds(new ExamplesWindowContents(operation, + browser_context), gfx::Rect(0, 0, 850, 300))->Show(); } } diff --git a/ui/views/examples/examples_window.h b/ui/views/examples/examples_window.h index 33a6d6f..cdfe2be 100644 --- a/ui/views/examples/examples_window.h +++ b/ui/views/examples/examples_window.h @@ -6,6 +6,10 @@ #define UI_VIEWS_EXAMPLES_EXAMPLES_WINDOW_H_ #pragma once +namespace content { +class BrowserContext; +} + namespace views { namespace examples { @@ -15,7 +19,8 @@ enum Operation { }; // Shows a window with the views examples in it. -void ShowExamplesWindow(Operation operation); +void ShowExamplesWindow(Operation operation, + content::BrowserContext* browser_context); } // namespace examples } // namespace views diff --git a/ui/views/examples/webview_example.cc b/ui/views/examples/webview_example.cc new file mode 100644 index 0000000..55ae0af --- /dev/null +++ b/ui/views/examples/webview_example.cc @@ -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. + +#include "ui/views/examples/webview_example.h" + +#include "base/utf_string_conversions.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/navigation_controller.h" +#include "grit/ui_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/controls/webview/webview.h" + +namespace views { +namespace examples { + +WebViewExample::WebViewExample(content::BrowserContext* browser_context) + : ExampleBase("WebView"), + webview_(NULL), + browser_context_(browser_context) { +} + +WebViewExample::~WebViewExample() { +} + +void WebViewExample::CreateExampleView(View* container) { + webview_ = new WebView(browser_context_); + container->SetLayoutManager(new FillLayout); + container->AddChildView(webview_); + + webview_->web_contents()->GetController().LoadURL( + GURL("http://www.google.com/"), + content::Referrer(), + content::PAGE_TRANSITION_TYPED, + std::string()); + webview_->web_contents()->Focus(); +} + +} // namespace examples +} // namespace views diff --git a/ui/views/examples/webview_example.h b/ui/views/examples/webview_example.h new file mode 100644 index 0000000..444b7f4 --- /dev/null +++ b/ui/views/examples/webview_example.h @@ -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. + +#ifndef UI_VIEWS_EXAMPLES_WEBVIEW_EXAMPLE_H_ +#define UI_VIEWS_EXAMPLES_WEBVIEW_EXAMPLE_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/views/examples/example_base.h" + +namespace content { +class BrowserContext; +} + +namespace views { +class WebView; + +namespace examples { + +class WebViewExample : public ExampleBase { + public: + explicit WebViewExample(content::BrowserContext* browser_context); + virtual ~WebViewExample(); + + // Overridden from ExampleBase: + virtual void CreateExampleView(View* container) OVERRIDE; + + private: + WebView* webview_; + content::BrowserContext* browser_context_; + + DISALLOW_COPY_AND_ASSIGN(WebViewExample); +}; + +} // namespace examples +} // namespace views + +#endif // UI_VIEWS_EXAMPLES_WEBVIEW_EXAMPLE_H_ |