Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/render_sandbox_host_linux.h" | 5 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <fontconfig/fontconfig.h> | 8 #include <fontconfig/fontconfig.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <sys/poll.h> | 10 #include <sys/poll.h> |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 if (!pickle.ReadString(&iter, &face) || | 400 if (!pickle.ReadString(&iter, &face) || |
| 401 face.empty() || | 401 face.empty() || |
| 402 !pickle.ReadBool(&iter, &is_bold) || | 402 !pickle.ReadBool(&iter, &is_bold) || |
| 403 !pickle.ReadBool(&iter, &is_italic) || | 403 !pickle.ReadBool(&iter, &is_italic) || |
| 404 !pickle.ReadUInt32(&iter, &charset) || | 404 !pickle.ReadUInt32(&iter, &charset) || |
| 405 !pickle.ReadUInt32(&iter, &fallback_family)) { | 405 !pickle.ReadUInt32(&iter, &fallback_family)) { |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 | 408 |
| 409 FcLangSet* langset = FcLangSetCreate(); | 409 FcLangSet* langset = FcLangSetCreate(); |
| 410 MSCharSetToFontconfig(langset, charset); | 410 bool is_lgc = MSCharSetToFontconfig(langset, charset); |
| 411 | 411 |
| 412 FcPattern* pattern = FcPatternCreate(); | 412 FcPattern* pattern = FcPatternCreate(); |
| 413 // TODO(agl): FC_FAMILy needs to change | |
| 414 FcPatternAddString(pattern, FC_FAMILY, | 413 FcPatternAddString(pattern, FC_FAMILY, |
| 415 reinterpret_cast<const FcChar8*>(face.c_str())); | 414 reinterpret_cast<const FcChar8*>(face.c_str())); |
| 416 | 415 |
| 416 // TODO(thestig) Check if we can access Chrome's per-script font preference | |
| 417 // here and select better default fonts for non-LGC case. | |
| 417 std::string generic_font_name; | 418 std::string generic_font_name; |
| 418 switch (fallback_family) { | 419 if (is_lgc) { |
| 419 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 420 switch (fallback_family) { |
| 420 generic_font_name = "Times New Roman"; | 421 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
| 421 break; | 422 generic_font_name = "Times New Roman"; |
| 422 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: | 423 break; |
| 423 generic_font_name = "Arial"; | 424 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: |
| 424 break; | 425 generic_font_name = "Arial"; |
| 425 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: | 426 break; |
| 426 generic_font_name = "Courier New"; | 427 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: |
| 427 break; | 428 generic_font_name = "Courier New"; |
| 429 break; | |
| 430 } | |
| 428 } | 431 } |
| 429 if (!generic_font_name.empty()) { | 432 if (!generic_font_name.empty()) { |
| 430 const FcChar8* fc_generic_font_name = | 433 const FcChar8* fc_generic_font_name = |
| 431 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); | 434 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); |
| 432 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); | 435 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); |
| 433 } | 436 } |
| 434 | 437 |
| 435 if (is_bold) | 438 if (is_bold) |
| 436 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); | 439 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); |
| 437 if (is_italic) | 440 if (is_italic) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 SendRendererReply(fds, reply, font_fd); | 543 SendRendererReply(fds, reply, font_fd); |
| 541 | 544 |
| 542 if (font_fd >= 0) { | 545 if (font_fd >= 0) { |
| 543 if (IGNORE_EINTR(close(font_fd)) < 0) | 546 if (IGNORE_EINTR(close(font_fd)) < 0) |
| 544 PLOG(ERROR) << "close"; | 547 PLOG(ERROR) << "close"; |
| 545 } | 548 } |
| 546 } | 549 } |
| 547 | 550 |
| 548 // MSCharSetToFontconfig translates a Microsoft charset identifier to a | 551 // MSCharSetToFontconfig translates a Microsoft charset identifier to a |
| 549 // fontconfig language set by appending to |langset|. | 552 // fontconfig language set by appending to |langset|. |
| 550 static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { | 553 // Returns true if |langset| is Latin/Greek/Cyrillic. |
| 554 static bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { | |
| 551 // We have need to translate raw fdwCharSet values into terms that | 555 // We have need to translate raw fdwCharSet values into terms that |
| 552 // fontconfig can understand. (See the description of fdwCharSet in the MSDN | 556 // fontconfig can understand. (See the description of fdwCharSet in the MSDN |
| 553 // documentation for CreateFont: | 557 // documentation for CreateFont: |
| 554 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) | 558 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) |
| 555 // | 559 // |
| 556 // Although the argument is /called/ 'charset', the actual values conflate | 560 // Although the argument is /called/ 'charset', the actual values conflate |
| 557 // character sets (which are sets of Unicode code points) and character | 561 // character sets (which are sets of Unicode code points) and character |
| 558 // encodings (which are algorithms for turning a series of bits into a | 562 // encodings (which are algorithms for turning a series of bits into a |
| 559 // series of code points.) Sometimes the values will name a language, | 563 // series of code points.) Sometimes the values will name a language, |
| 560 // sometimes they'll name an encoding. In the latter case I'm assuming that | 564 // sometimes they'll name an encoding. In the latter case I'm assuming that |
| 561 // they mean the set of code points in the domain of that encoding. | 565 // they mean the set of code points in the domain of that encoding. |
| 562 // | 566 // |
| 563 // fontconfig deals with ISO 639-1 language codes: | 567 // fontconfig deals with ISO 639-1 language codes: |
| 564 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | 568 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes |
| 565 // | 569 // |
| 566 // So, for each of the documented fdwCharSet values I've had to take a | 570 // So, for each of the documented fdwCharSet values I've had to take a |
| 567 // guess at the set of ISO 639-1 languages intended. | 571 // guess at the set of ISO 639-1 languages intended. |
| 568 | 572 |
| 573 bool is_lgc = false; | |
| 569 switch (fdwCharSet) { | 574 switch (fdwCharSet) { |
| 570 case NPCharsetAnsi: | 575 case NPCharsetAnsi: |
| 571 // These values I don't really know what to do with, so I'm going to map | 576 // These values I don't really know what to do with, so I'm going to map |
| 572 // them to English also. | 577 // them to English also. |
| 573 case NPCharsetDefault: | 578 case NPCharsetDefault: |
| 574 case NPCharsetMac: | 579 case NPCharsetMac: |
| 575 case NPCharsetOEM: | 580 case NPCharsetOEM: |
| 576 case NPCharsetSymbol: | 581 case NPCharsetSymbol: |
| 582 is_lgc = true; | |
| 577 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); | 583 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); |
| 578 break; | 584 break; |
| 579 case NPCharsetBaltic: | 585 case NPCharsetBaltic: |
| 580 // The three baltic languages. | 586 // The three baltic languages. |
| 581 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); | 587 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); |
| 582 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); | 588 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); |
| 583 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); | 589 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); |
|
jungshik at Google
2014/03/28 23:03:01
lgc=true
| |
| 584 break; | 590 break; |
| 585 // TODO(jungshik): Would we be better off mapping Big5 to zh-tw | |
| 586 // and GB2312 to zh-cn? Fontconfig has 4 separate orthography | |
| 587 // files (zh-{cn,tw,hk,mo}. | |
| 588 case NPCharsetChineseBIG5: | 591 case NPCharsetChineseBIG5: |
| 592 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw")); | |
| 593 break; | |
| 589 case NPCharsetGB2312: | 594 case NPCharsetGB2312: |
| 590 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh")); | 595 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn")); |
| 591 break; | 596 break; |
| 592 case NPCharsetEastEurope: | 597 case NPCharsetEastEurope: |
| 593 // A scattering of eastern European languages. | 598 // A scattering of eastern European languages. |
| 594 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); | 599 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); |
| 595 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); | 600 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); |
| 596 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); | 601 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); |
| 597 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); | 602 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); |
| 598 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); | 603 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); |
|
jungshik at Google
2014/03/28 23:03:01
lgc=true
| |
| 599 break; | 604 break; |
| 600 case NPCharsetGreek: | 605 case NPCharsetGreek: |
| 601 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); | 606 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); |
|
jungshik at Google
2014/03/28 23:03:01
ditto
| |
| 602 break; | 607 break; |
| 603 case NPCharsetHangul: | 608 case NPCharsetHangul: |
| 604 case NPCharsetJohab: | 609 case NPCharsetJohab: |
| 605 // Korean | 610 // Korean |
| 606 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); | 611 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); |
| 607 break; | 612 break; |
| 608 case NPCharsetRussian: | 613 case NPCharsetRussian: |
| 609 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); | 614 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); |
|
jungshik at Google
2014/03/28 23:03:01
ditto
| |
| 610 break; | 615 break; |
| 611 case NPCharsetShiftJIS: | 616 case NPCharsetShiftJIS: |
| 612 // Japanese | 617 // Japanese |
| 613 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); | 618 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); |
| 614 break; | 619 break; |
| 615 case NPCharsetTurkish: | 620 case NPCharsetTurkish: |
| 616 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); | 621 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); |
|
jungshik at Google
2014/03/28 23:03:01
ditto
| |
| 617 break; | 622 break; |
| 618 case NPCharsetVietnamese: | 623 case NPCharsetVietnamese: |
| 619 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); | 624 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); |
|
jungshik at Google
2014/03/28 23:03:01
ditto
| |
| 620 break; | 625 break; |
| 621 case NPCharsetArabic: | 626 case NPCharsetArabic: |
| 622 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); | 627 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); |
| 623 break; | 628 break; |
| 624 case NPCharsetHebrew: | 629 case NPCharsetHebrew: |
| 625 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); | 630 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); |
| 626 break; | 631 break; |
| 627 case NPCharsetThai: | 632 case NPCharsetThai: |
| 628 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); | 633 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); |
| 629 break; | 634 break; |
| 630 // default: | 635 // default: |
| 631 // Don't add any languages in that case that we don't recognise the | 636 // Don't add any languages in that case that we don't recognise the |
| 632 // constant. | 637 // constant. |
| 633 } | 638 } |
| 639 return is_lgc; | |
| 634 } | 640 } |
| 635 | 641 |
| 636 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, | 642 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, |
| 637 int reply_fd) { | 643 int reply_fd) { |
| 638 struct msghdr msg; | 644 struct msghdr msg; |
| 639 memset(&msg, 0, sizeof(msg)); | 645 memset(&msg, 0, sizeof(msg)); |
| 640 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; | 646 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; |
| 641 msg.msg_iov = &iov; | 647 msg.msg_iov = &iov; |
| 642 msg.msg_iovlen = 1; | 648 msg.msg_iovlen = 1; |
| 643 | 649 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 761 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
| 756 if (initialized_) { | 762 if (initialized_) { |
| 757 if (IGNORE_EINTR(close(renderer_socket_)) < 0) | 763 if (IGNORE_EINTR(close(renderer_socket_)) < 0) |
| 758 PLOG(ERROR) << "close"; | 764 PLOG(ERROR) << "close"; |
| 759 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) | 765 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) |
| 760 PLOG(ERROR) << "close"; | 766 PLOG(ERROR) << "close"; |
| 761 } | 767 } |
| 762 } | 768 } |
| 763 | 769 |
| 764 } // namespace content | 770 } // namespace content |
| OLD | NEW |