Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(925)

Side by Side Diff: content/renderer/renderer_font_platform_win.cc

Issue 508393002: Adding more checking and some debugging information in Custom Font Collection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/crash_keys.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
15 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
16 #include "base/files/memory_mapped_file.h" 17 #include "base/files/memory_mapped_file.h"
17 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
19 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/strings/utf_string_conversions.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
21 #include "base/win/iat_patch_function.h" 23 #include "base/win/iat_patch_function.h"
22 #include "base/win/registry.h" 24 #include "base/win/registry.h"
23 #include "base/win/scoped_comptr.h" 25 #include "base/win/scoped_comptr.h"
24 26
25 namespace { 27 namespace {
26 28
27 namespace mswr = Microsoft::WRL; 29 namespace mswr = Microsoft::WRL;
28 namespace mswrw = Microsoft::WRL::Wrappers; 30 namespace mswrw = Microsoft::WRL::Wrappers;
29 31
32 static const char kFontKeyName[] = "font_key_name";
33
30 class FontCollectionLoader 34 class FontCollectionLoader
31 : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, 35 : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>,
32 IDWriteFontCollectionLoader> { 36 IDWriteFontCollectionLoader> {
33 public: 37 public:
34 // IDWriteFontCollectionLoader methods. 38 // IDWriteFontCollectionLoader methods.
35 virtual HRESULT STDMETHODCALLTYPE 39 virtual HRESULT STDMETHODCALLTYPE
36 CreateEnumeratorFromKey(IDWriteFactory* factory, 40 CreateEnumeratorFromKey(IDWriteFactory* factory,
37 void const* key, 41 void const* key,
38 UINT32 key_size, 42 UINT32 key_size,
39 IDWriteFontFileEnumerator** file_enumerator); 43 IDWriteFontFileEnumerator** file_enumerator);
(...skipping 20 matching lines...) Expand all
60 class FontFileStream 64 class FontFileStream
61 : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, 65 : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>,
62 IDWriteFontFileStream> { 66 IDWriteFontFileStream> {
63 public: 67 public:
64 // IDWriteFontFileStream methods. 68 // IDWriteFontFileStream methods.
65 virtual HRESULT STDMETHODCALLTYPE 69 virtual HRESULT STDMETHODCALLTYPE
66 ReadFileFragment(void const** fragment_start, 70 ReadFileFragment(void const** fragment_start,
67 UINT64 file_offset, 71 UINT64 file_offset,
68 UINT64 fragment_size, 72 UINT64 fragment_size,
69 void** context) { 73 void** context) {
70 if (!memory_.get() || !memory_->IsValid()) 74 if (!memory_.get() || !memory_->IsValid() ||
75 file_offset >= memory_->length() ||
76 (file_offset + fragment_size) > memory_->length())
71 return E_FAIL; 77 return E_FAIL;
72 78
73 *fragment_start = static_cast<BYTE const*>(memory_->data()) + 79 *fragment_start = static_cast<BYTE const*>(memory_->data()) +
74 static_cast<size_t>(file_offset); 80 static_cast<size_t>(file_offset);
75 *context = NULL; 81 *context = NULL;
76 return S_OK; 82 return S_OK;
77 } 83 }
78 84
79 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* context) {} 85 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* context) {}
80 86
(...skipping 18 matching lines...) Expand all
99 *last_write_time = 0; 105 *last_write_time = 0;
100 return S_OK; 106 return S_OK;
101 } 107 }
102 108
103 FontFileStream::FontFileStream() : font_key_(0) { 109 FontFileStream::FontFileStream() : font_key_(0) {
104 }; 110 };
105 111
106 HRESULT RuntimeClassInitialize(UINT32 font_key) { 112 HRESULT RuntimeClassInitialize(UINT32 font_key) {
107 base::FilePath path; 113 base::FilePath path;
108 PathService::Get(base::DIR_WINDOWS_FONTS, &path); 114 PathService::Get(base::DIR_WINDOWS_FONTS, &path);
109 path = path.Append(g_font_loader->GetFontNameFromKey(font_key).c_str()); 115 std::wstring font_key_name(g_font_loader->GetFontNameFromKey(font_key));
116 path = path.Append(font_key_name.c_str());
110 memory_.reset(new base::MemoryMappedFile()); 117 memory_.reset(new base::MemoryMappedFile());
111 118
112 // Put some debug information on stack. 119 // Put some debug information on stack.
113 WCHAR font_name[256]; 120 WCHAR font_name[256];
114 path.value().copy(font_name, arraysize(font_name)); 121 path.value().copy(font_name, arraysize(font_name));
115 base::debug::Alias(font_name); 122 base::debug::Alias(font_name);
116 123
117 if (!memory_->Initialize(path)) { 124 if (!memory_->Initialize(path)) {
118 memory_.reset(); 125 memory_.reset();
119 return E_FAIL; 126 return E_FAIL;
120 } 127 }
121 128
122 font_key_ = font_key; 129 font_key_ = font_key;
130
131 base::debug::SetCrashKeyValue(kFontKeyName,
132 base::WideToUTF8(font_key_name));
123 return S_OK; 133 return S_OK;
124 } 134 }
125 135
126 virtual ~FontFileStream() {} 136 virtual ~FontFileStream() {}
127 137
128 UINT32 font_key_; 138 UINT32 font_key_;
129 scoped_ptr<base::MemoryMappedFile> memory_; 139 scoped_ptr<base::MemoryMappedFile> memory_;
130 }; 140 };
131 141
132 class FontFileLoader 142 class FontFileLoader
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 302
293 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick; 303 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick;
294 int64 delta = time_delta.ToInternalValue(); 304 int64 delta = time_delta.ToInternalValue();
295 base::debug::Alias(&delta); 305 base::debug::Alias(&delta);
296 UINT32 size = g_font_loader->GetFontMapSize(); 306 UINT32 size = g_font_loader->GetFontMapSize();
297 base::debug::Alias(&size); 307 base::debug::Alias(&size);
298 308
299 CHECK(SUCCEEDED(hr)); 309 CHECK(SUCCEEDED(hr));
300 CHECK(g_font_collection.Get() != NULL); 310 CHECK(g_font_collection.Get() != NULL);
301 311
312 base::debug::ClearCrashKey(kFontKeyName);
313
302 return g_font_collection.Get(); 314 return g_font_collection.Get();
303 } 315 }
304 316
305 } // namespace content 317 } // namespace content
OLDNEW
« no previous file with comments | « chrome/common/crash_keys.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698