diff options
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_sandbox_host_linux.cc | 46 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/common/sandbox_methods_linux.h | 19 | ||||
-rw-r--r-- | chrome/renderer/renderer_sandbox_support_linux.cc | 35 | ||||
-rw-r--r-- | chrome/renderer/renderer_sandbox_support_linux.h | 25 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.cc | 25 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.h | 21 | ||||
-rw-r--r-- | webkit/api/public/gtk/WebFontInfo.h | 52 | ||||
-rw-r--r-- | webkit/api/public/linux/WebSandboxSupport.h | 56 | ||||
-rw-r--r-- | webkit/api/src/ChromiumBridge.cpp | 17 | ||||
-rw-r--r-- | webkit/api/src/gtk/WebFontInfo.cpp | 83 | ||||
-rw-r--r-- | webkit/webkit.gyp | 3 |
13 files changed, 382 insertions, 4 deletions
@@ -1,7 +1,7 @@ vars = { "webkit_trunk": "http://svn.webkit.org/repository/webkit/trunk", - "webkit_revision": "45176", + "webkit_revision": "45191", } diff --git a/chrome/browser/renderer_host/render_sandbox_host_linux.cc b/chrome/browser/renderer_host/render_sandbox_host_linux.cc index dcd20d9..e657af4 100644 --- a/chrome/browser/renderer_host/render_sandbox_host_linux.cc +++ b/chrome/browser/renderer_host/render_sandbox_host_linux.cc @@ -15,11 +15,18 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/pickle.h" +#include "base/string_util.h" #include "base/unix_domain_socket_posix.h" +#include "chrome/common/sandbox_methods_linux.h" +#include "webkit/api/public/gtk/WebFontInfo.h" #include "SkFontHost_fontconfig_direct.h" #include "SkFontHost_fontconfig_ipc.h" +using WebKit::WebFontInfo; +using WebKit::WebString; +using WebKit::WebUChar; + // http://code.google.com/p/chromium/wiki/LinuxSandboxIPC // BEWARE: code in this file run across *processes* (not just threads). @@ -101,6 +108,8 @@ class SandboxIPCProcess { HandleFontMatchRequest(fd, pickle, iter, fds); } else if (kind == FontConfigIPC::METHOD_OPEN) { HandleFontOpenRequest(fd, pickle, iter, fds); + } else if (kind == LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS) { + HandleGetFontFamilyForChars(fd, pickle, iter, fds); } error: @@ -166,6 +175,43 @@ class SandboxIPCProcess { SendRendererReply(fds, reply, result_fd); } + void HandleGetFontFamilyForChars(int fd, Pickle& pickle, void* iter, + std::vector<int>& fds) { + // The other side of this call is + // chrome/renderer/renderer_sandbox_support_linux.cc + + int num_chars; + if (!pickle.ReadInt(&iter, &num_chars)) + return; + + // We don't want a corrupt renderer asking too much of us, it might + // overflow later in the code. + static const int kMaxChars = 4096; + if (num_chars < 1 || num_chars > kMaxChars) { + LOG(WARNING) << "HandleGetFontFamilyForChars: too many chars: " + << num_chars; + return; + } + + scoped_array<WebUChar> chars(new WebUChar[num_chars]); + + for (int i = 0; i < num_chars; ++i) { + uint32_t c; + if (!pickle.ReadUInt32(&iter, &c)) { + return; + } + + chars[i] = c; + } + + const WebString family = WebFontInfo::familyForChars(chars.get(), num_chars); + const std::string family_utf8 = UTF16ToUTF8(family); + + Pickle reply; + reply.WriteString(family_utf8); + SendRendererReply(fds, reply, -1); + } + void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, int reply_fd) { struct msghdr msg; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 3c287dc..2d5099c 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2253,6 +2253,8 @@ 'renderer/renderer_main_platform_delegate_linux.cc', 'renderer/renderer_main_platform_delegate_mac.mm', 'renderer/renderer_main_platform_delegate_win.cc', + 'renderer/renderer_sandbox_support_linux.cc', + 'renderer/renderer_sandbox_support_linux.h', 'renderer/renderer_webkitclient_impl.cc', 'renderer/renderer_webkitclient_impl.h', 'renderer/user_script_slave.cc', diff --git a/chrome/common/sandbox_methods_linux.h b/chrome/common/sandbox_methods_linux.h new file mode 100644 index 0000000..cfa2c84 --- /dev/null +++ b/chrome/common/sandbox_methods_linux.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009 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 CHROME_COMMON_SANDBOX_METHODS_LINUX_H_ +#define CHROME_COMMON_SANDBOX_METHODS_LINUX_H_ + +// This is a list of sandbox IPC methods which the renderer may send to the +// sandbox host. See http://code.google.com/p/chromium/LinuxSandboxIPC +// This isn't the full list, values < 32 are reserved for methods called from +// Skia. +class LinuxSandbox { + public: + enum Methods { + METHOD_GET_FONT_FAMILY_FOR_CHARS = 32, + }; +}; + +#endif // CHROME_COMMON_SANDBOX_METHODS_LINUX_H_ diff --git a/chrome/renderer/renderer_sandbox_support_linux.cc b/chrome/renderer/renderer_sandbox_support_linux.cc new file mode 100644 index 0000000..29fe183 --- /dev/null +++ b/chrome/renderer/renderer_sandbox_support_linux.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2009 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 "chrome/renderer/renderer_sandbox_support_linux.h" + +#include "base/pickle.h" +#include "base/unix_domain_socket_posix.h" +#include "chrome/common/sandbox_methods_linux.h" + +namespace renderer_sandbox_support { + +std::string getFontFamilyForCharacters(const uint16_t* utf16, size_t num_utf16) { + Pickle request; + request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS); + request.WriteInt(num_utf16); + for (size_t i = 0; i < num_utf16; ++i) + request.WriteUInt32(utf16[i]); + + uint8_t buf[512]; + static const int kMagicSandboxFD = 4; + const ssize_t n = base::SendRecvMsg(kMagicSandboxFD, buf, sizeof(buf), NULL, + request); + + std::string family_name; + if (n != -1) { + Pickle reply(reinterpret_cast<char*>(buf), n); + void* pickle_iter = NULL; + reply.ReadString(&pickle_iter, &family_name); + } + + return family_name; +} + +} // namespace render_sandbox_support diff --git a/chrome/renderer/renderer_sandbox_support_linux.h b/chrome/renderer/renderer_sandbox_support_linux.h new file mode 100644 index 0000000..b7d6b77 --- /dev/null +++ b/chrome/renderer/renderer_sandbox_support_linux.h @@ -0,0 +1,25 @@ +// Copyright (c) 2009 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 CHROME_RENDERER_RENDERER_SANDBOX_SUPPORT_H_ +#define CHROME_RENDERER_RENDERER_SANDBOX_SUPPORT_H_ + +#include <stdint.h> + +#include <string> + +namespace renderer_sandbox_support { + +// Return a font family which provides glyphs for the Unicode code points +// specified by |utf16| +// utf16: a native-endian UTF16 string +// num_utf16: the number of 16-bit words in |utf16| +// +// Returns: the font family or an empty string if the request could not be +// satisfied. +std::string getFontFamilyForCharacters(const uint16_t* utf16, size_t num_utf16); + +}; // namespace render_sandbox_support + +#endif // CHROME_RENDERER_RENDER_SANDBOX_SUPPORT_H_ diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc index 408ddef..a193447 100644 --- a/chrome/renderer/renderer_webkitclient_impl.cc +++ b/chrome/renderer/renderer_webkitclient_impl.cc @@ -16,6 +16,10 @@ #include "webkit/glue/glue_util.h" #include "webkit/glue/webkit_glue.h" +#if defined(OS_LINUX) +#include "chrome/renderer/renderer_sandbox_support_linux.h" +#endif + using WebKit::WebString; using WebKit::WebURL; @@ -30,7 +34,7 @@ WebKit::WebMimeRegistry* RendererWebKitClientImpl::mimeRegistry() { } WebKit::WebSandboxSupport* RendererWebKitClientImpl::sandboxSupport() { -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) return &sandbox_support_; #else return NULL; @@ -139,4 +143,23 @@ bool RendererWebKitClientImpl::SandboxSupport::ensureFontLoaded(HFONT font) { return RenderThread::current()->Send(new ViewHostMsg_LoadFont(logfont)); } +#elif defined(OS_LINUX) + +WebString RendererWebKitClientImpl::SandboxSupport::getFontFamilyForCharacters( + const WebKit::WebUChar* characters, size_t num_characters) { + AutoLock lock(unicode_font_families_mutex_); + const std::string key(reinterpret_cast<const char*>(characters), + num_characters * sizeof(characters[0])); + const std::map<std::string, std::string>::const_iterator iter = + unicode_font_families_.find(key); + if (iter != unicode_font_families_.end()) + return WebString::fromUTF8(iter->second.data(), iter->second.size()); + + const std::string family_name = + renderer_sandbox_support::getFontFamilyForCharacters(characters, + num_characters); + unicode_font_families_.insert(make_pair(key, family_name)); + return WebString::fromUTF8(family_name); +} + #endif diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h index 3150b12..27d11f8 100644 --- a/chrome/renderer/renderer_webkitclient_impl.h +++ b/chrome/renderer/renderer_webkitclient_impl.h @@ -11,6 +11,11 @@ #if defined(OS_WIN) #include "webkit/api/public/win/WebSandboxSupport.h" +#elif defined(OS_LINUX) +#include <string> +#include <map> +#include "base/lock.h" +#include "webkit/api/public/linux/WebSandboxSupport.h" #endif class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { @@ -45,12 +50,26 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { public: virtual bool ensureFontLoaded(HFONT); }; +#elif defined(OS_LINUX) + class SandboxSupport : public WebKit::WebSandboxSupport { + public: + virtual WebKit::WebString getFontFamilyForCharacters( + const WebKit::WebUChar* characters, size_t numCharacters); + + 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. + Lock unicode_font_families_mutex_; + std::map<std::string, std::string> unicode_font_families_; + }; #endif webkit_glue::WebClipboardImpl clipboard_; MimeRegistry mime_registry_; -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) SandboxSupport sandbox_support_; #endif }; diff --git a/webkit/api/public/gtk/WebFontInfo.h b/webkit/api/public/gtk/WebFontInfo.h new file mode 100644 index 0000000..d77ce68 --- /dev/null +++ b/webkit/api/public/gtk/WebFontInfo.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebFontInfo_h +#define WebFontInfo_h + +#include "../WebString.h" + +namespace WebKit { + + class WebFontInfo { + public: + // Return a font family which provides glyphs for the Unicode code points + // specified by |utf16| + // characters: a native-endian UTF16 string + // numCharacters: the number of 16-bit words in |utf16| + // + // Returns: the font family or an empty string if the request could not be + // satisfied. + WEBKIT_API static WebString familyForChars(const WebUChar* characters, size_t numCharacters); + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/public/linux/WebSandboxSupport.h b/webkit/api/public/linux/WebSandboxSupport.h new file mode 100644 index 0000000..4e20387 --- /dev/null +++ b/webkit/api/public/linux/WebSandboxSupport.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebSandboxSupport_h +#define WebSandboxSupport_h + +#include "webkit/api/public/WebCommon.h" +#include "webkit/api/public/WebString.h" + +namespace WebKit { + + // Put methods here that are required due to sandbox restrictions. + class WebSandboxSupport { + public: + // Fonts --------------------------------------------------------------- + + // Get a font family which contains glyphs for the given Unicode + // code-points. + // characters: a UTF-16 encoded string + // numCharacters: the number of 16-bit words in |characters| + // + // Returns a string with the font family on an empty string if the + // request cannot be satisfied. + virtual WebString getFontFamilyForCharacters(const WebUChar* characters, size_t numCharacters) = 0; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/src/ChromiumBridge.cpp b/webkit/api/src/ChromiumBridge.cpp index a544baa..3fdef0a 100644 --- a/webkit/api/src/ChromiumBridge.cpp +++ b/webkit/api/src/ChromiumBridge.cpp @@ -49,6 +49,11 @@ #include "WebThemeEngine.h" #endif +#if PLATFORM(LINUX) +#include "WebSandboxSupport.h" +#include "WebFontInfo.h" +#endif + #include "BitmapImage.h" #include "GraphicsContext.h" #include "KURL.h" @@ -145,7 +150,7 @@ void ChromiumBridge::prefetchDNS(const String& hostname) // Font ----------------------------------------------------------------------- -#if defined(OS_WIN) +#if PLATFORM(WIN_OS) bool ChromiumBridge::ensureFontLoaded(HFONT font) { WebSandboxSupport* ss = webKitClient()->sandboxSupport(); @@ -156,6 +161,16 @@ bool ChromiumBridge::ensureFontLoaded(HFONT font) } #endif +#if PLATFORM(LINUX) +String ChromiumBridge::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters) +{ + if (webKitClient()->sandboxSupport()) + return webKitClient()->sandboxSupport()->getFontFamilyForCharacters(characters, numCharacters); + else + return WebFontInfo::familyForChars(characters, numCharacters); +} +#endif + // Language ------------------------------------------------------------------- String ChromiumBridge::computedDefaultLanguage() diff --git a/webkit/api/src/gtk/WebFontInfo.cpp b/webkit/api/src/gtk/WebFontInfo.cpp new file mode 100644 index 0000000..2485022 --- /dev/null +++ b/webkit/api/src/gtk/WebFontInfo.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebFontInfo.h" + +#include <string.h> + +#include <unicode/utf16.h> +#include <fontconfig/fontconfig.h> + +namespace WebKit { + +WebString WebFontInfo::familyForChars(const WebUChar* characters, size_t numCharacters) +{ + FcCharSet* cset = FcCharSetCreate(); + for (int i = 0; i < numCharacters; ++i) { + if (U16_IS_SURROGATE(characters[i]) + && U16_IS_SURROGATE_LEAD(characters[i]) + && i != numCharacters - 1 + && U16_IS_TRAIL(characters[i + 1])) { + FcCharSetAddChar(cset, U16_GET_SUPPLEMENTARY(characters[i], characters[i+1])); + i++; + } else + FcCharSetAddChar(cset, characters[i]); + } + FcPattern* pattern = FcPatternCreate(); + + FcValue fcvalue; + fcvalue.type = FcTypeCharSet; + fcvalue.u.c = cset; + FcPatternAdd(pattern, FC_CHARSET, fcvalue, 0); + + FcConfigSubstitute(0, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); + + FcResult result; + FcPattern* match = FcFontMatch(0, pattern, &result); + FcPatternDestroy(pattern); + FcCharSetDestroy(cset); + + if (match) { + FcChar8* family; + WebString result; + if (FcPatternGetString(match, FC_FAMILY, 0, &family) == FcResultMatch) { + const char* charFamily = reinterpret_cast<char*>(family); + result = WebString::fromUTF8(charFamily, strlen(charFamily)); + } + FcPatternDestroy(match); + return result; + } + + return WebString(); +} + +} // namespace WebKit diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 16c255f..dae7b42 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -4254,6 +4254,8 @@ 'api/src/ChromiumBridge.cpp', 'api/src/ChromiumCurrentTime.cpp', 'api/src/ChromiumThreading.cpp', + 'api/src/gtk/WebFontInfo.cpp', + 'api/src/gtk/WebFontInfo.h', 'api/src/gtk/WebInputEventFactory.cpp', 'api/src/x11/WebScreenInfoFactory.cpp', 'api/src/mac/WebInputEventFactory.mm', @@ -4296,6 +4298,7 @@ 'include_dirs': [ 'api/public/x11', 'api/public/gtk', + 'api/public/linux', ], }, { # else: OS!="linux" 'sources/': [ |