Windows: Add DirectWrite font cache support (issue #1652)

This commit is contained in:
Marshall Greenblatt 2015-06-11 18:08:33 -04:00
parent de05577c86
commit ee90dc0915
11 changed files with 93 additions and 34 deletions

View File

@ -1255,6 +1255,9 @@
'<(DEPTH)/chrome/renderer/pepper/pepper_flash_menu_host.h',
'<(DEPTH)/chrome/renderer/pepper/pepper_flash_renderer_host.cc',
'<(DEPTH)/chrome/renderer/pepper/pepper_flash_renderer_host.h',
# Include sources required by chrome_utility_messages.h.
'<(DEPTH)/chrome/common/safe_browsing/zip_analyzer_results.h',
'<(DEPTH)/chrome/common/safe_browsing/zip_analyzer_results.cc',
],
'conditions': [
['OS=="win"', {
@ -1276,13 +1279,15 @@
'<(DEPTH)/chrome/browser/printing/pdf_to_emf_converter.cc',
'<(DEPTH)/chrome/browser/printing/pdf_to_emf_converter.h',
'<(DEPTH)/chrome/common/chrome_utility_printing_messages.h',
# Include sources for font cache.
'<(DEPTH)/chrome/utility/font_cache_handler_win.cc',
'<(DEPTH)/chrome/utility/font_cache_handler_win.h',
],
}],
[ 'OS=="mac"', {
'sources': [
'<@(includes_mac)',
'libcef/browser/browser_host_impl_mac.mm',
'libcef/browser/browser_main_mac.mm',
'libcef/browser/javascript_dialog_mac.mm',
'libcef/browser/menu_creator_runner_mac.h',
'libcef/browser/menu_creator_runner_mac.mm',
@ -1307,7 +1312,6 @@
'sources': [
'<@(includes_linux)',
'libcef/browser/browser_host_impl_linux.cc',
'libcef/browser/browser_main_linux.cc',
'libcef/browser/javascript_dialog_linux.cc',
'libcef/browser/menu_creator_runner_linux.cc',
'libcef/browser/menu_creator_runner_linux.h',

View File

@ -99,7 +99,10 @@ void CefBrowserMainParts::PostMainMessageLoopStart() {
}
int CefBrowserMainParts::PreCreateThreads() {
#if defined(OS_WIN)
PlatformInitialize();
#endif
net::NetModule::SetResourceProvider(&NetResourceProvider);
// Initialize the GpuDataManager before IO access restrictions are applied and
@ -140,6 +143,10 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
LOG(WARNING) << "Invalid http debugger port number " << port;
}
}
#if defined(OS_WIN)
PlatformPreMainMessageLoopRun();
#endif
}
void CefBrowserMainParts::PostMainMessageLoopRun() {
@ -166,6 +173,4 @@ void CefBrowserMainParts::PostDestroyThreads() {
// No CefURLRequestContext instances should exist at this point.
DCHECK_EQ(0, CefURLRequestContext::DebugObjCt);
#endif
PlatformCleanup();
}

View File

@ -52,8 +52,10 @@ class CefBrowserMainParts : public content::BrowserMainParts {
PrefService* pref_service() const { return pref_service_.get(); }
private:
#if defined(OS_WIN)
void PlatformInitialize();
void PlatformCleanup();
void PlatformPreMainMessageLoopRun();
#endif // defined(OS_WIN)
scoped_refptr<CefBrowserContextImpl> global_browser_context_;
CefDevToolsDelegate* devtools_delegate_; // Deletes itself.

View File

@ -1,11 +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 "libcef/browser/browser_main.h"
void CefBrowserMainParts::PlatformInitialize() {
}
void CefBrowserMainParts::PlatformCleanup() {
}

View File

@ -1,11 +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 "libcef/browser/browser_main.h"
void CefBrowserMainParts::PlatformInitialize() {
}
void CefBrowserMainParts::PlatformCleanup() {
}

View File

@ -9,6 +9,28 @@
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_main.h"
#include "chrome/common/chrome_utility_messages.h"
#include "content/public/browser/utility_process_host.h"
#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/dwrite_font_platform_win.h"
#include "grit/cef_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/win/direct_write.h"
namespace {
void ExecuteFontCacheBuildTask(const base::FilePath& path) {
base::WeakPtr<content::UtilityProcessHost> utility_process_host(
content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
utility_process_host->SetName(l10n_util::GetStringUTF16(
IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME));
utility_process_host->DisableSandbox();
utility_process_host->Send(
new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path));
}
} // namespace
void CefBrowserMainParts::PlatformInitialize() {
HRESULT res;
@ -28,5 +50,38 @@ void CefBrowserMainParts::PlatformInitialize() {
CefBrowserHostImpl::RegisterWindowClass();
}
void CefBrowserMainParts::PlatformCleanup() {
void CefBrowserMainParts::PlatformPreMainMessageLoopRun() {
// From ChromeBrowserMainPartsWin::PostProfileInit().
// DirectWrite support is mainly available on Windows 7 and up.
if (gfx::win::ShouldUseDirectWrite()) {
const base::FilePath& cache_path = global_browser_context_->GetPath();
if (cache_path.empty())
return;
const base::FilePath& font_cache_path =
cache_path.AppendASCII(content::kFontCacheSharedSectionName);
// This function will create a read only section if cache file exists
// otherwise it will spawn utility process to build cache file, which will
// be used during next browser start/postprofileinit.
if (!content::LoadFontCache(font_cache_path)) {
// We delay building of font cache until first startup page loads.
// During first renderer start there are lot of things happening
// simultaneously some of them are:
// - Renderer is going through all font files on the system to create
// a font collection.
// - Renderer loading up startup URL, accessing HTML/JS File cache,
// net activity etc.
// - Extension initialization.
// We delay building of cache mainly to avoid parallel font file
// loading along with Renderer. Some systems have significant number of
// font files which takes long time to process.
// Related information is at http://crbug.com/436195.
const int kBuildFontCacheDelaySec = 30;
content::BrowserThread::PostDelayedTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(ExecuteFontCacheBuildTask, font_cache_path),
base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
}
}
}

View File

@ -8,26 +8,31 @@
// Generate constructors.
#include "ipc/struct_constructor_macros.h"
#include "chrome/common/safe_browsing/ipc_protobuf_message_null_macros.h"
#include "libcef/common/cef_message_generator.h"
// Generate destructors.
#include "ipc/struct_destructor_macros.h"
#include "chrome/common/safe_browsing/ipc_protobuf_message_null_macros.h"
#include "libcef/common/cef_message_generator.h"
// Generate param traits write methods.
#include "ipc/param_traits_write_macros.h"
#include "chrome/common/safe_browsing/protobuf_message_write_macros.h"
namespace IPC {
#include "libcef/common/cef_message_generator.h"
} // namespace IPC
// Generate param traits read methods.
#include "ipc/param_traits_read_macros.h"
#include "chrome/common/safe_browsing/protobuf_message_read_macros.h"
namespace IPC {
#include "libcef/common/cef_message_generator.h"
} // namespace IPC
// Generate param traits log methods.
#include "ipc/param_traits_log_macros.h"
#include "chrome/common/safe_browsing/protobuf_message_log_macros.h"
namespace IPC {
#include "libcef/common/cef_message_generator.h"
} // namespace IPC

View File

@ -5,3 +5,10 @@
// Multiply-included file, hence no include guard.
#include "libcef/common/cef_messages.h"
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/spellcheck_messages.h"
#if defined(OS_WIN)
#include "chrome/common/chrome_utility_printing_messages.h"
#endif

View File

@ -218,9 +218,3 @@ struct ParamTraits<scoped_refptr<net::UploadData> > {
} // namespace IPC
#endif // CEF_LIBCEF_COMMON_CEF_MESSAGES_H_
#include "chrome/common/spellcheck_messages.h"
#if defined(OS_WIN)
#include "chrome/common/chrome_utility_printing_messages.h"
#endif

View File

@ -349,6 +349,13 @@ need to be translated for each locale.-->
<message name="IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS" desc="The name of the No Spelling Suggestions display in the content area context menu">
&amp;No spelling suggestions
</message>
<!-- Font cache -->
<if expr="is_win">
<message name="IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME" desc="The name of the utility process used for building the DirectWrite font cache.">
DirectWrite Font Cache Builder
</message>
</if>
</messages>
</release>
</grit>

View File

@ -13,6 +13,7 @@
#if defined(OS_WIN)
#include "libcef/utility/printing_handler.h"
#include "chrome/utility/font_cache_handler_win.h"
#endif
namespace {
@ -35,6 +36,7 @@ void CreateProxyResolverFactory(
CefContentUtilityClient::CefContentUtilityClient() {
#if defined(OS_WIN)
handlers_.push_back(new PrintingHandler());
handlers_.push_back(new FontCacheHandler());
#endif
}