From 556a723898f50c02e6453a0aa5836cd6ba864877 Mon Sep 17 00:00:00 2001 From: tfarina <tfarina@chromium.org> Date: Sat, 4 Oct 2014 18:02:09 -0700 Subject: content: Rename all classes with WebKitPlatform to BlinkPlatform. BUG=359244 TEST=None R=avi@chromium.org Review URL: https://codereview.chromium.org/628793003 Cr-Commit-Position: refs/heads/master@{#298176} --- content/browser/android/content_view_statics.cc | 2 +- .../browser/net/view_blob_internals_job_factory.h | 5 +- content/browser/renderer_host/sandbox_ipc_linux.cc | 8 +- content/browser/renderer_host/sandbox_ipc_linux.h | 2 +- content/child/database_util.h | 5 +- content/child/resource_loader_bridge.h | 5 +- content/common/gpu/gpu_command_buffer_stub.cc | 2 +- content/content_ppapi_plugin.gypi | 4 +- content/content_renderer.gypi | 4 +- content/content_tests.gypi | 4 +- content/plugin/plugin_thread.cc | 6 +- content/plugin/plugin_thread.h | 2 +- content/ppapi_plugin/BUILD.gn | 4 +- content/ppapi_plugin/ppapi_blink_platform_impl.cc | 263 +++++ content/ppapi_plugin/ppapi_blink_platform_impl.h | 62 + content/ppapi_plugin/ppapi_thread.cc | 8 +- content/ppapi_plugin/ppapi_thread.h | 6 +- .../ppapi_webkitplatformsupport_impl.cc | 261 ----- .../ppapi_webkitplatformsupport_impl.h | 62 - content/public/test/layouttest_support.h | 6 +- content/public/test/render_view_test.cc | 24 +- content/public/test/render_view_test.h | 17 +- content/public/test/unittest_test_suite.cc | 6 +- content/public/test/unittest_test_suite.h | 4 +- content/renderer/gamepad_shared_memory_reader.cc | 2 +- content/renderer/render_thread_impl.cc | 38 +- content/renderer/render_thread_impl.h | 12 +- content/renderer/render_widget.cc | 2 +- content/renderer/renderer_blink_platform_impl.cc | 1180 +++++++++++++++++++ content/renderer/renderer_blink_platform_impl.h | 247 ++++ .../renderer_webkitplatformsupport_impl.cc | 1196 -------------------- .../renderer/renderer_webkitplatformsupport_impl.h | 248 ---- content/test/blink_test_environment.cc | 12 +- content/test/layouttest_support.cc | 19 +- content/test/test_blink_web_unit_test_support.cc | 307 +++++ content/test/test_blink_web_unit_test_support.h | 111 ++ content/test/test_webkit_platform_support.cc | 305 ----- content/test/test_webkit_platform_support.h | 111 -- .../test/web_layer_tree_view_impl_for_testing.cc | 2 +- content/test/weburl_loader_mock_factory.h | 2 +- content/utility/utility_thread_impl.cc | 4 +- content/utility/utility_thread_impl.h | 2 +- 42 files changed, 2279 insertions(+), 2293 deletions(-) create mode 100644 content/ppapi_plugin/ppapi_blink_platform_impl.cc create mode 100644 content/ppapi_plugin/ppapi_blink_platform_impl.h delete mode 100644 content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc delete mode 100644 content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h create mode 100644 content/renderer/renderer_blink_platform_impl.cc create mode 100644 content/renderer/renderer_blink_platform_impl.h delete mode 100644 content/renderer/renderer_webkitplatformsupport_impl.cc delete mode 100644 content/renderer/renderer_webkitplatformsupport_impl.h create mode 100644 content/test/test_blink_web_unit_test_support.cc create mode 100644 content/test/test_blink_web_unit_test_support.h delete mode 100644 content/test/test_webkit_platform_support.cc delete mode 100644 content/test/test_webkit_platform_support.h diff --git a/content/browser/android/content_view_statics.cc b/content/browser/android/content_view_statics.cc index 00b5600..48dfe7f 100644 --- a/content/browser/android/content_view_statics.cc +++ b/content/browser/android/content_view_statics.cc @@ -32,7 +32,7 @@ namespace { // This tracks the renderer processes that received a suspend request. It's // important on resume to only resume the renderer processes that were actually // suspended as opposed to all the current renderer processes because the -// suspend calls are refcounted within WebKitPlatformSupport and it expects a +// suspend calls are refcounted within BlinkPlatformImpl and it expects a // perfectly matched number of resume calls. // Note that this class is only accessed from the UI thread. class SuspendedProcessWatcher : public content::RenderProcessHostObserver { diff --git a/content/browser/net/view_blob_internals_job_factory.h b/content/browser/net/view_blob_internals_job_factory.h index b1aaaf7..cc8bd14 100644 --- a/content/browser/net/view_blob_internals_job_factory.h +++ b/content/browser/net/view_blob_internals_job_factory.h @@ -9,10 +9,11 @@ namespace net { class NetworkDelegate; class URLRequest; class URLRequestJob; -} // namespace net +} + namespace storage { class BlobStorageContext; -} // webkit_blob +} class GURL; diff --git a/content/browser/renderer_host/sandbox_ipc_linux.cc b/content/browser/renderer_host/sandbox_ipc_linux.cc index b2dd3f8..b2e024e 100644 --- a/content/browser/renderer_host/sandbox_ipc_linux.cc +++ b/content/browser/renderer_host/sandbox_ipc_linux.cc @@ -443,7 +443,7 @@ void SandboxIPCHandler::SendRendererReply( SandboxIPCHandler::~SandboxIPCHandler() { paths_.deleteAll(); - if (webkit_platform_support_) + if (blink_platform_impl_) blink::shutdownWithoutV8(); if (IGNORE_EINTR(close(lifeline_fd_)) < 0) @@ -453,10 +453,10 @@ SandboxIPCHandler::~SandboxIPCHandler() { } void SandboxIPCHandler::EnsureWebKitInitialized() { - if (webkit_platform_support_) + if (blink_platform_impl_) return; - webkit_platform_support_.reset(new BlinkPlatformImpl); - blink::initializeWithoutV8(webkit_platform_support_.get()); + blink_platform_impl_.reset(new BlinkPlatformImpl); + blink::initializeWithoutV8(blink_platform_impl_.get()); } } // namespace content diff --git a/content/browser/renderer_host/sandbox_ipc_linux.h b/content/browser/renderer_host/sandbox_ipc_linux.h index fc986a6..4c39a31 100644 --- a/content/browser/renderer_host/sandbox_ipc_linux.h +++ b/content/browser/renderer_host/sandbox_ipc_linux.h @@ -76,7 +76,7 @@ class SandboxIPCHandler : public base::DelegateSimpleThread::Delegate { const int lifeline_fd_; const int browser_socket_; - scoped_ptr<BlinkPlatformImpl> webkit_platform_support_; + scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; SkTDArray<SkString*> paths_; DISALLOW_COPY_AND_ASSIGN(SandboxIPCHandler); diff --git a/content/child/database_util.h b/content/child/database_util.h index 8be607c..c53e7ce 100644 --- a/content/child/database_util.h +++ b/content/child/database_util.h @@ -12,8 +12,9 @@ class SyncMessageFilter; } namespace content { -// A class of utility functions used by RendererWebKitPlatformSupportImpl and -// WorkerWebKitPlatformSupportImpl to handle database file accesses. + +// A class of utility functions used by RendererBlinkPlatformImpl to handle +// database file accesses. class DatabaseUtil { public: static blink::Platform::FileHandle DatabaseOpenFile( diff --git a/content/child/resource_loader_bridge.h b/content/child/resource_loader_bridge.h index 7dbc48d..759f832 100644 --- a/content/child/resource_loader_bridge.h +++ b/content/child/resource_loader_bridge.h @@ -35,7 +35,7 @@ struct SyncLoadResponse; // now that it lives in content/. class CONTENT_EXPORT ResourceLoaderBridge { public: - // use WebKitPlatformSupportImpl::CreateResourceLoader() for construction, but + // use BlinkPlatformImpl::CreateResourceLoader() for construction, but // anybody can delete at any time, INCLUDING during processing of callbacks. virtual ~ResourceLoaderBridge(); @@ -78,8 +78,7 @@ class CONTENT_EXPORT ResourceLoaderBridge { virtual void SyncLoad(SyncLoadResponse* response) = 0; protected: - // Construction must go through - // WebKitPlatformSupportImpl::CreateResourceLoader() + // Construction must go through BlinkPlatformImpl::CreateResourceLoader(). // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload // methods may be called to construct the body of the request. ResourceLoaderBridge(); diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index 94d6874..13df96f 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -91,7 +91,7 @@ class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker { // url_hash matches. void FastSetActiveURL(const GURL& url, size_t url_hash) { // Leave the previously set URL in the empty case -- empty URLs are given by - // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the + // BlinkPlatformImpl::createOffscreenGraphicsContext3D. Hopefully the // onscreen context URL was set previously and will show up even when a crash // occurs during offscreen command processing. if (url.is_empty()) diff --git a/content/content_ppapi_plugin.gypi b/content/content_ppapi_plugin.gypi index 2376b80..8731034 100644 --- a/content/content_ppapi_plugin.gypi +++ b/content/content_ppapi_plugin.gypi @@ -19,12 +19,12 @@ 'ppapi_plugin/broker_process_dispatcher.h', 'ppapi_plugin/plugin_process_dispatcher.cc', 'ppapi_plugin/plugin_process_dispatcher.h', + 'ppapi_plugin/ppapi_blink_platform_impl.cc', + 'ppapi_plugin/ppapi_blink_platform_impl.h', 'ppapi_plugin/ppapi_broker_main.cc', 'ppapi_plugin/ppapi_plugin_main.cc', 'ppapi_plugin/ppapi_thread.cc', 'ppapi_plugin/ppapi_thread.h', - 'ppapi_plugin/ppapi_webkitplatformsupport_impl.cc', - 'ppapi_plugin/ppapi_webkitplatformsupport_impl.h', ], 'include_dirs': [ '..', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 7ad20e5..78edaf8 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -340,6 +340,8 @@ 'renderer/render_widget.h', 'renderer/render_widget_fullscreen.cc', 'renderer/render_widget_fullscreen.h', + 'renderer/renderer_blink_platform_impl.cc', + 'renderer/renderer_blink_platform_impl.h', 'renderer/renderer_clipboard_client.cc', 'renderer/renderer_clipboard_client.h', 'renderer/renderer_font_platform_win.cc', @@ -356,8 +358,6 @@ 'renderer/renderer_webcolorchooser_impl.h', 'renderer/renderer_webcookiejar_impl.cc', 'renderer/renderer_webcookiejar_impl.h', - 'renderer/renderer_webkitplatformsupport_impl.cc', - 'renderer/renderer_webkitplatformsupport_impl.h', 'renderer/resizing_mode_selector.cc', 'renderer/resizing_mode_selector.h', 'renderer/sad_plugin.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index d26c798..56b6f71 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -130,6 +130,8 @@ 'test/net/url_request_slow_download_job.h', 'test/ppapi_unittest.cc', 'test/ppapi_unittest.h', + 'test/test_blink_web_unit_test_support.cc', + 'test/test_blink_web_unit_test_support.h', 'test/test_content_browser_client.cc', 'test/test_content_browser_client.h', 'test/test_content_client.cc', @@ -146,8 +148,6 @@ 'test/test_render_view_host_factory.h', 'test/test_web_contents.cc', 'test/test_web_contents.h', - 'test/test_webkit_platform_support.cc', - 'test/test_webkit_platform_support.h', 'test/web_gesture_curve_mock.cc', 'test/web_gesture_curve_mock.h', 'test/web_layer_tree_view_impl_for_testing.cc', diff --git a/content/plugin/plugin_thread.cc b/content/plugin/plugin_thread.cc index bec0f98..ddef4ee8 100644 --- a/content/plugin/plugin_thread.cc +++ b/content/plugin/plugin_thread.cc @@ -93,9 +93,9 @@ PluginThread::PluginThread() channel()->AddFilter(new EnsureTerminateMessageFilter()); - // This is needed because we call some code which uses WebKit strings. - webkit_platform_support_.reset(new BlinkPlatformImpl); - blink::initialize(webkit_platform_support_.get()); + // This is needed because we call some code which uses Blink strings. + blink_platform_impl_.reset(new BlinkPlatformImpl); + blink::initialize(blink_platform_impl_.get()); } PluginThread::~PluginThread() { diff --git a/content/plugin/plugin_thread.h b/content/plugin/plugin_thread.h index f76cfa1..55c498a 100644 --- a/content/plugin/plugin_thread.h +++ b/content/plugin/plugin_thread.h @@ -52,7 +52,7 @@ class PluginThread : public ChildThread { bool forcefully_terminate_plugin_process_; - scoped_ptr<BlinkPlatformImpl> webkit_platform_support_; + scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; DISALLOW_COPY_AND_ASSIGN(PluginThread); }; diff --git a/content/ppapi_plugin/BUILD.gn b/content/ppapi_plugin/BUILD.gn index 6c111ec..eff00a52 100644 --- a/content/ppapi_plugin/BUILD.gn +++ b/content/ppapi_plugin/BUILD.gn @@ -10,12 +10,12 @@ source_set("ppapi_plugin") { "broker_process_dispatcher.h", "plugin_process_dispatcher.cc", "plugin_process_dispatcher.h", + "ppapi_blink_platform_impl.cc", + "ppapi_blink_platform_impl.h", "ppapi_broker_main.cc", "ppapi_plugin_main.cc", "ppapi_thread.cc", "ppapi_thread.h", - "ppapi_webkitplatformsupport_impl.cc", - "ppapi_webkitplatformsupport_impl.h", ] configs += [ "//content:content_implementation" ] diff --git a/content/ppapi_plugin/ppapi_blink_platform_impl.cc b/content/ppapi_plugin/ppapi_blink_platform_impl.cc new file mode 100644 index 0000000..0904975 --- /dev/null +++ b/content/ppapi_plugin/ppapi_blink_platform_impl.cc @@ -0,0 +1,263 @@ +// 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/ppapi_plugin/ppapi_blink_platform_impl.h" + +#include <map> + +#include "base/logging.h" +#include "base/strings/string16.h" +#include "base/threading/platform_thread.h" +#include "build/build_config.h" +#include "content/child/child_thread.h" +#include "content/common/child_process_messages.h" +#include "ppapi/proxy/plugin_globals.h" +#include "ppapi/shared_impl/proxy_lock.h" +#include "third_party/WebKit/public/platform/WebString.h" + +#if defined(OS_WIN) +#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" +#elif defined(OS_MACOSX) +#include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h" +#elif defined(OS_ANDROID) +#include "third_party/WebKit/public/platform/android/WebSandboxSupport.h" +#elif defined(OS_POSIX) +#include "content/common/child_process_sandbox_support_impl_linux.h" +#include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" +#include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" +#include "third_party/icu/source/common/unicode/utf16.h" +#endif + +using blink::WebSandboxSupport; +using blink::WebString; +using blink::WebUChar; +using blink::WebUChar32; + +typedef struct CGFont* CGFontRef; + +namespace content { + +class PpapiBlinkPlatformImpl::SandboxSupport : public WebSandboxSupport { + public: + virtual ~SandboxSupport() {} + +#if defined(OS_WIN) + virtual bool ensureFontLoaded(HFONT); +#elif defined(OS_MACOSX) + virtual bool loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID); +#elif defined(OS_ANDROID) + // Empty class. +#elif defined(OS_POSIX) + SandboxSupport(); + virtual void getFallbackFontForCharacter( + WebUChar32 character, + const char* preferred_locale, + blink::WebFallbackFont* fallbackFont); + virtual void getRenderStyleForStrike(const char* family, + int sizeAndStyle, + blink::WebFontRenderStyle* out); + + private: + // WebKit likes to ask us for the correct font family to use for a set of + // unicode code points. It needs this information frequently so we cache it + // here. + std::map<int32_t, blink::WebFallbackFont> unicode_font_families_; + // For debugging crbug.com/312965 + base::PlatformThreadId creation_thread_; +#endif +}; + +#if defined(OS_WIN) + +bool PpapiBlinkPlatformImpl::SandboxSupport::ensureFontLoaded(HFONT font) { + LOGFONT logfont; + GetObject(font, sizeof(LOGFONT), &logfont); + + // Use the proxy sender rather than going directly to the ChildThread since + // the proxy browser sender will properly unlock during sync messages. + return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send( + new ChildProcessHostMsg_PreCacheFont(logfont)); +} + +#elif defined(OS_MACOSX) + +bool PpapiBlinkPlatformImpl::SandboxSupport::loadFont(NSFont* src_font, + CGFontRef* out, + uint32_t* font_id) { + // TODO(brettw) this should do the something similar to what + // RendererBlinkPlatformImpl does and request that the browser load the font. + // Note: need to unlock the proxy lock like ensureFontLoaded does. + NOTIMPLEMENTED(); + return false; +} + +#elif defined(OS_ANDROID) + +// Empty class. + +#elif defined(OS_POSIX) + +PpapiBlinkPlatformImpl::SandboxSupport::SandboxSupport() + : creation_thread_(base::PlatformThread::CurrentId()) { +} + +void PpapiBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter( + WebUChar32 character, + const char* preferred_locale, + blink::WebFallbackFont* fallbackFont) { + ppapi::ProxyLock::AssertAcquired(); + // For debugging crbug.com/312965 + CHECK_EQ(creation_thread_, base::PlatformThread::CurrentId()); + const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter = + unicode_font_families_.find(character); + if (iter != unicode_font_families_.end()) { + fallbackFont->name = iter->second.name; + fallbackFont->filename = iter->second.filename; + fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId; + fallbackFont->ttcIndex = iter->second.ttcIndex; + fallbackFont->isBold = iter->second.isBold; + fallbackFont->isItalic = iter->second.isItalic; + return; + } + + GetFallbackFontForCharacter(character, preferred_locale, fallbackFont); + unicode_font_families_.insert(std::make_pair(character, *fallbackFont)); +} + +void PpapiBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike( + const char* family, + int sizeAndStyle, + blink::WebFontRenderStyle* out) { + GetRenderStyleForStrike(family, sizeAndStyle, out); +} + +#endif + +PpapiBlinkPlatformImpl::PpapiBlinkPlatformImpl() + : sandbox_support_(new PpapiBlinkPlatformImpl::SandboxSupport()) { +} + +PpapiBlinkPlatformImpl::~PpapiBlinkPlatformImpl() { +} + +void PpapiBlinkPlatformImpl::Shutdown() { + // SandboxSupport contains a map of WebFontFamily objects, which hold + // WebCStrings, which become invalidated when blink is shut down. Hence, we + // need to clear that map now, just before blink::shutdown() is called. + sandbox_support_.reset(); +} + +blink::WebClipboard* PpapiBlinkPlatformImpl::clipboard() { + NOTREACHED(); + return NULL; +} + +blink::WebMimeRegistry* PpapiBlinkPlatformImpl::mimeRegistry() { + NOTREACHED(); + return NULL; +} + +blink::WebFileUtilities* PpapiBlinkPlatformImpl::fileUtilities() { + NOTREACHED(); + return NULL; +} + +blink::WebSandboxSupport* PpapiBlinkPlatformImpl::sandboxSupport() { + return sandbox_support_.get(); +} + +bool PpapiBlinkPlatformImpl::sandboxEnabled() { + return true; // Assume PPAPI is always sandboxed. +} + +unsigned long long PpapiBlinkPlatformImpl::visitedLinkHash( + const char* canonical_url, + size_t length) { + NOTREACHED(); + return 0; +} + +bool PpapiBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash) { + NOTREACHED(); + return false; +} + +void PpapiBlinkPlatformImpl::createMessageChannel( + blink::WebMessagePortChannel** channel1, + blink::WebMessagePortChannel** channel2) { + NOTREACHED(); + *channel1 = NULL; + *channel2 = NULL; +} + +void PpapiBlinkPlatformImpl::setCookies( + const blink::WebURL& url, + const blink::WebURL& first_party_for_cookies, + const blink::WebString& value) { + NOTREACHED(); +} + +blink::WebString PpapiBlinkPlatformImpl::cookies( + const blink::WebURL& url, + const blink::WebURL& first_party_for_cookies) { + NOTREACHED(); + return blink::WebString(); +} + +blink::WebString PpapiBlinkPlatformImpl::defaultLocale() { + NOTREACHED(); + return blink::WebString(); +} + +blink::WebThemeEngine* PpapiBlinkPlatformImpl::themeEngine() { + NOTREACHED(); + return NULL; +} + +blink::WebURLLoader* PpapiBlinkPlatformImpl::createURLLoader() { + NOTREACHED(); + return NULL; +} + +blink::WebSocketStreamHandle* +PpapiBlinkPlatformImpl::createSocketStreamHandle() { + NOTREACHED(); + return NULL; +} + +void PpapiBlinkPlatformImpl::getPluginList( + bool refresh, + blink::WebPluginListBuilder* builder) { + NOTREACHED(); +} + +blink::WebData PpapiBlinkPlatformImpl::loadResource(const char* name) { + NOTREACHED(); + return blink::WebData(); +} + +blink::WebStorageNamespace* +PpapiBlinkPlatformImpl::createLocalStorageNamespace() { + NOTREACHED(); + return 0; +} + +void PpapiBlinkPlatformImpl::dispatchStorageEvent( + const blink::WebString& key, + const blink::WebString& old_value, + const blink::WebString& new_value, + const blink::WebString& origin, + const blink::WebURL& url, + bool is_local_storage) { + NOTREACHED(); +} + +int PpapiBlinkPlatformImpl::databaseDeleteFile( + const blink::WebString& vfs_file_name, + bool sync_dir) { + NOTREACHED(); + return 0; +} + +} // namespace content diff --git a/content/ppapi_plugin/ppapi_blink_platform_impl.h b/content/ppapi_plugin/ppapi_blink_platform_impl.h new file mode 100644 index 0000000..daba3f4 --- /dev/null +++ b/content/ppapi_plugin/ppapi_blink_platform_impl.h @@ -0,0 +1,62 @@ +// 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_PPAPI_PLUGIN_PPAPI_BLINK_PLATFORM_IMPL_H_ +#define CONTENT_PPAPI_PLUGIN_PPAPI_BLINK_PLATFORM_IMPL_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "content/child/blink_platform_impl.h" + +namespace content { + +class PpapiBlinkPlatformImpl : public BlinkPlatformImpl { + public: + PpapiBlinkPlatformImpl(); + virtual ~PpapiBlinkPlatformImpl(); + + // Shutdown must be called just prior to shutting down blink. + void Shutdown(); + + // BlinkPlatformImpl methods: + virtual blink::WebClipboard* clipboard(); + virtual blink::WebMimeRegistry* mimeRegistry(); + virtual blink::WebFileUtilities* fileUtilities(); + virtual blink::WebSandboxSupport* sandboxSupport(); + virtual bool sandboxEnabled(); + virtual unsigned long long visitedLinkHash(const char* canonicalURL, + size_t length); + virtual bool isLinkVisited(unsigned long long linkHash); + virtual void createMessageChannel(blink::WebMessagePortChannel** channel1, + blink::WebMessagePortChannel** channel2); + virtual void setCookies(const blink::WebURL& url, + const blink::WebURL& first_party_for_cookies, + const blink::WebString& value); + virtual blink::WebString cookies( + const blink::WebURL& url, + const blink::WebURL& first_party_for_cookies); + virtual blink::WebString defaultLocale(); + virtual blink::WebThemeEngine* themeEngine(); + virtual blink::WebURLLoader* createURLLoader(); + virtual blink::WebSocketStreamHandle* createSocketStreamHandle(); + virtual void getPluginList(bool refresh, blink::WebPluginListBuilder*); + virtual blink::WebData loadResource(const char* name); + virtual blink::WebStorageNamespace* createLocalStorageNamespace(); + virtual void dispatchStorageEvent(const blink::WebString& key, + const blink::WebString& oldValue, const blink::WebString& newValue, + const blink::WebString& origin, const blink::WebURL& url, + bool isLocalStorage); + virtual int databaseDeleteFile(const blink::WebString& vfs_file_name, + bool sync_dir); + + private: + class SandboxSupport; + scoped_ptr<SandboxSupport> sandbox_support_; + + DISALLOW_COPY_AND_ASSIGN(PpapiBlinkPlatformImpl); +}; + +} // namespace content + +#endif // CONTENT_PPAPI_PLUGIN_PPAPI_BLINK_PLATFORM_IMPL_H_ diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index fe5fa1a..142f647 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -24,7 +24,7 @@ #include "content/common/sandbox_util.h" #include "content/ppapi_plugin/broker_process_dispatcher.h" #include "content/ppapi_plugin/plugin_process_dispatcher.h" -#include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" +#include "content/ppapi_plugin/ppapi_blink_platform_impl.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "content/public/common/pepper_plugin_info.h" @@ -111,8 +111,8 @@ PpapiThread::PpapiThread(const CommandLine& command_line, bool is_broker) globals->set_command_line( command_line.GetSwitchValueASCII(switches::kPpapiFlashArgs)); - webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl); - blink::initialize(webkit_platform_support_.get()); + blink_platform_impl_.reset(new PpapiBlinkPlatformImpl); + blink::initialize(blink_platform_impl_.get()); if (!is_broker_) { channel()->AddFilter( @@ -130,7 +130,7 @@ void PpapiThread::Shutdown() { ppapi::proxy::PluginGlobals::Get()->ResetPluginProxyDelegate(); if (plugin_entry_points_.shutdown_module) plugin_entry_points_.shutdown_module(); - webkit_platform_support_->Shutdown(); + blink_platform_impl_->Shutdown(); blink::shutdown(); } diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h index 87ac2cc..505872c 100644 --- a/content/ppapi_plugin/ppapi_thread.h +++ b/content/ppapi_plugin/ppapi_thread.h @@ -38,7 +38,7 @@ struct ChannelHandle; namespace content { -class PpapiWebKitPlatformSupportImpl; +class PpapiBlinkPlatformImpl; class PpapiThread : public ChildThread, public ppapi::proxy::PluginDispatcher::PluginDelegate, @@ -149,8 +149,8 @@ class PpapiThread : public ChildThread, std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_; uint32 next_plugin_dispatcher_id_; - // The WebKitPlatformSupport implementation. - scoped_ptr<PpapiWebKitPlatformSupportImpl> webkit_platform_support_; + // The BlinkPlatformImpl implementation. + scoped_ptr<PpapiBlinkPlatformImpl> blink_platform_impl_; #if defined(OS_WIN) // Caches the handle to the peer process if this is a broker. diff --git a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc b/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc deleted file mode 100644 index c4a1153..0000000 --- a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc +++ /dev/null @@ -1,261 +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/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" - -#include <map> - -#include "base/logging.h" -#include "base/strings/string16.h" -#include "base/threading/platform_thread.h" -#include "build/build_config.h" -#include "content/child/child_thread.h" -#include "content/common/child_process_messages.h" -#include "ppapi/proxy/plugin_globals.h" -#include "ppapi/shared_impl/proxy_lock.h" -#include "third_party/WebKit/public/platform/WebString.h" - -#if defined(OS_WIN) -#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" -#elif defined(OS_MACOSX) -#include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h" -#elif defined(OS_ANDROID) -#include "third_party/WebKit/public/platform/android/WebSandboxSupport.h" -#elif defined(OS_POSIX) -#include "content/common/child_process_sandbox_support_impl_linux.h" -#include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" -#include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" -#include "third_party/icu/source/common/unicode/utf16.h" -#endif - -using blink::WebSandboxSupport; -using blink::WebString; -using blink::WebUChar; -using blink::WebUChar32; - -typedef struct CGFont* CGFontRef; - -namespace content { - -class PpapiWebKitPlatformSupportImpl::SandboxSupport - : public WebSandboxSupport { - public: - virtual ~SandboxSupport() {} - -#if defined(OS_WIN) - virtual bool ensureFontLoaded(HFONT); -#elif defined(OS_MACOSX) - virtual bool loadFont( - NSFont* srcFont, CGFontRef* out, uint32_t* fontID); -#elif defined(OS_ANDROID) - // Empty class. -#elif defined(OS_POSIX) - SandboxSupport(); - virtual void getFallbackFontForCharacter( - WebUChar32 character, - const char* preferred_locale, - blink::WebFallbackFont* fallbackFont); - virtual void getRenderStyleForStrike( - const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out); - - private: - // WebKit likes to ask us for the correct font family to use for a set of - // unicode code points. It needs this information frequently so we cache it - // here. - std::map<int32_t, blink::WebFallbackFont> unicode_font_families_; - // For debugging crbug.com/312965 - base::PlatformThreadId creation_thread_; -#endif -}; - -#if defined(OS_WIN) - -bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( - HFONT font) { - LOGFONT logfont; - GetObject(font, sizeof(LOGFONT), &logfont); - - // Use the proxy sender rather than going directly to the ChildThread since - // the proxy browser sender will properly unlock during sync messages. - return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send( - new ChildProcessHostMsg_PreCacheFont(logfont)); -} - -#elif defined(OS_MACOSX) - -bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont( - NSFont* src_font, - CGFontRef* out, - uint32_t* font_id) { - // TODO(brettw) this should do the something similar to what - // RendererWebKitClientImpl does and request that the browser load the font. - // Note: need to unlock the proxy lock like ensureFontLoaded does. - NOTIMPLEMENTED(); - return false; -} - -#elif defined(OS_ANDROID) - -// Empty class. - -#elif defined(OS_POSIX) - -PpapiWebKitPlatformSupportImpl::SandboxSupport::SandboxSupport() - : creation_thread_(base::PlatformThread::CurrentId()) { -} - -void -PpapiWebKitPlatformSupportImpl::SandboxSupport::getFallbackFontForCharacter( - WebUChar32 character, - const char* preferred_locale, - blink::WebFallbackFont* fallbackFont) { - ppapi::ProxyLock::AssertAcquired(); - // For debugging crbug.com/312965 - CHECK_EQ(creation_thread_, base::PlatformThread::CurrentId()); - const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter = - unicode_font_families_.find(character); - if (iter != unicode_font_families_.end()) { - fallbackFont->name = iter->second.name; - fallbackFont->filename = iter->second.filename; - fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId; - fallbackFont->ttcIndex = iter->second.ttcIndex; - fallbackFont->isBold = iter->second.isBold; - fallbackFont->isItalic = iter->second.isItalic; - return; - } - - GetFallbackFontForCharacter(character, preferred_locale, fallbackFont); - unicode_font_families_.insert(std::make_pair(character, *fallbackFont)); -} - -void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( - const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out) { - GetRenderStyleForStrike(family, sizeAndStyle, out); -} - -#endif - -PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl() - : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) { -} - -PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() { -} - -void PpapiWebKitPlatformSupportImpl::Shutdown() { - // SandboxSupport contains a map of WebFontFamily objects, which hold - // WebCStrings, which become invalidated when blink is shut down. Hence, we - // need to clear that map now, just before blink::shutdown() is called. - sandbox_support_.reset(); -} - -blink::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() { - NOTREACHED(); - return NULL; -} - -blink::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() { - NOTREACHED(); - return NULL; -} - -blink::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() { - NOTREACHED(); - return NULL; -} - -blink::WebSandboxSupport* PpapiWebKitPlatformSupportImpl::sandboxSupport() { - return sandbox_support_.get(); -} - -bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() { - return true; // Assume PPAPI is always sandboxed. -} - -unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash( - const char* canonical_url, - size_t length) { - NOTREACHED(); - return 0; -} - -bool PpapiWebKitPlatformSupportImpl::isLinkVisited( - unsigned long long link_hash) { - NOTREACHED(); - return false; -} - -void PpapiWebKitPlatformSupportImpl::createMessageChannel( - blink::WebMessagePortChannel** channel1, - blink::WebMessagePortChannel** channel2) { - NOTREACHED(); - *channel1 = NULL; - *channel2 = NULL; -} - -void PpapiWebKitPlatformSupportImpl::setCookies( - const blink::WebURL& url, - const blink::WebURL& first_party_for_cookies, - const blink::WebString& value) { - NOTREACHED(); -} - -blink::WebString PpapiWebKitPlatformSupportImpl::cookies( - const blink::WebURL& url, - const blink::WebURL& first_party_for_cookies) { - NOTREACHED(); - return blink::WebString(); -} - -blink::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() { - NOTREACHED(); - return blink::WebString(); -} - -blink::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() { - NOTREACHED(); - return NULL; -} - -blink::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() { - NOTREACHED(); - return NULL; -} - -blink::WebSocketStreamHandle* - PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() { - NOTREACHED(); - return NULL; -} - -void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh, - blink::WebPluginListBuilder* builder) { - NOTREACHED(); -} - -blink::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) { - NOTREACHED(); - return blink::WebData(); -} - -blink::WebStorageNamespace* -PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() { - NOTREACHED(); - return 0; -} - -void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent( - const blink::WebString& key, const blink::WebString& old_value, - const blink::WebString& new_value, const blink::WebString& origin, - const blink::WebURL& url, bool is_local_storage) { - NOTREACHED(); -} - -int PpapiWebKitPlatformSupportImpl::databaseDeleteFile( - const blink::WebString& vfs_file_name, bool sync_dir) { - NOTREACHED(); - return 0; -} - -} // namespace content diff --git a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h b/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h deleted file mode 100644 index 3361304..0000000 --- a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h +++ /dev/null @@ -1,62 +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 CONTENT_PPAPI_PLUGIN_PPAPI_WEBKITPLATFORMSUPPORT_IMPL_H_ -#define CONTENT_PPAPI_PLUGIN_PPAPI_WEBKITPLATFORMSUPPORT_IMPL_H_ - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "content/child/blink_platform_impl.h" - -namespace content { - -class PpapiWebKitPlatformSupportImpl : public BlinkPlatformImpl { - public: - PpapiWebKitPlatformSupportImpl(); - virtual ~PpapiWebKitPlatformSupportImpl(); - - // Shutdown must be called just prior to shutting down blink. - void Shutdown(); - - // WebKitPlatformSupport methods: - virtual blink::WebClipboard* clipboard(); - virtual blink::WebMimeRegistry* mimeRegistry(); - virtual blink::WebFileUtilities* fileUtilities(); - virtual blink::WebSandboxSupport* sandboxSupport(); - virtual bool sandboxEnabled(); - virtual unsigned long long visitedLinkHash(const char* canonicalURL, - size_t length); - virtual bool isLinkVisited(unsigned long long linkHash); - virtual void createMessageChannel(blink::WebMessagePortChannel** channel1, - blink::WebMessagePortChannel** channel2); - virtual void setCookies(const blink::WebURL& url, - const blink::WebURL& first_party_for_cookies, - const blink::WebString& value); - virtual blink::WebString cookies( - const blink::WebURL& url, - const blink::WebURL& first_party_for_cookies); - virtual blink::WebString defaultLocale(); - virtual blink::WebThemeEngine* themeEngine(); - virtual blink::WebURLLoader* createURLLoader(); - virtual blink::WebSocketStreamHandle* createSocketStreamHandle(); - virtual void getPluginList(bool refresh, blink::WebPluginListBuilder*); - virtual blink::WebData loadResource(const char* name); - virtual blink::WebStorageNamespace* createLocalStorageNamespace(); - virtual void dispatchStorageEvent(const blink::WebString& key, - const blink::WebString& oldValue, const blink::WebString& newValue, - const blink::WebString& origin, const blink::WebURL& url, - bool isLocalStorage); - virtual int databaseDeleteFile(const blink::WebString& vfs_file_name, - bool sync_dir); - - private: - class SandboxSupport; - scoped_ptr<SandboxSupport> sandbox_support_; - - DISALLOW_COPY_AND_ASSIGN(PpapiWebKitPlatformSupportImpl); -}; - -} // namespace content - -#endif // CONTENT_PPAPI_PLUGIN_PPAPI_WEBKITPLATFORMSUPPORT_IMPL_H_ diff --git a/content/public/test/layouttest_support.h b/content/public/test/layouttest_support.h index f155a8c..23354ff 100644 --- a/content/public/test/layouttest_support.h +++ b/content/public/test/layouttest_support.h @@ -58,15 +58,15 @@ void FetchManifest(blink::WebView* view, const GURL& url, void SetMockGamepadProvider(scoped_ptr<RendererGamepadProvider> provider); // Sets a double that should be used when registering -// a listener through WebKitPlatformSupport::setDeviceLightListener(). +// a listener through BlinkPlatformImpl::setDeviceLightListener(). void SetMockDeviceLightData(const double data); // Sets WebDeviceMotionData that should be used when registering -// a listener through WebKitPlatformSupport::setDeviceMotionListener(). +// a listener through BlinkPlatformImpl::setDeviceMotionListener(). void SetMockDeviceMotionData(const blink::WebDeviceMotionData& data); // Sets WebDeviceOrientationData that should be used when registering -// a listener through WebKitPlatformSupport::setDeviceOrientationListener(). +// a listener through BlinkPlatformImpl::setDeviceOrientationListener(). void SetMockDeviceOrientationData(const blink::WebDeviceOrientationData& data); // Notifies blink that battery status has changed. diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc index be2793f..f8f0088 100644 --- a/content/public/test/render_view_test.cc +++ b/content/public/test/render_view_test.cc @@ -19,8 +19,8 @@ #include "content/renderer/history_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" +#include "content/renderer/renderer_blink_platform_impl.h" #include "content/renderer/renderer_main_platform_delegate.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" #include "content/test/mock_render_process.h" #include "content/test/test_content_client.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" @@ -57,27 +57,25 @@ const int32 kSurfaceId = 42; namespace content { -class RendererWebKitPlatformSupportImplNoSandboxImpl - : public RendererWebKitPlatformSupportImpl { +class RendererBlinkPlatformImplNoSandboxImpl + : public RendererBlinkPlatformImpl { public: virtual blink::WebSandboxSupport* sandboxSupport() { return NULL; } }; -RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox:: - RendererWebKitPlatformSupportImplNoSandbox() { - webkit_platform_support_.reset( - new RendererWebKitPlatformSupportImplNoSandboxImpl()); +RenderViewTest::RendererBlinkPlatformImplNoSandbox:: + RendererBlinkPlatformImplNoSandbox() { + blink_platform_impl_.reset(new RendererBlinkPlatformImplNoSandboxImpl()); } -RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox:: - ~RendererWebKitPlatformSupportImplNoSandbox() { +RenderViewTest::RendererBlinkPlatformImplNoSandbox:: + ~RendererBlinkPlatformImplNoSandbox() { } -blink::Platform* - RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox::Get() { - return webkit_platform_support_.get(); +blink::Platform* RenderViewTest::RendererBlinkPlatformImplNoSandbox::Get() { + return blink_platform_impl_.get(); } RenderViewTest::RenderViewTest() @@ -167,7 +165,7 @@ void RenderViewTest::SetUp() { // hacky, but this is the world we live in... std::string flags("--expose-gc"); v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); - blink::initialize(webkit_platform_support_.Get()); + blink::initialize(blink_platform_impl_.Get()); // Ensure that we register any necessary schemes when initializing WebKit, // since we are using a MockRenderThread. diff --git a/content/public/test/render_view_test.h b/content/public/test/render_view_test.h index 7f10ee8..3fefec5 100644 --- a/content/public/test/render_view_test.h +++ b/content/public/test/render_view_test.h @@ -34,22 +34,21 @@ class ContentRendererClient; class MockRenderProcess; class PageState; class RendererMainPlatformDelegate; -class RendererWebKitPlatformSupportImplNoSandboxImpl; +class RendererBlinkPlatformImplNoSandboxImpl; class RenderView; class RenderViewTest : public testing::Test { public: - // A special WebKitPlatformSupportImpl class for getting rid off the - // dependency to the sandbox, which is not available in RenderViewTest. - class RendererWebKitPlatformSupportImplNoSandbox { + // A special BlinkPlatformImpl class for getting rid off the dependency to the + // sandbox, which is not available in RenderViewTest. + class RendererBlinkPlatformImplNoSandbox { public: - RendererWebKitPlatformSupportImplNoSandbox(); - ~RendererWebKitPlatformSupportImplNoSandbox(); + RendererBlinkPlatformImplNoSandbox(); + ~RendererBlinkPlatformImplNoSandbox(); blink::Platform* Get(); private: - scoped_ptr<RendererWebKitPlatformSupportImplNoSandboxImpl> - webkit_platform_support_; + scoped_ptr<RendererBlinkPlatformImplNoSandboxImpl> blink_platform_impl_; }; RenderViewTest(); @@ -142,7 +141,7 @@ class RenderViewTest : public testing::Test { // We use a naked pointer because we don't want to expose RenderViewImpl in // the embedder's namespace. RenderView* view_; - RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; + RendererBlinkPlatformImplNoSandbox blink_platform_impl_; scoped_ptr<ContentClient> content_client_; scoped_ptr<ContentBrowserClient> content_browser_client_; scoped_ptr<ContentRendererClient> content_renderer_client_; diff --git a/content/public/test/unittest_test_suite.cc b/content/public/test/unittest_test_suite.cc index 67f3bb4..2a6c6b8 100644 --- a/content/public/test/unittest_test_suite.cc +++ b/content/public/test/unittest_test_suite.cc @@ -8,7 +8,7 @@ #include "base/rand_util.h" #include "base/test/test_suite.h" #if !defined(OS_IOS) -#include "content/test/test_webkit_platform_support.h" +#include "content/test/test_blink_web_unit_test_support.h" #endif #include "third_party/WebKit/public/web/WebKit.h" @@ -18,13 +18,13 @@ UnitTestTestSuite::UnitTestTestSuite(base::TestSuite* test_suite) : test_suite_(test_suite) { DCHECK(test_suite); #if !defined(OS_IOS) - platform_support_.reset(new TestWebKitPlatformSupport); + blink_test_support_.reset(new TestBlinkWebUnitTestSupport); #endif } UnitTestTestSuite::~UnitTestTestSuite() { #if !defined(OS_IOS) - platform_support_.reset(); + blink_test_support_.reset(); #endif } diff --git a/content/public/test/unittest_test_suite.h b/content/public/test/unittest_test_suite.h index 5b46ee6..b59cdd0 100644 --- a/content/public/test/unittest_test_suite.h +++ b/content/public/test/unittest_test_suite.h @@ -13,7 +13,7 @@ class TestSuite; } namespace content { -class TestWebKitPlatformSupport; +class TestBlinkWebUnitTestSupport; // A special test suite that also initializes WebKit once for all unittests. // This is useful for two reasons: @@ -32,7 +32,7 @@ class UnitTestTestSuite { scoped_ptr<base::TestSuite> test_suite_; #if !defined(OS_IOS) - scoped_ptr<TestWebKitPlatformSupport> platform_support_; + scoped_ptr<TestBlinkWebUnitTestSupport> blink_test_support_; #endif DISALLOW_COPY_AND_ASSIGN(UnitTestTestSuite); diff --git a/content/renderer/gamepad_shared_memory_reader.cc b/content/renderer/gamepad_shared_memory_reader.cc index 7040a9b..ab75d7e 100644 --- a/content/renderer/gamepad_shared_memory_reader.cc +++ b/content/renderer/gamepad_shared_memory_reader.cc @@ -9,7 +9,7 @@ #include "content/common/gamepad_hardware_buffer.h" #include "content/common/gamepad_user_gesture.h" #include "content/public/renderer/render_thread.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" +#include "content/renderer/renderer_blink_platform_impl.h" #include "ipc/ipc_sync_message_filter.h" #include "third_party/WebKit/public/platform/WebGamepadListener.h" #include "third_party/WebKit/public/platform/WebPlatformEventListener.h" diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index c2da03a..5581284 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -91,7 +91,7 @@ #include "content/renderer/render_frame_proxy.h" #include "content/renderer/render_process_impl.h" #include "content/renderer/render_view_impl.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" +#include "content/renderer/renderer_blink_platform_impl.h" #include "content/renderer/scheduler_proxy_task_runner.h" #include "content/renderer/service_worker/embedded_worker_context_message_filter.h" #include "content/renderer/service_worker/embedded_worker_dispatcher.h" @@ -594,13 +594,13 @@ void RenderThreadImpl::Shutdown() { } // Wait for all databases to be closed. - if (webkit_platform_support_) { + if (blink_platform_impl_) { // WaitForAllDatabasesToClose might run a nested message loop. To avoid // processing timer events while we're already in the process of shutting // down blink, put a ScopePageLoadDeferrer on the stack. WebView::willEnterModalLoop(); - webkit_platform_support_->web_database_observer_impl()-> - WaitForAllDatabasesToClose(); + blink_platform_impl_->web_database_observer_impl() + ->WaitForAllDatabasesToClose(); WebView::didExitModalLoop(); } @@ -657,7 +657,7 @@ void RenderThreadImpl::Shutdown() { main_thread_compositor_task_runner_ = NULL; - if (webkit_platform_support_) + if (blink_platform_impl_) blink::shutdown(); lazy_tls.Pointer()->Set(NULL); @@ -698,7 +698,7 @@ bool RenderThreadImpl::Send(IPC::Message* msg) { if (pumping_events) { if (suspend_webkit_shared_timer) - webkit_platform_support_->SuspendSharedTimer(); + blink_platform_impl_->SuspendSharedTimer(); if (notify_webkit_of_modal_loop) WebView::willEnterModalLoop(); @@ -727,7 +727,7 @@ bool RenderThreadImpl::Send(IPC::Message* msg) { WebView::didExitModalLoop(); if (suspend_webkit_shared_timer) - webkit_platform_support_->ResumeSharedTimer(); + blink_platform_impl_->ResumeSharedTimer(); } return rv; @@ -834,11 +834,11 @@ void RenderThreadImpl::SetResourceDispatcherDelegate( } void RenderThreadImpl::EnsureWebKitInitialized() { - if (webkit_platform_support_) + if (blink_platform_impl_) return; - webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); - blink::initialize(webkit_platform_support_.get()); + blink_platform_impl_.reset(new RendererBlinkPlatformImpl); + blink::initialize(blink_platform_impl_.get()); main_thread_compositor_task_runner_ = base::MessageLoopProxy::current(); v8::Isolate* isolate = blink::mainThreadIsolate(); @@ -1466,9 +1466,9 @@ void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { // point we already know that the browser has refreshed its list, so disable // refresh temporarily to prevent each renderer process causing the list to be // regenerated. - webkit_platform_support_->set_plugin_refresh_allowed(false); + blink_platform_impl_->set_plugin_refresh_allowed(false); blink::resetPluginCache(reload_pages); - webkit_platform_support_->set_plugin_refresh_allowed(true); + blink_platform_impl_->set_plugin_refresh_allowed(true); FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged()); } @@ -1499,9 +1499,9 @@ void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) { if (suspend_webkit_shared_timer_) { EnsureWebKitInitialized(); if (suspend) { - webkit_platform_support_->SuspendSharedTimer(); + blink_platform_impl_->SuspendSharedTimer(); } else { - webkit_platform_support_->ResumeSharedTimer(); + blink_platform_impl_->ResumeSharedTimer(); } webkit_shared_timer_suspended_ = suspend; } @@ -1517,8 +1517,8 @@ void RenderThreadImpl::OnUpdateScrollbarTheme( bool redraw) { EnsureWebKitInitialized(); static_cast<WebScrollbarBehaviorImpl*>( - webkit_platform_support_->scrollbarBehavior())->set_jump_on_track_click( - jump_on_track_click); + blink_platform_impl_->scrollbarBehavior()) + ->set_jump_on_track_click(jump_on_track_click); blink::WebScrollbarTheme::updateScrollbars(initial_button_delay, autoscroll_button_delay, preferred_scroller_style, @@ -1544,13 +1544,13 @@ void RenderThreadImpl::OnMemoryPressure( // Trigger full v8 garbage collection on critical memory notification. This // will potentially hang the renderer for a long time, however, when we // receive a memory pressure notification, we might be about to be killed. - if (webkit_platform_support_ && blink::mainThreadIsolate()) { + if (blink_platform_impl_ && blink::mainThreadIsolate()) { blink::mainThreadIsolate()->LowMemoryNotification(); } if (memory_pressure_level == base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL) { - if (webkit_platform_support_) { + if (blink_platform_impl_) { // Clear the image cache. Do not call into blink if it is not initialized. blink::WebImageCache::clear(); } @@ -1588,7 +1588,7 @@ RenderThreadImpl::GetMediaThreadTaskRunner() { } void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { - webkit_platform_support_->sampleGamepads(*data); + blink_platform_impl_->sampleGamepads(*data); } void RenderThreadImpl::WidgetCreated() { diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 954c074..b1ed5ce 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -95,9 +95,9 @@ class MidiMessageFilter; class NetInfoDispatcher; class P2PSocketDispatcher; class PeerConnectionTracker; -class RendererDemuxerAndroid; -class RendererWebKitPlatformSupportImpl; class RenderProcessObserver; +class RendererBlinkPlatformImpl; +class RendererDemuxerAndroid; class VideoCaptureImplManager; class WebGraphicsContext3DCommandBufferImpl; class WebRTCIdentityService; @@ -194,9 +194,9 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, layout_test_mode_ = layout_test_mode; } - RendererWebKitPlatformSupportImpl* webkit_platform_support() const { - DCHECK(webkit_platform_support_); - return webkit_platform_support_.get(); + RendererBlinkPlatformImpl* blink_platform_impl() const { + DCHECK(blink_platform_impl_); + return blink_platform_impl_.get(); } scoped_refptr<base::SingleThreadTaskRunner> @@ -458,7 +458,7 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, scoped_ptr<AppCacheDispatcher> appcache_dispatcher_; scoped_ptr<DomStorageDispatcher> dom_storage_dispatcher_; scoped_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_; - scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_; + scoped_ptr<RendererBlinkPlatformImpl> blink_platform_impl_; scoped_ptr<EmbeddedWorkerDispatcher> embedded_worker_dispatcher_; // Used on the render thread and deleted by WebKit at shutdown. diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index c17cd7e..b643c4a 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -49,7 +49,7 @@ #include "content/renderer/render_frame_proxy.h" #include "content/renderer/render_process.h" #include "content/renderer/render_thread_impl.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" +#include "content/renderer/renderer_blink_platform_impl.h" #include "content/renderer/resizing_mode_selector.h" #include "ipc/ipc_sync_message.h" #include "skia/ext/platform_canvas.h" diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc new file mode 100644 index 0000000..3a0ccc3 --- /dev/null +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -0,0 +1,1180 @@ +// 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/renderer/renderer_blink_platform_impl.h" + +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/lazy_instance.h" +#include "base/logging.h" +#include "base/memory/shared_memory.h" +#include "base/message_loop/message_loop_proxy.h" +#include "base/metrics/histogram.h" +#include "base/numerics/safe_conversions.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" +#include "content/child/database_util.h" +#include "content/child/file_info_util.h" +#include "content/child/fileapi/webfilesystem_impl.h" +#include "content/child/indexed_db/webidbfactory_impl.h" +#include "content/child/npapi/npobject_util.h" +#include "content/child/quota_dispatcher.h" +#include "content/child/quota_message_filter.h" +#include "content/child/simple_webmimeregistry_impl.h" +#include "content/child/thread_safe_sender.h" +#include "content/child/web_database_observer_impl.h" +#include "content/child/webblobregistry_impl.h" +#include "content/child/webfileutilities_impl.h" +#include "content/child/webmessageportchannel_impl.h" +#include "content/common/file_utilities_messages.h" +#include "content/common/gpu/client/context_provider_command_buffer.h" +#include "content/common/gpu/client/gpu_channel_host.h" +#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" +#include "content/common/gpu/gpu_process_launch_causes.h" +#include "content/common/mime_registry_messages.h" +#include "content/common/view_messages.h" +#include "content/public/common/content_switches.h" +#include "content/public/common/webplugininfo.h" +#include "content/public/renderer/content_renderer_client.h" +#include "content/renderer/battery_status/battery_status_dispatcher.h" +#include "content/renderer/device_sensors/device_light_event_pump.h" +#include "content/renderer/device_sensors/device_motion_event_pump.h" +#include "content/renderer/device_sensors/device_orientation_event_pump.h" +#include "content/renderer/dom_storage/webstoragenamespace_impl.h" +#include "content/renderer/gamepad_shared_memory_reader.h" +#include "content/renderer/media/audio_decoder.h" +#include "content/renderer/media/crypto/key_systems.h" +#include "content/renderer/media/renderer_webaudiodevice_impl.h" +#include "content/renderer/media/renderer_webmidiaccessor_impl.h" +#include "content/renderer/media/webcontentdecryptionmodule_impl.h" +#include "content/renderer/render_thread_impl.h" +#include "content/renderer/renderer_clipboard_client.h" +#include "content/renderer/screen_orientation/screen_orientation_observer.h" +#include "content/renderer/webclipboard_impl.h" +#include "content/renderer/webgraphicscontext3d_provider_impl.h" +#include "content/renderer/webpublicsuffixlist_impl.h" +#include "gpu/config/gpu_info.h" +#include "ipc/ipc_sync_message_filter.h" +#include "media/audio/audio_output_device.h" +#include "media/base/audio_hardware_config.h" +#include "media/filters/stream_parser_factory.h" +#include "net/base/mime_util.h" +#include "net/base/net_util.h" +#include "storage/common/quota/quota_types.h" +#include "third_party/WebKit/public/platform/WebBatteryStatusListener.h" +#include "third_party/WebKit/public/platform/WebBlobRegistry.h" +#include "third_party/WebKit/public/platform/WebDeviceLightListener.h" +#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h" +#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h" +#include "third_party/WebKit/public/platform/WebFileInfo.h" +#include "third_party/WebKit/public/platform/WebGamepads.h" +#include "third_party/WebKit/public/platform/WebMediaStreamCenter.h" +#include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" +#include "third_party/WebKit/public/platform/WebPluginListBuilder.h" +#include "third_party/WebKit/public/platform/WebURL.h" +#include "third_party/WebKit/public/platform/WebVector.h" +#include "ui/gfx/color_profile.h" +#include "url/gurl.h" +#include "webkit/common/gpu/context_provider_web_context.h" + +#if defined(OS_ANDROID) +#include "content/renderer/android/synchronous_compositor_factory.h" +#include "content/renderer/media/android/audio_decoder_android.h" +#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" +#endif + +#if defined(OS_MACOSX) +#include "content/common/mac/font_descriptor.h" +#include "content/common/mac/font_loader.h" +#include "content/renderer/webscrollbarbehavior_impl_mac.h" +#include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h" +#endif + +#if defined(OS_POSIX) +#include "base/file_descriptor_posix.h" +#if !defined(OS_MACOSX) && !defined(OS_ANDROID) +#include <map> +#include <string> + +#include "base/synchronization/lock.h" +#include "content/common/child_process_sandbox_support_impl_linux.h" +#include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" +#include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" +#include "third_party/icu/source/common/unicode/utf16.h" +#endif +#endif + +#if defined(OS_WIN) +#include "content/common/child_process_messages.h" +#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" +#endif + +#if defined(USE_AURA) +#include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" +#elif !defined(OS_MACOSX) +#include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" +#define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior +#endif + +#if defined(ENABLE_WEBRTC) +#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" +#endif + +using blink::Platform; +using blink::WebAudioDevice; +using blink::WebBlobRegistry; +using blink::WebDatabaseObserver; +using blink::WebFileInfo; +using blink::WebFileSystem; +using blink::WebGamepad; +using blink::WebGamepads; +using blink::WebIDBFactory; +using blink::WebMIDIAccessor; +using blink::WebMediaStreamCenter; +using blink::WebMediaStreamCenterClient; +using blink::WebMimeRegistry; +using blink::WebRTCPeerConnectionHandler; +using blink::WebRTCPeerConnectionHandlerClient; +using blink::WebStorageNamespace; +using blink::WebString; +using blink::WebURL; +using blink::WebVector; + +namespace content { + +namespace { + +bool g_sandbox_enabled = true; +double g_test_device_light_data = -1; +base::LazyInstance<blink::WebDeviceMotionData>::Leaky + g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance<blink::WebDeviceOrientationData>::Leaky + g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; + +} // namespace + +//------------------------------------------------------------------------------ + +class RendererBlinkPlatformImpl::MimeRegistry + : public SimpleWebMimeRegistryImpl { + public: + virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( + const blink::WebString& mime_type, + const blink::WebString& codecs, + const blink::WebString& key_system); + virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type, + const blink::WebString& codecs); + virtual bool supportsEncryptedMediaMIMEType(const WebString& key_system, + const WebString& mime_type, + const WebString& codecs) OVERRIDE; + virtual blink::WebString mimeTypeForExtension( + const blink::WebString& file_extension); + virtual blink::WebString mimeTypeFromFile( + const blink::WebString& file_path); +}; + +class RendererBlinkPlatformImpl::FileUtilities : public WebFileUtilitiesImpl { + public: + explicit FileUtilities(ThreadSafeSender* sender) + : thread_safe_sender_(sender) {} + virtual bool getFileInfo(const WebString& path, WebFileInfo& result); + private: + bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const; + scoped_refptr<ThreadSafeSender> thread_safe_sender_; +}; + +#if defined(OS_ANDROID) +// WebKit doesn't use WebSandboxSupport on android so we don't need to +// implement anything here. +class RendererBlinkPlatformImpl::SandboxSupport {}; +#else +class RendererBlinkPlatformImpl::SandboxSupport + : public blink::WebSandboxSupport { + public: + virtual ~SandboxSupport() {} + +#if defined(OS_WIN) + virtual bool ensureFontLoaded(HFONT); +#elif defined(OS_MACOSX) + virtual bool loadFont( + NSFont* src_font, + CGFontRef* container, + uint32* font_id); +#elif defined(OS_POSIX) + virtual void getFallbackFontForCharacter( + blink::WebUChar32 character, + const char* preferred_locale, + blink::WebFallbackFont* fallbackFont); + virtual void getRenderStyleForStrike( + const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out); + + private: + // WebKit likes to ask us for the correct font family to use for a set of + // unicode code points. It needs this information frequently so we cache it + // here. + base::Lock unicode_font_families_mutex_; + std::map<int32_t, blink::WebFallbackFont> unicode_font_families_; +#endif +}; +#endif // defined(OS_ANDROID) + +//------------------------------------------------------------------------------ + +RendererBlinkPlatformImpl::RendererBlinkPlatformImpl() + : clipboard_client_(new RendererClipboardClient), + clipboard_(new WebClipboardImpl(clipboard_client_.get())), + mime_registry_(new RendererBlinkPlatformImpl::MimeRegistry), + sudden_termination_disables_(0), + plugin_refresh_allowed_(true), + child_thread_loop_(base::MessageLoopProxy::current()), + web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) { + if (g_sandbox_enabled && sandboxEnabled()) { + sandbox_support_.reset(new RendererBlinkPlatformImpl::SandboxSupport); + } else { + DVLOG(1) << "Disabling sandbox support for testing."; + } + + // ChildThread may not exist in some tests. + if (ChildThread::current()) { + sync_message_filter_ = ChildThread::current()->sync_message_filter(); + thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); + quota_message_filter_ = ChildThread::current()->quota_message_filter(); + blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get())); + web_idb_factory_.reset(new WebIDBFactoryImpl(thread_safe_sender_.get())); + web_database_observer_impl_.reset( + new WebDatabaseObserverImpl(sync_message_filter_.get())); + } +} + +RendererBlinkPlatformImpl::~RendererBlinkPlatformImpl() { + WebFileSystemImpl::DeleteThreadSpecificInstance(); +} + +//------------------------------------------------------------------------------ + +blink::WebClipboard* RendererBlinkPlatformImpl::clipboard() { + blink::WebClipboard* clipboard = + GetContentClient()->renderer()->OverrideWebClipboard(); + if (clipboard) + return clipboard; + return clipboard_.get(); +} + +blink::WebMimeRegistry* RendererBlinkPlatformImpl::mimeRegistry() { + return mime_registry_.get(); +} + +blink::WebFileUtilities* RendererBlinkPlatformImpl::fileUtilities() { + if (!file_utilities_) { + file_utilities_.reset(new FileUtilities(thread_safe_sender_.get())); + file_utilities_->set_sandbox_enabled(sandboxEnabled()); + } + return file_utilities_.get(); +} + +blink::WebSandboxSupport* RendererBlinkPlatformImpl::sandboxSupport() { +#if defined(OS_ANDROID) + // WebKit doesn't use WebSandboxSupport on android. + return NULL; +#else + return sandbox_support_.get(); +#endif +} + +blink::WebCookieJar* RendererBlinkPlatformImpl::cookieJar() { + NOTREACHED() << "Use WebFrameClient::cookieJar() instead!"; + return NULL; +} + +blink::WebThemeEngine* RendererBlinkPlatformImpl::themeEngine() { + blink::WebThemeEngine* theme_engine = + GetContentClient()->renderer()->OverrideThemeEngine(); + if (theme_engine) + return theme_engine; + return BlinkPlatformImpl::themeEngine(); +} + +bool RendererBlinkPlatformImpl::sandboxEnabled() { + // As explained in Platform.h, this function is used to decide + // whether to allow file system operations to come out of WebKit or not. + // Even if the sandbox is disabled, there's no reason why the code should + // act any differently...unless we're in single process mode. In which + // case, we have no other choice. Platform.h discourages using + // this switch unless absolutely necessary, so hopefully we won't end up + // with too many code paths being different in single-process mode. + return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); +} + +unsigned long long RendererBlinkPlatformImpl::visitedLinkHash( + const char* canonical_url, + size_t length) { + return GetContentClient()->renderer()->VisitedLinkHash(canonical_url, length); +} + +bool RendererBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash) { + return GetContentClient()->renderer()->IsLinkVisited(link_hash); +} + +void RendererBlinkPlatformImpl::createMessageChannel( + blink::WebMessagePortChannel** channel1, + blink::WebMessagePortChannel** channel2) { + WebMessagePortChannelImpl::CreatePair( + child_thread_loop_.get(), channel1, channel2); +} + +blink::WebPrescientNetworking* +RendererBlinkPlatformImpl::prescientNetworking() { + return GetContentClient()->renderer()->GetPrescientNetworking(); +} + +void RendererBlinkPlatformImpl::cacheMetadata(const blink::WebURL& url, + double response_time, + const char* data, + size_t size) { + // Let the browser know we generated cacheable metadata for this resource. The + // browser may cache it and return it on subsequent responses to speed + // the processing of this resource. + std::vector<char> copy(data, data + size); + RenderThread::Get()->Send( + new ViewHostMsg_DidGenerateCacheableMetadata(url, response_time, copy)); +} + +WebString RendererBlinkPlatformImpl::defaultLocale() { + return base::ASCIIToUTF16(RenderThread::Get()->GetLocale()); +} + +void RendererBlinkPlatformImpl::suddenTerminationChanged(bool enabled) { + if (enabled) { + // We should not get more enables than disables, but we want it to be a + // non-fatal error if it does happen. + DCHECK_GT(sudden_termination_disables_, 0); + sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, + 0); + if (sudden_termination_disables_ != 0) + return; + } else { + sudden_termination_disables_++; + if (sudden_termination_disables_ != 1) + return; + } + + RenderThread* thread = RenderThread::Get(); + if (thread) // NULL in unittests. + thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); +} + +WebStorageNamespace* RendererBlinkPlatformImpl::createLocalStorageNamespace() { + return new WebStorageNamespaceImpl(); +} + + +//------------------------------------------------------------------------------ + +WebIDBFactory* RendererBlinkPlatformImpl::idbFactory() { + return web_idb_factory_.get(); +} + +//------------------------------------------------------------------------------ + +WebFileSystem* RendererBlinkPlatformImpl::fileSystem() { + return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get()); +} + +//------------------------------------------------------------------------------ + +WebMimeRegistry::SupportsType +RendererBlinkPlatformImpl::MimeRegistry::supportsMediaMIMEType( + const WebString& mime_type, + const WebString& codecs, + const WebString& key_system) { + const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); + // Not supporting the container is a flat-out no. + if (!net::IsSupportedMediaMimeType(mime_type_ascii)) + return IsNotSupported; + + if (!key_system.isEmpty()) { + // Check whether the key system is supported with the mime_type and codecs. + + // Chromium only supports ASCII parameters. + if (!base::IsStringASCII(key_system)) + return IsNotSupported; + + std::string key_system_ascii = + GetUnprefixedKeySystemName(base::UTF16ToASCII(key_system)); + std::vector<std::string> strict_codecs; + net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, true); + + if (!IsSupportedKeySystemWithMediaMimeType( + mime_type_ascii, strict_codecs, key_system_ascii)) { + return IsNotSupported; + } + + // Continue processing the mime_type and codecs. + } + + // Check list of strict codecs to see if it is supported. + if (net::IsStrictMediaMimeType(mime_type_ascii)) { + // Check if the codecs are a perfect match. + std::vector<std::string> strict_codecs; + net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); + return static_cast<WebMimeRegistry::SupportsType> ( + net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); + } + + // If we don't recognize the codec, it's possible we support it. + std::vector<std::string> parsed_codecs; + net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); + if (!net::AreSupportedMediaCodecs(parsed_codecs)) + return MayBeSupported; + + // Otherwise we have a perfect match. + return IsSupported; +} + +bool RendererBlinkPlatformImpl::MimeRegistry::supportsMediaSourceMIMEType( + const blink::WebString& mime_type, + const WebString& codecs) { + const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); + std::vector<std::string> parsed_codec_ids; + net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); + if (mime_type_ascii.empty()) + return false; + return media::StreamParserFactory::IsTypeSupported( + mime_type_ascii, parsed_codec_ids); +} + +bool RendererBlinkPlatformImpl::MimeRegistry::supportsEncryptedMediaMIMEType( + const WebString& key_system, + const WebString& mime_type, + const WebString& codecs) { + // Chromium only supports ASCII parameters. + if (!base::IsStringASCII(key_system) || !base::IsStringASCII(mime_type) || + !base::IsStringASCII(codecs)) { + return false; + } + + if (key_system.isEmpty()) + return false; + + const std::string mime_type_ascii = base::UTF16ToASCII(mime_type); + + std::vector<std::string> codec_vector; + bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii); + net::ParseCodecString(base::UTF16ToASCII(codecs), &codec_vector, + strip_suffix); + + return IsSupportedKeySystemWithMediaMimeType( + mime_type_ascii, codec_vector, base::UTF16ToASCII(key_system)); +} + +WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeForExtension( + const WebString& file_extension) { + if (IsPluginProcess()) + return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); + + // The sandbox restricts our access to the registry, so we need to proxy + // these calls over to the browser process. + std::string mime_type; + RenderThread::Get()->Send( + new MimeRegistryMsg_GetMimeTypeFromExtension( + base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type)); + return base::ASCIIToUTF16(mime_type); +} + +WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeFromFile( + const WebString& file_path) { + if (IsPluginProcess()) + return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); + + // The sandbox restricts our access to the registry, so we need to proxy + // these calls over to the browser process. + std::string mime_type; + RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( + base::FilePath::FromUTF16Unsafe(file_path), + &mime_type)); + return base::ASCIIToUTF16(mime_type); +} + +//------------------------------------------------------------------------------ + +bool RendererBlinkPlatformImpl::FileUtilities::getFileInfo( + const WebString& path, + WebFileInfo& web_file_info) { + base::File::Info file_info; + base::File::Error status = base::File::FILE_ERROR_MAX; + if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo( + base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) || + status != base::File::FILE_OK) { + return false; + } + FileInfoToWebFileInfo(file_info, &web_file_info); + web_file_info.platformPath = path; + return true; +} + +bool RendererBlinkPlatformImpl::FileUtilities::SendSyncMessageFromAnyThread( + IPC::SyncMessage* msg) const { + base::TimeTicks begin = base::TimeTicks::Now(); + const bool success = thread_safe_sender_->Send(msg); + base::TimeDelta delta = base::TimeTicks::Now() - begin; + UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta); + return success; +} + +//------------------------------------------------------------------------------ + +#if defined(OS_WIN) + +bool RendererBlinkPlatformImpl::SandboxSupport::ensureFontLoaded(HFONT font) { + LOGFONT logfont; + GetObject(font, sizeof(LOGFONT), &logfont); + RenderThread::Get()->PreCacheFont(logfont); + return true; +} + +#elif defined(OS_MACOSX) + +bool RendererBlinkPlatformImpl::SandboxSupport::loadFont(NSFont* src_font, + CGFontRef* out, + uint32* font_id) { + uint32 font_data_size; + FontDescriptor src_font_descriptor(src_font); + base::SharedMemoryHandle font_data; + if (!RenderThread::Get()->Send(new ViewHostMsg_LoadFont( + src_font_descriptor, &font_data_size, &font_data, font_id))) { + *out = NULL; + *font_id = 0; + return false; + } + + if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || + *font_id == 0) { + LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " << + src_font_descriptor.font_name; + *out = NULL; + *font_id = 0; + return false; + } + + // TODO(jeremy): Need to call back into WebKit to make sure that the font + // isn't already activated, based on the font id. If it's already + // activated, don't reactivate it here - crbug.com/72727 . + + return FontLoader::CGFontRefFromBuffer(font_data, font_data_size, out); +} + +#elif defined(OS_ANDROID) + +// WebKit doesn't use WebSandboxSupport on android so we don't need to +// implement anything here. This is cleaner to support than excluding the +// whole class for android. + +#elif defined(OS_POSIX) + +void RendererBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter( + blink::WebUChar32 character, + const char* preferred_locale, + blink::WebFallbackFont* fallbackFont) { + base::AutoLock lock(unicode_font_families_mutex_); + const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter = + unicode_font_families_.find(character); + if (iter != unicode_font_families_.end()) { + fallbackFont->name = iter->second.name; + fallbackFont->filename = iter->second.filename; + fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId; + fallbackFont->ttcIndex = iter->second.ttcIndex; + fallbackFont->isBold = iter->second.isBold; + fallbackFont->isItalic = iter->second.isItalic; + return; + } + + GetFallbackFontForCharacter(character, preferred_locale, fallbackFont); + unicode_font_families_.insert(std::make_pair(character, *fallbackFont)); +} + +void RendererBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike( + const char* family, + int sizeAndStyle, + blink::WebFontRenderStyle* out) { + GetRenderStyleForStrike(family, sizeAndStyle, out); +} + +#endif + +//------------------------------------------------------------------------------ + +Platform::FileHandle RendererBlinkPlatformImpl::databaseOpenFile( + const WebString& vfs_file_name, + int desired_flags) { + return DatabaseUtil::DatabaseOpenFile( + vfs_file_name, desired_flags, sync_message_filter_.get()); +} + +int RendererBlinkPlatformImpl::databaseDeleteFile( + const WebString& vfs_file_name, + bool sync_dir) { + return DatabaseUtil::DatabaseDeleteFile( + vfs_file_name, sync_dir, sync_message_filter_.get()); +} + +long RendererBlinkPlatformImpl::databaseGetFileAttributes( + const WebString& vfs_file_name) { + return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name, + sync_message_filter_.get()); +} + +long long RendererBlinkPlatformImpl::databaseGetFileSize( + const WebString& vfs_file_name) { + return DatabaseUtil::DatabaseGetFileSize(vfs_file_name, + sync_message_filter_.get()); +} + +long long RendererBlinkPlatformImpl::databaseGetSpaceAvailableForOrigin( + const WebString& origin_identifier) { + return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier, + sync_message_filter_.get()); +} + +bool RendererBlinkPlatformImpl::canAccelerate2dCanvas() { + RenderThreadImpl* thread = RenderThreadImpl::current(); + GpuChannelHost* host = thread->EstablishGpuChannelSync( + CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); + if (!host) + return false; + + return host->gpu_info().SupportsAccelerated2dCanvas(); +} + +bool RendererBlinkPlatformImpl::isThreadedCompositingEnabled() { + RenderThreadImpl* thread = RenderThreadImpl::current(); + // thread can be NULL in tests. + return thread && thread->compositor_message_loop_proxy().get(); +} + +double RendererBlinkPlatformImpl::audioHardwareSampleRate() { + RenderThreadImpl* thread = RenderThreadImpl::current(); + return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); +} + +size_t RendererBlinkPlatformImpl::audioHardwareBufferSize() { + RenderThreadImpl* thread = RenderThreadImpl::current(); + return thread->GetAudioHardwareConfig()->GetOutputBufferSize(); +} + +unsigned RendererBlinkPlatformImpl::audioHardwareOutputChannels() { + RenderThreadImpl* thread = RenderThreadImpl::current(); + return thread->GetAudioHardwareConfig()->GetOutputChannels(); +} + +WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() { + return web_database_observer_impl_.get(); +} + +WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice( + size_t buffer_size, + unsigned input_channels, + unsigned channels, + double sample_rate, + WebAudioDevice::RenderCallback* callback, + const blink::WebString& input_device_id) { + // Use a mock for testing. + blink::WebAudioDevice* mock_device = + GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate); + if (mock_device) + return mock_device; + + // The |channels| does not exactly identify the channel layout of the + // device. The switch statement below assigns a best guess to the channel + // layout based on number of channels. + // TODO(crogers): WebKit should give the channel layout instead of the hard + // channel count. + media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED; + switch (channels) { + case 1: + layout = media::CHANNEL_LAYOUT_MONO; + break; + case 2: + layout = media::CHANNEL_LAYOUT_STEREO; + break; + case 3: + layout = media::CHANNEL_LAYOUT_2_1; + break; + case 4: + layout = media::CHANNEL_LAYOUT_4_0; + break; + case 5: + layout = media::CHANNEL_LAYOUT_5_0; + break; + case 6: + layout = media::CHANNEL_LAYOUT_5_1; + break; + case 7: + layout = media::CHANNEL_LAYOUT_7_0; + break; + case 8: + layout = media::CHANNEL_LAYOUT_7_1; + break; + default: + layout = media::CHANNEL_LAYOUT_STEREO; + } + + int session_id = 0; + if (input_device_id.isNull() || + !base::StringToInt(base::UTF16ToUTF8(input_device_id), &session_id)) { + if (input_channels > 0) + DLOG(WARNING) << "createAudioDevice(): request for audio input ignored"; + + input_channels = 0; + } + + media::AudioParameters params( + media::AudioParameters::AUDIO_PCM_LOW_LATENCY, + layout, static_cast<int>(sample_rate), 16, buffer_size, + media::AudioParameters::NO_EFFECTS); + + return new RendererWebAudioDeviceImpl(params, callback, session_id); +} + +#if defined(OS_ANDROID) +bool RendererBlinkPlatformImpl::loadAudioResource( + blink::WebAudioBus* destination_bus, + const char* audio_file_data, + size_t data_size) { + return DecodeAudioFileData(destination_bus, + audio_file_data, + data_size, + thread_safe_sender_); +} +#else +bool RendererBlinkPlatformImpl::loadAudioResource( + blink::WebAudioBus* destination_bus, + const char* audio_file_data, + size_t data_size) { + return DecodeAudioFileData( + destination_bus, audio_file_data, data_size); +} +#endif // defined(OS_ANDROID) + +//------------------------------------------------------------------------------ + +blink::WebMIDIAccessor* RendererBlinkPlatformImpl::createMIDIAccessor( + blink::WebMIDIAccessorClient* client) { + blink::WebMIDIAccessor* accessor = + GetContentClient()->renderer()->OverrideCreateMIDIAccessor(client); + if (accessor) + return accessor; + + return new RendererWebMIDIAccessorImpl(client); +} + +void RendererBlinkPlatformImpl::getPluginList( + bool refresh, + blink::WebPluginListBuilder* builder) { +#if defined(ENABLE_PLUGINS) + std::vector<WebPluginInfo> plugins; + if (!plugin_refresh_allowed_) + refresh = false; + RenderThread::Get()->Send( + new ViewHostMsg_GetPlugins(refresh, &plugins)); + for (size_t i = 0; i < plugins.size(); ++i) { + const WebPluginInfo& plugin = plugins[i]; + + builder->addPlugin( + plugin.name, plugin.desc, + plugin.path.BaseName().AsUTF16Unsafe()); + + for (size_t j = 0; j < plugin.mime_types.size(); ++j) { + const WebPluginMimeType& mime_type = plugin.mime_types[j]; + + builder->addMediaTypeToLastPlugin( + WebString::fromUTF8(mime_type.mime_type), mime_type.description); + + for (size_t k = 0; k < mime_type.file_extensions.size(); ++k) { + builder->addFileExtensionToLastMediaType( + WebString::fromUTF8(mime_type.file_extensions[k])); + } + } + } +#endif +} + +//------------------------------------------------------------------------------ + +blink::WebPublicSuffixList* RendererBlinkPlatformImpl::publicSuffixList() { + return &public_suffix_list_; +} + +//------------------------------------------------------------------------------ + +blink::WebString RendererBlinkPlatformImpl::signedPublicKeyAndChallengeString( + unsigned key_size_index, + const blink::WebString& challenge, + const blink::WebURL& url) { + std::string signed_public_key; + RenderThread::Get()->Send(new ViewHostMsg_Keygen( + static_cast<uint32>(key_size_index), + challenge.utf8(), + GURL(url), + &signed_public_key)); + return WebString::fromUTF8(signed_public_key); +} + +//------------------------------------------------------------------------------ + +void RendererBlinkPlatformImpl::screenColorProfile( + WebVector<char>* to_profile) { +#if defined(OS_WIN) + // On Windows screen color profile is only available in the browser. + std::vector<char> profile; + // This Send() can be called from any impl-side thread. Use a thread + // safe send to avoid crashing trying to access RenderThread::Get(), + // which is not accessible from arbitrary threads. + thread_safe_sender_->Send( + new ViewHostMsg_GetMonitorColorProfile(&profile)); + *to_profile = profile; +#else + // On other platforms, the primary monitor color profile can be read + // directly. + gfx::ColorProfile profile; + *to_profile = profile.profile(); +#endif +} + +//------------------------------------------------------------------------------ + +blink::WebScrollbarBehavior* RendererBlinkPlatformImpl::scrollbarBehavior() { + return web_scrollbar_behavior_.get(); +} + +//------------------------------------------------------------------------------ + +WebBlobRegistry* RendererBlinkPlatformImpl::blobRegistry() { + // blob_registry_ can be NULL when running some tests. + return blob_registry_.get(); +} + +//------------------------------------------------------------------------------ + +void RendererBlinkPlatformImpl::sampleGamepads(WebGamepads& gamepads) { + PlatformEventObserverBase* observer = + platform_event_observers_.Lookup(blink::WebPlatformEventGamepad); + if (!observer) + return; + static_cast<RendererGamepadProvider*>(observer)->SampleGamepads(gamepads); +} + +//------------------------------------------------------------------------------ + +WebRTCPeerConnectionHandler* +RendererBlinkPlatformImpl::createRTCPeerConnectionHandler( + WebRTCPeerConnectionHandlerClient* client) { + RenderThreadImpl* render_thread = RenderThreadImpl::current(); + DCHECK(render_thread); + if (!render_thread) + return NULL; + +#if defined(ENABLE_WEBRTC) + WebRTCPeerConnectionHandler* peer_connection_handler = + GetContentClient()->renderer()->OverrideCreateWebRTCPeerConnectionHandler( + client); + if (peer_connection_handler) + return peer_connection_handler; + + PeerConnectionDependencyFactory* rtc_dependency_factory = + render_thread->GetPeerConnectionDependencyFactory(); + return rtc_dependency_factory->CreateRTCPeerConnectionHandler(client); +#else + return NULL; +#endif // defined(ENABLE_WEBRTC) +} + +//------------------------------------------------------------------------------ + +WebMediaStreamCenter* RendererBlinkPlatformImpl::createMediaStreamCenter( + WebMediaStreamCenterClient* client) { + RenderThreadImpl* render_thread = RenderThreadImpl::current(); + DCHECK(render_thread); + if (!render_thread) + return NULL; + return render_thread->CreateMediaStreamCenter(client); +} + +// static +bool RendererBlinkPlatformImpl::SetSandboxEnabledForTesting(bool enable) { + bool was_enabled = g_sandbox_enabled; + g_sandbox_enabled = enable; + return was_enabled; +} + +//------------------------------------------------------------------------------ + +blink::WebSpeechSynthesizer* RendererBlinkPlatformImpl::createSpeechSynthesizer( + blink::WebSpeechSynthesizerClient* client) { + return GetContentClient()->renderer()->OverrideSpeechSynthesizer(client); +} + +//------------------------------------------------------------------------------ + +bool RendererBlinkPlatformImpl::processMemorySizesInBytes( + size_t* private_bytes, + size_t* shared_bytes) { + content::RenderThread::Get()->Send( + new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); + return true; +} + +//------------------------------------------------------------------------------ + +blink::WebGraphicsContext3D* +RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D( + const blink::WebGraphicsContext3D::Attributes& attributes) { + return createOffscreenGraphicsContext3D(attributes, NULL); +} + +blink::WebGraphicsContext3D* +RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D( + const blink::WebGraphicsContext3D::Attributes& attributes, + blink::WebGraphicsContext3D* share_context) { + if (!RenderThreadImpl::current()) + return NULL; + +#if defined(OS_ANDROID) + if (SynchronousCompositorFactory* factory = + SynchronousCompositorFactory::GetInstance()) { + scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl> + in_process_context( + factory->CreateOffscreenGraphicsContext3D(attributes)); + if (!in_process_context || + !in_process_context->InitializeOnCurrentThread()) + return NULL; + return in_process_context.release(); + } +#endif + + scoped_refptr<GpuChannelHost> gpu_channel_host( + RenderThreadImpl::current()->EstablishGpuChannelSync( + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)); + + WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; + bool lose_context_when_out_of_memory = false; + scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( + WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( + gpu_channel_host.get(), + attributes, + lose_context_when_out_of_memory, + GURL(attributes.topDocumentURL), + limits, + static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context))); + + // Most likely the GPU process exited and the attempt to reconnect to it + // failed. Need to try to restore the context again later. + if (!context || !context->InitializeOnCurrentThread()) + return NULL; + return context.release(); +} + +//------------------------------------------------------------------------------ + +blink::WebGraphicsContext3DProvider* +RendererBlinkPlatformImpl::createSharedOffscreenGraphicsContext3DProvider() { + scoped_refptr<webkit::gpu::ContextProviderWebContext> provider = + RenderThreadImpl::current()->SharedMainThreadContextProvider(); + if (!provider.get()) + return NULL; + return new WebGraphicsContext3DProviderImpl(provider); +} + +//------------------------------------------------------------------------------ + +blink::WebCompositorSupport* RendererBlinkPlatformImpl::compositorSupport() { + return &compositor_support_; +} + +//------------------------------------------------------------------------------ + +blink::WebString RendererBlinkPlatformImpl::convertIDNToUnicode( + const blink::WebString& host, + const blink::WebString& languages) { + return net::IDNToUnicode(host.utf8(), languages.utf8()); +} + +//------------------------------------------------------------------------------ + +// static +void RendererBlinkPlatformImpl::SetMockDeviceLightDataForTesting(double data) { + g_test_device_light_data = data; +} + +//------------------------------------------------------------------------------ + +// static +void RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting( + const blink::WebDeviceMotionData& data) { + g_test_device_motion_data.Get() = data; +} + +//------------------------------------------------------------------------------ + +// static +void RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting( + const blink::WebDeviceOrientationData& data) { + g_test_device_orientation_data.Get() = data; +} + +//------------------------------------------------------------------------------ + +void RendererBlinkPlatformImpl::vibrate(unsigned int milliseconds) { + RenderThread::Get()->Send( + new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); +} + +void RendererBlinkPlatformImpl::cancelVibration() { + RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); +} + +//------------------------------------------------------------------------------ + +// static +PlatformEventObserverBase* +RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( + blink::WebPlatformEventType type) { + RenderThread* thread = RenderThreadImpl::current(); + + // When running layout tests, those observers should not listen to the actual + // hardware changes. In order to make that happen, they will receive a null + // thread. + if (thread && RenderThreadImpl::current()->layout_test_mode()) + thread = 0; + + switch (type) { + case blink::WebPlatformEventDeviceMotion: { + return new DeviceMotionEventPump(thread); + } + case blink::WebPlatformEventDeviceOrientation: { + return new DeviceOrientationEventPump(thread); + } + case blink::WebPlatformEventDeviceLight: { + return new DeviceLightEventPump(thread); + } + case blink::WebPlatformEventBattery: { + return new BatteryStatusDispatcher(thread); + } + case blink::WebPlatformEventGamepad: + return new GamepadSharedMemoryReader(thread); + break; + case blink::WebPlatformEventScreenOrientation: + return new ScreenOrientationObserver(); + default: + // A default statement is required to prevent compilation errors when Blink + // adds a new type. + VLOG(1) << "RendererBlinkPlatformImpl::startListening() with " + "unknown type."; + } + + return 0; +} + +void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( + blink::WebPlatformEventType type, + scoped_ptr<PlatformEventObserverBase> observer) { + if (platform_event_observers_.Lookup(type)) + platform_event_observers_.Remove(type); + platform_event_observers_.AddWithID(observer.release(), type); +} + +void RendererBlinkPlatformImpl::startListening( + blink::WebPlatformEventType type, + blink::WebPlatformEventListener* listener) { + PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); + if (!observer) { + observer = CreatePlatformEventObserverFromType(type); + if (!observer) + return; + platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); + } + observer->Start(listener); + + // Device events (motion, orientation and light) expect to get an event fired + // as soon as a listener is registered if a fake data was passed before. + // TODO(mlamouri,timvolodine): make those send mock values directly instead of + // using this broken pattern. + if (RenderThreadImpl::current() && + RenderThreadImpl::current()->layout_test_mode() && + (type == blink::WebPlatformEventDeviceMotion || + type == blink::WebPlatformEventDeviceOrientation || + type == blink::WebPlatformEventDeviceLight)) { + SendFakeDeviceEventDataForTesting(type); + } +} + +void RendererBlinkPlatformImpl::SendFakeDeviceEventDataForTesting( + blink::WebPlatformEventType type) { + PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); + CHECK(observer); + + void* data = 0; + + switch (type) { + case blink::WebPlatformEventDeviceMotion: + if (!(g_test_device_motion_data == 0)) + data = &g_test_device_motion_data.Get(); + break; + case blink::WebPlatformEventDeviceOrientation: + if (!(g_test_device_orientation_data == 0)) + data = &g_test_device_orientation_data.Get(); + break; + case blink::WebPlatformEventDeviceLight: + if (g_test_device_light_data >= 0) + data = &g_test_device_light_data; + break; + default: + NOTREACHED(); + break; + } + + if (!data) + return; + + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, + base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, + base::Unretained(observer), data)); +} + +void RendererBlinkPlatformImpl::stopListening( + blink::WebPlatformEventType type) { + PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); + if (!observer) + return; + observer->Stop(); +} + +//------------------------------------------------------------------------------ + +void RendererBlinkPlatformImpl::queryStorageUsageAndQuota( + const blink::WebURL& storage_partition, + blink::WebStorageQuotaType type, + blink::WebStorageQuotaCallbacks callbacks) { + if (!thread_safe_sender_.get() || !quota_message_filter_.get()) + return; + QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(), + quota_message_filter_.get()) + ->QueryStorageUsageAndQuota( + storage_partition, + static_cast<storage::StorageType>(type), + QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); +} + +//------------------------------------------------------------------------------ + +void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting( + const blink::WebBatteryStatus& status) { + PlatformEventObserverBase* observer = + platform_event_observers_.Lookup(blink::WebPlatformEventBattery); + if (!observer) + return; + observer->SendFakeDataForTesting((void*)&status); +} + +} // namespace content diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h new file mode 100644 index 0000000..9d881bf --- /dev/null +++ b/content/renderer/renderer_blink_platform_impl.h @@ -0,0 +1,247 @@ +// 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_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_ +#define CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_ + +#include "base/compiler_specific.h" +#include "base/id_map.h" +#include "base/memory/scoped_ptr.h" +#include "cc/blink/web_compositor_support_impl.h" +#include "content/child/blink_platform_impl.h" +#include "content/common/content_export.h" +#include "content/renderer/webpublicsuffixlist_impl.h" +#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" +#include "third_party/WebKit/public/platform/WebIDBFactory.h" +#include "third_party/WebKit/public/platform/WebScreenOrientationType.h" + +namespace base { +class MessageLoopProxy; +} + +namespace cc { +class ContextProvider; +} + +namespace IPC { +class SyncMessageFilter; +} + +namespace blink { +class WebBatteryStatus; +class WebDeviceMotionData; +class WebDeviceOrientationData; +class WebGraphicsContext3DProvider; +} + +namespace content { +class BatteryStatusDispatcher; +class DeviceLightEventPump; +class DeviceMotionEventPump; +class DeviceOrientationEventPump; +class PlatformEventObserverBase; +class QuotaMessageFilter; +class RendererClipboardClient; +class RenderView; +class ThreadSafeSender; +class WebClipboardImpl; +class WebDatabaseObserverImpl; +class WebFileSystemImpl; + +class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { + public: + RendererBlinkPlatformImpl(); + virtual ~RendererBlinkPlatformImpl(); + + void set_plugin_refresh_allowed(bool plugin_refresh_allowed) { + plugin_refresh_allowed_ = plugin_refresh_allowed; + } + // Platform methods: + virtual blink::WebClipboard* clipboard(); + virtual blink::WebMimeRegistry* mimeRegistry(); + virtual blink::WebFileUtilities* fileUtilities(); + virtual blink::WebSandboxSupport* sandboxSupport(); + virtual blink::WebCookieJar* cookieJar(); + virtual blink::WebThemeEngine* themeEngine(); + virtual blink::WebSpeechSynthesizer* createSpeechSynthesizer( + blink::WebSpeechSynthesizerClient* client); + virtual bool sandboxEnabled(); + virtual unsigned long long visitedLinkHash( + const char* canonicalURL, size_t length); + virtual bool isLinkVisited(unsigned long long linkHash); + virtual void createMessageChannel(blink::WebMessagePortChannel** channel1, + blink::WebMessagePortChannel** channel2); + virtual blink::WebPrescientNetworking* prescientNetworking(); + virtual void cacheMetadata( + const blink::WebURL&, double, const char*, size_t); + virtual blink::WebString defaultLocale(); + virtual void suddenTerminationChanged(bool enabled); + virtual blink::WebStorageNamespace* createLocalStorageNamespace(); + virtual blink::Platform::FileHandle databaseOpenFile( + const blink::WebString& vfs_file_name, int desired_flags); + virtual int databaseDeleteFile(const blink::WebString& vfs_file_name, + bool sync_dir); + virtual long databaseGetFileAttributes( + const blink::WebString& vfs_file_name); + virtual long long databaseGetFileSize( + const blink::WebString& vfs_file_name); + virtual long long databaseGetSpaceAvailableForOrigin( + const blink::WebString& origin_identifier); + virtual blink::WebString signedPublicKeyAndChallengeString( + unsigned key_size_index, + const blink::WebString& challenge, + const blink::WebURL& url); + virtual void getPluginList(bool refresh, + blink::WebPluginListBuilder* builder); + virtual blink::WebPublicSuffixList* publicSuffixList(); + virtual void screenColorProfile(blink::WebVector<char>* to_profile); + virtual blink::WebScrollbarBehavior* scrollbarBehavior(); + virtual blink::WebIDBFactory* idbFactory(); + virtual blink::WebFileSystem* fileSystem(); + virtual bool canAccelerate2dCanvas(); + virtual bool isThreadedCompositingEnabled(); + virtual double audioHardwareSampleRate(); + virtual size_t audioHardwareBufferSize(); + virtual unsigned audioHardwareOutputChannels(); + virtual blink::WebDatabaseObserver* databaseObserver(); + + virtual blink::WebAudioDevice* createAudioDevice( + size_t buffer_size, unsigned input_channels, unsigned channels, + double sample_rate, blink::WebAudioDevice::RenderCallback* callback, + const blink::WebString& input_device_id); + + virtual bool loadAudioResource( + blink::WebAudioBus* destination_bus, const char* audio_file_data, + size_t data_size); + + virtual blink::WebMIDIAccessor* + createMIDIAccessor(blink::WebMIDIAccessorClient* client); + + virtual blink::WebBlobRegistry* blobRegistry(); + virtual void sampleGamepads(blink::WebGamepads&); + virtual blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler( + blink::WebRTCPeerConnectionHandlerClient* client); + virtual blink::WebMediaStreamCenter* createMediaStreamCenter( + blink::WebMediaStreamCenterClient* client); + virtual bool processMemorySizesInBytes( + size_t* private_bytes, size_t* shared_bytes); + virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D( + const blink::WebGraphicsContext3D::Attributes& attributes); + virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D( + const blink::WebGraphicsContext3D::Attributes& attributes, + blink::WebGraphicsContext3D* share_context); + virtual blink::WebGraphicsContext3DProvider* + createSharedOffscreenGraphicsContext3DProvider(); + virtual blink::WebCompositorSupport* compositorSupport(); + virtual blink::WebString convertIDNToUnicode( + const blink::WebString& host, const blink::WebString& languages); + virtual void startListening(blink::WebPlatformEventType, + blink::WebPlatformEventListener*); + virtual void stopListening(blink::WebPlatformEventType); + virtual void queryStorageUsageAndQuota( + const blink::WebURL& storage_partition, + blink::WebStorageQuotaType, + blink::WebStorageQuotaCallbacks); + virtual void vibrate(unsigned int milliseconds); + virtual void cancelVibration(); + + // Set the PlatformEventObserverBase in |platform_event_observers_| associated + // with |type| to |observer|. If there was already an observer associated to + // the given |type|, it will be replaced. + // Note that |observer| will be owned by this object after the call. + void SetPlatformEventObserverForTesting( + blink::WebPlatformEventType type, + scoped_ptr<PlatformEventObserverBase> observer); + + // Disables the WebSandboxSupport implementation for testing. + // Tests that do not set up a full sandbox environment should call + // SetSandboxEnabledForTesting(false) _before_ creating any instances + // of this class, to ensure that we don't attempt to use sandbox-related + // file descriptors or other resources. + // + // Returns the previous |enable| value. + static bool SetSandboxEnabledForTesting(bool enable); + + // Set a double to return when setDeviceLightListener is invoked. + static void SetMockDeviceLightDataForTesting(double data); + // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked. + static void SetMockDeviceMotionDataForTesting( + const blink::WebDeviceMotionData& data); + // Set WebDeviceOrientationData to return when setDeviceOrientationListener + // is invoked. + static void SetMockDeviceOrientationDataForTesting( + const blink::WebDeviceOrientationData& data); + + // Notifies blink::WebBatteryStatusListener that battery status has changed. + void MockBatteryStatusChangedForTesting( + const blink::WebBatteryStatus& status); + + WebDatabaseObserverImpl* web_database_observer_impl() { + return web_database_observer_impl_.get(); + } + + private: + bool CheckPreparsedJsCachingEnabled() const; + + // Factory that takes a type and return PlatformEventObserverBase that matches + // it. + static PlatformEventObserverBase* CreatePlatformEventObserverFromType( + blink::WebPlatformEventType type); + + // Use the data previously set via SetMockDevice...DataForTesting() and send + // them to the registered listener. + void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type); + + scoped_ptr<RendererClipboardClient> clipboard_client_; + scoped_ptr<WebClipboardImpl> clipboard_; + + class FileUtilities; + scoped_ptr<FileUtilities> file_utilities_; + + class MimeRegistry; + scoped_ptr<MimeRegistry> mime_registry_; + + class SandboxSupport; + scoped_ptr<SandboxSupport> sandbox_support_; + + // This counter keeps track of the number of times sudden termination is + // enabled or disabled. It starts at 0 (enabled) and for every disable + // increments by 1, for every enable decrements by 1. When it reaches 0, + // we tell the browser to enable fast termination. + int sudden_termination_disables_; + + // If true, then a GetPlugins call is allowed to rescan the disk. + bool plugin_refresh_allowed_; + + scoped_ptr<blink::WebIDBFactory> web_idb_factory_; + + scoped_ptr<blink::WebBlobRegistry> blob_registry_; + + WebPublicSuffixListImpl public_suffix_list_; + + scoped_ptr<DeviceLightEventPump> device_light_event_pump_; + scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_; + scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_; + + scoped_refptr<base::MessageLoopProxy> child_thread_loop_; + scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; + scoped_refptr<ThreadSafeSender> thread_safe_sender_; + scoped_refptr<QuotaMessageFilter> quota_message_filter_; + + scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; + + cc_blink::WebCompositorSupportImpl compositor_support_; + + scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_; + + scoped_ptr<BatteryStatusDispatcher> battery_status_dispatcher_; + + IDMap<PlatformEventObserverBase, IDMapOwnPointer> platform_event_observers_; + + DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_ diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc deleted file mode 100644 index d2c087c..0000000 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ /dev/null @@ -1,1196 +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/renderer/renderer_webkitplatformsupport_impl.h" - -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/memory/shared_memory.h" -#include "base/message_loop/message_loop_proxy.h" -#include "base/metrics/histogram.h" -#include "base/numerics/safe_conversions.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "content/child/database_util.h" -#include "content/child/file_info_util.h" -#include "content/child/fileapi/webfilesystem_impl.h" -#include "content/child/indexed_db/webidbfactory_impl.h" -#include "content/child/npapi/npobject_util.h" -#include "content/child/quota_dispatcher.h" -#include "content/child/quota_message_filter.h" -#include "content/child/simple_webmimeregistry_impl.h" -#include "content/child/thread_safe_sender.h" -#include "content/child/web_database_observer_impl.h" -#include "content/child/webblobregistry_impl.h" -#include "content/child/webfileutilities_impl.h" -#include "content/child/webmessageportchannel_impl.h" -#include "content/common/file_utilities_messages.h" -#include "content/common/gpu/client/context_provider_command_buffer.h" -#include "content/common/gpu/client/gpu_channel_host.h" -#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" -#include "content/common/gpu/gpu_process_launch_causes.h" -#include "content/common/mime_registry_messages.h" -#include "content/common/view_messages.h" -#include "content/public/common/content_switches.h" -#include "content/public/common/webplugininfo.h" -#include "content/public/renderer/content_renderer_client.h" -#include "content/renderer/battery_status/battery_status_dispatcher.h" -#include "content/renderer/device_sensors/device_light_event_pump.h" -#include "content/renderer/device_sensors/device_motion_event_pump.h" -#include "content/renderer/device_sensors/device_orientation_event_pump.h" -#include "content/renderer/dom_storage/webstoragenamespace_impl.h" -#include "content/renderer/gamepad_shared_memory_reader.h" -#include "content/renderer/media/audio_decoder.h" -#include "content/renderer/media/crypto/key_systems.h" -#include "content/renderer/media/renderer_webaudiodevice_impl.h" -#include "content/renderer/media/renderer_webmidiaccessor_impl.h" -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" -#include "content/renderer/render_thread_impl.h" -#include "content/renderer/renderer_clipboard_client.h" -#include "content/renderer/screen_orientation/screen_orientation_observer.h" -#include "content/renderer/webclipboard_impl.h" -#include "content/renderer/webgraphicscontext3d_provider_impl.h" -#include "content/renderer/webpublicsuffixlist_impl.h" -#include "gpu/config/gpu_info.h" -#include "ipc/ipc_sync_message_filter.h" -#include "media/audio/audio_output_device.h" -#include "media/base/audio_hardware_config.h" -#include "media/filters/stream_parser_factory.h" -#include "net/base/mime_util.h" -#include "net/base/net_util.h" -#include "storage/common/quota/quota_types.h" -#include "third_party/WebKit/public/platform/WebBatteryStatusListener.h" -#include "third_party/WebKit/public/platform/WebBlobRegistry.h" -#include "third_party/WebKit/public/platform/WebDeviceLightListener.h" -#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h" -#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h" -#include "third_party/WebKit/public/platform/WebFileInfo.h" -#include "third_party/WebKit/public/platform/WebGamepads.h" -#include "third_party/WebKit/public/platform/WebMediaStreamCenter.h" -#include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" -#include "third_party/WebKit/public/platform/WebPluginListBuilder.h" -#include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/platform/WebVector.h" -#include "ui/gfx/color_profile.h" -#include "url/gurl.h" -#include "webkit/common/gpu/context_provider_web_context.h" - -#if defined(OS_ANDROID) -#include "content/renderer/android/synchronous_compositor_factory.h" -#include "content/renderer/media/android/audio_decoder_android.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" -#endif - -#if defined(OS_MACOSX) -#include "content/common/mac/font_descriptor.h" -#include "content/common/mac/font_loader.h" -#include "content/renderer/webscrollbarbehavior_impl_mac.h" -#include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h" -#endif - -#if defined(OS_POSIX) -#include "base/file_descriptor_posix.h" -#if !defined(OS_MACOSX) && !defined(OS_ANDROID) -#include <map> -#include <string> - -#include "base/synchronization/lock.h" -#include "content/common/child_process_sandbox_support_impl_linux.h" -#include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" -#include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" -#include "third_party/icu/source/common/unicode/utf16.h" -#endif -#endif - -#if defined(OS_WIN) -#include "content/common/child_process_messages.h" -#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" -#endif - -#if defined(USE_AURA) -#include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" -#elif !defined(OS_MACOSX) -#include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" -#define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior -#endif - -#if defined(ENABLE_WEBRTC) -#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" -#endif - -using blink::Platform; -using blink::WebAudioDevice; -using blink::WebBlobRegistry; -using blink::WebDatabaseObserver; -using blink::WebFileInfo; -using blink::WebFileSystem; -using blink::WebGamepad; -using blink::WebGamepads; -using blink::WebIDBFactory; -using blink::WebMIDIAccessor; -using blink::WebMediaStreamCenter; -using blink::WebMediaStreamCenterClient; -using blink::WebMimeRegistry; -using blink::WebRTCPeerConnectionHandler; -using blink::WebRTCPeerConnectionHandlerClient; -using blink::WebStorageNamespace; -using blink::WebString; -using blink::WebURL; -using blink::WebVector; - -namespace content { - -namespace { - -bool g_sandbox_enabled = true; -double g_test_device_light_data = -1; -base::LazyInstance<blink::WebDeviceMotionData>::Leaky - g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; -base::LazyInstance<blink::WebDeviceOrientationData>::Leaky - g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; - -} // namespace - -//------------------------------------------------------------------------------ - -class RendererWebKitPlatformSupportImpl::MimeRegistry - : public SimpleWebMimeRegistryImpl { - public: - virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( - const blink::WebString& mime_type, - const blink::WebString& codecs, - const blink::WebString& key_system); - virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type, - const blink::WebString& codecs); - virtual bool supportsEncryptedMediaMIMEType(const WebString& key_system, - const WebString& mime_type, - const WebString& codecs) OVERRIDE; - virtual blink::WebString mimeTypeForExtension( - const blink::WebString& file_extension); - virtual blink::WebString mimeTypeFromFile( - const blink::WebString& file_path); -}; - -class RendererWebKitPlatformSupportImpl::FileUtilities - : public WebFileUtilitiesImpl { - public: - explicit FileUtilities(ThreadSafeSender* sender) - : thread_safe_sender_(sender) {} - virtual bool getFileInfo(const WebString& path, WebFileInfo& result); - private: - bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const; - scoped_refptr<ThreadSafeSender> thread_safe_sender_; -}; - -#if defined(OS_ANDROID) -// WebKit doesn't use WebSandboxSupport on android so we don't need to -// implement anything here. -class RendererWebKitPlatformSupportImpl::SandboxSupport { -}; -#else -class RendererWebKitPlatformSupportImpl::SandboxSupport - : public blink::WebSandboxSupport { - public: - virtual ~SandboxSupport() {} - -#if defined(OS_WIN) - virtual bool ensureFontLoaded(HFONT); -#elif defined(OS_MACOSX) - virtual bool loadFont( - NSFont* src_font, - CGFontRef* container, - uint32* font_id); -#elif defined(OS_POSIX) - virtual void getFallbackFontForCharacter( - blink::WebUChar32 character, - const char* preferred_locale, - blink::WebFallbackFont* fallbackFont); - virtual void getRenderStyleForStrike( - const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out); - - private: - // WebKit likes to ask us for the correct font family to use for a set of - // unicode code points. It needs this information frequently so we cache it - // here. - base::Lock unicode_font_families_mutex_; - std::map<int32_t, blink::WebFallbackFont> unicode_font_families_; -#endif -}; -#endif // defined(OS_ANDROID) - -//------------------------------------------------------------------------------ - -RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() - : clipboard_client_(new RendererClipboardClient), - clipboard_(new WebClipboardImpl(clipboard_client_.get())), - mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), - sudden_termination_disables_(0), - plugin_refresh_allowed_(true), - child_thread_loop_(base::MessageLoopProxy::current()), - web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) { - if (g_sandbox_enabled && sandboxEnabled()) { - sandbox_support_.reset( - new RendererWebKitPlatformSupportImpl::SandboxSupport); - } else { - DVLOG(1) << "Disabling sandbox support for testing."; - } - - // ChildThread may not exist in some tests. - if (ChildThread::current()) { - sync_message_filter_ = ChildThread::current()->sync_message_filter(); - thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); - quota_message_filter_ = ChildThread::current()->quota_message_filter(); - blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get())); - web_idb_factory_.reset(new WebIDBFactoryImpl(thread_safe_sender_.get())); - web_database_observer_impl_.reset( - new WebDatabaseObserverImpl(sync_message_filter_.get())); - } -} - -RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { - WebFileSystemImpl::DeleteThreadSpecificInstance(); -} - -//------------------------------------------------------------------------------ - -blink::WebClipboard* RendererWebKitPlatformSupportImpl::clipboard() { - blink::WebClipboard* clipboard = - GetContentClient()->renderer()->OverrideWebClipboard(); - if (clipboard) - return clipboard; - return clipboard_.get(); -} - -blink::WebMimeRegistry* RendererWebKitPlatformSupportImpl::mimeRegistry() { - return mime_registry_.get(); -} - -blink::WebFileUtilities* -RendererWebKitPlatformSupportImpl::fileUtilities() { - if (!file_utilities_) { - file_utilities_.reset(new FileUtilities(thread_safe_sender_.get())); - file_utilities_->set_sandbox_enabled(sandboxEnabled()); - } - return file_utilities_.get(); -} - -blink::WebSandboxSupport* RendererWebKitPlatformSupportImpl::sandboxSupport() { -#if defined(OS_ANDROID) - // WebKit doesn't use WebSandboxSupport on android. - return NULL; -#else - return sandbox_support_.get(); -#endif -} - -blink::WebCookieJar* RendererWebKitPlatformSupportImpl::cookieJar() { - NOTREACHED() << "Use WebFrameClient::cookieJar() instead!"; - return NULL; -} - -blink::WebThemeEngine* RendererWebKitPlatformSupportImpl::themeEngine() { - blink::WebThemeEngine* theme_engine = - GetContentClient()->renderer()->OverrideThemeEngine(); - if (theme_engine) - return theme_engine; - return BlinkPlatformImpl::themeEngine(); -} - -bool RendererWebKitPlatformSupportImpl::sandboxEnabled() { - // As explained in Platform.h, this function is used to decide - // whether to allow file system operations to come out of WebKit or not. - // Even if the sandbox is disabled, there's no reason why the code should - // act any differently...unless we're in single process mode. In which - // case, we have no other choice. Platform.h discourages using - // this switch unless absolutely necessary, so hopefully we won't end up - // with too many code paths being different in single-process mode. - return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); -} - -unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash( - const char* canonical_url, - size_t length) { - return GetContentClient()->renderer()->VisitedLinkHash(canonical_url, length); -} - -bool RendererWebKitPlatformSupportImpl::isLinkVisited( - unsigned long long link_hash) { - return GetContentClient()->renderer()->IsLinkVisited(link_hash); -} - -void RendererWebKitPlatformSupportImpl::createMessageChannel( - blink::WebMessagePortChannel** channel1, - blink::WebMessagePortChannel** channel2) { - WebMessagePortChannelImpl::CreatePair( - child_thread_loop_.get(), channel1, channel2); -} - -blink::WebPrescientNetworking* -RendererWebKitPlatformSupportImpl::prescientNetworking() { - return GetContentClient()->renderer()->GetPrescientNetworking(); -} - -void RendererWebKitPlatformSupportImpl::cacheMetadata( - const blink::WebURL& url, - double response_time, - const char* data, - size_t size) { - // Let the browser know we generated cacheable metadata for this resource. The - // browser may cache it and return it on subsequent responses to speed - // the processing of this resource. - std::vector<char> copy(data, data + size); - RenderThread::Get()->Send( - new ViewHostMsg_DidGenerateCacheableMetadata(url, response_time, copy)); -} - -WebString RendererWebKitPlatformSupportImpl::defaultLocale() { - return base::ASCIIToUTF16(RenderThread::Get()->GetLocale()); -} - -void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled) { - if (enabled) { - // We should not get more enables than disables, but we want it to be a - // non-fatal error if it does happen. - DCHECK_GT(sudden_termination_disables_, 0); - sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, - 0); - if (sudden_termination_disables_ != 0) - return; - } else { - sudden_termination_disables_++; - if (sudden_termination_disables_ != 1) - return; - } - - RenderThread* thread = RenderThread::Get(); - if (thread) // NULL in unittests. - thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); -} - -WebStorageNamespace* -RendererWebKitPlatformSupportImpl::createLocalStorageNamespace() { - return new WebStorageNamespaceImpl(); -} - - -//------------------------------------------------------------------------------ - -WebIDBFactory* RendererWebKitPlatformSupportImpl::idbFactory() { - return web_idb_factory_.get(); -} - -//------------------------------------------------------------------------------ - -WebFileSystem* RendererWebKitPlatformSupportImpl::fileSystem() { - return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get()); -} - -//------------------------------------------------------------------------------ - -WebMimeRegistry::SupportsType -RendererWebKitPlatformSupportImpl::MimeRegistry::supportsMediaMIMEType( - const WebString& mime_type, - const WebString& codecs, - const WebString& key_system) { - const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); - // Not supporting the container is a flat-out no. - if (!net::IsSupportedMediaMimeType(mime_type_ascii)) - return IsNotSupported; - - if (!key_system.isEmpty()) { - // Check whether the key system is supported with the mime_type and codecs. - - // Chromium only supports ASCII parameters. - if (!base::IsStringASCII(key_system)) - return IsNotSupported; - - std::string key_system_ascii = - GetUnprefixedKeySystemName(base::UTF16ToASCII(key_system)); - std::vector<std::string> strict_codecs; - net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, true); - - if (!IsSupportedKeySystemWithMediaMimeType( - mime_type_ascii, strict_codecs, key_system_ascii)) { - return IsNotSupported; - } - - // Continue processing the mime_type and codecs. - } - - // Check list of strict codecs to see if it is supported. - if (net::IsStrictMediaMimeType(mime_type_ascii)) { - // Check if the codecs are a perfect match. - std::vector<std::string> strict_codecs; - net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); - return static_cast<WebMimeRegistry::SupportsType> ( - net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); - } - - // If we don't recognize the codec, it's possible we support it. - std::vector<std::string> parsed_codecs; - net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); - if (!net::AreSupportedMediaCodecs(parsed_codecs)) - return MayBeSupported; - - // Otherwise we have a perfect match. - return IsSupported; -} - -bool -RendererWebKitPlatformSupportImpl::MimeRegistry::supportsMediaSourceMIMEType( - const blink::WebString& mime_type, - const WebString& codecs) { - const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); - std::vector<std::string> parsed_codec_ids; - net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); - if (mime_type_ascii.empty()) - return false; - return media::StreamParserFactory::IsTypeSupported( - mime_type_ascii, parsed_codec_ids); -} - -bool -RendererWebKitPlatformSupportImpl::MimeRegistry::supportsEncryptedMediaMIMEType( - const WebString& key_system, - const WebString& mime_type, - const WebString& codecs) { - // Chromium only supports ASCII parameters. - if (!base::IsStringASCII(key_system) || !base::IsStringASCII(mime_type) || - !base::IsStringASCII(codecs)) { - return false; - } - - if (key_system.isEmpty()) - return false; - - const std::string mime_type_ascii = base::UTF16ToASCII(mime_type); - - std::vector<std::string> codec_vector; - bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii); - net::ParseCodecString(base::UTF16ToASCII(codecs), &codec_vector, - strip_suffix); - - return IsSupportedKeySystemWithMediaMimeType( - mime_type_ascii, codec_vector, base::UTF16ToASCII(key_system)); -} - -WebString -RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension( - const WebString& file_extension) { - if (IsPluginProcess()) - return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); - - // The sandbox restricts our access to the registry, so we need to proxy - // these calls over to the browser process. - std::string mime_type; - RenderThread::Get()->Send( - new MimeRegistryMsg_GetMimeTypeFromExtension( - base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type)); - return base::ASCIIToUTF16(mime_type); -} - -WebString RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile( - const WebString& file_path) { - if (IsPluginProcess()) - return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); - - // The sandbox restricts our access to the registry, so we need to proxy - // these calls over to the browser process. - std::string mime_type; - RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( - base::FilePath::FromUTF16Unsafe(file_path), - &mime_type)); - return base::ASCIIToUTF16(mime_type); -} - -//------------------------------------------------------------------------------ - -bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileInfo( - const WebString& path, - WebFileInfo& web_file_info) { - base::File::Info file_info; - base::File::Error status = base::File::FILE_ERROR_MAX; - if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo( - base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) || - status != base::File::FILE_OK) { - return false; - } - FileInfoToWebFileInfo(file_info, &web_file_info); - web_file_info.platformPath = path; - return true; -} - -bool RendererWebKitPlatformSupportImpl::FileUtilities:: -SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const { - base::TimeTicks begin = base::TimeTicks::Now(); - const bool success = thread_safe_sender_->Send(msg); - base::TimeDelta delta = base::TimeTicks::Now() - begin; - UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta); - return success; -} - -//------------------------------------------------------------------------------ - -#if defined(OS_WIN) - -bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( - HFONT font) { - LOGFONT logfont; - GetObject(font, sizeof(LOGFONT), &logfont); - RenderThread::Get()->PreCacheFont(logfont); - return true; -} - -#elif defined(OS_MACOSX) - -bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont( - NSFont* src_font, CGFontRef* out, uint32* font_id) { - uint32 font_data_size; - FontDescriptor src_font_descriptor(src_font); - base::SharedMemoryHandle font_data; - if (!RenderThread::Get()->Send(new ViewHostMsg_LoadFont( - src_font_descriptor, &font_data_size, &font_data, font_id))) { - *out = NULL; - *font_id = 0; - return false; - } - - if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || - *font_id == 0) { - LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " << - src_font_descriptor.font_name; - *out = NULL; - *font_id = 0; - return false; - } - - // TODO(jeremy): Need to call back into WebKit to make sure that the font - // isn't already activated, based on the font id. If it's already - // activated, don't reactivate it here - crbug.com/72727 . - - return FontLoader::CGFontRefFromBuffer(font_data, font_data_size, out); -} - -#elif defined(OS_ANDROID) - -// WebKit doesn't use WebSandboxSupport on android so we don't need to -// implement anything here. This is cleaner to support than excluding the -// whole class for android. - -#elif defined(OS_POSIX) - -void -RendererWebKitPlatformSupportImpl::SandboxSupport::getFallbackFontForCharacter( - blink::WebUChar32 character, - const char* preferred_locale, - blink::WebFallbackFont* fallbackFont) { - base::AutoLock lock(unicode_font_families_mutex_); - const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter = - unicode_font_families_.find(character); - if (iter != unicode_font_families_.end()) { - fallbackFont->name = iter->second.name; - fallbackFont->filename = iter->second.filename; - fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId; - fallbackFont->ttcIndex = iter->second.ttcIndex; - fallbackFont->isBold = iter->second.isBold; - fallbackFont->isItalic = iter->second.isItalic; - return; - } - - GetFallbackFontForCharacter(character, preferred_locale, fallbackFont); - unicode_font_families_.insert(std::make_pair(character, *fallbackFont)); -} - -void -RendererWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( - const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out) { - GetRenderStyleForStrike(family, sizeAndStyle, out); -} - -#endif - -//------------------------------------------------------------------------------ - -Platform::FileHandle -RendererWebKitPlatformSupportImpl::databaseOpenFile( - const WebString& vfs_file_name, int desired_flags) { - return DatabaseUtil::DatabaseOpenFile( - vfs_file_name, desired_flags, sync_message_filter_.get()); -} - -int RendererWebKitPlatformSupportImpl::databaseDeleteFile( - const WebString& vfs_file_name, bool sync_dir) { - return DatabaseUtil::DatabaseDeleteFile( - vfs_file_name, sync_dir, sync_message_filter_.get()); -} - -long RendererWebKitPlatformSupportImpl::databaseGetFileAttributes( - const WebString& vfs_file_name) { - return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name, - sync_message_filter_.get()); -} - -long long RendererWebKitPlatformSupportImpl::databaseGetFileSize( - const WebString& vfs_file_name) { - return DatabaseUtil::DatabaseGetFileSize(vfs_file_name, - sync_message_filter_.get()); -} - -long long RendererWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin( - const WebString& origin_identifier) { - return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier, - sync_message_filter_.get()); -} - -bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() { - RenderThreadImpl* thread = RenderThreadImpl::current(); - GpuChannelHost* host = thread->EstablishGpuChannelSync( - CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); - if (!host) - return false; - - return host->gpu_info().SupportsAccelerated2dCanvas(); -} - -bool RendererWebKitPlatformSupportImpl::isThreadedCompositingEnabled() { - RenderThreadImpl* thread = RenderThreadImpl::current(); - // thread can be NULL in tests. - return thread && thread->compositor_message_loop_proxy().get(); -} - -double RendererWebKitPlatformSupportImpl::audioHardwareSampleRate() { - RenderThreadImpl* thread = RenderThreadImpl::current(); - return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); -} - -size_t RendererWebKitPlatformSupportImpl::audioHardwareBufferSize() { - RenderThreadImpl* thread = RenderThreadImpl::current(); - return thread->GetAudioHardwareConfig()->GetOutputBufferSize(); -} - -unsigned RendererWebKitPlatformSupportImpl::audioHardwareOutputChannels() { - RenderThreadImpl* thread = RenderThreadImpl::current(); - return thread->GetAudioHardwareConfig()->GetOutputChannels(); -} - -WebDatabaseObserver* RendererWebKitPlatformSupportImpl::databaseObserver() { - return web_database_observer_impl_.get(); -} - -WebAudioDevice* -RendererWebKitPlatformSupportImpl::createAudioDevice( - size_t buffer_size, - unsigned input_channels, - unsigned channels, - double sample_rate, - WebAudioDevice::RenderCallback* callback, - const blink::WebString& input_device_id) { - // Use a mock for testing. - blink::WebAudioDevice* mock_device = - GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate); - if (mock_device) - return mock_device; - - // The |channels| does not exactly identify the channel layout of the - // device. The switch statement below assigns a best guess to the channel - // layout based on number of channels. - // TODO(crogers): WebKit should give the channel layout instead of the hard - // channel count. - media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED; - switch (channels) { - case 1: - layout = media::CHANNEL_LAYOUT_MONO; - break; - case 2: - layout = media::CHANNEL_LAYOUT_STEREO; - break; - case 3: - layout = media::CHANNEL_LAYOUT_2_1; - break; - case 4: - layout = media::CHANNEL_LAYOUT_4_0; - break; - case 5: - layout = media::CHANNEL_LAYOUT_5_0; - break; - case 6: - layout = media::CHANNEL_LAYOUT_5_1; - break; - case 7: - layout = media::CHANNEL_LAYOUT_7_0; - break; - case 8: - layout = media::CHANNEL_LAYOUT_7_1; - break; - default: - layout = media::CHANNEL_LAYOUT_STEREO; - } - - int session_id = 0; - if (input_device_id.isNull() || - !base::StringToInt(base::UTF16ToUTF8(input_device_id), &session_id)) { - if (input_channels > 0) - DLOG(WARNING) << "createAudioDevice(): request for audio input ignored"; - - input_channels = 0; - } - - media::AudioParameters params( - media::AudioParameters::AUDIO_PCM_LOW_LATENCY, - layout, static_cast<int>(sample_rate), 16, buffer_size, - media::AudioParameters::NO_EFFECTS); - - return new RendererWebAudioDeviceImpl(params, callback, session_id); -} - -#if defined(OS_ANDROID) -bool RendererWebKitPlatformSupportImpl::loadAudioResource( - blink::WebAudioBus* destination_bus, const char* audio_file_data, - size_t data_size) { - return DecodeAudioFileData(destination_bus, - audio_file_data, - data_size, - thread_safe_sender_); -} -#else -bool RendererWebKitPlatformSupportImpl::loadAudioResource( - blink::WebAudioBus* destination_bus, const char* audio_file_data, - size_t data_size) { - return DecodeAudioFileData( - destination_bus, audio_file_data, data_size); -} -#endif // defined(OS_ANDROID) - -//------------------------------------------------------------------------------ - -blink::WebMIDIAccessor* -RendererWebKitPlatformSupportImpl::createMIDIAccessor( - blink::WebMIDIAccessorClient* client) { - blink::WebMIDIAccessor* accessor = - GetContentClient()->renderer()->OverrideCreateMIDIAccessor(client); - if (accessor) - return accessor; - - return new RendererWebMIDIAccessorImpl(client); -} - -void RendererWebKitPlatformSupportImpl::getPluginList( - bool refresh, - blink::WebPluginListBuilder* builder) { -#if defined(ENABLE_PLUGINS) - std::vector<WebPluginInfo> plugins; - if (!plugin_refresh_allowed_) - refresh = false; - RenderThread::Get()->Send( - new ViewHostMsg_GetPlugins(refresh, &plugins)); - for (size_t i = 0; i < plugins.size(); ++i) { - const WebPluginInfo& plugin = plugins[i]; - - builder->addPlugin( - plugin.name, plugin.desc, - plugin.path.BaseName().AsUTF16Unsafe()); - - for (size_t j = 0; j < plugin.mime_types.size(); ++j) { - const WebPluginMimeType& mime_type = plugin.mime_types[j]; - - builder->addMediaTypeToLastPlugin( - WebString::fromUTF8(mime_type.mime_type), mime_type.description); - - for (size_t k = 0; k < mime_type.file_extensions.size(); ++k) { - builder->addFileExtensionToLastMediaType( - WebString::fromUTF8(mime_type.file_extensions[k])); - } - } - } -#endif -} - -//------------------------------------------------------------------------------ - -blink::WebPublicSuffixList* -RendererWebKitPlatformSupportImpl::publicSuffixList() { - return &public_suffix_list_; -} - -//------------------------------------------------------------------------------ - -blink::WebString -RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( - unsigned key_size_index, - const blink::WebString& challenge, - const blink::WebURL& url) { - std::string signed_public_key; - RenderThread::Get()->Send(new ViewHostMsg_Keygen( - static_cast<uint32>(key_size_index), - challenge.utf8(), - GURL(url), - &signed_public_key)); - return WebString::fromUTF8(signed_public_key); -} - -//------------------------------------------------------------------------------ - -void RendererWebKitPlatformSupportImpl::screenColorProfile( - WebVector<char>* to_profile) { -#if defined(OS_WIN) - // On Windows screen color profile is only available in the browser. - std::vector<char> profile; - // This Send() can be called from any impl-side thread. Use a thread - // safe send to avoid crashing trying to access RenderThread::Get(), - // which is not accessible from arbitrary threads. - thread_safe_sender_->Send( - new ViewHostMsg_GetMonitorColorProfile(&profile)); - *to_profile = profile; -#else - // On other platforms, the primary monitor color profile can be read - // directly. - gfx::ColorProfile profile; - *to_profile = profile.profile(); -#endif -} - -//------------------------------------------------------------------------------ - -blink::WebScrollbarBehavior* - RendererWebKitPlatformSupportImpl::scrollbarBehavior() { - return web_scrollbar_behavior_.get(); -} - -//------------------------------------------------------------------------------ - -WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { - // blob_registry_ can be NULL when running some tests. - return blob_registry_.get(); -} - -//------------------------------------------------------------------------------ - -void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { - PlatformEventObserverBase* observer = - platform_event_observers_.Lookup(blink::WebPlatformEventGamepad); - if (!observer) - return; - static_cast<RendererGamepadProvider*>(observer)->SampleGamepads(gamepads); -} - -//------------------------------------------------------------------------------ - -WebRTCPeerConnectionHandler* -RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler( - WebRTCPeerConnectionHandlerClient* client) { - RenderThreadImpl* render_thread = RenderThreadImpl::current(); - DCHECK(render_thread); - if (!render_thread) - return NULL; - -#if defined(ENABLE_WEBRTC) - WebRTCPeerConnectionHandler* peer_connection_handler = - GetContentClient()->renderer()->OverrideCreateWebRTCPeerConnectionHandler( - client); - if (peer_connection_handler) - return peer_connection_handler; - - PeerConnectionDependencyFactory* rtc_dependency_factory = - render_thread->GetPeerConnectionDependencyFactory(); - return rtc_dependency_factory->CreateRTCPeerConnectionHandler(client); -#else - return NULL; -#endif // defined(ENABLE_WEBRTC) -} - -//------------------------------------------------------------------------------ - -WebMediaStreamCenter* -RendererWebKitPlatformSupportImpl::createMediaStreamCenter( - WebMediaStreamCenterClient* client) { - RenderThreadImpl* render_thread = RenderThreadImpl::current(); - DCHECK(render_thread); - if (!render_thread) - return NULL; - return render_thread->CreateMediaStreamCenter(client); -} - -// static -bool RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting( - bool enable) { - bool was_enabled = g_sandbox_enabled; - g_sandbox_enabled = enable; - return was_enabled; -} - -//------------------------------------------------------------------------------ - -blink::WebSpeechSynthesizer* -RendererWebKitPlatformSupportImpl::createSpeechSynthesizer( - blink::WebSpeechSynthesizerClient* client) { - return GetContentClient()->renderer()->OverrideSpeechSynthesizer(client); -} - -//------------------------------------------------------------------------------ - -bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( - size_t* private_bytes, size_t* shared_bytes) { - content::RenderThread::Get()->Send( - new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); - return true; -} - -//------------------------------------------------------------------------------ - -blink::WebGraphicsContext3D* -RendererWebKitPlatformSupportImpl::createOffscreenGraphicsContext3D( - const blink::WebGraphicsContext3D::Attributes& attributes) { - return createOffscreenGraphicsContext3D(attributes, NULL); -} - -blink::WebGraphicsContext3D* -RendererWebKitPlatformSupportImpl::createOffscreenGraphicsContext3D( - const blink::WebGraphicsContext3D::Attributes& attributes, - blink::WebGraphicsContext3D* share_context) { - if (!RenderThreadImpl::current()) - return NULL; - -#if defined(OS_ANDROID) - if (SynchronousCompositorFactory* factory = - SynchronousCompositorFactory::GetInstance()) { - scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl> - in_process_context( - factory->CreateOffscreenGraphicsContext3D(attributes)); - if (!in_process_context || - !in_process_context->InitializeOnCurrentThread()) - return NULL; - return in_process_context.release(); - } -#endif - - scoped_refptr<GpuChannelHost> gpu_channel_host( - RenderThreadImpl::current()->EstablishGpuChannelSync( - CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)); - - WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; - bool lose_context_when_out_of_memory = false; - scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( - WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( - gpu_channel_host.get(), - attributes, - lose_context_when_out_of_memory, - GURL(attributes.topDocumentURL), - limits, - static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context))); - - // Most likely the GPU process exited and the attempt to reconnect to it - // failed. Need to try to restore the context again later. - if (!context || !context->InitializeOnCurrentThread()) - return NULL; - return context.release(); -} - -//------------------------------------------------------------------------------ - -blink::WebGraphicsContext3DProvider* RendererWebKitPlatformSupportImpl:: - createSharedOffscreenGraphicsContext3DProvider() { - scoped_refptr<webkit::gpu::ContextProviderWebContext> provider = - RenderThreadImpl::current()->SharedMainThreadContextProvider(); - if (!provider.get()) - return NULL; - return new WebGraphicsContext3DProviderImpl(provider); -} - -//------------------------------------------------------------------------------ - -blink::WebCompositorSupport* -RendererWebKitPlatformSupportImpl::compositorSupport() { - return &compositor_support_; -} - -//------------------------------------------------------------------------------ - -blink::WebString RendererWebKitPlatformSupportImpl::convertIDNToUnicode( - const blink::WebString& host, - const blink::WebString& languages) { - return net::IDNToUnicode(host.utf8(), languages.utf8()); -} - -//------------------------------------------------------------------------------ - -// static -void RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting( - double data) { - g_test_device_light_data = data; -} - -//------------------------------------------------------------------------------ - -// static -void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( - const blink::WebDeviceMotionData& data) { - g_test_device_motion_data.Get() = data; -} - -//------------------------------------------------------------------------------ - -// static -void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting( - const blink::WebDeviceOrientationData& data) { - g_test_device_orientation_data.Get() = data; -} - -//------------------------------------------------------------------------------ - -void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) { - RenderThread::Get()->Send( - new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); -} - -void RendererWebKitPlatformSupportImpl::cancelVibration() { - RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); -} - -//------------------------------------------------------------------------------ - -// static -PlatformEventObserverBase* -RendererWebKitPlatformSupportImpl::CreatePlatformEventObserverFromType( - blink::WebPlatformEventType type) { - RenderThread* thread = RenderThreadImpl::current(); - - // When running layout tests, those observers should not listen to the actual - // hardware changes. In order to make that happen, they will receive a null - // thread. - if (thread && RenderThreadImpl::current()->layout_test_mode()) - thread = 0; - - switch (type) { - case blink::WebPlatformEventDeviceMotion: { - return new DeviceMotionEventPump(thread); - } - case blink::WebPlatformEventDeviceOrientation: { - return new DeviceOrientationEventPump(thread); - } - case blink::WebPlatformEventDeviceLight: { - return new DeviceLightEventPump(thread); - } - case blink::WebPlatformEventBattery: { - return new BatteryStatusDispatcher(thread); - } - case blink::WebPlatformEventGamepad: - return new GamepadSharedMemoryReader(thread); - break; - case blink::WebPlatformEventScreenOrientation: - return new ScreenOrientationObserver(); - default: - // A default statement is required to prevent compilation errors when Blink - // adds a new type. - VLOG(1) << "RendererWebKitPlatformSupportImpl::startListening() with " - "unknown type."; - } - - return 0; -} - -void RendererWebKitPlatformSupportImpl::SetPlatformEventObserverForTesting( - blink::WebPlatformEventType type, - scoped_ptr<PlatformEventObserverBase> observer) { - if (platform_event_observers_.Lookup(type)) - platform_event_observers_.Remove(type); - platform_event_observers_.AddWithID(observer.release(), type); -} - -void RendererWebKitPlatformSupportImpl::startListening( - blink::WebPlatformEventType type, - blink::WebPlatformEventListener* listener) { - PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); - if (!observer) { - observer = CreatePlatformEventObserverFromType(type); - if (!observer) - return; - platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); - } - observer->Start(listener); - - // Device events (motion, orientation and light) expect to get an event fired - // as soon as a listener is registered if a fake data was passed before. - // TODO(mlamouri,timvolodine): make those send mock values directly instead of - // using this broken pattern. - if (RenderThreadImpl::current() && - RenderThreadImpl::current()->layout_test_mode() && - (type == blink::WebPlatformEventDeviceMotion || - type == blink::WebPlatformEventDeviceOrientation || - type == blink::WebPlatformEventDeviceLight)) { - SendFakeDeviceEventDataForTesting(type); - } -} - -void RendererWebKitPlatformSupportImpl::SendFakeDeviceEventDataForTesting( - blink::WebPlatformEventType type) { - PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); - CHECK(observer); - - void* data = 0; - - switch (type) { - case blink::WebPlatformEventDeviceMotion: - if (!(g_test_device_motion_data == 0)) - data = &g_test_device_motion_data.Get(); - break; - case blink::WebPlatformEventDeviceOrientation: - if (!(g_test_device_orientation_data == 0)) - data = &g_test_device_orientation_data.Get(); - break; - case blink::WebPlatformEventDeviceLight: - if (g_test_device_light_data >= 0) - data = &g_test_device_light_data; - break; - default: - NOTREACHED(); - break; - } - - if (!data) - return; - - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, - base::Unretained(observer), data)); -} - -void RendererWebKitPlatformSupportImpl::stopListening( - blink::WebPlatformEventType type) { - PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); - if (!observer) - return; - observer->Stop(); -} - -//------------------------------------------------------------------------------ - -void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( - const blink::WebURL& storage_partition, - blink::WebStorageQuotaType type, - blink::WebStorageQuotaCallbacks callbacks) { - if (!thread_safe_sender_.get() || !quota_message_filter_.get()) - return; - QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(), - quota_message_filter_.get()) - ->QueryStorageUsageAndQuota( - storage_partition, - static_cast<storage::StorageType>(type), - QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); -} - -//------------------------------------------------------------------------------ - -void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( - const blink::WebBatteryStatus& status) { - PlatformEventObserverBase* observer = - platform_event_observers_.Lookup(blink::WebPlatformEventBattery); - if (!observer) - return; - observer->SendFakeDataForTesting((void*)&status); -} - -} // namespace content diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h deleted file mode 100644 index 462186c..0000000 --- a/content/renderer/renderer_webkitplatformsupport_impl.h +++ /dev/null @@ -1,248 +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 CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_ -#define CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_ - -#include "base/compiler_specific.h" -#include "base/id_map.h" -#include "base/memory/scoped_ptr.h" -#include "cc/blink/web_compositor_support_impl.h" -#include "content/child/blink_platform_impl.h" -#include "content/common/content_export.h" -#include "content/renderer/webpublicsuffixlist_impl.h" -#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" -#include "third_party/WebKit/public/platform/WebIDBFactory.h" -#include "third_party/WebKit/public/platform/WebScreenOrientationType.h" - -namespace base { -class MessageLoopProxy; -} - -namespace cc { -class ContextProvider; -} - -namespace IPC { -class SyncMessageFilter; -} - -namespace blink { -class WebBatteryStatus; -class WebDeviceMotionData; -class WebDeviceOrientationData; -class WebGraphicsContext3DProvider; -} - -namespace content { -class BatteryStatusDispatcher; -class DeviceLightEventPump; -class DeviceMotionEventPump; -class DeviceOrientationEventPump; -class PlatformEventObserverBase; -class QuotaMessageFilter; -class RendererClipboardClient; -class RenderView; -class ThreadSafeSender; -class WebClipboardImpl; -class WebDatabaseObserverImpl; -class WebFileSystemImpl; - -class CONTENT_EXPORT RendererWebKitPlatformSupportImpl - : public BlinkPlatformImpl { - public: - RendererWebKitPlatformSupportImpl(); - virtual ~RendererWebKitPlatformSupportImpl(); - - void set_plugin_refresh_allowed(bool plugin_refresh_allowed) { - plugin_refresh_allowed_ = plugin_refresh_allowed; - } - // Platform methods: - virtual blink::WebClipboard* clipboard(); - virtual blink::WebMimeRegistry* mimeRegistry(); - virtual blink::WebFileUtilities* fileUtilities(); - virtual blink::WebSandboxSupport* sandboxSupport(); - virtual blink::WebCookieJar* cookieJar(); - virtual blink::WebThemeEngine* themeEngine(); - virtual blink::WebSpeechSynthesizer* createSpeechSynthesizer( - blink::WebSpeechSynthesizerClient* client); - virtual bool sandboxEnabled(); - virtual unsigned long long visitedLinkHash( - const char* canonicalURL, size_t length); - virtual bool isLinkVisited(unsigned long long linkHash); - virtual void createMessageChannel(blink::WebMessagePortChannel** channel1, - blink::WebMessagePortChannel** channel2); - virtual blink::WebPrescientNetworking* prescientNetworking(); - virtual void cacheMetadata( - const blink::WebURL&, double, const char*, size_t); - virtual blink::WebString defaultLocale(); - virtual void suddenTerminationChanged(bool enabled); - virtual blink::WebStorageNamespace* createLocalStorageNamespace(); - virtual blink::Platform::FileHandle databaseOpenFile( - const blink::WebString& vfs_file_name, int desired_flags); - virtual int databaseDeleteFile(const blink::WebString& vfs_file_name, - bool sync_dir); - virtual long databaseGetFileAttributes( - const blink::WebString& vfs_file_name); - virtual long long databaseGetFileSize( - const blink::WebString& vfs_file_name); - virtual long long databaseGetSpaceAvailableForOrigin( - const blink::WebString& origin_identifier); - virtual blink::WebString signedPublicKeyAndChallengeString( - unsigned key_size_index, - const blink::WebString& challenge, - const blink::WebURL& url); - virtual void getPluginList(bool refresh, - blink::WebPluginListBuilder* builder); - virtual blink::WebPublicSuffixList* publicSuffixList(); - virtual void screenColorProfile(blink::WebVector<char>* to_profile); - virtual blink::WebScrollbarBehavior* scrollbarBehavior(); - virtual blink::WebIDBFactory* idbFactory(); - virtual blink::WebFileSystem* fileSystem(); - virtual bool canAccelerate2dCanvas(); - virtual bool isThreadedCompositingEnabled(); - virtual double audioHardwareSampleRate(); - virtual size_t audioHardwareBufferSize(); - virtual unsigned audioHardwareOutputChannels(); - virtual blink::WebDatabaseObserver* databaseObserver(); - - virtual blink::WebAudioDevice* createAudioDevice( - size_t buffer_size, unsigned input_channels, unsigned channels, - double sample_rate, blink::WebAudioDevice::RenderCallback* callback, - const blink::WebString& input_device_id); - - virtual bool loadAudioResource( - blink::WebAudioBus* destination_bus, const char* audio_file_data, - size_t data_size); - - virtual blink::WebMIDIAccessor* - createMIDIAccessor(blink::WebMIDIAccessorClient* client); - - virtual blink::WebBlobRegistry* blobRegistry(); - virtual void sampleGamepads(blink::WebGamepads&); - virtual blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler( - blink::WebRTCPeerConnectionHandlerClient* client); - virtual blink::WebMediaStreamCenter* createMediaStreamCenter( - blink::WebMediaStreamCenterClient* client); - virtual bool processMemorySizesInBytes( - size_t* private_bytes, size_t* shared_bytes); - virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D( - const blink::WebGraphicsContext3D::Attributes& attributes); - virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D( - const blink::WebGraphicsContext3D::Attributes& attributes, - blink::WebGraphicsContext3D* share_context); - virtual blink::WebGraphicsContext3DProvider* - createSharedOffscreenGraphicsContext3DProvider(); - virtual blink::WebCompositorSupport* compositorSupport(); - virtual blink::WebString convertIDNToUnicode( - const blink::WebString& host, const blink::WebString& languages); - virtual void startListening(blink::WebPlatformEventType, - blink::WebPlatformEventListener*); - virtual void stopListening(blink::WebPlatformEventType); - virtual void queryStorageUsageAndQuota( - const blink::WebURL& storage_partition, - blink::WebStorageQuotaType, - blink::WebStorageQuotaCallbacks); - virtual void vibrate(unsigned int milliseconds); - virtual void cancelVibration(); - - // Set the PlatformEventObserverBase in |platform_event_observers_| associated - // with |type| to |observer|. If there was already an observer associated to - // the given |type|, it will be replaced. - // Note that |observer| will be owned by this object after the call. - void SetPlatformEventObserverForTesting( - blink::WebPlatformEventType type, - scoped_ptr<PlatformEventObserverBase> observer); - - // Disables the WebSandboxSupport implementation for testing. - // Tests that do not set up a full sandbox environment should call - // SetSandboxEnabledForTesting(false) _before_ creating any instances - // of this class, to ensure that we don't attempt to use sandbox-related - // file descriptors or other resources. - // - // Returns the previous |enable| value. - static bool SetSandboxEnabledForTesting(bool enable); - - // Set a double to return when setDeviceLightListener is invoked. - static void SetMockDeviceLightDataForTesting(double data); - // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked. - static void SetMockDeviceMotionDataForTesting( - const blink::WebDeviceMotionData& data); - // Set WebDeviceOrientationData to return when setDeviceOrientationListener - // is invoked. - static void SetMockDeviceOrientationDataForTesting( - const blink::WebDeviceOrientationData& data); - - // Notifies blink::WebBatteryStatusListener that battery status has changed. - void MockBatteryStatusChangedForTesting( - const blink::WebBatteryStatus& status); - - WebDatabaseObserverImpl* web_database_observer_impl() { - return web_database_observer_impl_.get(); - } - - private: - bool CheckPreparsedJsCachingEnabled() const; - - // Factory that takes a type and return PlatformEventObserverBase that matches - // it. - static PlatformEventObserverBase* CreatePlatformEventObserverFromType( - blink::WebPlatformEventType type); - - // Use the data previously set via SetMockDevice...DataForTesting() and send - // them to the registered listener. - void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type); - - scoped_ptr<RendererClipboardClient> clipboard_client_; - scoped_ptr<WebClipboardImpl> clipboard_; - - class FileUtilities; - scoped_ptr<FileUtilities> file_utilities_; - - class MimeRegistry; - scoped_ptr<MimeRegistry> mime_registry_; - - class SandboxSupport; - scoped_ptr<SandboxSupport> sandbox_support_; - - // This counter keeps track of the number of times sudden termination is - // enabled or disabled. It starts at 0 (enabled) and for every disable - // increments by 1, for every enable decrements by 1. When it reaches 0, - // we tell the browser to enable fast termination. - int sudden_termination_disables_; - - // If true, then a GetPlugins call is allowed to rescan the disk. - bool plugin_refresh_allowed_; - - scoped_ptr<blink::WebIDBFactory> web_idb_factory_; - - scoped_ptr<blink::WebBlobRegistry> blob_registry_; - - WebPublicSuffixListImpl public_suffix_list_; - - scoped_ptr<DeviceLightEventPump> device_light_event_pump_; - scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_; - scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_; - - scoped_refptr<base::MessageLoopProxy> child_thread_loop_; - scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; - scoped_refptr<ThreadSafeSender> thread_safe_sender_; - scoped_refptr<QuotaMessageFilter> quota_message_filter_; - - scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; - - cc_blink::WebCompositorSupportImpl compositor_support_; - - scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_; - - scoped_ptr<BatteryStatusDispatcher> battery_status_dispatcher_; - - IDMap<PlatformEventObserverBase, IDMapOwnPointer> platform_event_observers_; - - DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_ diff --git a/content/test/blink_test_environment.cc b/content/test/blink_test_environment.cc index 94f9b47..b9655fe 100644 --- a/content/test/blink_test_environment.cc +++ b/content/test/blink_test_environment.cc @@ -14,7 +14,7 @@ #include "content/public/common/content_switches.h" #include "content/public/common/user_agent.h" #include "content/public/test/test_content_client_initializer.h" -#include "content/test/test_webkit_platform_support.h" +#include "content/test/test_blink_web_unit_test_support.h" #include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebKit.h" #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" @@ -63,21 +63,21 @@ class TestEnvironment { TestEnvironment() { main_message_loop_.reset(new MessageLoopType); - // TestWebKitPlatformSupport must be instantiated after MessageLoopType. - webkit_platform_support_.reset(new TestWebKitPlatformSupport); + // TestBlinkWebUnitTestSupport must be instantiated after MessageLoopType. + blink_test_support_.reset(new TestBlinkWebUnitTestSupport); content_initializer_.reset(new content::TestContentClientInitializer()); } ~TestEnvironment() { } - TestWebKitPlatformSupport* webkit_platform_support() const { - return webkit_platform_support_.get(); + TestBlinkWebUnitTestSupport* blink_platform_impl() const { + return blink_test_support_.get(); } private: scoped_ptr<MessageLoopType> main_message_loop_; - scoped_ptr<TestWebKitPlatformSupport> webkit_platform_support_; + scoped_ptr<TestBlinkWebUnitTestSupport> blink_test_support_; scoped_ptr<TestContentClientInitializer> content_initializer_; }; diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc index 776ad69..a98a2da 100644 --- a/content/test/layouttest_support.cc +++ b/content/test/layouttest_support.cc @@ -17,7 +17,7 @@ #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" +#include "content/renderer/renderer_blink_platform_impl.h" #include "content/shell/renderer/test_runner/test_common.h" #include "content/shell/renderer/test_runner/web_frame_test_proxy.h" #include "content/shell/renderer/test_runner/web_test_proxy.h" @@ -109,28 +109,29 @@ void FetchManifest(blink::WebView* view, const GURL& url, } void SetMockGamepadProvider(scoped_ptr<RendererGamepadProvider> provider) { - RenderThreadImpl::current()->webkit_platform_support()-> - SetPlatformEventObserverForTesting( + RenderThreadImpl::current() + ->blink_platform_impl() + ->SetPlatformEventObserverForTesting( blink::WebPlatformEventGamepad, provider.PassAs<PlatformEventObserverBase>()); } void SetMockDeviceLightData(const double data) { - RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting(data); + RendererBlinkPlatformImpl::SetMockDeviceLightDataForTesting(data); } void SetMockDeviceMotionData(const WebDeviceMotionData& data) { - RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(data); + RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(data); } void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) { - RendererWebKitPlatformSupportImpl:: - SetMockDeviceOrientationDataForTesting(data); + RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); } void MockBatteryStatusChanged(const WebBatteryStatus& status) { - RenderThreadImpl::current()->webkit_platform_support()-> - MockBatteryStatusChangedForTesting(status); + RenderThreadImpl::current() + ->blink_platform_impl() + ->MockBatteryStatusChangedForTesting(status); } void EnableRendererLayoutTestMode() { diff --git a/content/test/test_blink_web_unit_test_support.cc b/content/test/test_blink_web_unit_test_support.cc new file mode 100644 index 0000000..8f743ed --- /dev/null +++ b/content/test/test_blink_web_unit_test_support.cc @@ -0,0 +1,307 @@ +// Copyright 2013 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_blink_web_unit_test_support.h" + +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/files/scoped_temp_dir.h" +#include "base/metrics/stats_counters.h" +#include "base/path_service.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/common/content_switches.h" +#include "content/test/mock_webclipboard_impl.h" +#include "content/test/web_gesture_curve_mock.h" +#include "content/test/web_layer_tree_view_impl_for_testing.h" +#include "content/test/weburl_loader_mock_factory.h" +#include "media/base/media.h" +#include "net/cookies/cookie_monster.h" +#include "net/test/spawned_test_server/spawned_test_server.h" +#include "storage/browser/database/vfs_backend.h" +#include "third_party/WebKit/public/platform/WebData.h" +#include "third_party/WebKit/public/platform/WebFileSystem.h" +#include "third_party/WebKit/public/platform/WebStorageArea.h" +#include "third_party/WebKit/public/platform/WebStorageNamespace.h" +#include "third_party/WebKit/public/platform/WebString.h" +#include "third_party/WebKit/public/platform/WebURL.h" +#include "third_party/WebKit/public/web/WebDatabase.h" +#include "third_party/WebKit/public/web/WebKit.h" +#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" +#include "third_party/WebKit/public/web/WebSecurityPolicy.h" +#include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" +#include "v8/include/v8.h" + +#if defined(OS_MACOSX) +#include "base/mac/mac_util.h" +#include "base/mac/scoped_nsautorelease_pool.h" +#endif + +namespace content { + +TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { +#if defined(OS_MACOSX) + base::mac::ScopedNSAutoreleasePool autorelease_pool; +#endif + + url_loader_factory_.reset(new WebURLLoaderMockFactory()); + mock_clipboard_.reset(new MockWebClipboardImpl()); + + // Create an anonymous stats table since we don't need to share between + // processes. + stats_table_.reset( + new base::StatsTable(base::StatsTable::TableIdentifier(), 20, 200)); + base::StatsTable::set_current(stats_table_.get()); + + blink::initialize(this); + blink::mainThreadIsolate()->SetCounterFunction( + base::StatsTable::FindLocation); + blink::setLayoutTestMode(true); + blink::WebSecurityPolicy::registerURLSchemeAsLocal( + blink::WebString::fromUTF8("test-shell-resource")); + blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( + blink::WebString::fromUTF8("test-shell-resource")); + blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( + blink::WebString::fromUTF8("test-shell-resource")); + blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( + blink::WebString::fromUTF8("test-shell-resource")); + blink::WebRuntimeFeatures::enableApplicationCache(true); + blink::WebRuntimeFeatures::enableDatabase(true); + blink::WebRuntimeFeatures::enableNotifications(true); + blink::WebRuntimeFeatures::enableTouch(true); + + // Load libraries for media and enable the media player. + bool enable_media = false; + base::FilePath module_path; + if (PathService::Get(base::DIR_MODULE, &module_path)) { +#if defined(OS_MACOSX) + if (base::mac::AmIBundled()) + module_path = module_path.DirName().DirName().DirName(); +#endif + if (media::InitializeMediaLibrary(module_path)) + enable_media = true; + } + blink::WebRuntimeFeatures::enableMediaPlayer(enable_media); + LOG_IF(WARNING, !enable_media) << "Failed to initialize the media library.\n"; + + file_utilities_.set_sandbox_enabled(false); + + if (!file_system_root_.CreateUniqueTempDir()) { + LOG(WARNING) << "Failed to create a temp dir for the filesystem." + "FileSystem feature will be disabled."; + DCHECK(file_system_root_.path().empty()); + } + +#if defined(OS_WIN) + // Ensure we pick up the default theme engine. + SetThemeEngine(NULL); +#endif + + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFileCookies); + + // Test shell always exposes the GC. + std::string flags("--expose-gc"); + v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); +} + +TestBlinkWebUnitTestSupport::~TestBlinkWebUnitTestSupport() { + url_loader_factory_.reset(); + mock_clipboard_.reset(); + blink::shutdown(); + base::StatsTable::set_current(NULL); + stats_table_.reset(); +} + +blink::WebBlobRegistry* TestBlinkWebUnitTestSupport::blobRegistry() { + return &blob_registry_; +} + +blink::WebClipboard* TestBlinkWebUnitTestSupport::clipboard() { + // Mock out clipboard calls so that tests don't mess + // with each other's copies/pastes when running in parallel. + return mock_clipboard_.get(); +} + +blink::WebFileUtilities* TestBlinkWebUnitTestSupport::fileUtilities() { + return &file_utilities_; +} + +blink::WebIDBFactory* TestBlinkWebUnitTestSupport::idbFactory() { + NOTREACHED() << + "IndexedDB cannot be tested with in-process harnesses."; + return NULL; +} + +blink::WebMimeRegistry* TestBlinkWebUnitTestSupport::mimeRegistry() { + return &mime_registry_; +} + +blink::WebURLLoader* TestBlinkWebUnitTestSupport::createURLLoader() { + return url_loader_factory_->CreateURLLoader( + BlinkPlatformImpl::createURLLoader()); +} + +blink::WebString TestBlinkWebUnitTestSupport::userAgent() { + return blink::WebString::fromUTF8("DumpRenderTree/0.0.0.0"); +} + +blink::WebData TestBlinkWebUnitTestSupport::loadResource(const char* name) { + if (!strcmp(name, "deleteButton")) { + // Create a red 30x30 square. + const char red_square[] = + "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" + "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" + "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" + "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" + "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" + "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" + "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" + "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" + "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" + "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" + "\x82"; + return blink::WebData(red_square, arraysize(red_square)); + } + return BlinkPlatformImpl::loadResource(name); +} + +blink::WebString TestBlinkWebUnitTestSupport::queryLocalizedString( + blink::WebLocalizedString::Name name) { + // Returns placeholder strings to check if they are correctly localized. + switch (name) { + case blink::WebLocalizedString::OtherDateLabel: + return base::ASCIIToUTF16("<<OtherDateLabel>>"); + case blink::WebLocalizedString::OtherMonthLabel: + return base::ASCIIToUTF16("<<OtherMonthLabel>>"); + case blink::WebLocalizedString::OtherTimeLabel: + return base::ASCIIToUTF16("<<OtherTimeLabel>>"); + case blink::WebLocalizedString::OtherWeekLabel: + return base::ASCIIToUTF16("<<OtherWeekLabel>>"); + case blink::WebLocalizedString::CalendarClear: + return base::ASCIIToUTF16("<<CalendarClear>>"); + case blink::WebLocalizedString::CalendarToday: + return base::ASCIIToUTF16("<<CalendarToday>>"); + case blink::WebLocalizedString::ThisMonthButtonLabel: + return base::ASCIIToUTF16("<<ThisMonthLabel>>"); + case blink::WebLocalizedString::ThisWeekButtonLabel: + return base::ASCIIToUTF16("<<ThisWeekLabel>>"); + case blink::WebLocalizedString::WeekFormatTemplate: + return base::ASCIIToUTF16("Week $2, $1"); + default: + return blink::WebString(); + } +} + +blink::WebString TestBlinkWebUnitTestSupport::queryLocalizedString( + blink::WebLocalizedString::Name name, + const blink::WebString& value) { + if (name == blink::WebLocalizedString::ValidationRangeUnderflow) + return base::ASCIIToUTF16("range underflow"); + if (name == blink::WebLocalizedString::ValidationRangeOverflow) + return base::ASCIIToUTF16("range overflow"); + if (name == blink::WebLocalizedString::SelectMenuListText) + return base::ASCIIToUTF16("$1 selected"); + return BlinkPlatformImpl::queryLocalizedString(name, value); +} + +blink::WebString TestBlinkWebUnitTestSupport::queryLocalizedString( + blink::WebLocalizedString::Name name, + const blink::WebString& value1, + const blink::WebString& value2) { + if (name == blink::WebLocalizedString::ValidationTooLong) + return base::ASCIIToUTF16("too long"); + if (name == blink::WebLocalizedString::ValidationStepMismatch) + return base::ASCIIToUTF16("step mismatch"); + return BlinkPlatformImpl::queryLocalizedString(name, value1, value2); +} + +blink::WebString TestBlinkWebUnitTestSupport::defaultLocale() { + return base::ASCIIToUTF16("en-US"); +} + +#if defined(OS_WIN) || defined(OS_MACOSX) +void TestBlinkWebUnitTestSupport::SetThemeEngine( + blink::WebThemeEngine* engine) { + active_theme_engine_ = engine ? engine : BlinkPlatformImpl::themeEngine(); +} + +blink::WebThemeEngine* TestBlinkWebUnitTestSupport::themeEngine() { + return active_theme_engine_; +} +#endif + +blink::WebCompositorSupport* TestBlinkWebUnitTestSupport::compositorSupport() { + return &compositor_support_; +} + +blink::WebGestureCurve* TestBlinkWebUnitTestSupport::createFlingAnimationCurve( + blink::WebGestureDevice device_source, + const blink::WebFloatPoint& velocity, + const blink::WebSize& cumulative_scroll) { + // Caller will retain and release. + return new WebGestureCurveMock(velocity, cumulative_scroll); +} + +blink::WebUnitTestSupport* TestBlinkWebUnitTestSupport::unitTestSupport() { + return this; +} + +void TestBlinkWebUnitTestSupport::registerMockedURL( + const blink::WebURL& url, + const blink::WebURLResponse& response, + const blink::WebString& file_path) { + url_loader_factory_->RegisterURL(url, response, file_path); +} + +void TestBlinkWebUnitTestSupport::registerMockedErrorURL( + const blink::WebURL& url, + const blink::WebURLResponse& response, + const blink::WebURLError& error) { + url_loader_factory_->RegisterErrorURL(url, response, error); +} + +void TestBlinkWebUnitTestSupport::unregisterMockedURL( + const blink::WebURL& url) { + url_loader_factory_->UnregisterURL(url); +} + +void TestBlinkWebUnitTestSupport::unregisterAllMockedURLs() { + url_loader_factory_->UnregisterAllURLs(); +} + +void TestBlinkWebUnitTestSupport::serveAsynchronousMockedRequests() { + url_loader_factory_->ServeAsynchronousRequests(); +} + +blink::WebString TestBlinkWebUnitTestSupport::webKitRootDir() { + base::FilePath path; + PathService::Get(base::DIR_SOURCE_ROOT, &path); + path = path.Append(FILE_PATH_LITERAL("third_party/WebKit")); + path = base::MakeAbsoluteFilePath(path); + CHECK(!path.empty()); + std::string path_ascii = path.MaybeAsASCII(); + CHECK(!path_ascii.empty()); + return blink::WebString::fromUTF8(path_ascii.c_str()); +} + +blink::WebLayerTreeView* +TestBlinkWebUnitTestSupport::createLayerTreeViewForTesting() { + scoped_ptr<WebLayerTreeViewImplForTesting> view( + new WebLayerTreeViewImplForTesting()); + + view->Initialize(); + return view.release(); +} + +blink::WebData TestBlinkWebUnitTestSupport::readFromFile( + const blink::WebString& path) { + base::FilePath file_path = base::FilePath::FromUTF16Unsafe(path); + + std::string buffer; + base::ReadFileToString(file_path, &buffer); + + return blink::WebData(buffer.data(), buffer.size()); +} + +} // namespace content diff --git a/content/test/test_blink_web_unit_test_support.h b/content/test/test_blink_web_unit_test_support.h new file mode 100644 index 0000000..cea6cf9 --- /dev/null +++ b/content/test/test_blink_web_unit_test_support.h @@ -0,0 +1,111 @@ +// Copyright 2013 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_BLINK_WEB_UNIT_TEST_SUPPORT_H_ +#define CONTENT_TEST_TEST_BLINK_WEB_UNIT_TEST_SUPPORT_H_ + +#include "base/compiler_specific.h" +#include "base/files/scoped_temp_dir.h" +#include "cc/blink/web_compositor_support_impl.h" +#include "content/child/blink_platform_impl.h" +#include "content/child/simple_webmimeregistry_impl.h" +#include "content/child/webfileutilities_impl.h" +#include "content/test/mock_webblob_registry_impl.h" +#include "content/test/mock_webclipboard_impl.h" +#include "content/test/weburl_loader_mock_factory.h" +#include "third_party/WebKit/public/platform/WebUnitTestSupport.h" + +namespace base { +class StatsTable; +} + +namespace blink { +class WebLayerTreeView; +} + +namespace content { + +// An implementation of blink::WebUnitTestSupport and BlinkPlatformImpl for +// tests. +class TestBlinkWebUnitTestSupport : public blink::WebUnitTestSupport, + public BlinkPlatformImpl { + public: + TestBlinkWebUnitTestSupport(); + virtual ~TestBlinkWebUnitTestSupport(); + + virtual blink::WebBlobRegistry* blobRegistry(); + virtual blink::WebClipboard* clipboard(); + virtual blink::WebFileUtilities* fileUtilities(); + virtual blink::WebIDBFactory* idbFactory(); + virtual blink::WebMimeRegistry* mimeRegistry(); + + virtual blink::WebURLLoader* createURLLoader(); + virtual blink::WebString userAgent() OVERRIDE; + virtual blink::WebData loadResource(const char* name); + virtual blink::WebString queryLocalizedString( + blink::WebLocalizedString::Name name); + virtual blink::WebString queryLocalizedString( + blink::WebLocalizedString::Name name, + const blink::WebString& value); + virtual blink::WebString queryLocalizedString( + blink::WebLocalizedString::Name name, + const blink::WebString& value1, + const blink::WebString& value2); + virtual blink::WebString defaultLocale(); + +#if defined(OS_WIN) || defined(OS_MACOSX) + void SetThemeEngine(blink::WebThemeEngine* engine); + virtual blink::WebThemeEngine* themeEngine(); +#endif + + virtual blink::WebCompositorSupport* compositorSupport(); + + WebURLLoaderMockFactory* url_loader_factory() { + return url_loader_factory_.get(); + } + + const base::FilePath& file_system_root() const { + return file_system_root_.path(); + } + + virtual blink::WebGestureCurve* createFlingAnimationCurve( + blink::WebGestureDevice device_source, + const blink::WebFloatPoint& velocity, + const blink::WebSize& cumulative_scroll) OVERRIDE; + + virtual blink::WebUnitTestSupport* unitTestSupport(); + + // WebUnitTestSupport implementation + virtual void registerMockedURL(const blink::WebURL& url, + const blink::WebURLResponse& response, + const blink::WebString& filePath); + virtual void registerMockedErrorURL(const blink::WebURL& url, + const blink::WebURLResponse& response, + const blink::WebURLError& error); + virtual void unregisterMockedURL(const blink::WebURL& url); + virtual void unregisterAllMockedURLs(); + virtual void serveAsynchronousMockedRequests(); + virtual blink::WebString webKitRootDir(); + virtual blink::WebLayerTreeView* createLayerTreeViewForTesting(); + virtual blink::WebData readFromFile(const blink::WebString& path); + + private: + MockWebBlobRegistryImpl blob_registry_; + SimpleWebMimeRegistryImpl mime_registry_; + scoped_ptr<MockWebClipboardImpl> mock_clipboard_; + WebFileUtilitiesImpl file_utilities_; + base::ScopedTempDir file_system_root_; + scoped_ptr<WebURLLoaderMockFactory> url_loader_factory_; + cc_blink::WebCompositorSupportImpl compositor_support_; + scoped_ptr<base::StatsTable> stats_table_; + +#if defined(OS_WIN) || defined(OS_MACOSX) + blink::WebThemeEngine* active_theme_engine_; +#endif + DISALLOW_COPY_AND_ASSIGN(TestBlinkWebUnitTestSupport); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_BLINK_WEB_UNIT_TEST_SUPPORT_H_ diff --git a/content/test/test_webkit_platform_support.cc b/content/test/test_webkit_platform_support.cc deleted file mode 100644 index 804c2d3..0000000 --- a/content/test/test_webkit_platform_support.cc +++ /dev/null @@ -1,305 +0,0 @@ -// Copyright 2013 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_webkit_platform_support.h" - -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/metrics/stats_counters.h" -#include "base/path_service.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/common/content_switches.h" -#include "content/test/mock_webclipboard_impl.h" -#include "content/test/web_gesture_curve_mock.h" -#include "content/test/web_layer_tree_view_impl_for_testing.h" -#include "content/test/weburl_loader_mock_factory.h" -#include "media/base/media.h" -#include "net/cookies/cookie_monster.h" -#include "net/test/spawned_test_server/spawned_test_server.h" -#include "storage/browser/database/vfs_backend.h" -#include "third_party/WebKit/public/platform/WebData.h" -#include "third_party/WebKit/public/platform/WebFileSystem.h" -#include "third_party/WebKit/public/platform/WebStorageArea.h" -#include "third_party/WebKit/public/platform/WebStorageNamespace.h" -#include "third_party/WebKit/public/platform/WebString.h" -#include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/web/WebDatabase.h" -#include "third_party/WebKit/public/web/WebKit.h" -#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" -#include "third_party/WebKit/public/web/WebSecurityPolicy.h" -#include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" -#include "v8/include/v8.h" - -#if defined(OS_MACOSX) -#include "base/mac/mac_util.h" -#include "base/mac/scoped_nsautorelease_pool.h" -#endif - -namespace content { - -TestWebKitPlatformSupport::TestWebKitPlatformSupport() { -#if defined(OS_MACOSX) - base::mac::ScopedNSAutoreleasePool autorelease_pool; -#endif - - url_loader_factory_.reset(new WebURLLoaderMockFactory()); - mock_clipboard_.reset(new MockWebClipboardImpl()); - - // Create an anonymous stats table since we don't need to share between - // processes. - stats_table_.reset( - new base::StatsTable(base::StatsTable::TableIdentifier(), 20, 200)); - base::StatsTable::set_current(stats_table_.get()); - - blink::initialize(this); - blink::mainThreadIsolate()->SetCounterFunction( - base::StatsTable::FindLocation); - blink::setLayoutTestMode(true); - blink::WebSecurityPolicy::registerURLSchemeAsLocal( - blink::WebString::fromUTF8("test-shell-resource")); - blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( - blink::WebString::fromUTF8("test-shell-resource")); - blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( - blink::WebString::fromUTF8("test-shell-resource")); - blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( - blink::WebString::fromUTF8("test-shell-resource")); - blink::WebRuntimeFeatures::enableApplicationCache(true); - blink::WebRuntimeFeatures::enableDatabase(true); - blink::WebRuntimeFeatures::enableNotifications(true); - blink::WebRuntimeFeatures::enableTouch(true); - - // Load libraries for media and enable the media player. - bool enable_media = false; - base::FilePath module_path; - if (PathService::Get(base::DIR_MODULE, &module_path)) { -#if defined(OS_MACOSX) - if (base::mac::AmIBundled()) - module_path = module_path.DirName().DirName().DirName(); -#endif - if (media::InitializeMediaLibrary(module_path)) - enable_media = true; - } - blink::WebRuntimeFeatures::enableMediaPlayer(enable_media); - LOG_IF(WARNING, !enable_media) << "Failed to initialize the media library.\n"; - - file_utilities_.set_sandbox_enabled(false); - - if (!file_system_root_.CreateUniqueTempDir()) { - LOG(WARNING) << "Failed to create a temp dir for the filesystem." - "FileSystem feature will be disabled."; - DCHECK(file_system_root_.path().empty()); - } - -#if defined(OS_WIN) - // Ensure we pick up the default theme engine. - SetThemeEngine(NULL); -#endif - - CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFileCookies); - - // Test shell always exposes the GC. - std::string flags("--expose-gc"); - v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); -} - -TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { - url_loader_factory_.reset(); - mock_clipboard_.reset(); - blink::shutdown(); - base::StatsTable::set_current(NULL); - stats_table_.reset(); -} - -blink::WebBlobRegistry* TestWebKitPlatformSupport::blobRegistry() { - return &blob_registry_; -} - -blink::WebClipboard* TestWebKitPlatformSupport::clipboard() { - // Mock out clipboard calls so that tests don't mess - // with each other's copies/pastes when running in parallel. - return mock_clipboard_.get(); -} - -blink::WebFileUtilities* TestWebKitPlatformSupport::fileUtilities() { - return &file_utilities_; -} - -blink::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { - NOTREACHED() << - "IndexedDB cannot be tested with in-process harnesses."; - return NULL; -} - -blink::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { - return &mime_registry_; -} - -blink::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() { - return url_loader_factory_->CreateURLLoader( - BlinkPlatformImpl::createURLLoader()); -} - -blink::WebString TestWebKitPlatformSupport::userAgent() { - return blink::WebString::fromUTF8("DumpRenderTree/0.0.0.0"); -} - -blink::WebData TestWebKitPlatformSupport::loadResource(const char* name) { - if (!strcmp(name, "deleteButton")) { - // Create a red 30x30 square. - const char red_square[] = - "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" - "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" - "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" - "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" - "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" - "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" - "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" - "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" - "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" - "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" - "\x82"; - return blink::WebData(red_square, arraysize(red_square)); - } - return BlinkPlatformImpl::loadResource(name); -} - -blink::WebString TestWebKitPlatformSupport::queryLocalizedString( - blink::WebLocalizedString::Name name) { - // Returns placeholder strings to check if they are correctly localized. - switch (name) { - case blink::WebLocalizedString::OtherDateLabel: - return base::ASCIIToUTF16("<<OtherDateLabel>>"); - case blink::WebLocalizedString::OtherMonthLabel: - return base::ASCIIToUTF16("<<OtherMonthLabel>>"); - case blink::WebLocalizedString::OtherTimeLabel: - return base::ASCIIToUTF16("<<OtherTimeLabel>>"); - case blink::WebLocalizedString::OtherWeekLabel: - return base::ASCIIToUTF16("<<OtherWeekLabel>>"); - case blink::WebLocalizedString::CalendarClear: - return base::ASCIIToUTF16("<<CalendarClear>>"); - case blink::WebLocalizedString::CalendarToday: - return base::ASCIIToUTF16("<<CalendarToday>>"); - case blink::WebLocalizedString::ThisMonthButtonLabel: - return base::ASCIIToUTF16("<<ThisMonthLabel>>"); - case blink::WebLocalizedString::ThisWeekButtonLabel: - return base::ASCIIToUTF16("<<ThisWeekLabel>>"); - case blink::WebLocalizedString::WeekFormatTemplate: - return base::ASCIIToUTF16("Week $2, $1"); - default: - return blink::WebString(); - } -} - -blink::WebString TestWebKitPlatformSupport::queryLocalizedString( - blink::WebLocalizedString::Name name, - const blink::WebString& value) { - if (name == blink::WebLocalizedString::ValidationRangeUnderflow) - return base::ASCIIToUTF16("range underflow"); - if (name == blink::WebLocalizedString::ValidationRangeOverflow) - return base::ASCIIToUTF16("range overflow"); - if (name == blink::WebLocalizedString::SelectMenuListText) - return base::ASCIIToUTF16("$1 selected"); - return BlinkPlatformImpl::queryLocalizedString(name, value); -} - -blink::WebString TestWebKitPlatformSupport::queryLocalizedString( - blink::WebLocalizedString::Name name, - const blink::WebString& value1, - const blink::WebString& value2) { - if (name == blink::WebLocalizedString::ValidationTooLong) - return base::ASCIIToUTF16("too long"); - if (name == blink::WebLocalizedString::ValidationStepMismatch) - return base::ASCIIToUTF16("step mismatch"); - return BlinkPlatformImpl::queryLocalizedString(name, value1, value2); -} - -blink::WebString TestWebKitPlatformSupport::defaultLocale() { - return base::ASCIIToUTF16("en-US"); -} - -#if defined(OS_WIN) || defined(OS_MACOSX) -void TestWebKitPlatformSupport::SetThemeEngine(blink::WebThemeEngine* engine) { - active_theme_engine_ = engine ? engine : BlinkPlatformImpl::themeEngine(); -} - -blink::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { - return active_theme_engine_; -} -#endif - -blink::WebCompositorSupport* TestWebKitPlatformSupport::compositorSupport() { - return &compositor_support_; -} - -blink::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( - blink::WebGestureDevice device_source, - const blink::WebFloatPoint& velocity, - const blink::WebSize& cumulative_scroll) { - // Caller will retain and release. - return new WebGestureCurveMock(velocity, cumulative_scroll); -} - -blink::WebUnitTestSupport* TestWebKitPlatformSupport::unitTestSupport() { - return this; -} - -void TestWebKitPlatformSupport::registerMockedURL( - const blink::WebURL& url, - const blink::WebURLResponse& response, - const blink::WebString& file_path) { - url_loader_factory_->RegisterURL(url, response, file_path); -} - -void TestWebKitPlatformSupport::registerMockedErrorURL( - const blink::WebURL& url, - const blink::WebURLResponse& response, - const blink::WebURLError& error) { - url_loader_factory_->RegisterErrorURL(url, response, error); -} - -void TestWebKitPlatformSupport::unregisterMockedURL(const blink::WebURL& url) { - url_loader_factory_->UnregisterURL(url); -} - -void TestWebKitPlatformSupport::unregisterAllMockedURLs() { - url_loader_factory_->UnregisterAllURLs(); -} - -void TestWebKitPlatformSupport::serveAsynchronousMockedRequests() { - url_loader_factory_->ServeAsynchronousRequests(); -} - -blink::WebString TestWebKitPlatformSupport::webKitRootDir() { - base::FilePath path; - PathService::Get(base::DIR_SOURCE_ROOT, &path); - path = path.Append(FILE_PATH_LITERAL("third_party/WebKit")); - path = base::MakeAbsoluteFilePath(path); - CHECK(!path.empty()); - std::string path_ascii = path.MaybeAsASCII(); - CHECK(!path_ascii.empty()); - return blink::WebString::fromUTF8(path_ascii.c_str()); -} - -blink::WebLayerTreeView* -TestWebKitPlatformSupport::createLayerTreeViewForTesting() { - scoped_ptr<WebLayerTreeViewImplForTesting> view( - new WebLayerTreeViewImplForTesting()); - - view->Initialize(); - return view.release(); -} - -blink::WebData TestWebKitPlatformSupport::readFromFile( - const blink::WebString& path) { - base::FilePath file_path = base::FilePath::FromUTF16Unsafe(path); - - std::string buffer; - base::ReadFileToString(file_path, &buffer); - - return blink::WebData(buffer.data(), buffer.size()); -} - -} // namespace content diff --git a/content/test/test_webkit_platform_support.h b/content/test/test_webkit_platform_support.h deleted file mode 100644 index 2bda542..0000000 --- a/content/test/test_webkit_platform_support.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 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_WEBKIT_PLATFORM_SUPPORT_H_ -#define CONTENT_TEST_TEST_WEBKIT_PLATFORM_SUPPORT_H_ - -#include "base/compiler_specific.h" -#include "base/files/scoped_temp_dir.h" -#include "cc/blink/web_compositor_support_impl.h" -#include "content/child/blink_platform_impl.h" -#include "content/child/simple_webmimeregistry_impl.h" -#include "content/child/webfileutilities_impl.h" -#include "content/test/mock_webblob_registry_impl.h" -#include "content/test/mock_webclipboard_impl.h" -#include "content/test/weburl_loader_mock_factory.h" -#include "third_party/WebKit/public/platform/WebUnitTestSupport.h" - -namespace base { -class StatsTable; -} - -namespace blink { -class WebLayerTreeView; -} - -namespace content { - -// An implementation of WebKitPlatformSupport for tests. -class TestWebKitPlatformSupport - : public blink::WebUnitTestSupport, - public BlinkPlatformImpl { - public: - TestWebKitPlatformSupport(); - virtual ~TestWebKitPlatformSupport(); - - virtual blink::WebBlobRegistry* blobRegistry(); - virtual blink::WebClipboard* clipboard(); - virtual blink::WebFileUtilities* fileUtilities(); - virtual blink::WebIDBFactory* idbFactory(); - virtual blink::WebMimeRegistry* mimeRegistry(); - - virtual blink::WebURLLoader* createURLLoader(); - virtual blink::WebString userAgent() OVERRIDE; - virtual blink::WebData loadResource(const char* name); - virtual blink::WebString queryLocalizedString( - blink::WebLocalizedString::Name name); - virtual blink::WebString queryLocalizedString( - blink::WebLocalizedString::Name name, - const blink::WebString& value); - virtual blink::WebString queryLocalizedString( - blink::WebLocalizedString::Name name, - const blink::WebString& value1, - const blink::WebString& value2); - virtual blink::WebString defaultLocale(); - -#if defined(OS_WIN) || defined(OS_MACOSX) - void SetThemeEngine(blink::WebThemeEngine* engine); - virtual blink::WebThemeEngine* themeEngine(); -#endif - - virtual blink::WebCompositorSupport* compositorSupport(); - - WebURLLoaderMockFactory* url_loader_factory() { - return url_loader_factory_.get(); - } - - const base::FilePath& file_system_root() const { - return file_system_root_.path(); - } - - virtual blink::WebGestureCurve* createFlingAnimationCurve( - blink::WebGestureDevice device_source, - const blink::WebFloatPoint& velocity, - const blink::WebSize& cumulative_scroll) OVERRIDE; - - virtual blink::WebUnitTestSupport* unitTestSupport(); - - // WebUnitTestSupport implementation - virtual void registerMockedURL(const blink::WebURL& url, - const blink::WebURLResponse& response, - const blink::WebString& filePath); - virtual void registerMockedErrorURL(const blink::WebURL& url, - const blink::WebURLResponse& response, - const blink::WebURLError& error); - virtual void unregisterMockedURL(const blink::WebURL& url); - virtual void unregisterAllMockedURLs(); - virtual void serveAsynchronousMockedRequests(); - virtual blink::WebString webKitRootDir(); - virtual blink::WebLayerTreeView* createLayerTreeViewForTesting(); - virtual blink::WebData readFromFile(const blink::WebString& path); - - private: - MockWebBlobRegistryImpl blob_registry_; - SimpleWebMimeRegistryImpl mime_registry_; - scoped_ptr<MockWebClipboardImpl> mock_clipboard_; - WebFileUtilitiesImpl file_utilities_; - base::ScopedTempDir file_system_root_; - scoped_ptr<WebURLLoaderMockFactory> url_loader_factory_; - cc_blink::WebCompositorSupportImpl compositor_support_; - scoped_ptr<base::StatsTable> stats_table_; - -#if defined(OS_WIN) || defined(OS_MACOSX) - blink::WebThemeEngine* active_theme_engine_; -#endif - DISALLOW_COPY_AND_ASSIGN(TestWebKitPlatformSupport); -}; - -} // namespace content - -#endif // CONTENT_TEST_TEST_WEBKIT_PLATFORM_SUPPORT_H_ diff --git a/content/test/web_layer_tree_view_impl_for_testing.cc b/content/test/web_layer_tree_view_impl_for_testing.cc index b188384..5714a2f 100644 --- a/content/test/web_layer_tree_view_impl_for_testing.cc +++ b/content/test/web_layer_tree_view_impl_for_testing.cc @@ -14,7 +14,7 @@ #include "cc/output/output_surface.h" #include "cc/test/test_context_provider.h" #include "cc/trees/layer_tree_host.h" -#include "content/test/test_webkit_platform_support.h" +#include "content/test/test_blink_web_unit_test_support.h" #include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" #include "third_party/WebKit/public/platform/WebLayer.h" diff --git a/content/test/weburl_loader_mock_factory.h b/content/test/weburl_loader_mock_factory.h index a51987bc..6455d19 100644 --- a/content/test/weburl_loader_mock_factory.h +++ b/content/test/weburl_loader_mock_factory.h @@ -31,7 +31,7 @@ class WebURLLoaderMockFactory { WebURLLoaderMockFactory(); virtual ~WebURLLoaderMockFactory(); - // Called by TestWebKitPlatformSupport to create a WebURLLoader. + // Called by TestBlinkWebUnitTestSupport to create a WebURLLoader. // Non-mocked request are forwarded to |default_loader| which should not be // NULL. virtual blink::WebURLLoader* CreateURLLoader( diff --git a/content/utility/utility_thread_impl.cc b/content/utility/utility_thread_impl.cc index d885d8c..32f9814 100644 --- a/content/utility/utility_thread_impl.cc +++ b/content/utility/utility_thread_impl.cc @@ -94,8 +94,8 @@ void UtilityThreadImpl::Init() { // we run the utility thread on separate thread. This means that if any code // needs WebKit initialized in the utility process, they need to have // another path to support single process mode. - webkit_platform_support_.reset(new BlinkPlatformImpl); - blink::initialize(webkit_platform_support_.get()); + blink_platform_impl_.reset(new BlinkPlatformImpl); + blink::initialize(blink_platform_impl_.get()); } GetContentClient()->utility()->UtilityThreadStarted(); } diff --git a/content/utility/utility_thread_impl.h b/content/utility/utility_thread_impl.h index 229cd0a..079555a 100644 --- a/content/utility/utility_thread_impl.h +++ b/content/utility/utility_thread_impl.h @@ -58,7 +58,7 @@ class UtilityThreadImpl : public UtilityThread, // True if running in single process mode. bool single_process_; - scoped_ptr<BlinkPlatformImpl> webkit_platform_support_; + scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; DISALLOW_COPY_AND_ASSIGN(UtilityThreadImpl); }; -- cgit v1.1