OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/renderer_font_platform_win.h" | 5 #include "content/renderer/renderer_font_platform_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include <wrl/implements.h> | 10 #include <wrl/implements.h> |
11 #include <wrl/wrappers/corewrappers.h> | 11 #include <wrl/wrappers/corewrappers.h> |
12 | 12 |
13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
14 #include "base/debug/crash_logging.h" | 14 #include "base/debug/crash_logging.h" |
15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/files/memory_mapped_file.h" | 17 #include "base/files/memory_mapped_file.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/metrics/histogram.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "base/win/iat_patch_function.h" | 24 #include "base/win/iat_patch_function.h" |
24 #include "base/win/registry.h" | 25 #include "base/win/registry.h" |
25 #include "base/win/scoped_comptr.h" | 26 #include "base/win/scoped_comptr.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 namespace mswr = Microsoft::WRL; | 30 namespace mswr = Microsoft::WRL; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 bool FontCollectionLoader::LoadFontListFromRegistry() { | 260 bool FontCollectionLoader::LoadFontListFromRegistry() { |
260 const wchar_t kFontsRegistry[] = | 261 const wchar_t kFontsRegistry[] = |
261 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; | 262 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; |
262 CHECK(reg_fonts_.empty()); | 263 CHECK(reg_fonts_.empty()); |
263 base::win::RegKey regkey; | 264 base::win::RegKey regkey; |
264 if (regkey.Open(HKEY_LOCAL_MACHINE, kFontsRegistry, KEY_READ) != | 265 if (regkey.Open(HKEY_LOCAL_MACHINE, kFontsRegistry, KEY_READ) != |
265 ERROR_SUCCESS) { | 266 ERROR_SUCCESS) { |
266 return false; | 267 return false; |
267 } | 268 } |
268 | 269 |
| 270 base::FilePath system_font_path; |
| 271 PathService::Get(base::DIR_WINDOWS_FONTS, &system_font_path); |
| 272 |
269 std::wstring name; | 273 std::wstring name; |
270 std::wstring value; | 274 std::wstring value; |
271 for (DWORD idx = 0; idx < regkey.GetValueCount(); idx++) { | 275 for (DWORD idx = 0; idx < regkey.GetValueCount(); idx++) { |
272 if (regkey.GetValueNameAt(idx, &name) == ERROR_SUCCESS && | 276 if (regkey.GetValueNameAt(idx, &name) == ERROR_SUCCESS && |
273 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) { | 277 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) { |
274 base::FilePath path(value.c_str()); | 278 base::FilePath path(value.c_str()); |
275 // We need to check if file name is the only component that exists, | 279 // We need to check if file name is the only component that exists, |
276 // we will ignore all other registry entries. | 280 // we will ignore all other registry entries. |
277 std::vector<base::FilePath::StringType> components; | 281 std::vector<base::FilePath::StringType> components; |
278 path.GetComponents(&components); | 282 path.GetComponents(&components); |
279 if (components.size() == 1) { | 283 if (components.size() == 1 || |
280 reg_fonts_.push_back(value.c_str()); | 284 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), |
| 285 path.DirName().value())) { |
| 286 reg_fonts_.push_back(path.BaseName().value()); |
281 } | 287 } |
282 } | 288 } |
283 } | 289 } |
| 290 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); |
| 291 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", |
| 292 regkey.GetValueCount() - reg_fonts_.size()); |
284 return true; | 293 return true; |
285 } | 294 } |
286 | 295 |
287 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. | 296 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. |
288 const wchar_t* kRestrictedFontSet[] = { | 297 const wchar_t* kRestrictedFontSet[] = { |
289 L"times.ttf", // IDS_STANDARD_FONT_FAMILY | 298 L"times.ttf", // IDS_STANDARD_FONT_FAMILY |
290 L"timesbd.ttf", // IDS_STANDARD_FONT_FAMILY | 299 L"timesbd.ttf", // IDS_STANDARD_FONT_FAMILY |
291 L"timesbi.ttf", // IDS_STANDARD_FONT_FAMILY | 300 L"timesbi.ttf", // IDS_STANDARD_FONT_FAMILY |
292 L"timesi.ttf", // IDS_STANDARD_FONT_FAMILY | 301 L"timesi.ttf", // IDS_STANDARD_FONT_FAMILY |
293 L"cour.ttf", // IDS_FIXED_FONT_FAMILY | 302 L"cour.ttf", // IDS_FIXED_FONT_FAMILY |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick; | 368 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick; |
360 int64 delta = time_delta.ToInternalValue(); | 369 int64 delta = time_delta.ToInternalValue(); |
361 base::debug::Alias(&delta); | 370 base::debug::Alias(&delta); |
362 UINT32 size = g_font_loader->GetFontMapSize(); | 371 UINT32 size = g_font_loader->GetFontMapSize(); |
363 base::debug::Alias(&size); | 372 base::debug::Alias(&size); |
364 base::debug::Alias(&loadingRestricted); | 373 base::debug::Alias(&loadingRestricted); |
365 | 374 |
366 CHECK(SUCCEEDED(hr)); | 375 CHECK(SUCCEEDED(hr)); |
367 CHECK(g_font_collection.Get() != NULL); | 376 CHECK(g_font_collection.Get() != NULL); |
368 | 377 |
| 378 UMA_HISTOGRAM_TIMES("DirectWrite.Fonts.LoadTime", time_delta); |
| 379 |
369 base::debug::ClearCrashKey(kFontKeyName); | 380 base::debug::ClearCrashKey(kFontKeyName); |
370 | 381 |
371 return g_font_collection.Get(); | 382 return g_font_collection.Get(); |
372 } | 383 } |
373 | 384 |
374 } // namespace content | 385 } // namespace content |
OLD | NEW |