diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:17:48 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:17:48 +0000 |
commit | 7a1f7c6f6c982287b3f6bb2acded619f3824416c (patch) | |
tree | 82ff404c4bcf84520c21ea7f0526ad5a40661641 /content/ppapi_plugin | |
parent | bafaee12825a06890f114a282880e135a8b0b1ae (diff) | |
download | chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.zip chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.tar.gz chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.tar.bz2 |
Make the Pepper proxy support in-process font rendering.
This implements a WebKit thread in the PPAPI plugin process so we can do the
font calls without IPC. The existing font support was refactored into
a virtual class (to prevent PPAPI from depending on WebKit and creating a
circular GYP dependency).
This moves the renderer sandbox support into content/common so that it can
be used by the PPAPI process.
Review URL: http://codereview.chromium.org/6981001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/ppapi_plugin')
-rw-r--r-- | content/ppapi_plugin/ppapi_thread.cc | 15 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_thread.h | 9 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_webkit_thread.cc | 44 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_webkit_thread.h | 50 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_webkitclient_impl.cc | 238 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_webkitclient_impl.h | 66 |
6 files changed, 422 insertions, 0 deletions
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index 91c3f85..73c0d5f 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -12,11 +12,13 @@ #include "content/common/child_process.h" #include "content/ppapi_plugin/broker_process_dispatcher.h" #include "content/ppapi_plugin/plugin_process_dispatcher.h" +#include "content/ppapi_plugin/ppapi_webkit_thread.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_sync_channel.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppp.h" #include "ppapi/proxy/ppapi_messages.h" +#include "webkit/plugins/ppapi/webkit_forwarding_impl.h" #if defined(OS_WIN) #include "sandbox/src/sandbox.h" @@ -81,6 +83,19 @@ std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { return &globally_seen_instance_ids_; } +pp::shared_impl::WebKitForwarding* PpapiThread::GetWebKitForwarding() { + if (!webkit_forwarding_.get()) + webkit_forwarding_.reset(new webkit::ppapi::WebKitForwardingImpl); + return webkit_forwarding_.get(); +} + +void PpapiThread::PostToWebKitThread(const tracked_objects::Location& from_here, + const base::Closure& task) { + if (!webkit_thread_.get()) + webkit_thread_.reset(new PpapiWebKitThread); + webkit_thread_->PostTask(from_here, task); +} + void PpapiThread::OnMsgLoadPlugin(const FilePath& path) { base::ScopedNativeLibrary library(base::LoadNativeLibrary(path, NULL)); diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h index 50bda11..5b7e3c4 100644 --- a/content/ppapi_plugin/ppapi_thread.h +++ b/content/ppapi_plugin/ppapi_thread.h @@ -17,6 +17,7 @@ #include "ppapi/c/trusted/ppp_broker.h" class FilePath; +class PpapiWebKitThread; namespace IPC { struct ChannelHandle; @@ -36,6 +37,9 @@ class PpapiThread : public ChildThread, virtual base::MessageLoopProxy* GetIPCMessageLoop(); virtual base::WaitableEvent* GetShutdownEvent(); virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet(); + virtual pp::shared_impl::WebKitForwarding* GetWebKitForwarding(); + virtual void PostToWebKitThread(const tracked_objects::Location& from_here, + const base::Closure& task); // Message handlers. void OnMsgLoadPlugin(const FilePath& path); @@ -70,6 +74,11 @@ class PpapiThread : public ChildThread, // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet. std::set<PP_Instance> globally_seen_instance_ids_; + // Lazily created by GetWebKitForwarding. + scoped_ptr<pp::shared_impl::WebKitForwarding> webkit_forwarding_; + + scoped_ptr<PpapiWebKitThread> webkit_thread_; + DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread); }; diff --git a/content/ppapi_plugin/ppapi_webkit_thread.cc b/content/ppapi_plugin/ppapi_webkit_thread.cc new file mode 100644 index 0000000..1320138 --- /dev/null +++ b/content/ppapi_plugin/ppapi_webkit_thread.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2011 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_webkit_thread.h" + +#include "base/logging.h" +#include "content/ppapi_plugin/ppapi_webkitclient_impl.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" + +PpapiWebKitThread::PpapiWebKitThread() { + DCHECK(!webkit_thread_.get()); + + webkit_thread_.reset(new InternalWebKitThread); + bool started = webkit_thread_->Start(); + DCHECK(started); +} + +PpapiWebKitThread::~PpapiWebKitThread() { +} + +void PpapiWebKitThread::PostTask(const tracked_objects::Location& from_here, + const base::Closure& task) { + webkit_thread_->message_loop()->PostTask(from_here, task); +} + +PpapiWebKitThread::InternalWebKitThread::InternalWebKitThread() + : base::Thread("PPAPIWebKit") { +} + +PpapiWebKitThread::InternalWebKitThread::~InternalWebKitThread() { + Stop(); +} + +void PpapiWebKitThread::InternalWebKitThread::Init() { + DCHECK(!webkit_client_.get()); + webkit_client_.reset(new PpapiWebKitClientImpl); + WebKit::initialize(webkit_client_.get()); +} + +void PpapiWebKitThread::InternalWebKitThread::CleanUp() { + DCHECK(webkit_client_.get()); + WebKit::shutdown(); +} diff --git a/content/ppapi_plugin/ppapi_webkit_thread.h b/content/ppapi_plugin/ppapi_webkit_thread.h new file mode 100644 index 0000000..a6f338e --- /dev/null +++ b/content/ppapi_plugin/ppapi_webkit_thread.h @@ -0,0 +1,50 @@ +// Copyright (c) 2011 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_WEBKIT_THREAD_H_ +#define CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "base/threading/thread.h" + +class PpapiWebKitClientImpl; + +// This creates a WebKit main thread on instantiation on construction and kills +// it on deletion. See also content/browser/in_process_webkit for the +// corresponding concept in the browser process. +class PpapiWebKitThread { + public: + PpapiWebKitThread(); + ~PpapiWebKitThread(); + + // Posts the given task to the thread, see MessageLoop::PostTask. + void PostTask( + const tracked_objects::Location& from_here, + const base::Closure& task); + + private: + // Must be private so that we can carefully control its lifetime. + class InternalWebKitThread : public base::Thread { + public: + InternalWebKitThread(); + virtual ~InternalWebKitThread(); + // Does the actual initialization and shutdown of WebKit. Called at the + // beginning and end of the thread's lifetime. + virtual void Init(); + virtual void CleanUp(); + + private: + // The WebKitClient implementation. Only access on WebKit thread. + scoped_ptr<PpapiWebKitClientImpl> webkit_client_; + }; + + // Pointer to the actual WebKitThread. + scoped_ptr<InternalWebKitThread> webkit_thread_; + + DISALLOW_COPY_AND_ASSIGN(PpapiWebKitThread); +}; + +#endif // CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_ diff --git a/content/ppapi_plugin/ppapi_webkitclient_impl.cc b/content/ppapi_plugin/ppapi_webkitclient_impl.cc new file mode 100644 index 0000000..1abbe94 --- /dev/null +++ b/content/ppapi_plugin/ppapi_webkitclient_impl.cc @@ -0,0 +1,238 @@ +// Copyright (c) 2011 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_webkitclient_impl.h" + +#include <map> + +#include "base/synchronization/lock.h" +#include "base/logging.h" +#include "base/string16.h" +#include "build/build_config.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" + +#if defined(OS_WIN) +#include "third_party/WebKit/Source/WebKit/chromium/public/win/WebSandboxSupport.h" +#elif defined(OS_MACOSX) +#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSandboxSupport.h" +#elif defined(OS_LINUX) +#include "content/common/child_process_sandbox_support_linux.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSupport.h" +#endif + +using WebKit::WebSandboxSupport; +using WebKit::WebString; +using WebKit::WebUChar; + +class PpapiWebKitClientImpl::SandboxSupport : public WebSandboxSupport { + public: +#if defined(OS_WIN) + virtual bool ensureFontLoaded(HFONT); +#elif defined(OS_MACOSX) + virtual bool loadFont(NSFont* srcFont, ATSFontContainerRef* out); +#elif defined(OS_LINUX) + virtual WebString getFontFamilyForCharacters( + const WebUChar* characters, + size_t numCharacters, + const char* preferred_locale); + virtual void getRenderStyleForStrike( + const char* family, int sizeAndStyle, WebKit::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. The key in this map is an array of 16-bit UTF16 values from WebKit. + // The value is a string containing the correct font family. + base::Lock unicode_font_families_mutex_; + std::map<string16, std::string> unicode_font_families_; +#endif +}; + +#if defined(OS_WIN) + +bool PpapiWebKitClientImpl::SandboxSupport::ensureFontLoaded(HFONT font) { + // TODO(brettw) this should do the something similar to what + // RendererWebKitClientImpl does and request that the browser load the font. + NOTIMPLEMENTED(); + return false; +} + +#elif defined(OS_MACOSX) + +bool PpapiWebKitClientImpl::SandboxSupport::loadFont(NSFont* srcFont, + ATSFontContainerRef* out) { + // TODO(brettw) this should do the something similar to what + // RendererWebKitClientImpl does and request that the browser load the font. + NOTIMPLEMENTED(); + return false; +} + +#elif defined(OS_LINUX) + +WebString PpapiWebKitClientImpl::SandboxSupport::getFontFamilyForCharacters( + const WebUChar* characters, + size_t num_characters, + const char* preferred_locale) { + base::AutoLock lock(unicode_font_families_mutex_); + const string16 key(characters, num_characters); + const std::map<string16, std::string>::const_iterator iter = + unicode_font_families_.find(key); + if (iter != unicode_font_families_.end()) + return WebString::fromUTF8(iter->second); + + const std::string family_name = + child_process_sandbox_support::getFontFamilyForCharacters( + characters, + num_characters, + preferred_locale); + unicode_font_families_.insert(make_pair(key, family_name)); + return WebString::fromUTF8(family_name); +} + +void PpapiWebKitClientImpl::SandboxSupport::getRenderStyleForStrike( + const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { + child_process_sandbox_support::getRenderStyleForStrike(family, sizeAndStyle, + out); +} + +#endif + +PpapiWebKitClientImpl::PpapiWebKitClientImpl() { +} + +PpapiWebKitClientImpl::~PpapiWebKitClientImpl() { +} + +WebKit::WebClipboard* PpapiWebKitClientImpl::clipboard() { + NOTREACHED(); + return NULL; +} + +WebKit::WebMimeRegistry* PpapiWebKitClientImpl::mimeRegistry() { + NOTREACHED(); + return NULL; +} + +WebKit::WebFileUtilities* PpapiWebKitClientImpl::fileUtilities() { + NOTREACHED(); + return NULL; +} + +WebKit::WebSandboxSupport* PpapiWebKitClientImpl::sandboxSupport() { + return sandbox_support_.get(); +} + +bool PpapiWebKitClientImpl::sandboxEnabled() { + return true; // Assume PPAPI is always sandboxed. +} + +unsigned long long PpapiWebKitClientImpl::visitedLinkHash( + const char* canonical_url, + size_t length) { + NOTREACHED(); + return 0; +} + +bool PpapiWebKitClientImpl::isLinkVisited(unsigned long long link_hash) { + NOTREACHED(); + return false; +} + +WebKit::WebMessagePortChannel* +PpapiWebKitClientImpl::createMessagePortChannel() { + NOTREACHED(); + return NULL; +} + +void PpapiWebKitClientImpl::setCookies( + const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies, + const WebKit::WebString& value) { + NOTREACHED(); +} + +WebKit::WebString PpapiWebKitClientImpl::cookies( + const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies) { + NOTREACHED(); + return WebKit::WebString(); +} + +void PpapiWebKitClientImpl::prefetchHostName(const WebKit::WebString&) { + NOTREACHED(); +} + +WebKit::WebString PpapiWebKitClientImpl::defaultLocale() { + NOTREACHED(); + return WebKit::WebString(); +} + +WebKit::WebThemeEngine* PpapiWebKitClientImpl::themeEngine() { + NOTREACHED(); + return NULL; +} + +WebKit::WebURLLoader* PpapiWebKitClientImpl::createURLLoader() { + NOTREACHED(); + return NULL; +} + +WebKit::WebSocketStreamHandle* + PpapiWebKitClientImpl::createSocketStreamHandle() { + NOTREACHED(); + return NULL; +} + +void PpapiWebKitClientImpl::getPluginList(bool refresh, + WebKit::WebPluginListBuilder* builder) { + NOTREACHED(); +} + +WebKit::WebData PpapiWebKitClientImpl::loadResource(const char* name) { + NOTREACHED(); + return WebKit::WebData(); +} + +WebKit::WebStorageNamespace* +PpapiWebKitClientImpl::createLocalStorageNamespace( + const WebKit::WebString& path, unsigned quota) { + NOTREACHED(); + return 0; +} + +void PpapiWebKitClientImpl::dispatchStorageEvent( + const WebKit::WebString& key, const WebKit::WebString& old_value, + const WebKit::WebString& new_value, const WebKit::WebString& origin, + const WebKit::WebURL& url, bool is_local_storage) { + NOTREACHED(); +} + +WebKit::WebSharedWorkerRepository* +PpapiWebKitClientImpl::sharedWorkerRepository() { + NOTREACHED(); + return NULL; +} + +int PpapiWebKitClientImpl::databaseDeleteFile( + const WebKit::WebString& vfs_file_name, bool sync_dir) { + NOTREACHED(); + return 0; +} + +void PpapiWebKitClientImpl::createIDBKeysFromSerializedValuesAndKeyPath( + const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, + const WebKit::WebString& keyPath, + WebKit::WebVector<WebKit::WebIDBKey>& keys) { + NOTREACHED(); +} + +WebKit::WebSerializedScriptValue +PpapiWebKitClientImpl::injectIDBKeyIntoSerializedValue( + const WebKit::WebIDBKey& key, + const WebKit::WebSerializedScriptValue& value, + const WebKit::WebString& keyPath) { + NOTREACHED(); + return WebKit::WebSerializedScriptValue(); +} diff --git a/content/ppapi_plugin/ppapi_webkitclient_impl.h b/content/ppapi_plugin/ppapi_webkitclient_impl.h new file mode 100644 index 0000000..5c3b90e --- /dev/null +++ b/content/ppapi_plugin/ppapi_webkitclient_impl.h @@ -0,0 +1,66 @@ +// Copyright (c) 2011 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_WEBKITCLIENT_IMPL_H_ +#define CONTENT_PPAPI_PLUGIN_PPAPI_WEBKITCLIENT_IMPL_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "webkit/glue/webkitclient_impl.h" + +class PpapiWebKitClientImpl : public webkit_glue::WebKitClientImpl { + public: + PpapiWebKitClientImpl(); + virtual ~PpapiWebKitClientImpl(); + + // WebKitClient methods: + virtual WebKit::WebClipboard* clipboard(); + virtual WebKit::WebMimeRegistry* mimeRegistry(); + virtual WebKit::WebFileUtilities* fileUtilities(); + virtual WebKit::WebSandboxSupport* sandboxSupport(); + virtual bool sandboxEnabled(); + virtual unsigned long long visitedLinkHash(const char* canonicalURL, + size_t length); + virtual bool isLinkVisited(unsigned long long linkHash); + virtual WebKit::WebMessagePortChannel* createMessagePortChannel(); + virtual void setCookies(const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies, + const WebKit::WebString& value); + virtual WebKit::WebString cookies( + const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies); + virtual void prefetchHostName(const WebKit::WebString&); + virtual WebKit::WebString defaultLocale(); + virtual WebKit::WebThemeEngine* themeEngine(); + virtual WebKit::WebURLLoader* createURLLoader(); + virtual WebKit::WebSocketStreamHandle* createSocketStreamHandle(); + virtual void getPluginList(bool refresh, WebKit::WebPluginListBuilder*); + virtual WebKit::WebData loadResource(const char* name); + virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( + const WebKit::WebString& path, unsigned quota); + virtual void dispatchStorageEvent(const WebKit::WebString& key, + const WebKit::WebString& oldValue, const WebKit::WebString& newValue, + const WebKit::WebString& origin, const WebKit::WebURL& url, + bool isLocalStorage); + virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository(); + virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name, + bool sync_dir); + virtual void createIDBKeysFromSerializedValuesAndKeyPath( + const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, + const WebKit::WebString& keyPath, + WebKit::WebVector<WebKit::WebIDBKey>& keys); + virtual WebKit::WebSerializedScriptValue injectIDBKeyIntoSerializedValue( + const WebKit::WebIDBKey& key, + const WebKit::WebSerializedScriptValue& value, + const WebKit::WebString& keyPath); + + private: + class SandboxSupport; + scoped_ptr<SandboxSupport> sandbox_support_; + + DISALLOW_COPY_AND_ASSIGN(PpapiWebKitClientImpl); +}; + +#endif // CONTENT_PPAPI_PLUGIN_PPAPI_WEBKITCLIENT_IMPL_H_ |