| Index: content/common/font_warmup_win.cc
|
| diff --git a/content/common/font_warmup_win.cc b/content/common/font_warmup_win.cc
|
| index 6a059d03c42bd6b74630921e4b2b817fe7ff0934..c5d17e06cf16ce4653dbacdecc4e02e0160cc87f 100644
|
| --- a/content/common/font_warmup_win.cc
|
| +++ b/content/common/font_warmup_win.cc
|
| @@ -20,7 +20,7 @@
|
| #include "base/trace_event/trace_event.h"
|
| #include "base/win/iat_patch_function.h"
|
| #include "base/win/windows_version.h"
|
| -#include "content/public/common/dwrite_font_platform_win.h"
|
| +#include "ppapi/shared_impl/proxy_lock.h"
|
| #include "skia/ext/fontmgr_default_win.h"
|
| #include "skia/ext/refptr.h"
|
| #include "third_party/WebKit/public/web/win/WebFontRendering.h"
|
| @@ -96,105 +96,6 @@ NTSTATUS WINAPI NtALpcConnectPortPatch(HANDLE* port_handle,
|
| return STATUS_ACCESS_DENIED;
|
| }
|
|
|
| -// Directwrite connects to the font cache service to retrieve information about
|
| -// fonts installed on the system etc. This works well outside the sandbox and
|
| -// within the sandbox as long as the lpc connection maintained by the current
|
| -// process with the font cache service remains valid. It appears that there
|
| -// are cases when this connection is dropped after which directwrite is unable
|
| -// to connect to the font cache service which causes problems with characters
|
| -// disappearing.
|
| -// Directwrite has fallback code to enumerate fonts if it is unable to connect
|
| -// to the font cache service. We need to intercept the following APIs to
|
| -// ensure that it does not connect to the font cache service.
|
| -// NtALpcConnectPort
|
| -// OpenSCManagerW
|
| -// OpenServiceW
|
| -// StartServiceW
|
| -// CloseServiceHandle.
|
| -// These are all IAT patched.
|
| -void PatchServiceManagerCalls() {
|
| - static bool is_patched = false;
|
| - if (is_patched)
|
| - return;
|
| - const char* service_provider_dll =
|
| - (base::win::GetVersion() >= base::win::VERSION_WIN8
|
| - ? "api-ms-win-service-management-l1-1-0.dll"
|
| - : "advapi32.dll");
|
| -
|
| - is_patched = true;
|
| -
|
| - DWORD patched =
|
| - g_iat_patch_open_sc_manager.Patch(L"dwrite.dll", service_provider_dll,
|
| - "OpenSCManagerW", OpenSCManagerWPatch);
|
| - DCHECK(patched == 0);
|
| -
|
| - patched = g_iat_patch_close_service_handle.Patch(
|
| - L"dwrite.dll", service_provider_dll, "CloseServiceHandle",
|
| - CloseServiceHandlePatch);
|
| - DCHECK(patched == 0);
|
| -
|
| - patched = g_iat_patch_open_service.Patch(L"dwrite.dll", service_provider_dll,
|
| - "OpenServiceW", OpenServiceWPatch);
|
| - DCHECK(patched == 0);
|
| -
|
| - patched = g_iat_patch_start_service.Patch(
|
| - L"dwrite.dll", service_provider_dll, "StartServiceW", StartServiceWPatch);
|
| - DCHECK(patched == 0);
|
| -
|
| - patched = g_iat_patch_nt_connect_port.Patch(
|
| - L"dwrite.dll", "ntdll.dll", "NtAlpcConnectPort", NtALpcConnectPortPatch);
|
| - DCHECK(patched == 0);
|
| -}
|
| -
|
| -// Windows-only DirectWrite support. These warm up the DirectWrite paths
|
| -// before sandbox lock down to allow Skia access to the Font Manager service.
|
| -void CreateDirectWriteFactory(IDWriteFactory** factory) {
|
| - typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
|
| - HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
|
| - // TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
|
| - if (!dwrite_dll) {
|
| - DWORD load_library_get_last_error = GetLastError();
|
| - base::debug::Alias(&dwrite_dll);
|
| - base::debug::Alias(&load_library_get_last_error);
|
| - CHECK(false);
|
| - }
|
| -
|
| - PatchServiceManagerCalls();
|
| -
|
| - DWriteCreateFactoryProc dwrite_create_factory_proc =
|
| - reinterpret_cast<DWriteCreateFactoryProc>(
|
| - GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
|
| - // TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
|
| - if (!dwrite_create_factory_proc) {
|
| - DWORD get_proc_address_get_last_error = GetLastError();
|
| - base::debug::Alias(&dwrite_create_factory_proc);
|
| - base::debug::Alias(&get_proc_address_get_last_error);
|
| - CHECK(false);
|
| - }
|
| - CHECK(SUCCEEDED(dwrite_create_factory_proc(
|
| - DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
|
| - reinterpret_cast<IUnknown**>(factory))));
|
| -}
|
| -
|
| -HRESULT STDMETHODCALLTYPE StubFontCollection(IDWriteFactory* factory,
|
| - IDWriteFontCollection** col,
|
| - BOOL checkUpdates) {
|
| - // We always return pre-created font collection from here.
|
| - IDWriteFontCollection* custom_collection = GetCustomFontCollection(factory);
|
| - DCHECK(custom_collection != nullptr);
|
| - *col = custom_collection;
|
| - return S_OK;
|
| -}
|
| -
|
| -void PatchDWriteFactory(IDWriteFactory* factory) {
|
| - const unsigned int kGetSystemFontCollectionVTableIndex = 3;
|
| -
|
| - PROC* vtable = *reinterpret_cast<PROC**>(factory);
|
| - PROC* function_ptr = &vtable[kGetSystemFontCollectionVTableIndex];
|
| - void* stub_function = &StubFontCollection;
|
| - base::win::ModifyCode(function_ptr, &stub_function, sizeof(PROC));
|
| -}
|
| -
|
| // Class to fake out a DC or a Font object. Maintains a reference to a
|
| // SkTypeFace to emulate the simple operation of a DC and Font.
|
| class FakeGdiObject : public base::RefCountedThreadSafe<FakeGdiObject> {
|
| @@ -303,6 +204,7 @@ skia::RefPtr<SkTypeface> GetTypefaceFromLOGFONT(const LOGFONTW* log_font) {
|
| : SkFontStyle::kUpright_Slant);
|
|
|
| std::string family_name = base::WideToUTF8(log_font->lfFaceName);
|
| + ppapi::ProxyAutoLock lock;
|
| return skia::AdoptRef(
|
| g_warmup_fontmgr->matchFamilyStyle(family_name.c_str(), style));
|
| }
|
| @@ -461,30 +363,59 @@ GdiFontPatchDataImpl::GdiFontPatchDataImpl(const base::FilePath& path) {
|
|
|
| } // namespace
|
|
|
| -void DoPreSandboxWarmupForTypeface(SkTypeface* typeface) {
|
| - SkPaint paint_warmup;
|
| - paint_warmup.setTypeface(typeface);
|
| - wchar_t glyph = L'S';
|
| - paint_warmup.measureText(&glyph, 2);
|
| -}
|
| +// Directwrite connects to the font cache service to retrieve information about
|
| +// fonts installed on the system etc. This works well outside the sandbox and
|
| +// within the sandbox as long as the lpc connection maintained by the current
|
| +// process with the font cache service remains valid. It appears that there
|
| +// are cases when this connection is dropped after which directwrite is unable
|
| +// to connect to the font cache service which causes problems with characters
|
| +// disappearing.
|
| +// Directwrite has fallback code to enumerate fonts if it is unable to connect
|
| +// to the font cache service. We need to intercept the following APIs to
|
| +// ensure that it does not connect to the font cache service.
|
| +// NtALpcConnectPort
|
| +// OpenSCManagerW
|
| +// OpenServiceW
|
| +// StartServiceW
|
| +// CloseServiceHandle.
|
| +// These are all IAT patched.
|
| +void PatchServiceManagerCalls() {
|
| + static bool is_patched = false;
|
| + if (is_patched)
|
| + return;
|
| + const char* service_provider_dll =
|
| + (base::win::GetVersion() >= base::win::VERSION_WIN8
|
| + ? "api-ms-win-service-management-l1-1-0.dll"
|
| + : "advapi32.dll");
|
|
|
| -SkFontMgr* GetPreSandboxWarmupFontMgr() {
|
| - if (!g_warmup_fontmgr) {
|
| - IDWriteFactory* factory;
|
| - CreateDirectWriteFactory(&factory);
|
| + is_patched = true;
|
|
|
| - GetCustomFontCollection(factory);
|
| + DWORD patched =
|
| + g_iat_patch_open_sc_manager.Patch(L"dwrite.dll", service_provider_dll,
|
| + "OpenSCManagerW", OpenSCManagerWPatch);
|
| + DCHECK(patched == 0);
|
|
|
| - PatchDWriteFactory(factory);
|
| + patched = g_iat_patch_close_service_handle.Patch(
|
| + L"dwrite.dll", service_provider_dll, "CloseServiceHandle",
|
| + CloseServiceHandlePatch);
|
| + DCHECK(patched == 0);
|
|
|
| - blink::WebFontRendering::setDirectWriteFactory(factory);
|
| - g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory);
|
| - }
|
| - return g_warmup_fontmgr;
|
| + patched = g_iat_patch_open_service.Patch(L"dwrite.dll", service_provider_dll,
|
| + "OpenServiceW", OpenServiceWPatch);
|
| + DCHECK(patched == 0);
|
| +
|
| + patched = g_iat_patch_start_service.Patch(
|
| + L"dwrite.dll", service_provider_dll, "StartServiceW", StartServiceWPatch);
|
| + DCHECK(patched == 0);
|
| +
|
| + patched = g_iat_patch_nt_connect_port.Patch(
|
| + L"dwrite.dll", "ntdll.dll", "NtAlpcConnectPort", NtALpcConnectPortPatch);
|
| + DCHECK(patched == 0);
|
| }
|
|
|
| GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) {
|
| // We assume the fontmgr is already warmed up before calling this.
|
| + g_warmup_fontmgr = SkFontMgr_New_DirectWrite();
|
| DCHECK(g_warmup_fontmgr);
|
| return new GdiFontPatchDataImpl(path);
|
| }
|
| @@ -497,25 +428,4 @@ void ResetEmulatedGdiHandlesForTesting() {
|
| g_fake_gdi_object_factory.Get().ResetObjectHandles();
|
| }
|
|
|
| -void SetPreSandboxWarmupFontMgrForTesting(SkFontMgr* fontmgr) {
|
| - g_warmup_fontmgr = fontmgr;
|
| -}
|
| -
|
| -void WarmupDirectWrite() {
|
| - TRACE_EVENT0("startup", "content::WarmupDirectWrite");
|
| -
|
| - // The objects used here are intentionally not freed as we want the Skia
|
| - // code to use these objects after warmup.
|
| - SetDefaultSkiaFactory(GetPreSandboxWarmupFontMgr());
|
| -
|
| - // We need to warm up *some* font for DirectWrite. We also need to pass one
|
| - // down for the CC HUD code, so use the same one here. Note that we don't use
|
| - // a monospace as would be nice in an attempt to avoid a small startup time
|
| - // regression, see http://crbug.com/463613.
|
| - skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef(
|
| - GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0));
|
| - DoPreSandboxWarmupForTypeface(hud_typeface.get());
|
| - gfx::SetHudTypeface(hud_typeface);
|
| -}
|
| -
|
| } // namespace content
|
|
|