Chromium Code Reviews| Index: content/child/dwrite_font_proxy/dwrite_font_proxy_win.cc |
| diff --git a/content/child/dwrite_font_proxy/dwrite_font_proxy_win.cc b/content/child/dwrite_font_proxy/dwrite_font_proxy_win.cc |
| index 887f99747b83ae9d93ae7c1030af4cb1ff02e013..c1ec32c150f1cc0e275dcc265236effd8e6c1d19 100644 |
| --- a/content/child/dwrite_font_proxy/dwrite_font_proxy_win.cc |
| +++ b/content/child/dwrite_font_proxy/dwrite_font_proxy_win.cc |
| @@ -192,14 +192,26 @@ HRESULT DWriteFontCollectionProxy::CreateEnumeratorFromKey( |
| DCHECK(!families_[*family_index]->IsLoaded()); |
| std::vector<base::string16> file_names; |
| - if (!GetSender()->Send( |
| - new DWriteFontProxyMsg_GetFontFiles(*family_index, &file_names))) { |
| + std::vector<uint32_t> file_handles; |
| + if (!GetSender()->Send(new DWriteFontProxyMsg_GetFontFiles( |
| + *family_index, &file_names, &file_handles))) { |
| LogFontProxyError(GET_FONT_FILES_SEND_FAILED); |
| return E_FAIL; |
| } |
| + std::vector<size_t> file_references; |
| + file_references.reserve(file_names.size() + file_handles.size()); |
| + for (base::string16& file_name : file_names) { |
| + file_references.push_back(CreateFontFileReference(std::move(file_name))); |
| + } |
| + file_names.clear(); // Clear the vector since we moved all the paths out. |
| + for (uint32_t file_handle : file_handles) { |
| + file_references.push_back( |
| + CreateFontFileReference(reinterpret_cast<HANDLE>(file_handle))); |
| + } |
| + |
| HRESULT hr = mswr::MakeAndInitialize<FontFileEnumerator>( |
| - font_file_enumerator, factory, this, &file_names); |
| + font_file_enumerator, factory, this, &file_references); |
| if (!SUCCEEDED(hr)) { |
| DCHECK(false); |
| @@ -213,26 +225,35 @@ HRESULT DWriteFontCollectionProxy::CreateStreamFromKey( |
| const void* font_file_reference_key, |
| UINT32 font_file_reference_key_size, |
| IDWriteFontFileStream** font_file_stream) { |
| - if (!font_file_reference_key) { |
| + if (font_file_reference_key_size != sizeof(size_t)) { |
| return E_FAIL; |
| } |
| - const base::char16* file_name = |
| - reinterpret_cast<const base::char16*>(font_file_reference_key); |
| - DCHECK_EQ(font_file_reference_key_size % sizeof(base::char16), 0u); |
| - size_t file_name_size = |
| - static_cast<size_t>(font_file_reference_key_size) / sizeof(base::char16); |
| + TRACE_EVENT0("dwrite", "FontFileEnumerator::CreateStreamFromKey"); |
| + |
| + size_t font_file_index = |
| + *reinterpret_cast<const size_t*>(font_file_reference_key); |
| - if (file_name_size == 0 || file_name[file_name_size - 1] != L'\0') { |
| + if (font_file_index >= font_files_.size()) |
| return E_FAIL; |
| - } |
| - TRACE_EVENT0("dwrite", "FontFileEnumerator::CreateStreamFromKey"); |
| + FontFileReference& reference = font_files_[font_file_index]; |
| mswr::ComPtr<IDWriteFontFileStream> stream; |
| - if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, file_name))) { |
| - DCHECK(false); |
| - return E_FAIL; |
| + if (reference.Type() == FontFileReference::PATH) { |
| + if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, |
| + reference.Path()))) { |
| + DCHECK(false); |
| + return E_FAIL; |
| + } |
| + } else if (reference.Type() == FontFileReference::FILE) { |
| + if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, |
| + reference.File()))) { |
| + DCHECK(false); |
| + return E_FAIL; |
| + } |
| + } else { |
| + CHECK(false); |
| } |
| *font_file_stream = stream.Detach(); |
| return S_OK; |
| @@ -328,6 +349,17 @@ bool DWriteFontCollectionProxy::CreateFamily(UINT32 family_index) { |
| return true; |
| } |
| +size_t DWriteFontCollectionProxy::CreateFontFileReference( |
| + base::string16 file_path) { |
| + font_files_.emplace_back(file_path); |
|
nasko
2016/07/20 16:40:03
This is confusing for me. Why are we stashing stri
Ilya Kulshin
2016/07/21 04:17:37
font_files_ is of type FontFileReference. emplace_
|
| + return font_files_.size() - 1; |
| +} |
| + |
| +size_t DWriteFontCollectionProxy::CreateFontFileReference(HANDLE file_handle) { |
| + font_files_.emplace_back(file_handle); |
|
nasko
2016/07/20 16:40:03
Mixing paths and handles in the same type seems ve
Ilya Kulshin
2016/07/21 04:17:37
After thinking about it a bit, I changed the code
|
| + return font_files_.size() - 1; |
| +} |
| + |
| IPC::Sender* DWriteFontCollectionProxy::GetSender() { |
| return sender_override_ ? sender_override_ : ChildThread::Get(); |
| } |
| @@ -505,23 +537,34 @@ bool DWriteFontFamilyProxy::LoadFamily() { |
| return SUCCEEDED(hr); |
| } |
| +DWriteFontCollectionProxy::FontFileReference::FontFileReference( |
| + base::string16 file_path) { |
| + reference_type_ = PATH; |
| + file_path_.swap(file_path); |
| +} |
| +DWriteFontCollectionProxy::FontFileReference::FontFileReference( |
|
ananta
2016/07/20 01:34:59
newline
Ilya Kulshin
2016/07/21 04:17:37
Done.
|
| + HANDLE file_handle) |
| + : file_(file_handle) { |
| + reference_type_ = FILE; |
| +} |
| + |
| FontFileEnumerator::FontFileEnumerator() = default; |
| FontFileEnumerator::~FontFileEnumerator() = default; |
| HRESULT FontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** file) { |
| DCHECK(file); |
| - if (current_file_ >= file_names_.size()) { |
| + if (current_file_ >= file_references_.size()) { |
| return E_FAIL; |
| } |
| TRACE_EVENT0("dwrite", "FontFileEnumerator::GetCurrentFontFile"); |
| + |
| // CreateCustomFontFileReference ends up calling |
| // DWriteFontCollectionProxy::CreateStreamFromKey. |
| HRESULT hr = factory_->CreateCustomFontFileReference( |
| - reinterpret_cast<const void*>(file_names_[current_file_].c_str()), |
| - (file_names_[current_file_].length() + 1) * sizeof(base::char16), |
| - loader_.Get() /*IDWriteFontFileLoader*/, file); |
| + reinterpret_cast<const void*>(&file_references_[current_file_]), |
| + sizeof(size_t), loader_.Get() /*IDWriteFontFileLoader*/, file); |
| DCHECK(SUCCEEDED(hr)); |
| return hr; |
| } |
| @@ -530,7 +573,7 @@ HRESULT FontFileEnumerator::MoveNext(BOOL* has_current_file) { |
| DCHECK(has_current_file); |
| TRACE_EVENT0("dwrite", "FontFileEnumerator::MoveNext"); |
| - if (next_file_ >= file_names_.size()) { |
| + if (next_file_ >= file_references_.size()) { |
| *has_current_file = FALSE; |
| current_file_ = UINT_MAX; |
| return S_OK; |
| @@ -545,11 +588,10 @@ HRESULT FontFileEnumerator::MoveNext(BOOL* has_current_file) { |
| HRESULT FontFileEnumerator::RuntimeClassInitialize( |
| IDWriteFactory* factory, |
| IDWriteFontFileLoader* loader, |
| - std::vector<base::string16>* file_names) { |
| + std::vector<size_t>* file_references) { |
| factory_ = factory; |
| loader_ = loader; |
| - file_names_.swap(*file_names); |
| - file_streams_.resize(file_names_.size()); |
| + file_references_.swap(*file_references); |
| return S_OK; |
| } |
| @@ -581,8 +623,17 @@ HRESULT FontFileStream::ReadFileFragment(const void** fragment_start, |
| } |
| HRESULT FontFileStream::RuntimeClassInitialize( |
| - const base::string16& file_name) { |
| - data_.Initialize(base::FilePath(file_name)); |
| + const base::string16* file_name) { |
| + data_.Initialize(base::FilePath(file_name->c_str())); |
| + if (!data_.IsValid()) { |
| + LogFontProxyError(MAPPED_FILE_FAILED); |
| + return E_FAIL; |
| + } |
| + return S_OK; |
| +} |
| + |
| +HRESULT FontFileStream::RuntimeClassInitialize(const base::File* file) { |
| + data_.Initialize(const_cast<base::File*>(file)->Duplicate()); |
| if (!data_.IsValid()) { |
| LogFontProxyError(MAPPED_FILE_FAILED); |
| return E_FAIL; |