diff options
48 files changed, 792 insertions, 401 deletions
diff --git a/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.cc b/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.cc deleted file mode 100644 index 1f080f3..0000000 --- a/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.cc +++ /dev/null @@ -1,48 +0,0 @@ -// 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 "chrome/browser/ui/webui/options/font_settings_fonts_list_loader.h" - -#include "chrome/browser/ui/webui/options/font_settings_utils.h" -#include "content/browser/browser_thread.h" - -FontSettingsFontsListLoader::FontSettingsFontsListLoader(Observer* observer) - : observer_(observer) { -} - -FontSettingsFontsListLoader::~FontSettingsFontsListLoader() { -} - -ListValue* FontSettingsFontsListLoader::GetFontsList() { - return fonts_list_.get(); -} - -void FontSettingsFontsListLoader::StartLoadFontsList() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - NewRunnableMethod(this, - &FontSettingsFontsListLoader::GetFontsListOnFileThread)); -} - -void FontSettingsFontsListLoader::SetObserver(Observer* observer) { - observer_ = observer; -} - -void FontSettingsFontsListLoader::GetFontsListOnFileThread() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - - fonts_list_.reset(FontSettingsUtilities::GetFontsList()); - - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &FontSettingsFontsListLoader::FinishFontsListOnUIThread)); -} - -void FontSettingsFontsListLoader::FinishFontsListOnUIThread() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (observer_) - observer_->FontsListHasLoaded(); -} - diff --git a/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.h b/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.h deleted file mode 100644 index e103b50..0000000 --- a/chrome/browser/ui/webui/options/font_settings_fonts_list_loader.h +++ /dev/null @@ -1,60 +0,0 @@ -// 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 CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_ -#define CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_ -#pragma once - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -// This class allows asynchronous retrieval of the system fonts list. The -// loading of the fonts is handled by a platform specific implementation, but -// the retrieval is done on the File thread so that UI does not block for what -// could be a long operation (if the user has a large number of fonts.) -class FontSettingsFontsListLoader - : public base::RefCountedThreadSafe<FontSettingsFontsListLoader> { - public: - // Any clients of this class must implement this observer interface in - // order to be called back when the fonts list has been loaded. - class Observer { - public: - virtual void FontsListHasLoaded() = 0; - - protected: - virtual ~Observer() {} - }; - - // Pass in an observer, often 'this'. - explicit FontSettingsFontsListLoader(Observer* observer); - - // Get the font list. This must only be called after receiveing the - // FontsListHasLoaded() notification. - ListValue* GetFontsList(); - - // Start loading of the fonts list. The observer will be notified when this - // operation has completed. - void StartLoadFontsList(); - - // Set the observer. This class does not take ownership of the observer. - // The observer can be NULL. - void SetObserver(Observer* observer); - - private: - friend class base::RefCountedThreadSafe<FontSettingsFontsListLoader>; - - ~FontSettingsFontsListLoader(); - - void GetFontsListOnFileThread(); - void FinishFontsListOnUIThread(); - - scoped_ptr<ListValue> fonts_list_; - Observer* observer_; // weak - - DISALLOW_COPY_AND_ASSIGN(FontSettingsFontsListLoader); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_ - diff --git a/chrome/browser/ui/webui/options/font_settings_handler.cc b/chrome/browser/ui/webui/options/font_settings_handler.cc index 8fab693..7e416ba 100644 --- a/chrome/browser/ui/webui/options/font_settings_handler.cc +++ b/chrome/browser/ui/webui/options/font_settings_handler.cc @@ -7,6 +7,7 @@ #include <string> #include "base/basictypes.h" +#include "base/bind.h" #include "base/i18n/rtl.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -24,12 +25,9 @@ #include "ui/base/l10n/l10n_util.h" FontSettingsHandler::FontSettingsHandler() { - fonts_list_loader_ = new FontSettingsFontsListLoader(this); } FontSettingsHandler::~FontSettingsHandler() { - if (fonts_list_loader_) - fonts_list_loader_->SetObserver(NULL); } void FontSettingsHandler::GetLocalizedValues( @@ -104,12 +102,12 @@ void FontSettingsHandler::RegisterMessages() { } void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { - fonts_list_loader_->StartLoadFontsList(); + content::GetFontListAsync( + base::Bind(&FontSettingsHandler::FontsListHasLoaded, AsWeakPtr())); } -void FontSettingsHandler::FontsListHasLoaded() { - ListValue* fonts_list = fonts_list_loader_->GetFontsList(); - +void FontSettingsHandler::FontsListHasLoaded( + scoped_refptr<content::FontListResult> list) { ListValue encoding_list; const std::vector<CharacterEncoding::EncodingInfo>* encodings; PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); @@ -147,7 +145,8 @@ void FontSettingsHandler::FontsListHasLoaded() { selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); web_ui_->CallJavascriptFunction("FontSettings.setFontsData", - *fonts_list, encoding_list, selected_values); + *list->list.get(), encoding_list, + selected_values); } void FontSettingsHandler::Observe(NotificationType type, diff --git a/chrome/browser/ui/webui/options/font_settings_handler.h b/chrome/browser/ui/webui/options/font_settings_handler.h index 7fb77ee..1bfee9b 100644 --- a/chrome/browser/ui/webui/options/font_settings_handler.h +++ b/chrome/browser/ui/webui/options/font_settings_handler.h @@ -6,13 +6,14 @@ #define CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_HANDLER_H_ #pragma once +#include "base/memory/weak_ptr.h" #include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/webui/options/font_settings_fonts_list_loader.h" #include "chrome/browser/ui/webui/options/options_ui.h" +#include "content/browser/font_list_async.h" // Font settings overlay page UI handler. -class FontSettingsHandler : public OptionsPageUIHandler, - public FontSettingsFontsListLoader::Observer { +class FontSettingsHandler : public base::SupportsWeakPtr<FontSettingsHandler>, + public OptionsPageUIHandler { public: FontSettingsHandler(); virtual ~FontSettingsHandler(); @@ -30,12 +31,11 @@ class FontSettingsHandler : public OptionsPageUIHandler, const NotificationSource& source, const NotificationDetails& details); - // FontSettingsFontsListLoader::Observer implementation. - virtual void FontsListHasLoaded(); - private: void HandleFetchFontsData(const ListValue* args); + void FontsListHasLoaded(scoped_refptr<content::FontListResult> list); + void SetUpStandardFontSample(); void SetUpSerifFontSample(); void SetUpSansSerifFontSample(); @@ -51,8 +51,6 @@ class FontSettingsHandler : public OptionsPageUIHandler, IntegerPrefMember default_fixed_font_size_; IntegerPrefMember minimum_font_size_; - scoped_refptr<FontSettingsFontsListLoader> fonts_list_loader_; - DISALLOW_COPY_AND_ASSIGN(FontSettingsHandler); }; diff --git a/chrome/browser/ui/webui/options/font_settings_utils.h b/chrome/browser/ui/webui/options/font_settings_utils.h index 6a1954e..2a36bad 100644 --- a/chrome/browser/ui/webui/options/font_settings_utils.h +++ b/chrome/browser/ui/webui/options/font_settings_utils.h @@ -14,8 +14,6 @@ class PrefService; // Chrome advanced options utility methods. class FontSettingsUtilities { public: - static ListValue* GetFontsList(); - static void ValidateSavedFonts(PrefService* prefs); private: diff --git a/chrome/browser/ui/webui/options/font_settings_utils_gtk.cc b/chrome/browser/ui/webui/options/font_settings_utils_gtk.cc index b44f26c..022fc88 100644 --- a/chrome/browser/ui/webui/options/font_settings_utils_gtk.cc +++ b/chrome/browser/ui/webui/options/font_settings_utils_gtk.cc @@ -4,40 +4,7 @@ #include "chrome/browser/ui/webui/options/font_settings_utils.h" -#include <set> -#include <string> - -#include <pango/pango.h> -#include <pango/pangocairo.h> - -#include "base/values.h" - -ListValue* FontSettingsUtilities::GetFontsList() { - 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; -} - +// static void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { - // nothing to do for GTK. + // Nothing to do for GTK. } diff --git a/chrome/browser/ui/webui/options/font_settings_utils_mac.mm b/chrome/browser/ui/webui/options/font_settings_utils_mac.mm index 71cf22e..a7079bb 100644 --- a/chrome/browser/ui/webui/options/font_settings_utils_mac.mm +++ b/chrome/browser/ui/webui/options/font_settings_utils_mac.mm @@ -30,24 +30,7 @@ static void ValidateFontFamily(PrefService* prefs, } } -ListValue* FontSettingsUtilities::GetFontsList() { - 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; -} - +// static void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { ValidateFontFamily(prefs, prefs::kWebKitSerifFontFamily); ValidateFontFamily(prefs, prefs::kWebKitSansSerifFontFamily); diff --git a/chrome/browser/ui/webui/options/font_settings_utils_win.cc b/chrome/browser/ui/webui/options/font_settings_utils_win.cc index 694fc5e..3814a27 100644 --- a/chrome/browser/ui/webui/options/font_settings_utils_win.cc +++ b/chrome/browser/ui/webui/options/font_settings_utils_win.cc @@ -4,52 +4,8 @@ #include "chrome/browser/ui/webui/options/font_settings_utils.h" -#include <set> -#include <string> -#include <windows.h> - -#include "base/values.h" - -static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font, - NEWTEXTMETRICEXW *physical_font, - DWORD font_type, - LPARAM lparam) { - std::set<std::wstring>* font_names = - reinterpret_cast<std::set<std::wstring>*>(lparam); - if (font_names) { - const LOGFONTW& lf = logical_font->elfLogFont; - if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { - std::wstring face_name(lf.lfFaceName); - font_names->insert(face_name); - } - } - return 1; -} - -ListValue* FontSettingsUtilities::GetFontsList() { - std::set<std::wstring> 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<std::wstring>::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; -} - +// static void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { - // nothing to do for Windows. + // Nothing to do for Windows. } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index a46f6c9..7967900 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3366,8 +3366,6 @@ 'browser/ui/webui/options/cookies_view_handler.h', 'browser/ui/webui/options/core_options_handler.cc', 'browser/ui/webui/options/core_options_handler.h', - 'browser/ui/webui/options/font_settings_fonts_list_loader.cc', - 'browser/ui/webui/options/font_settings_fonts_list_loader.h', 'browser/ui/webui/options/font_settings_handler.cc', 'browser/ui/webui/options/font_settings_handler.h', 'browser/ui/webui/options/font_settings_utils.h', diff --git a/content/browser/browser_thread.cc b/content/browser/browser_thread.cc index 47b7861..3809989 100644 --- a/content/browser/browser_thread.cc +++ b/content/browser/browser_thread.cc @@ -139,6 +139,38 @@ bool BrowserThread::IsMessageLoopValid(ID identifier) { // static bool BrowserThread::PostTask(ID identifier, const tracked_objects::Location& from_here, + const base::Closure& task) { + return PostTaskHelper(identifier, from_here, task, 0, true); +} + +// static +bool BrowserThread::PostDelayedTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) { + return PostTaskHelper(identifier, from_here, task, delay_ms, true); +} + +// static +bool BrowserThread::PostNonNestableTask( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task) { + return PostTaskHelper(identifier, from_here, task, 0, false); +} + +// static +bool BrowserThread::PostNonNestableDelayedTask( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) { + return PostTaskHelper(identifier, from_here, task, delay_ms, false); +} + +// static +bool BrowserThread::PostTask(ID identifier, + const tracked_objects::Location& from_here, Task* task) { return PostTaskHelper(identifier, from_here, task, 0, true); } @@ -236,3 +268,41 @@ bool BrowserThread::PostTaskHelper( return !!message_loop; } + +// static +bool BrowserThread::PostTaskHelper( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms, + bool nestable) { + DCHECK(identifier >= 0 && identifier < ID_COUNT); + // Optimization: to avoid unnecessary locks, we listed the ID enumeration in + // order of lifetime. So no need to lock if we know that the other thread + // outlives this one. + // Note: since the array is so small, ok to loop instead of creating a map, + // which would require a lock because std::map isn't thread safe, defeating + // the whole purpose of this optimization. + ID current_thread; + bool guaranteed_to_outlive_target_thread = + GetCurrentThreadIdentifier(¤t_thread) && + current_thread >= identifier; + + if (!guaranteed_to_outlive_target_thread) + lock_.Acquire(); + + MessageLoop* message_loop = browser_threads_[identifier] ? + browser_threads_[identifier]->message_loop() : NULL; + if (message_loop) { + if (nestable) { + message_loop->PostDelayedTask(from_here, task, delay_ms); + } else { + message_loop->PostNonNestableDelayedTask(from_here, task, delay_ms); + } + } + + if (!guaranteed_to_outlive_target_thread) + lock_.Release(); + + return !!message_loop; +} diff --git a/content/browser/browser_thread.h b/content/browser/browser_thread.h index 680c25a..c226551 100644 --- a/content/browser/browser_thread.h +++ b/content/browser/browser_thread.h @@ -6,13 +6,15 @@ #define CONTENT_BROWSER_BROWSER_THREAD_H_ #pragma once -#if defined(UNIT_TEST) -#include "base/logging.h" -#endif // UNIT_TEST +#include "base/callback.h" #include "base/synchronization/lock.h" #include "base/task.h" #include "base/threading/thread.h" +#if defined(UNIT_TEST) +#include "base/logging.h" +#endif // UNIT_TEST + namespace base { class MessageLoopProxy; } @@ -105,6 +107,23 @@ class BrowserThread : public base::Thread { // the target thread may already have a Quit message in its queue. static bool PostTask(ID identifier, const tracked_objects::Location& from_here, + const base::Closure& task); + static bool PostDelayedTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms); + static bool PostNonNestableTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task); + static bool PostNonNestableDelayedTask( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms); + + // TODO(brettw) remove these when Task->Closure conversion is done. + static bool PostTask(ID identifier, + const tracked_objects::Location& from_here, Task* task); static bool PostDelayedTask(ID identifier, const tracked_objects::Location& from_here, @@ -203,12 +222,19 @@ class BrowserThread : public base::Thread { // Common initialization code for the constructors. void Initialize(); + // TODO(brettw) remove this variant when Task->Closure migration is complete. static bool PostTaskHelper( ID identifier, const tracked_objects::Location& from_here, Task* task, int64 delay_ms, bool nestable); + static bool PostTaskHelper( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms, + bool nestable); // The identifier of this thread. Only one thread can exist with a given // identifier at a given time. diff --git a/content/browser/font_list_async.cc b/content/browser/font_list_async.cc new file mode 100644 index 0000000..f24001f --- /dev/null +++ b/content/browser/font_list_async.cc @@ -0,0 +1,51 @@ +// 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/browser/font_list_async.h" + +#include "base/bind.h" +#include "base/values.h" +#include "content/browser/browser_thread.h" +#include "content/common/font_list.h" + +namespace content { + +namespace { + +// Just executes the given callback with the parameter. +void ReturnFontListToOriginalThread( + const base::Callback<void(scoped_refptr<FontListResult>)>& callback, + scoped_refptr<FontListResult> result) { + callback.Run(result); +} + +void GetFontListOnFileThread( + BrowserThread::ID calling_thread_id, + const base::Callback<void(scoped_refptr<FontListResult>)>& callback) { + scoped_refptr<FontListResult> result(new FontListResult); + result->list.reset(GetFontList_SlowBlocking()); + BrowserThread::PostTask(calling_thread_id, FROM_HERE, + base::Bind(&ReturnFontListToOriginalThread, callback, result)); +} + +} // namespace + +FontListResult::FontListResult() { +} + +FontListResult::~FontListResult() { +} + +void GetFontListAsync( + const base::Callback<void(scoped_refptr<FontListResult>)>& callback) { + BrowserThread::ID id; + bool well_known_thread = BrowserThread::GetCurrentThreadIdentifier(&id); + DCHECK(well_known_thread) + << "Can only call GetFontList from a well-known thread."; + + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + base::Bind(&GetFontListOnFileThread, id, callback)); +} + +} // namespace content diff --git a/content/browser/font_list_async.h b/content/browser/font_list_async.h new file mode 100644 index 0000000..0c3e786 --- /dev/null +++ b/content/browser/font_list_async.h @@ -0,0 +1,42 @@ +// 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_BROWSER_FONT_LIST_ASYNC_H_ +#define CONTENT_BROWSER_FONT_LIST_ASYNC_H_ + +#include "base/callback.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" + +class ListValue; + +namespace content { + +// Wraps ownership of a ListValue so we can send it across threads without +// having ownership problems (for example if the calling thread goes away +// before the callback is executed, we want the ListValue to be destroyed. +struct FontListResult : public base::RefCountedThreadSafe<FontListResult> { + FontListResult(); + ~FontListResult(); + + scoped_ptr<ListValue> list; +}; + +// Retrieves the list of fonts on the system as a list of strings. It provides +// a non-blocking interface to GetFontList_SlowBlocking in common/. +// +// This function will run asynchronously on a background thread since getting +// the font list from the system can be slow. This function may be called from +// any thread that has a BrowserThread::ID. The callback will be executed on +// the calling thread. +// +// If the caller wants to take ownership of the ListValue, it can just do +// FontListResult.list.release() or use scoped_ptr.swap() because this value +// isn't used for anything else. +void GetFontListAsync( + const base::Callback<void(scoped_refptr<FontListResult>)>& callback); + +} // namespace content + +#endif // CONTENT_BROWSER_FONT_LIST_ASYNC_H_ diff --git a/content/browser/plugin_service.cc b/content/browser/plugin_service.cc index 6d69f19..f4c293f 100644 --- a/content/browser/plugin_service.cc +++ b/content/browser/plugin_service.cc @@ -21,6 +21,7 @@ #include "content/browser/ppapi_plugin_process_host.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/resource_context.h" #include "content/common/notification_service.h" #include "content/common/notification_type.h" #include "content/common/pepper_plugin_registry.h" @@ -239,7 +240,8 @@ PluginProcessHost* PluginService::FindOrStartNpapiPluginProcess( } PpapiPluginProcessHost* PluginService::FindOrStartPpapiPluginProcess( - const FilePath& plugin_path) { + const FilePath& plugin_path, + PpapiPluginProcessHost::Client* client) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path); @@ -252,7 +254,8 @@ PpapiPluginProcessHost* PluginService::FindOrStartPpapiPluginProcess( return NULL; // This plugin isn't loaded by any plugin process, so create a new process. - scoped_ptr<PpapiPluginProcessHost> new_host(new PpapiPluginProcessHost); + scoped_ptr<PpapiPluginProcessHost> new_host(new PpapiPluginProcessHost( + client->GetResourceContext()->host_resolver())); if (!new_host->Init(*info)) { NOTREACHED(); // Init is not expected to fail. return NULL; @@ -304,7 +307,8 @@ void PluginService::OpenChannelToNpapiPlugin( void PluginService::OpenChannelToPpapiPlugin( const FilePath& path, PpapiPluginProcessHost::Client* client) { - PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(path); + PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( + path, client); if (plugin_host) plugin_host->OpenChannelToPlugin(client); else // Send error. diff --git a/content/browser/plugin_service.h b/content/browser/plugin_service.h index 1d8806b..2c8d115 100644 --- a/content/browser/plugin_service.h +++ b/content/browser/plugin_service.h @@ -73,7 +73,8 @@ class PluginService PluginProcessHost* FindOrStartNpapiPluginProcess( const FilePath& plugin_path); PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( - const FilePath& plugin_path); + const FilePath& plugin_path, + PpapiPluginProcessHost::Client* client); PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( const FilePath& plugin_path); diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc index 73ab851..f5a8885 100644 --- a/content/browser/ppapi_plugin_process_host.cc +++ b/content/browser/ppapi_plugin_process_host.cc @@ -16,8 +16,10 @@ #include "ipc/ipc_switches.h" #include "ppapi/proxy/ppapi_messages.h" -PpapiPluginProcessHost::PpapiPluginProcessHost() - : BrowserChildProcessHost(ChildProcessInfo::PPAPI_PLUGIN_PROCESS) { +PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) + : BrowserChildProcessHost(ChildProcessInfo::PPAPI_PLUGIN_PROCESS), + filter_(new PepperMessageFilter(host_resolver)) { + AddFilter(filter_.get()); } PpapiPluginProcessHost::~PpapiPluginProcessHost() { diff --git a/content/browser/ppapi_plugin_process_host.h b/content/browser/ppapi_plugin_process_host.h index 0412c25..15667d4 100644 --- a/content/browser/ppapi_plugin_process_host.h +++ b/content/browser/ppapi_plugin_process_host.h @@ -10,10 +10,20 @@ #include "base/basictypes.h" #include "base/file_path.h" +#include "base/memory/ref_counted.h" #include "content/browser/browser_child_process_host.h" +#include "content/browser/renderer_host/pepper_message_filter.h" struct PepperPluginInfo; +namespace content { +class ResourceContext; +} + +namespace net { +class HostResolver; +} + class PpapiPluginProcessHost : public BrowserChildProcessHost { public: class Client { @@ -28,10 +38,13 @@ class PpapiPluginProcessHost : public BrowserChildProcessHost { // IPC::ChannelHandle() virtual void OnChannelOpened(base::ProcessHandle plugin_process_handle, const IPC::ChannelHandle& channel_handle) = 0; + + // Returns the resource context for the renderer requesting the channel. + virtual const content::ResourceContext* GetResourceContext() = 0; }; // You must call Init before doing anything else. - PpapiPluginProcessHost(); + PpapiPluginProcessHost(net::HostResolver* host_resolver); virtual ~PpapiPluginProcessHost(); // Actually launches the process with the given plugin info. Returns true @@ -47,7 +60,6 @@ class PpapiPluginProcessHost : public BrowserChildProcessHost { // The client pointer must remain valid until its callback is issued. private: - void RequestPluginChannel(Client* client); virtual bool CanShutdown(); @@ -62,6 +74,9 @@ class PpapiPluginProcessHost : public BrowserChildProcessHost { // IPC message handlers. void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); + // Handles most requests from the plugin. + scoped_refptr<PepperMessageFilter> filter_; + // Channel requests that we are waiting to send to the plugin process once // the channel is opened. std::vector<Client*> pending_requests_; diff --git a/content/browser/renderer_host/pepper_message_filter.cc b/content/browser/renderer_host/pepper_message_filter.cc index 19208ae..9381ed6 100644 --- a/content/browser/renderer_host/pepper_message_filter.cc +++ b/content/browser/renderer_host/pepper_message_filter.cc @@ -5,9 +5,12 @@ #include "content/browser/renderer_host/pepper_message_filter.h" #include "base/basictypes.h" +#include "base/bind.h" #include "base/process_util.h" #include "base/threading/worker_pool.h" +#include "base/values.h" #include "content/browser/browser_thread.h" +#include "content/browser/font_list_async.h" #include "content/browser/renderer_host/browser_render_process_host.h" #include "content/browser/resource_context.h" #include "content/common/pepper_messages.h" @@ -17,6 +20,7 @@ #include "net/base/host_resolver.h" #include "net/url_request/url_request_context.h" #include "ppapi/c/private/ppb_flash_net_connector.h" +#include "ppapi/proxy/ppapi_messages.h" #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" #if defined(ENABLE_FLAPPER_HACKS) @@ -36,10 +40,17 @@ const PP_Flash_NetAddress kInvalidNetAddress = { 0 }; PepperMessageFilter::PepperMessageFilter( const content::ResourceContext* resource_context) - : resource_context_(resource_context) { + : resource_context_(resource_context), + host_resolver_(NULL) { DCHECK(resource_context_); } +PepperMessageFilter::PepperMessageFilter(net::HostResolver* host_resolver) + : resource_context_(NULL), + host_resolver_(host_resolver) { + DCHECK(host_resolver); +} + PepperMessageFilter::~PepperMessageFilter() {} bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, @@ -52,6 +63,8 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, #endif // ENABLE_FLAPPER_HACKS IPC_MESSAGE_HANDLER(PepperMsg_GetLocalTimeZoneOffset, OnGetLocalTimeZoneOffset) + IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_PPBFont_GetFontFamilies, + OnGetFontFamilies) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -178,7 +191,7 @@ void PepperMessageFilter::OnConnectTcp(int routing_id, // The lookup request will delete itself on completion. LookupRequest* lookup_request = - new LookupRequest(this, resource_context_->host_resolver(), + new LookupRequest(this, GetHostResolver(), routing_id, request_id, request_info); lookup_request->Start(); } @@ -295,3 +308,43 @@ void PepperMessageFilter::OnGetLocalTimeZoneOffset(base::Time t, base::Time cur = base::Time::FromUTCExploded(exploded); *result = (adj_time - cur).InSecondsF(); } + +void PepperMessageFilter::OnGetFontFamilies(IPC::Message* reply_msg) { + content::GetFontListAsync( + base::Bind(&PepperMessageFilter::GetFontFamiliesComplete, + this, reply_msg)); +} + +void PepperMessageFilter::GetFontFamiliesComplete( + IPC::Message* reply_msg, + scoped_refptr<content::FontListResult> result) { + ListValue* input = result->list.get(); + + std::string output; + for (size_t i = 0; i < input->GetSize(); i++) { + ListValue* cur_font; + if (!input->GetList(i, &cur_font)) + continue; + + // Each entry in the list is actually a list of (font name, localized name). + // We only care about the regular name. + std::string font_name; + if (!cur_font->GetString(0, &font_name)) + continue; + + // Font names are separated with nulls. We also want an explicit null at + // the end of the string (Pepper strings aren't null terminated so since + // we specify there will be a null, it should actually be in the string). + output.append(font_name); + output.push_back(0); + } + + PpapiHostMsg_PPBFont_GetFontFamilies::WriteReplyParams(reply_msg, output); + Send(reply_msg); +} + +net::HostResolver* PepperMessageFilter::GetHostResolver() { + if (resource_context_) + return resource_context_->host_resolver(); + return host_resolver_; +} diff --git a/content/browser/renderer_host/pepper_message_filter.h b/content/browser/renderer_host/pepper_message_filter.h index dbd2f77..f047ec9 100644 --- a/content/browser/renderer_host/pepper_message_filter.h +++ b/content/browser/renderer_host/pepper_message_filter.h @@ -12,6 +12,7 @@ #include "base/process.h" #include "base/time.h" #include "content/browser/browser_message_filter.h" +#include "content/browser/font_list_async.h" #include "ppapi/c/private/ppb_flash_net_connector.h" namespace content { @@ -20,19 +21,26 @@ class ResourceContext; namespace net { class AddressList; +class HostResolver; } +// This class is used in two contexts, both supporting PPAPI plugins. The first +// is on the renderer->browser channel, to handle requests from in-process +// PPAPI plugins and any requests that the PPAPI implementation code in the +// renderer needs to make. The second is on the plugin->browser channel to +// handle requests that out-of-process plugins send directly to the browser. class PepperMessageFilter : public BrowserMessageFilter { public: explicit PepperMessageFilter( - const content::ResourceContext* resource_context); + const content::ResourceContext* resource_context); + explicit PepperMessageFilter(net::HostResolver* host_resolver); virtual ~PepperMessageFilter(); - private: // BrowserMessageFilter methods. virtual bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); + private: #if defined(ENABLE_FLAPPER_HACKS) // Message handlers. void OnConnectTcp(int routing_id, @@ -66,8 +74,24 @@ class PepperMessageFilter : public BrowserMessageFilter { #endif // ENABLE_FLAPPER_HACKS void OnGetLocalTimeZoneOffset(base::Time t, double* result); + void OnGetFontFamilies(IPC::Message* reply); + + // Callback when the font list has been retrieved on a background thread. + void GetFontFamiliesComplete(IPC::Message* reply_msg, + scoped_refptr<content::FontListResult> result); + // Returns the host resolver (it may come from the resource context or the + // host_resolver_ member). + net::HostResolver* GetHostResolver(); + + // When non-NULL, this should be used instead of the host_resolver_. const content::ResourceContext* const resource_context_; + + // When non-NULL, this should be used instead of the resource_context_. Use + // GetHostResolver instead of accessing directly. + net::HostResolver* host_resolver_; + + DISALLOW_COPY_AND_ASSIGN(PepperMessageFilter); }; #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index cdcaf06..361d0e9 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -166,8 +166,10 @@ class OpenChannelToPpapiPluginCallback : public RenderMessageCompletionCallback, public PpapiPluginProcessHost::Client { public: OpenChannelToPpapiPluginCallback(RenderMessageFilter* filter, + const content::ResourceContext* context, IPC::Message* reply_msg) - : RenderMessageCompletionCallback(filter, reply_msg) { + : RenderMessageCompletionCallback(filter, reply_msg), + context_(context) { } virtual void GetChannelInfo(base::ProcessHandle* renderer_handle, @@ -182,6 +184,13 @@ class OpenChannelToPpapiPluginCallback : public RenderMessageCompletionCallback, reply_msg(), plugin_process_handle, channel_handle); SendReplyAndDeleteThis(); } + + virtual const content::ResourceContext* GetResourceContext() { + return context_; + } + + private: + const content::ResourceContext* context_; }; class OpenChannelToPpapiBrokerCallback : public PpapiBrokerProcessHost::Client { @@ -606,7 +615,9 @@ void RenderMessageFilter::OnOpenChannelToPepperPlugin( const FilePath& path, IPC::Message* reply_msg) { plugin_service_->OpenChannelToPpapiPlugin( - path, new OpenChannelToPpapiPluginCallback(this, reply_msg)); + path, + new OpenChannelToPpapiPluginCallback( + this, &resource_context_, reply_msg)); } void RenderMessageFilter::OnOpenChannelToPpapiBroker(int routing_id, 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_; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 0b26790..c14603a 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -72,6 +72,8 @@ 'browser/file_system/browser_file_system_helper.h', 'browser/file_system/file_system_dispatcher_host.cc', 'browser/file_system/file_system_dispatcher_host.h', + 'browser/font_list_async.cc', + 'browser/font_list_asnyc.h', 'browser/geolocation/access_token_store.h', 'browser/geolocation/arbitrator_dependency_factory.cc', 'browser/geolocation/arbitrator_dependency_factory.h', diff --git a/content/content_common.gypi b/content/content_common.gypi index e22ee0c..5e237d4 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -99,6 +99,10 @@ 'common/font_config_ipc_linux.h', 'common/font_descriptor_mac.h', 'common/font_descriptor_mac.mm', + 'common/font_list.h', + 'common/font_list_gtk.cc', + 'common/font_list_mac.mm', + 'common/font_list_win.cc', 'common/font_loader_mac.h', 'common/font_loader_mac.mm', 'common/geolocation_messages.h', diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index eb698da..4ad7cd2 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -96,6 +96,10 @@ void PpapiThread::PostToWebKitThread(const tracked_objects::Location& from_here, webkit_thread_->PostTask(from_here, task); } +bool PpapiThread::SendToBrowser(IPC::Message* msg) { + return Send(msg); +} + void PpapiThread::OnMsgLoadPlugin(const FilePath& path) { base::ScopedNativeLibrary library(base::LoadNativeLibrary(path, NULL)); @@ -187,11 +191,12 @@ bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, bool init_result = false; if (is_broker_) { BrokerProcessDispatcher* broker_dispatcher = - new BrokerProcessDispatcher(host_process_handle, connect_instance_func_); - init_result = broker_dispatcher->InitBrokerWithChannel(this, - plugin_handle, - false); - dispatcher = broker_dispatcher; + new BrokerProcessDispatcher(host_process_handle, + connect_instance_func_); + init_result = broker_dispatcher->InitBrokerWithChannel(this, + plugin_handle, + false); + dispatcher = broker_dispatcher; } else { PluginProcessDispatcher* plugin_dispatcher = new PluginProcessDispatcher(host_process_handle, get_plugin_interface_); diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h index d230be781..9dc2d72 100644 --- a/content/ppapi_plugin/ppapi_thread.h +++ b/content/ppapi_plugin/ppapi_thread.h @@ -13,7 +13,7 @@ #include "build/build_config.h" #include "content/common/child_thread.h" #include "ppapi/c/pp_module.h" -#include "ppapi/proxy/dispatcher.h" +#include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/c/trusted/ppp_broker.h" class FilePath; @@ -24,7 +24,7 @@ struct ChannelHandle; } class PpapiThread : public ChildThread, - public pp::proxy::Dispatcher::Delegate { + public pp::proxy::PluginDispatcher::PluginDelegate { public: explicit PpapiThread(bool is_broker); ~PpapiThread(); @@ -40,6 +40,7 @@ class PpapiThread : public ChildThread, virtual ppapi::WebKitForwarding* GetWebKitForwarding(); virtual void PostToWebKitThread(const tracked_objects::Location& from_here, const base::Closure& task); + virtual bool SendToBrowser(IPC::Message* msg); // Message handlers. void OnMsgLoadPlugin(const FilePath& path); diff --git a/ppapi/c/dev/ppb_font_dev.h b/ppapi/c/dev/ppb_font_dev.h index 8e45bb9..48b990c 100644 --- a/ppapi/c/dev/ppb_font_dev.h +++ b/ppapi/c/dev/ppb_font_dev.h @@ -12,25 +12,32 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_var.h" -#define PPB_FONT_DEV_INTERFACE_0_5 "PPB_Font(Dev);0.5" -#define PPB_FONT_DEV_INTERFACE PPB_FONT_DEV_INTERFACE_0_5 +#define PPB_FONT_DEV_INTERFACE_0_6 "PPB_Font(Dev);0.6" +#define PPB_FONT_DEV_INTERFACE PPB_FONT_DEV_INTERFACE_0_6 struct PP_Point; struct PP_Rect; typedef enum { - // Uses the user's default web page font (normally either the default serif - // or sans serif font). + /** + * Uses the user's default web page font (normally either the default serif + * or sans serif font). + */ PP_FONTFAMILY_DEFAULT = 0, - // These families will use the default web page font corresponding to the - // given family. + /** + * These families will use the default web page font corresponding to the + * given family. + */ PP_FONTFAMILY_SERIF = 1, PP_FONTFAMILY_SANSSERIF = 2, PP_FONTFAMILY_MONOSPACE = 3 } PP_FontFamily_Dev; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FontFamily_Dev, 4); +/** + * Specifies the font weight. Normally users will only use NORMAL or BOLD. + */ typedef enum { PP_FONTWEIGHT_100 = 0, PP_FONTWEIGHT_200, @@ -47,33 +54,46 @@ typedef enum { PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FontWeight_Dev, 4); struct PP_FontDescription_Dev { - // Font face name as a string. This can also be a Null var, in which case the - // generic family will be obeyed. + /** + * Font face name as a string. This can also be an undefined var, in which + * case the generic family will be obeyed. + */ struct PP_Var face; - // When face is a Null string, this specifies the generic font family type - // to use. If the face is specified, this will be ignored. + /** + * When face is an undefined var, this specifies the generic font family type + * to use. If the face is specified, this will be ignored. + */ PP_FontFamily_Dev family; + /** + * Size in pixels. + */ uint32_t size; - // Normally you will use either PP_FONTWEIGHT_NORMAL or PP_FONTWEIGHT_BOLD. + /** + * Normally you will use either PP_FONTWEIGHT_NORMAL or PP_FONTWEIGHT_BOLD. + */ PP_FontWeight_Dev weight; PP_Bool italic; PP_Bool small_caps; - // Adjustment to apply to letter and word spacing, respectively. Initialize - // to 0 to get normal spacing. Negative values bring letters/words closer - // together, positive values separate them. + /** + * Adjustment to apply to letter and word spacing, respectively. Initialize + * to 0 to get normal spacing. Negative values bring letters/words closer + * together, positive values separate them. + */ int32_t letter_spacing; int32_t word_spacing; - // Ensure that this struct is 48-bytes wide by padding the end. In some - // compilers, PP_Var is 8-byte aligned, so those compilers align this struct - // on 8-byte boundaries as well and pad it to 16 bytes even without this - // padding attribute. This padding makes its size consistent across - // compilers. + /** + * Ensure that this struct is 48-bytes wide by padding the end. In some + * compilers, PP_Var is 8-byte aligned, so those compilers align this struct + * on 8-byte boundaries as well and pad it to 16 bytes even without this + * padding attribute. This padding makes its size consistent across + * compilers. + */ int32_t padding; }; PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FontDescription_Dev, 48); @@ -88,60 +108,86 @@ struct PP_FontMetrics_Dev { PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FontMetrics_Dev, 20); struct PP_TextRun_Dev { - // This var must either be a string or a null var (which will be treated as - // a 0-length string). + /** + * This var must either be a string or a null/undefined var (which will be + * treated as a 0-length string). + */ struct PP_Var text; - // Set to PP_TRUE if the text is right-to-left. + /** + * Set to PP_TRUE if the text is right-to-left. + */ PP_Bool rtl; - // Set to PP_TRUE to force the directionality of the text regardless of - // content + /** + * Set to PP_TRUE to force the directionality of the text regardless of + * content + */ PP_Bool override_direction; }; PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_TextRun_Dev, 24); struct PPB_Font_Dev { - // Returns a font which best matches the given description. The return value - // will have a non-zero ID on success, or zero on failure. + /** + * Returns a list of all available font families on the system. You can use + * this list to decide whether to Create() a font. + * + * The return value will be a single string with null characters delimiting + * the end of each font name. For example: "Arial\0Courier\0Times\0". + * + * Returns an undefined var on failure (this typically means you passed an + * invalid instance). + */ + struct PP_Var (*GetFontFamilies)(PP_Instance instance); + + /** + * Returns a font which best matches the given description. The return value + * will have a non-zero ID on success, or zero on failure. + */ PP_Resource (*Create)(PP_Instance instance, const struct PP_FontDescription_Dev* description); - // Returns PP_TRUE if the given resource is a Font. Returns PP_FALSE if the - // resource is invalid or some type other than a Font. + /** + * Returns PP_TRUE if the given resource is a Font. Returns PP_FALSE if the + * resource is invalid or some type other than a Font. + */ PP_Bool (*IsFont)(PP_Resource resource); - // Loads the description and metrics of the font into the given structures. - // The description will be different than the description the font was - // created with since it will be filled with the real values from the font - // that was actually selected. - // - // The PP_Var in the description should be of type Void on input. On output, - // this will contain the string and will have a reference count of 1. The - // plugin is responsible for calling Release on this var. - // - // Returns PP_TRUE on success, PP_FALSE if the font is invalid or if the Var - // in the description isn't Null (to prevent leaks). + /** + * Loads the description and metrics of the font into the given structures. + * The description will be different than the description the font was + * created with since it will be filled with the real values from the font + * that was actually selected. + * + * The PP_Var in the description should be of type Void on input. On output, + * this will contain the string and will have a reference count of 1. The + * plugin is responsible for calling Release on this var. + * + * Returns PP_TRUE on success, PP_FALSE if the font is invalid or if the Var + * in the description isn't Null (to prevent leaks). + */ PP_Bool (*Describe)(PP_Resource font, struct PP_FontDescription_Dev* description, struct PP_FontMetrics_Dev* metrics); - // Draws the text to the image buffer. - // - // The given point represents the baseline of the left edge of the font, - // regardless of whether it is left-to-right or right-to-left (in the case of - // RTL text, this will actually represent the logical end of the text). - // - // The clip is optional and may be NULL. In this case, the text will be - // clipped to the image. - // - // The image_data_is_opaque flag indicates whether subpixel antialiasing can - // be performend, if it is supported. When the image below the text is - // opaque, subpixel antialiasing is supported and you should set this to - // PP_TRUE to pick up the user's default preferences. If your plugin is - // partially transparent, then subpixel antialiasing is not possible and - // grayscale antialiasing will be used instead (assuming the user has - // antialiasing enabled at all). + /** + * Draws the text to the image buffer. + * + * The given point represents the baseline of the left edge of the font, + * regardless of whether it is left-to-right or right-to-left (in the case of + * RTL text, this will actually represent the logical end of the text). + * + * The clip is optional and may be NULL. In this case, the text will be + * clipped to the image. + * + * The image_data_is_opaque flag indicates whether subpixel antialiasing can + * be performend, if it is supported. When the image below the text is + * opaque, subpixel antialiasing is supported and you should set this to + * PP_TRUE to pick up the user's default preferences. If your plugin is + * partially transparent, then subpixel antialiasing is not possible and + * grayscale antialiasing will be used instead (assuming the user has + * antialiasing enabled at all). + */ PP_Bool (*DrawTextAt)(PP_Resource font, PP_Resource image_data, const struct PP_TextRun_Dev* text, @@ -150,32 +196,40 @@ struct PPB_Font_Dev { const struct PP_Rect* clip, PP_Bool image_data_is_opaque); - // Returns the width of the given string. If the font is invalid or the var - // isn't a valid string, this will return -1. - // - // Note that this function handles complex scripts such as Arabic, combining - // accents, etc. so that adding the width of substrings won't necessarily - // produce the correct width of the entire string. - // - // Returns -1 on failure. + /** + * Returns the width of the given string. If the font is invalid or the var + * isn't a valid string, this will return -1. + * + * Note that this function handles complex scripts such as Arabic, combining + * accents, etc. so that adding the width of substrings won't necessarily + * produce the correct width of the entire string. + * + * Returns -1 on failure. + */ int32_t (*MeasureText)(PP_Resource font, const struct PP_TextRun_Dev* text); - // Returns the character at the given pixel X position from the beginning of - // the string. This handles complex scripts such as Arabic, where characters - // may be combined or replaced depending on the context. Returns (uint32)-1 - // on failure. + /** + * Returns the character at the given pixel X position from the beginning of + * the string. This handles complex scripts such as Arabic, where characters + * may be combined or replaced depending on the context. Returns (uint32)-1 + * on failure. + */ uint32_t (*CharacterOffsetForPixel)(PP_Resource font, const struct PP_TextRun_Dev* text, int32_t pixel_position); - // Returns the horizontal advance to the given character if the string was - // placed at the given position. This handles complex scripts such as Arabic, - // where characters may be combined or replaced depending on context. Returns - // -1 on error. + /** + * Returns the horizontal advance to the given character if the string was + * placed at the given position. This handles complex scripts such as Arabic, + * where characters may be combined or replaced depending on context. Returns + * -1 on error. + */ int32_t (*PixelOffsetForCharacter)(PP_Resource font, const struct PP_TextRun_Dev* text, uint32_t char_offset); + + }; #endif /* PPAPI_C_DEV_PPB_FONT_DEV_H_ */ diff --git a/ppapi/cpp/dev/font_dev.cc b/ppapi/cpp/dev/font_dev.cc index 4ca85b0..8c04de1 100644 --- a/ppapi/cpp/dev/font_dev.cc +++ b/ppapi/cpp/dev/font_dev.cc @@ -118,6 +118,15 @@ Font_Dev& Font_Dev::operator=(const Font_Dev& other) { return *this; } +// static +Var Font_Dev::GetFontFamilies(Instance* instance) { + if (!has_interface<PPB_Font_Dev>()) + return Var(); + return Var(Var::PassRef(), + get_interface<PPB_Font_Dev>()->GetFontFamilies( + instance->pp_instance())); +} + bool Font_Dev::Describe(FontDescription_Dev* description, PP_FontMetrics_Dev* metrics) const { if (!has_interface<PPB_Font_Dev>()) diff --git a/ppapi/cpp/dev/font_dev.h b/ppapi/cpp/dev/font_dev.h index fb31311..e95edbe 100644 --- a/ppapi/cpp/dev/font_dev.h +++ b/ppapi/cpp/dev/font_dev.h @@ -111,6 +111,7 @@ class Font_Dev : public Resource { Font_Dev& operator=(const Font_Dev& other); // PPB_Font methods: + static Var GetFontFamilies(Instance* instance); bool Describe(FontDescription_Dev* description, PP_FontMetrics_Dev* metrics) const; bool DrawTextAt(ImageData* dest, diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index ef14d08..b34ce48 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -181,7 +181,6 @@ InterfaceList* InterfaceList::GetInstance() { Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, GetInterfaceFunc local_get_interface) : ProxyChannel(remote_process_handle), - dispatcher_delegate_(NULL), disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. local_get_interface_(local_get_interface), callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { @@ -242,11 +241,6 @@ const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(InterfaceID id) { return list->id_to_plugin_info_[id]; } -void Dispatcher::SetDelegate(Delegate* delegate) { - DCHECK(!dispatcher_delegate_); - dispatcher_delegate_ = delegate; -} - void Dispatcher::SetSerializationRules( VarSerializationRules* var_serialization_rules) { serialization_rules_.reset(var_serialization_rules); diff --git a/ppapi/proxy/dispatcher.h b/ppapi/proxy/dispatcher.h index 2dc1fe6..39fa1e0 100644 --- a/ppapi/proxy/dispatcher.h +++ b/ppapi/proxy/dispatcher.h @@ -48,27 +48,6 @@ class Dispatcher : public ProxyChannel { typedef const void* (*GetInterfaceFunc)(const char*); typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc); - class Delegate : public ProxyChannel::Delegate { - public: - // Returns the set used for globally uniquifying PP_Instances. This same - // set must be returned for all channels. This is required only for the - // plugin side, for the host side, the return value may be NULL. - // - // DEREFERENCE ONLY ON THE I/O THREAD. - virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; - - // Returns the WebKit forwarding object used to make calls into WebKit. - // Necessary only on the plugin side. The host side can return NULL. - virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; - - // Posts the given task to the WebKit thread associated with this plugin - // process. For host processes, this will not be called and can do - // nothing. The WebKit thread should be lazily created if it does not - // exist yet. - virtual void PostToWebKitThread(const tracked_objects::Location& from_here, - const base::Closure& task) = 0; - }; - virtual ~Dispatcher(); // Returns true if the dispatcher is on the plugin side, or false if it's the @@ -121,8 +100,6 @@ class Dispatcher : public ProxyChannel { Dispatcher(base::ProcessHandle remote_process_handle, GetInterfaceFunc local_get_interface); - void SetDelegate(Delegate* delegate); - // Setter for the derived classes to set the appropriate var serialization. // Takes ownership of the given pointer, which must be on the heap. void SetSerializationRules(VarSerializationRules* var_serialization_rules); @@ -131,8 +108,6 @@ class Dispatcher : public ProxyChannel { return disallow_trusted_interfaces_; } - Delegate* dispatcher_delegate_; - private: bool disallow_trusted_interfaces_; diff --git a/ppapi/proxy/host_dispatcher.cc b/ppapi/proxy/host_dispatcher.cc index 2dce10a..4658fdb 100644 --- a/ppapi/proxy/host_dispatcher.cc +++ b/ppapi/proxy/host_dispatcher.cc @@ -95,7 +95,6 @@ bool HostDispatcher::InitHostWithChannel( bool is_client) { if (!Dispatcher::InitWithChannel(delegate, channel_handle, is_client)) return false; - SetDelegate(delegate); return true; } diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index b8ac146..dee2610 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -17,6 +17,7 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/plugin_var_serialization_rules.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppp_class_proxy.h" #include "ppapi/proxy/resource_creation_proxy.h" #include "ppapi/shared_impl/tracker_base.h" @@ -38,7 +39,8 @@ InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, GetInterfaceFunc get_interface) - : Dispatcher(remote_process_handle, get_interface) { + : Dispatcher(remote_process_handle, get_interface), + plugin_delegate_(NULL) { SetSerializationRules(new PluginVarSerializationRules); // As a plugin, we always support the PPP_Class interface. There's no @@ -74,12 +76,12 @@ const void* PluginDispatcher::GetInterfaceFromDispatcher( } bool PluginDispatcher::InitPluginWithChannel( - PluginDispatcher::Delegate* delegate, + PluginDelegate* delegate, const IPC::ChannelHandle& channel_handle, bool is_client) { if (!Dispatcher::InitWithChannel(delegate, channel_handle, is_client)) return false; - SetDelegate(delegate); + plugin_delegate_ = delegate; // The message filter will intercept and process certain messages directly // on the I/O thread. @@ -205,11 +207,15 @@ InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { void PluginDispatcher::PostToWebKitThread( const tracked_objects::Location& from_here, const base::Closure& task) { - return dispatcher_delegate_->PostToWebKitThread(from_here, task); + return plugin_delegate_->PostToWebKitThread(from_here, task); +} + +bool PluginDispatcher::SendToBrowser(IPC::Message* msg) { + return plugin_delegate_->SendToBrowser(msg); } ppapi::WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { - return dispatcher_delegate_->GetWebKitForwarding(); + return plugin_delegate_->GetWebKitForwarding(); } ::ppapi::FunctionGroupBase* PluginDispatcher::GetFunctionAPI( @@ -219,6 +225,8 @@ ppapi::WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { if (id == INTERFACE_ID_RESOURCE_CREATION) function_proxies_[id].reset(new ResourceCreationProxy(this)); + if (id == INTERFACE_ID_PPB_FONT) + function_proxies_[id].reset(new PPB_Font_Proxy(this, NULL)); return function_proxies_[id].get(); } diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 65c4c82..29460fa 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -34,6 +34,29 @@ struct InstanceData { class PluginDispatcher : public Dispatcher { public: + class PluginDelegate : public ProxyChannel::Delegate { + public: + // Returns the set used for globally uniquifying PP_Instances. This same + // set must be returned for all channels. + // + // DEREFERENCE ONLY ON THE I/O THREAD. + virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; + + // Returns the WebKit forwarding object used to make calls into WebKit. + // Necessary only on the plugin side. + virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; + + // Posts the given task to the WebKit thread associated with this plugin + // process. The WebKit thread should be lazily created if it does not + // exist yet. + virtual void PostToWebKitThread(const tracked_objects::Location& from_here, + const base::Closure& task) = 0; + + // Sends the given message to the browser. Identical semantics to + // IPC::Message::Sender interface. + virtual bool SendToBrowser(IPC::Message* msg) = 0; + }; + // Constructor for the plugin side. The init and shutdown functions will be // will be automatically called when requested by the renderer side. The // module ID will be set upon receipt of the InitializeModule message. @@ -54,9 +77,9 @@ class PluginDispatcher : public Dispatcher { // You must call this function before anything else. Returns true on success. // The delegate pointer must outlive this class, ownership is not // transferred. - virtual bool InitPluginWithChannel(Dispatcher::Delegate* delegate, - const IPC::ChannelHandle& channel_handle, - bool is_client); + bool InitPluginWithChannel(PluginDelegate* delegate, + const IPC::ChannelHandle& channel_handle, + bool is_client); // Dispatcher overrides. virtual bool IsPlugin() const; @@ -79,6 +102,9 @@ class PluginDispatcher : public Dispatcher { void PostToWebKitThread(const tracked_objects::Location& from_here, const base::Closure& task); + // Calls the PluginDelegate.SendToBrowser function. + bool SendToBrowser(IPC::Message* msg); + // Returns the WebKitForwarding object used to forward events to WebKit. ppapi::WebKitForwarding* GetWebKitForwarding(); @@ -99,6 +125,8 @@ class PluginDispatcher : public Dispatcher { // IPC message handlers. void OnMsgSupportsInterface(const std::string& interface_name, bool* result); + PluginDelegate* plugin_delegate_; + // All target proxies currently created. These are ones that receive // messages. scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index d00e6d0..6a313ee 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -518,6 +518,10 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress, pp::proxy::HostResource /* connector */, std::string /* net_address_as_string */) +// PPB_Font. +IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies, + std::string /* result */) + // PPB_Fullscreen. IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFullscreen_SetFullscreen, PP_Instance /* instance */, diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc index ace9f76..53eac45 100644 --- a/ppapi/proxy/ppb_font_proxy.cc +++ b/ppapi/proxy/ppb_font_proxy.cc @@ -9,7 +9,9 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_image_data_proxy.h" +#include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_image_data_api.h" #include "ppapi/thunk/thunk.h" @@ -61,6 +63,28 @@ const InterfaceProxy::Info* PPB_Font_Proxy::GetInfo() { return &info; } +::ppapi::thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsFont_FunctionAPI() { + return this; +} + +PP_Var PPB_Font_Proxy::GetFontFamilies(PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return PP_MakeUndefined(); + + // Assume the font families don't change, so we can cache the result globally. + static std::string families; + if (families.empty()) { + dispatcher->SendToBrowser( + new PpapiHostMsg_PPBFont_GetFontFamilies(&families)); + } + + PP_Var result; + result.type = PP_VARTYPE_STRING; + result.value.as_id = PluginVarTracker::GetInstance()->MakeString(families); + return result; +} + bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) { // There aren't any font messages. NOTREACHED(); diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index 8fec581..1dd9245 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -18,17 +18,25 @@ struct PPB_Font_Dev; namespace pp { namespace proxy { -class SerializedVarReceiveInput; +class SerializedVarReturnValue; -class PPB_Font_Proxy : public InterfaceProxy { +class PPB_Font_Proxy : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_Font_FunctionAPI, + public InterfaceProxy { public: PPB_Font_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Font_Proxy(); static const Info* GetInfo(); + // FunctionGroupBase overrides. + virtual ::ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() OVERRIDE; + + // PPB_Font_FunctionAPI implementation. + virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; + // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index 6b8976e..e6c61ea 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -8,6 +8,7 @@ namespace ppapi { namespace thunk { +class PPB_Font_FunctionAPI; class ResourceCreationAPI; } @@ -15,12 +16,17 @@ class FunctionGroupBase { public: // Dynamic casting for this object. Returns the pointer to the given type if // it's supported. + virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { return NULL; } virtual thunk::ResourceCreationAPI* AsResourceCreation() { return NULL; } template <typename T> T* GetAs() { return NULL; } }; template<> +inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() { + return AsFont_FunctionAPI(); +} +template<> inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { return AsResourceCreation(); } diff --git a/ppapi/thunk/ppb_font_api.h b/ppapi/thunk/ppb_font_api.h index b711545..8b55a33 100644 --- a/ppapi/thunk/ppb_font_api.h +++ b/ppapi/thunk/ppb_font_api.h @@ -6,10 +6,21 @@ #define PPAPI_THUNK_PPB_FONT_API_H_ #include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/proxy/interface_id.h" namespace ppapi { namespace thunk { +// API for static font functions. +class PPB_Font_FunctionAPI { + public: + static const ::pp::proxy::InterfaceID interface_id = + ::pp::proxy::INTERFACE_ID_PPB_FONT; + + virtual PP_Var GetFontFamilies(PP_Instance instance) = 0; +}; + +// API for font resources. class PPB_Font_API { public: virtual PP_Bool Describe(PP_FontDescription_Dev* description, diff --git a/ppapi/thunk/ppb_font_thunk.cc b/ppapi/thunk/ppb_font_thunk.cc index eac573e..ae13e01 100644 --- a/ppapi/thunk/ppb_font_thunk.cc +++ b/ppapi/thunk/ppb_font_thunk.cc @@ -12,6 +12,13 @@ namespace thunk { namespace { +PP_Var GetFontFamilies(PP_Instance instance) { + EnterFunction<PPB_Font_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->GetFontFamilies(instance); +} + PP_Resource Create(PP_Instance instance, const PP_FontDescription_Dev* description) { EnterFunction<ResourceCreationAPI> enter(instance, true); @@ -74,6 +81,7 @@ int32_t PixelOffsetForCharacter(PP_Resource font_id, } const PPB_Font_Dev g_ppb_font_thunk = { + &GetFontFamilies, &Create, &IsFont, &Describe, diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 881fe66..f22b766 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -284,7 +284,7 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_FLASH_MENU_INTERFACE) == 0) return PPB_Flash_Menu_Impl::GetInterface(); if (strcmp(name, PPB_FONT_DEV_INTERFACE) == 0) - return PPB_Font_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_Font_Thunk(); if (strcmp(name, PPB_FULLSCREEN_DEV_INTERFACE) == 0) return PluginInstance::GetFullscreenInterface(); if (strcmp(name, PPB_GRAPHICS_2D_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index a152691..c97fcb3 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -50,11 +50,6 @@ PPB_Font_Impl::PPB_Font_Impl(PluginInstance* instance, PPB_Font_Impl::~PPB_Font_Impl() { } -// static -const PPB_Font_Dev* PPB_Font_Impl::GetInterface() { - return ::ppapi::thunk::GetPPB_Font_Thunk(); -} - ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsFont_API() { return this; } @@ -130,6 +125,21 @@ int32_t PPB_Font_Impl::PixelOffsetForCharacter(const PP_TextRun_Dev* text, return result; } +PPB_Font_FunctionImpl::PPB_Font_FunctionImpl() { +} + +PPB_Font_FunctionImpl::~PPB_Font_FunctionImpl() { +} + +::ppapi::thunk::PPB_Font_FunctionAPI* +PPB_Font_FunctionImpl::AsFont_FunctionAPI() { + return this; +} + +PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { + return PP_MakeUndefined(); +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h index 4122a6b..86a6c8a 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ b/webkit/plugins/ppapi/ppb_font_impl.h @@ -27,10 +27,6 @@ class PPB_Font_Impl : public Resource, PPB_Font_Impl(PluginInstance* instance, const PP_FontDescription_Dev& desc); virtual ~PPB_Font_Impl(); - // Returns a pointer to the interface implementing PPB_Font that is exposed to - // the plugin. - static const PPB_Font_Dev* GetInterface(); - // ResourceObjectBase. virtual ::ppapi::thunk::PPB_Font_API* AsFont_API() OVERRIDE; @@ -58,6 +54,22 @@ class PPB_Font_Impl : public Resource, DISALLOW_COPY_AND_ASSIGN(PPB_Font_Impl); }; +class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_Font_FunctionAPI { + public: + PPB_Font_FunctionImpl(); + ~PPB_Font_FunctionImpl(); + + // FunctionGroupBase overrides. + virtual ::ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI(); + + // PPB_Font_FunctionAPI implementation. + virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(PPB_Font_FunctionImpl); +}; + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index a0c82a7..452b845 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -14,6 +14,7 @@ #include "ppapi/shared_impl/tracker_base.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" #include "webkit/plugins/ppapi/var.h" @@ -254,8 +255,11 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( if (function_proxies_[id].get()) return function_proxies_[id].get(); + // TODO(brettw) we need a better system for doing this. if (id == ::pp::proxy::INTERFACE_ID_RESOURCE_CREATION) function_proxies_[id].reset(new ResourceCreationImpl()); + else if (id == ::pp::proxy::INTERFACE_ID_PPB_FONT) + function_proxies_[id].reset(new PPB_Font_FunctionImpl); return function_proxies_[id].get(); } |