diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:31:09 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:31:09 +0000 |
commit | d259a8ecab95cd657b9c7d413e8bfa3c86d0d4cb (patch) | |
tree | 83805324a9ffeeb10b334d544b13155c8c52b069 /content/common | |
parent | 772b57ab0dcd7843157b961f10999e48088e8973 (diff) | |
download | chromium_src-d259a8ecab95cd657b9c7d413e8bfa3c86d0d4cb.zip chromium_src-d259a8ecab95cd657b9c7d413e8bfa3c86d0d4cb.tar.gz chromium_src-d259a8ecab95cd657b9c7d413e8bfa3c86d0d4cb.tar.bz2 |
Support getting the font list in Pepper. This currently only works out of
process.
This adds a function to the font interface to get the font list. Since we
don't have arrays or dictionaries in Pepper yet, I used a string with nulls
separating the names. A previous attempt to make a "font list resource" proved
excessively complicated and not actually much easier for clients to deal with.
This refactors the existing font list getting that used to be in the options
for the browser. I moved it to content and split it into two pieces, the
synchronous version, and then an asynchronous wrapper around that which both
the prefs code and the pepper code use. This cleaned up some of the preferences
code, and also fixes the leak of the entire font list in the code.
I used the new callback/bind system for the async font loading. I had to add
BrowserThread support for the new system.
This uses the PepperMessageFilter to listen for font load requests from the
plugin in the browser process. This is nice because we can add stuff here and
have messages serviced for both in-process and out-of-process plugins. This
proved to be complicated due to the HostResolver used in some of the existing
code, and thread restrictions for how to deal with it. This is why there are
two modes for the filter object.
I changed the delegates around for the Dispatcher. Now the PluginDispatcher
has the delegate interface since the HostDispatcher didn't actually need any
of them and we were accumulating a lot of empty functions in the
PepperPluginRegistry.
It's possible for the fonts to be loaded on Windows and Mac without IPC, since
enumerating fonts should be possible inside the sandbox. I didn't implement
this since it adds extra complexity and probably doesn't give that much
benefit.
TEST=manual
BUG=none
Review URL: http://codereview.chromium.org/7044012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/font_list.h | 26 | ||||
-rw-r--r-- | content/common/font_list_gtk.cc | 43 | ||||
-rw-r--r-- | content/common/font_list_mac.mm | 33 | ||||
-rw-r--r-- | content/common/font_list_win.cc | 55 | ||||
-rw-r--r-- | content/common/pepper_plugin_registry.cc | 19 | ||||
-rw-r--r-- | content/common/pepper_plugin_registry.h | 10 |
6 files changed, 160 insertions, 26 deletions
diff --git a/content/common/font_list.h b/content/common/font_list.h new file mode 100644 index 0000000..e4c01a9 --- /dev/null +++ b/content/common/font_list.h @@ -0,0 +1,26 @@ +// 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_COMMON_FONT_LIST_H_ +#define CONTENT_COMMON_FONT_LIST_H_ + +class ListValue; + +namespace content { + +// Retrieves the fonts available on the current platform and returns them. +// The caller will own the returned pointer. Each entry will be a list of +// two strings, the first being the font family, and the second being the +// localized name. +// +// This function is potentially slow (the system may do a bunch of I/O) so be +// sure not to call this on a time-critical thread like the UI or I/O threads. +// +// Most callers will want to use the GetFontListAsync function in +// content/browser/font_list_async.h which does an asynchronous call. +ListValue* GetFontList_SlowBlocking(); + +} // namespace content + +#endif // CONTENT_COMMON_FONT_LIST_H_ diff --git a/content/common/font_list_gtk.cc b/content/common/font_list_gtk.cc new file mode 100644 index 0000000..0742bb3 --- /dev/null +++ b/content/common/font_list_gtk.cc @@ -0,0 +1,43 @@ +// 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/common/font_list.h" + +#include <pango/pango.h> +#include <pango/pangocairo.h> + +#include <set> +#include <string> + +#include "base/values.h" + +namespace content { + +ListValue* GetFontList_SlowBlocking() { + ListValue* font_list = new ListValue; + + PangoFontMap* font_map = ::pango_cairo_font_map_get_default(); + PangoFontFamily** families = NULL; + int num_families = 0; + ::pango_font_map_list_families(font_map, &families, &num_families); + + std::set<std::string> sorted_families; + for (int i = 0; i < num_families; i++) { + sorted_families.insert(::pango_font_family_get_name(families[i])); + } + g_free(families); + + for (std::set<std::string>::const_iterator iter = sorted_families.begin(); + iter != sorted_families.end(); ++iter) { + ListValue* font_item = new ListValue(); + font_item->Append(Value::CreateStringValue(*iter)); + font_item->Append(Value::CreateStringValue(*iter)); // localized name. + // TODO(yusukes): Support localized family names. + font_list->Append(font_item); + } + + return font_list; +} + +} // namespace content diff --git a/content/common/font_list_mac.mm b/content/common/font_list_mac.mm new file mode 100644 index 0000000..08018cf --- /dev/null +++ b/content/common/font_list_mac.mm @@ -0,0 +1,33 @@ +// 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/common/font_list.h" + +#import <Cocoa/Cocoa.h> + +#include "base/mac/scoped_nsautorelease_pool.h" +#include "base/sys_string_conversions.h" +#include "base/values.h" + +namespace content { + +ListValue* GetFontList_SlowBlocking() { + base::mac::ScopedNSAutoreleasePool autorelease_pool; + ListValue* font_list = new ListValue; + NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; + NSArray* fonts = [fontManager availableFontFamilies]; + for (NSString* family_name in fonts) { + NSString* localized_family_name = + [fontManager localizedNameForFamily:family_name face:nil]; + ListValue* font_item = new ListValue(); + string16 family = base::SysNSStringToUTF16(family_name); + font_item->Append(Value::CreateStringValue(family)); + string16 loc_family = base::SysNSStringToUTF16(localized_family_name); + font_item->Append(Value::CreateStringValue(loc_family)); + font_list->Append(font_item); + } + return font_list; +} + +} // namespace content diff --git a/content/common/font_list_win.cc b/content/common/font_list_win.cc new file mode 100644 index 0000000..92428eb --- /dev/null +++ b/content/common/font_list_win.cc @@ -0,0 +1,55 @@ +// 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/common/font_list.h" + +#include <windows.h> + +#include <set> + +#include "base/string16.h" +#include "base/values.h" + +namespace content { + +static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font, + NEWTEXTMETRICEXW* physical_font, + DWORD font_type, + LPARAM lparam) { + std::set<string16>* font_names = + reinterpret_cast<std::set<string16>*>(lparam); + if (font_names) { + const LOGFONTW& lf = logical_font->elfLogFont; + if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { + string16 face_name(lf.lfFaceName); + font_names->insert(face_name); + } + } + return 1; +} + +ListValue* GetFontList_SlowBlocking() { + std::set<string16> font_names; + + LOGFONTW logfont; + memset(&logfont, 0, sizeof(logfont)); + logfont.lfCharSet = DEFAULT_CHARSET; + + HDC hdc = ::GetDC(NULL); + ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, + (LPARAM)&font_names, 0); + ::ReleaseDC(NULL, hdc); + + ListValue* font_list = new ListValue; + std::set<string16>::iterator iter; + for (iter = font_names.begin(); iter != font_names.end(); iter++) { + ListValue* font_item = new ListValue(); + font_item->Append(Value::CreateStringValue(*iter)); + font_item->Append(Value::CreateStringValue(*iter)); + font_list->Append(font_item); + } + return font_list; +} + +} // namespace content diff --git a/content/common/pepper_plugin_registry.cc b/content/common/pepper_plugin_registry.cc index 3966efa..9e68f44 100644 --- a/content/common/pepper_plugin_registry.cc +++ b/content/common/pepper_plugin_registry.cc @@ -229,22 +229,3 @@ base::WaitableEvent* PepperPluginRegistry::GetShutdownEvent() { DCHECK(ChildProcess::current()) << "Must be in the renderer."; return ChildProcess::current()->GetShutDownEvent(); } - -std::set<PP_Instance>* PepperPluginRegistry::GetGloballySeenInstanceIDSet() { - // This function is not needed on the host side of the proxy. - NOTREACHED(); - return NULL; -} - -ppapi::WebKitForwarding* PepperPluginRegistry::GetWebKitForwarding() { - // This function is not needed on the host side of the proxy. - NOTREACHED(); - return NULL; -} - -void PepperPluginRegistry::PostToWebKitThread( - const tracked_objects::Location& from_here, - const base::Closure& task) { - // This function is not needed on the host side of the proxy. - NOTREACHED(); -} diff --git a/content/common/pepper_plugin_registry.h b/content/common/pepper_plugin_registry.h index d6e320f..5e6389e 100644 --- a/content/common/pepper_plugin_registry.h +++ b/content/common/pepper_plugin_registry.h @@ -12,7 +12,7 @@ #include <vector> #include "base/file_path.h" -#include "ppapi/proxy/dispatcher.h" +#include "ppapi/proxy/proxy_channel.h" #include "webkit/plugins/npapi/webplugininfo.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -53,7 +53,7 @@ struct PepperPluginInfo { // not preloaded). class PepperPluginRegistry : public webkit::ppapi::PluginDelegate::ModuleLifetime, - public pp::proxy::Dispatcher::Delegate { + public pp::proxy::ProxyChannel::Delegate { public: ~PepperPluginRegistry(); @@ -96,13 +96,9 @@ class PepperPluginRegistry private: PepperPluginRegistry(); - // Dispatcher::Delegate implementation. + // ProxyChannel::Delegate implementation. virtual base::MessageLoopProxy* GetIPCMessageLoop(); virtual base::WaitableEvent* GetShutdownEvent(); - virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet(); - virtual ppapi::WebKitForwarding* GetWebKitForwarding(); - virtual void PostToWebKitThread(const tracked_objects::Location& from_here, - const base::Closure& task); // All known pepper plugins. std::vector<PepperPluginInfo> plugin_list_; |