summaryrefslogtreecommitdiffstats
path: root/webkit/api
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 21:25:31 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 21:25:31 +0000
commit22a27de7ddd22505f5f281d2fe90a124b7d6ecf0 (patch)
treebe34167345b2c3871c783cca9e16aefa0da1d4bb /webkit/api
parente1b1a5fa61da772666bf58632979776f0651c981 (diff)
downloadchromium_src-22a27de7ddd22505f5f281d2fe90a124b7d6ecf0.zip
chromium_src-22a27de7ddd22505f5f281d2fe90a124b7d6ecf0.tar.gz
chromium_src-22a27de7ddd22505f5f281d2fe90a124b7d6ecf0.tar.bz2
Linux: plumb fontconfig call out to the sandbox host.
This is hopefully the last step before our renderers can run cleanly in a chroot. WebKit needs to be able to ask for the correct font to use in the case that the current font doesn't include glyphs for certain code points. Currently we make a fontconfig call in our WebKit port to handle this. This patch changes this so that the call is sent our via ChromiumBridge. Since we are at ChromiumBridge, we could make a sync IPC to the browser. However, fontconfig is a single threaded library and we are already using it on the UI thread in the browser, so the sync IPC would have to terminate on the UI thread. Even if this doesn't deadlock, it causes huge spikes in latency. So, instead, we send the IPC to the sandbox host process which is already setup to handle fontconfig requests from Skia. See: http://code.google.com/p/chromium/wiki/LinuxSandboxIPC git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api')
-rw-r--r--webkit/api/public/gtk/WebFontInfo.h52
-rw-r--r--webkit/api/public/linux/WebSandboxSupport.h56
-rw-r--r--webkit/api/src/ChromiumBridge.cpp17
-rw-r--r--webkit/api/src/gtk/WebFontInfo.cpp83
4 files changed, 207 insertions, 1 deletions
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