Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | 5 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 | 185 |
| 186 if (*family_index >= GetFontFamilyCount()) { | 186 if (*family_index >= GetFontFamilyCount()) { |
| 187 LogFontProxyError(FAMILY_INDEX_OUT_OF_RANGE); | 187 LogFontProxyError(FAMILY_INDEX_OUT_OF_RANGE); |
| 188 return E_INVALIDARG; | 188 return E_INVALIDARG; |
| 189 } | 189 } |
| 190 | 190 |
| 191 // If we already loaded the family we should reuse the existing collection. | 191 // If we already loaded the family we should reuse the existing collection. |
| 192 DCHECK(!families_[*family_index]->IsLoaded()); | 192 DCHECK(!families_[*family_index]->IsLoaded()); |
| 193 | 193 |
| 194 std::vector<base::string16> file_names; | 194 std::vector<base::string16> file_names; |
| 195 if (!GetSender()->Send( | 195 std::vector<uint32_t> file_handles; |
| 196 new DWriteFontProxyMsg_GetFontFiles(*family_index, &file_names))) { | 196 if (!GetSender()->Send(new DWriteFontProxyMsg_GetFontFiles( |
| 197 *family_index, &file_names, &file_handles))) { | |
| 197 LogFontProxyError(GET_FONT_FILES_SEND_FAILED); | 198 LogFontProxyError(GET_FONT_FILES_SEND_FAILED); |
| 198 return E_FAIL; | 199 return E_FAIL; |
| 199 } | 200 } |
| 200 | 201 |
| 202 std::vector<size_t> file_references; | |
| 203 file_references.reserve(file_names.size() + file_handles.size()); | |
| 204 for (base::string16& file_name : file_names) { | |
| 205 file_references.push_back(CreateFontFileReference(std::move(file_name))); | |
| 206 } | |
| 207 file_names.clear(); // Clear the vector since we moved all the paths out. | |
| 208 for (uint32_t file_handle : file_handles) { | |
| 209 file_references.push_back( | |
| 210 CreateFontFileReference(reinterpret_cast<HANDLE>(file_handle))); | |
| 211 } | |
| 212 | |
| 201 HRESULT hr = mswr::MakeAndInitialize<FontFileEnumerator>( | 213 HRESULT hr = mswr::MakeAndInitialize<FontFileEnumerator>( |
| 202 font_file_enumerator, factory, this, &file_names); | 214 font_file_enumerator, factory, this, &file_references); |
| 203 | 215 |
| 204 if (!SUCCEEDED(hr)) { | 216 if (!SUCCEEDED(hr)) { |
| 205 DCHECK(false); | 217 DCHECK(false); |
| 206 return E_FAIL; | 218 return E_FAIL; |
| 207 } | 219 } |
| 208 | 220 |
| 209 return S_OK; | 221 return S_OK; |
| 210 } | 222 } |
| 211 | 223 |
| 212 HRESULT DWriteFontCollectionProxy::CreateStreamFromKey( | 224 HRESULT DWriteFontCollectionProxy::CreateStreamFromKey( |
| 213 const void* font_file_reference_key, | 225 const void* font_file_reference_key, |
| 214 UINT32 font_file_reference_key_size, | 226 UINT32 font_file_reference_key_size, |
| 215 IDWriteFontFileStream** font_file_stream) { | 227 IDWriteFontFileStream** font_file_stream) { |
| 216 if (!font_file_reference_key) { | 228 if (font_file_reference_key_size != sizeof(size_t)) { |
| 217 return E_FAIL; | |
| 218 } | |
| 219 | |
| 220 const base::char16* file_name = | |
| 221 reinterpret_cast<const base::char16*>(font_file_reference_key); | |
| 222 DCHECK_EQ(font_file_reference_key_size % sizeof(base::char16), 0u); | |
| 223 size_t file_name_size = | |
| 224 static_cast<size_t>(font_file_reference_key_size) / sizeof(base::char16); | |
| 225 | |
| 226 if (file_name_size == 0 || file_name[file_name_size - 1] != L'\0') { | |
| 227 return E_FAIL; | 229 return E_FAIL; |
| 228 } | 230 } |
| 229 | 231 |
| 230 TRACE_EVENT0("dwrite", "FontFileEnumerator::CreateStreamFromKey"); | 232 TRACE_EVENT0("dwrite", "FontFileEnumerator::CreateStreamFromKey"); |
| 231 | 233 |
| 234 size_t font_file_index = | |
| 235 *reinterpret_cast<const size_t*>(font_file_reference_key); | |
| 236 | |
| 237 if (font_file_index >= font_files_.size()) | |
| 238 return E_FAIL; | |
| 239 | |
| 240 FontFileReference& reference = font_files_[font_file_index]; | |
| 241 | |
| 232 mswr::ComPtr<IDWriteFontFileStream> stream; | 242 mswr::ComPtr<IDWriteFontFileStream> stream; |
| 233 if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, file_name))) { | 243 if (reference.Type() == FontFileReference::PATH) { |
| 234 DCHECK(false); | 244 if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, |
| 235 return E_FAIL; | 245 reference.Path()))) { |
| 246 DCHECK(false); | |
| 247 return E_FAIL; | |
| 248 } | |
| 249 } else if (reference.Type() == FontFileReference::FILE) { | |
| 250 if (!SUCCEEDED(mswr::MakeAndInitialize<FontFileStream>(&stream, | |
| 251 reference.File()))) { | |
| 252 DCHECK(false); | |
| 253 return E_FAIL; | |
| 254 } | |
| 255 } else { | |
| 256 CHECK(false); | |
| 236 } | 257 } |
| 237 *font_file_stream = stream.Detach(); | 258 *font_file_stream = stream.Detach(); |
| 238 return S_OK; | 259 return S_OK; |
| 239 } | 260 } |
| 240 | 261 |
| 241 HRESULT DWriteFontCollectionProxy::RuntimeClassInitialize( | 262 HRESULT DWriteFontCollectionProxy::RuntimeClassInitialize( |
| 242 IDWriteFactory* factory, | 263 IDWriteFactory* factory, |
| 243 IPC::Sender* sender_override) { | 264 IPC::Sender* sender_override) { |
| 244 DCHECK(factory); | 265 DCHECK(factory); |
| 245 | 266 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 mswr::ComPtr<DWriteFontFamilyProxy> family; | 342 mswr::ComPtr<DWriteFontFamilyProxy> family; |
| 322 HRESULT hr = mswr::MakeAndInitialize<DWriteFontFamilyProxy>(&family, this, | 343 HRESULT hr = mswr::MakeAndInitialize<DWriteFontFamilyProxy>(&family, this, |
| 323 family_index); | 344 family_index); |
| 324 DCHECK(SUCCEEDED(hr)); | 345 DCHECK(SUCCEEDED(hr)); |
| 325 DCHECK_LT(family_index, families_.size()); | 346 DCHECK_LT(family_index, families_.size()); |
| 326 | 347 |
| 327 families_[family_index] = family; | 348 families_[family_index] = family; |
| 328 return true; | 349 return true; |
| 329 } | 350 } |
| 330 | 351 |
| 352 size_t DWriteFontCollectionProxy::CreateFontFileReference( | |
| 353 base::string16 file_path) { | |
| 354 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_
| |
| 355 return font_files_.size() - 1; | |
| 356 } | |
| 357 | |
| 358 size_t DWriteFontCollectionProxy::CreateFontFileReference(HANDLE file_handle) { | |
| 359 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
| |
| 360 return font_files_.size() - 1; | |
| 361 } | |
| 362 | |
| 331 IPC::Sender* DWriteFontCollectionProxy::GetSender() { | 363 IPC::Sender* DWriteFontCollectionProxy::GetSender() { |
| 332 return sender_override_ ? sender_override_ : ChildThread::Get(); | 364 return sender_override_ ? sender_override_ : ChildThread::Get(); |
| 333 } | 365 } |
| 334 | 366 |
| 335 DWriteFontFamilyProxy::DWriteFontFamilyProxy() = default; | 367 DWriteFontFamilyProxy::DWriteFontFamilyProxy() = default; |
| 336 | 368 |
| 337 DWriteFontFamilyProxy::~DWriteFontFamilyProxy() = default; | 369 DWriteFontFamilyProxy::~DWriteFontFamilyProxy() = default; |
| 338 | 370 |
| 339 HRESULT DWriteFontFamilyProxy::GetFontCollection( | 371 HRESULT DWriteFontFamilyProxy::GetFontCollection( |
| 340 IDWriteFontCollection** font_collection) { | 372 IDWriteFontCollection** font_collection) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 } | 530 } |
| 499 | 531 |
| 500 LogLoadFamilyResult(family_count == 1 ? LOAD_FAMILY_SUCCESS_SINGLE_FAMILY | 532 LogLoadFamilyResult(family_count == 1 ? LOAD_FAMILY_SUCCESS_SINGLE_FAMILY |
| 501 : LOAD_FAMILY_ERROR_MULTIPLE_FAMILIES); | 533 : LOAD_FAMILY_ERROR_MULTIPLE_FAMILIES); |
| 502 | 534 |
| 503 hr = collection->GetFontFamily(0, &family_); | 535 hr = collection->GetFontFamily(0, &family_); |
| 504 | 536 |
| 505 return SUCCEEDED(hr); | 537 return SUCCEEDED(hr); |
| 506 } | 538 } |
| 507 | 539 |
| 540 DWriteFontCollectionProxy::FontFileReference::FontFileReference( | |
| 541 base::string16 file_path) { | |
| 542 reference_type_ = PATH; | |
| 543 file_path_.swap(file_path); | |
| 544 } | |
| 545 DWriteFontCollectionProxy::FontFileReference::FontFileReference( | |
|
ananta
2016/07/20 01:34:59
newline
Ilya Kulshin
2016/07/21 04:17:37
Done.
| |
| 546 HANDLE file_handle) | |
| 547 : file_(file_handle) { | |
| 548 reference_type_ = FILE; | |
| 549 } | |
| 550 | |
| 508 FontFileEnumerator::FontFileEnumerator() = default; | 551 FontFileEnumerator::FontFileEnumerator() = default; |
| 509 | 552 |
| 510 FontFileEnumerator::~FontFileEnumerator() = default; | 553 FontFileEnumerator::~FontFileEnumerator() = default; |
| 511 | 554 |
| 512 HRESULT FontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** file) { | 555 HRESULT FontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** file) { |
| 513 DCHECK(file); | 556 DCHECK(file); |
| 514 if (current_file_ >= file_names_.size()) { | 557 if (current_file_ >= file_references_.size()) { |
| 515 return E_FAIL; | 558 return E_FAIL; |
| 516 } | 559 } |
| 517 | 560 |
| 518 TRACE_EVENT0("dwrite", "FontFileEnumerator::GetCurrentFontFile"); | 561 TRACE_EVENT0("dwrite", "FontFileEnumerator::GetCurrentFontFile"); |
| 562 | |
| 519 // CreateCustomFontFileReference ends up calling | 563 // CreateCustomFontFileReference ends up calling |
| 520 // DWriteFontCollectionProxy::CreateStreamFromKey. | 564 // DWriteFontCollectionProxy::CreateStreamFromKey. |
| 521 HRESULT hr = factory_->CreateCustomFontFileReference( | 565 HRESULT hr = factory_->CreateCustomFontFileReference( |
| 522 reinterpret_cast<const void*>(file_names_[current_file_].c_str()), | 566 reinterpret_cast<const void*>(&file_references_[current_file_]), |
| 523 (file_names_[current_file_].length() + 1) * sizeof(base::char16), | 567 sizeof(size_t), loader_.Get() /*IDWriteFontFileLoader*/, file); |
| 524 loader_.Get() /*IDWriteFontFileLoader*/, file); | |
| 525 DCHECK(SUCCEEDED(hr)); | 568 DCHECK(SUCCEEDED(hr)); |
| 526 return hr; | 569 return hr; |
| 527 } | 570 } |
| 528 | 571 |
| 529 HRESULT FontFileEnumerator::MoveNext(BOOL* has_current_file) { | 572 HRESULT FontFileEnumerator::MoveNext(BOOL* has_current_file) { |
| 530 DCHECK(has_current_file); | 573 DCHECK(has_current_file); |
| 531 | 574 |
| 532 TRACE_EVENT0("dwrite", "FontFileEnumerator::MoveNext"); | 575 TRACE_EVENT0("dwrite", "FontFileEnumerator::MoveNext"); |
| 533 if (next_file_ >= file_names_.size()) { | 576 if (next_file_ >= file_references_.size()) { |
| 534 *has_current_file = FALSE; | 577 *has_current_file = FALSE; |
| 535 current_file_ = UINT_MAX; | 578 current_file_ = UINT_MAX; |
| 536 return S_OK; | 579 return S_OK; |
| 537 } | 580 } |
| 538 | 581 |
| 539 current_file_ = next_file_; | 582 current_file_ = next_file_; |
| 540 ++next_file_; | 583 ++next_file_; |
| 541 *has_current_file = TRUE; | 584 *has_current_file = TRUE; |
| 542 return S_OK; | 585 return S_OK; |
| 543 } | 586 } |
| 544 | 587 |
| 545 HRESULT FontFileEnumerator::RuntimeClassInitialize( | 588 HRESULT FontFileEnumerator::RuntimeClassInitialize( |
| 546 IDWriteFactory* factory, | 589 IDWriteFactory* factory, |
| 547 IDWriteFontFileLoader* loader, | 590 IDWriteFontFileLoader* loader, |
| 548 std::vector<base::string16>* file_names) { | 591 std::vector<size_t>* file_references) { |
| 549 factory_ = factory; | 592 factory_ = factory; |
| 550 loader_ = loader; | 593 loader_ = loader; |
| 551 file_names_.swap(*file_names); | 594 file_references_.swap(*file_references); |
| 552 file_streams_.resize(file_names_.size()); | |
| 553 return S_OK; | 595 return S_OK; |
| 554 } | 596 } |
| 555 | 597 |
| 556 FontFileStream::FontFileStream() = default; | 598 FontFileStream::FontFileStream() = default; |
| 557 | 599 |
| 558 FontFileStream::~FontFileStream() = default; | 600 FontFileStream::~FontFileStream() = default; |
| 559 | 601 |
| 560 HRESULT FontFileStream::GetFileSize(UINT64* file_size) { | 602 HRESULT FontFileStream::GetFileSize(UINT64* file_size) { |
| 561 *file_size = data_.length(); | 603 *file_size = data_.length(); |
| 562 return S_OK; | 604 return S_OK; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 574 if (fragment_offset + fragment_size < fragment_offset) | 616 if (fragment_offset + fragment_size < fragment_offset) |
| 575 return E_FAIL; | 617 return E_FAIL; |
| 576 if (fragment_offset + fragment_size > data_.length()) | 618 if (fragment_offset + fragment_size > data_.length()) |
| 577 return E_FAIL; | 619 return E_FAIL; |
| 578 *fragment_start = data_.data() + fragment_offset; | 620 *fragment_start = data_.data() + fragment_offset; |
| 579 *fragment_context = nullptr; | 621 *fragment_context = nullptr; |
| 580 return S_OK; | 622 return S_OK; |
| 581 } | 623 } |
| 582 | 624 |
| 583 HRESULT FontFileStream::RuntimeClassInitialize( | 625 HRESULT FontFileStream::RuntimeClassInitialize( |
| 584 const base::string16& file_name) { | 626 const base::string16* file_name) { |
| 585 data_.Initialize(base::FilePath(file_name)); | 627 data_.Initialize(base::FilePath(file_name->c_str())); |
| 586 if (!data_.IsValid()) { | 628 if (!data_.IsValid()) { |
| 587 LogFontProxyError(MAPPED_FILE_FAILED); | 629 LogFontProxyError(MAPPED_FILE_FAILED); |
| 588 return E_FAIL; | 630 return E_FAIL; |
| 631 } | |
| 632 return S_OK; | |
| 633 } | |
| 634 | |
| 635 HRESULT FontFileStream::RuntimeClassInitialize(const base::File* file) { | |
| 636 data_.Initialize(const_cast<base::File*>(file)->Duplicate()); | |
| 637 if (!data_.IsValid()) { | |
| 638 LogFontProxyError(MAPPED_FILE_FAILED); | |
| 639 return E_FAIL; | |
| 589 } | 640 } |
| 590 return S_OK; | 641 return S_OK; |
| 591 } | 642 } |
| 592 | 643 |
| 593 } // namespace content | 644 } // namespace content |
| OLD | NEW |