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_english = MSCharSetToFontconfig(langset, charset); |
411 | 411 |
412 FcPattern* pattern = FcPatternCreate(); | 412 FcPattern* pattern = FcPatternCreate(); |
413 // TODO(agl): FC_FAMILy needs to change | 413 // TODO(agl): FC_FAMILy needs to change |
414 FcPatternAddString(pattern, FC_FAMILY, | 414 FcPatternAddString(pattern, FC_FAMILY, |
415 reinterpret_cast<const FcChar8*>(face.c_str())); | 415 reinterpret_cast<const FcChar8*>(face.c_str())); |
416 | 416 |
417 std::string generic_font_name; | 417 std::string generic_font_name; |
418 switch (fallback_family) { | 418 if (is_english) { |
jungshik at Google
2014/03/27 11:06:11
Can we access Chrome's per-script font pref here?
Lei Zhang
2014/03/27 19:31:25
I don't know. Added a TODO. Will investigate in th
| |
419 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 419 switch (fallback_family) { |
420 generic_font_name = "Times New Roman"; | 420 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
421 break; | 421 generic_font_name = "Times New Roman"; |
422 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: | 422 break; |
423 generic_font_name = "Arial"; | 423 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: |
424 break; | 424 generic_font_name = "Arial"; |
425 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: | 425 break; |
426 generic_font_name = "Courier New"; | 426 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: |
427 break; | 427 generic_font_name = "Courier New"; |
428 break; | |
429 } | |
428 } | 430 } |
429 if (!generic_font_name.empty()) { | 431 if (!generic_font_name.empty()) { |
430 const FcChar8* fc_generic_font_name = | 432 const FcChar8* fc_generic_font_name = |
431 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); | 433 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); |
432 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); | 434 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); |
433 } | 435 } |
434 | 436 |
435 if (is_bold) | 437 if (is_bold) |
436 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); | 438 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); |
437 if (is_italic) | 439 if (is_italic) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 SendRendererReply(fds, reply, font_fd); | 542 SendRendererReply(fds, reply, font_fd); |
541 | 543 |
542 if (font_fd >= 0) { | 544 if (font_fd >= 0) { |
543 if (IGNORE_EINTR(close(font_fd)) < 0) | 545 if (IGNORE_EINTR(close(font_fd)) < 0) |
544 PLOG(ERROR) << "close"; | 546 PLOG(ERROR) << "close"; |
545 } | 547 } |
546 } | 548 } |
547 | 549 |
548 // MSCharSetToFontconfig translates a Microsoft charset identifier to a | 550 // MSCharSetToFontconfig translates a Microsoft charset identifier to a |
549 // fontconfig language set by appending to |langset|. | 551 // fontconfig language set by appending to |langset|. |
550 static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { | 552 static bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { |
551 // We have need to translate raw fdwCharSet values into terms that | 553 // We have need to translate raw fdwCharSet values into terms that |
552 // fontconfig can understand. (See the description of fdwCharSet in the MSDN | 554 // fontconfig can understand. (See the description of fdwCharSet in the MSDN |
553 // documentation for CreateFont: | 555 // documentation for CreateFont: |
554 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) | 556 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) |
555 // | 557 // |
556 // Although the argument is /called/ 'charset', the actual values conflate | 558 // Although the argument is /called/ 'charset', the actual values conflate |
557 // character sets (which are sets of Unicode code points) and character | 559 // character sets (which are sets of Unicode code points) and character |
558 // encodings (which are algorithms for turning a series of bits into a | 560 // encodings (which are algorithms for turning a series of bits into a |
559 // series of code points.) Sometimes the values will name a language, | 561 // 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 | 562 // 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. | 563 // they mean the set of code points in the domain of that encoding. |
562 // | 564 // |
563 // fontconfig deals with ISO 639-1 language codes: | 565 // fontconfig deals with ISO 639-1 language codes: |
564 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | 566 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes |
565 // | 567 // |
566 // So, for each of the documented fdwCharSet values I've had to take a | 568 // 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. | 569 // guess at the set of ISO 639-1 languages intended. |
568 | 570 |
571 bool is_english = false; | |
jungshik at Google
2014/03/27 11:06:11
Perhaps, it'd be better to change change |is_engli
Lei Zhang
2014/03/27 19:31:25
Done.
| |
569 switch (fdwCharSet) { | 572 switch (fdwCharSet) { |
570 case NPCharsetAnsi: | 573 case NPCharsetAnsi: |
571 // These values I don't really know what to do with, so I'm going to map | 574 // These values I don't really know what to do with, so I'm going to map |
572 // them to English also. | 575 // them to English also. |
573 case NPCharsetDefault: | 576 case NPCharsetDefault: |
574 case NPCharsetMac: | 577 case NPCharsetMac: |
575 case NPCharsetOEM: | 578 case NPCharsetOEM: |
576 case NPCharsetSymbol: | 579 case NPCharsetSymbol: |
580 is_english = true; | |
577 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); | 581 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); |
578 break; | 582 break; |
579 case NPCharsetBaltic: | 583 case NPCharsetBaltic: |
580 // The three baltic languages. | 584 // The three baltic languages. |
581 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); | 585 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); |
582 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); | 586 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); |
583 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); | 587 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); |
584 break; | 588 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: | 589 case NPCharsetChineseBIG5: |
590 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw")); | |
591 break; | |
589 case NPCharsetGB2312: | 592 case NPCharsetGB2312: |
590 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh")); | 593 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn")); |
591 break; | 594 break; |
592 case NPCharsetEastEurope: | 595 case NPCharsetEastEurope: |
593 // A scattering of eastern European languages. | 596 // A scattering of eastern European languages. |
594 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); | 597 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); |
595 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); | 598 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); |
596 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); | 599 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); |
597 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); | 600 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); |
598 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); | 601 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); |
599 break; | 602 break; |
600 case NPCharsetGreek: | 603 case NPCharsetGreek: |
(...skipping 23 matching lines...) Expand all Loading... | |
624 case NPCharsetHebrew: | 627 case NPCharsetHebrew: |
625 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); | 628 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); |
626 break; | 629 break; |
627 case NPCharsetThai: | 630 case NPCharsetThai: |
628 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); | 631 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); |
629 break; | 632 break; |
630 // default: | 633 // default: |
631 // Don't add any languages in that case that we don't recognise the | 634 // Don't add any languages in that case that we don't recognise the |
632 // constant. | 635 // constant. |
633 } | 636 } |
637 return is_english; | |
634 } | 638 } |
635 | 639 |
636 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, | 640 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, |
637 int reply_fd) { | 641 int reply_fd) { |
638 struct msghdr msg; | 642 struct msghdr msg; |
639 memset(&msg, 0, sizeof(msg)); | 643 memset(&msg, 0, sizeof(msg)); |
640 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; | 644 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; |
641 msg.msg_iov = &iov; | 645 msg.msg_iov = &iov; |
642 msg.msg_iovlen = 1; | 646 msg.msg_iovlen = 1; |
643 | 647 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 759 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
756 if (initialized_) { | 760 if (initialized_) { |
757 if (IGNORE_EINTR(close(renderer_socket_)) < 0) | 761 if (IGNORE_EINTR(close(renderer_socket_)) < 0) |
758 PLOG(ERROR) << "close"; | 762 PLOG(ERROR) << "close"; |
759 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) | 763 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) |
760 PLOG(ERROR) << "close"; | 764 PLOG(ERROR) << "close"; |
761 } | 765 } |
762 } | 766 } |
763 | 767 |
764 } // namespace content | 768 } // namespace content |
OLD | NEW |