OLD | NEW |
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/browser/renderer_host/sandbox_ipc_linux.h" | 5 #include "content/browser/renderer_host/sandbox_ipc_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <fontconfig/fontconfig.h> | 8 #include <fontconfig/fontconfig.h> |
9 #include <sys/poll.h> | 9 #include <sys/poll.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 using blink::WebCString; | 33 using blink::WebCString; |
34 using blink::WebFontInfo; | 34 using blink::WebFontInfo; |
35 using blink::WebUChar; | 35 using blink::WebUChar; |
36 using blink::WebUChar32; | 36 using blink::WebUChar32; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // MSCharSetToFontconfig translates a Microsoft charset identifier to a | 40 // MSCharSetToFontconfig translates a Microsoft charset identifier to a |
41 // fontconfig language set by appending to |langset|. | 41 // fontconfig language set by appending to |langset|. |
42 static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { | 42 // Returns true if |langset| is Latin/Greek/Cyrillic. |
| 43 bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { |
43 // We have need to translate raw fdwCharSet values into terms that | 44 // We have need to translate raw fdwCharSet values into terms that |
44 // fontconfig can understand. (See the description of fdwCharSet in the MSDN | 45 // fontconfig can understand. (See the description of fdwCharSet in the MSDN |
45 // documentation for CreateFont: | 46 // documentation for CreateFont: |
46 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) | 47 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) |
47 // | 48 // |
48 // Although the argument is /called/ 'charset', the actual values conflate | 49 // Although the argument is /called/ 'charset', the actual values conflate |
49 // character sets (which are sets of Unicode code points) and character | 50 // character sets (which are sets of Unicode code points) and character |
50 // encodings (which are algorithms for turning a series of bits into a | 51 // encodings (which are algorithms for turning a series of bits into a |
51 // series of code points.) Sometimes the values will name a language, | 52 // series of code points.) Sometimes the values will name a language, |
52 // sometimes they'll name an encoding. In the latter case I'm assuming that | 53 // sometimes they'll name an encoding. In the latter case I'm assuming that |
53 // they mean the set of code points in the domain of that encoding. | 54 // they mean the set of code points in the domain of that encoding. |
54 // | 55 // |
55 // fontconfig deals with ISO 639-1 language codes: | 56 // fontconfig deals with ISO 639-1 language codes: |
56 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | 57 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes |
57 // | 58 // |
58 // So, for each of the documented fdwCharSet values I've had to take a | 59 // So, for each of the documented fdwCharSet values I've had to take a |
59 // guess at the set of ISO 639-1 languages intended. | 60 // guess at the set of ISO 639-1 languages intended. |
60 | 61 |
| 62 bool is_lgc = false; |
61 switch (fdwCharSet) { | 63 switch (fdwCharSet) { |
62 case NPCharsetAnsi: | 64 case NPCharsetAnsi: |
63 // These values I don't really know what to do with, so I'm going to map | 65 // These values I don't really know what to do with, so I'm going to map |
64 // them to English also. | 66 // them to English also. |
65 case NPCharsetDefault: | 67 case NPCharsetDefault: |
66 case NPCharsetMac: | 68 case NPCharsetMac: |
67 case NPCharsetOEM: | 69 case NPCharsetOEM: |
68 case NPCharsetSymbol: | 70 case NPCharsetSymbol: |
| 71 is_lgc = true; |
69 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); | 72 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); |
70 break; | 73 break; |
71 case NPCharsetBaltic: | 74 case NPCharsetBaltic: |
72 // The three baltic languages. | 75 // The three baltic languages. |
| 76 is_lgc = true; |
73 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); | 77 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); |
74 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); | 78 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); |
75 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); | 79 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); |
76 break; | 80 break; |
77 // TODO(jungshik): Would we be better off mapping Big5 to zh-tw | |
78 // and GB2312 to zh-cn? Fontconfig has 4 separate orthography | |
79 // files (zh-{cn,tw,hk,mo}. | |
80 case NPCharsetChineseBIG5: | 81 case NPCharsetChineseBIG5: |
| 82 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw")); |
| 83 break; |
81 case NPCharsetGB2312: | 84 case NPCharsetGB2312: |
82 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh")); | 85 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn")); |
83 break; | 86 break; |
84 case NPCharsetEastEurope: | 87 case NPCharsetEastEurope: |
85 // A scattering of eastern European languages. | 88 // A scattering of eastern European languages. |
| 89 is_lgc = true; |
86 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); | 90 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); |
87 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); | 91 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); |
88 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); | 92 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); |
89 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); | 93 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); |
90 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); | 94 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); |
91 break; | 95 break; |
92 case NPCharsetGreek: | 96 case NPCharsetGreek: |
| 97 is_lgc = true; |
93 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); | 98 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); |
94 break; | 99 break; |
95 case NPCharsetHangul: | 100 case NPCharsetHangul: |
96 case NPCharsetJohab: | 101 case NPCharsetJohab: |
97 // Korean | 102 // Korean |
98 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); | 103 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); |
99 break; | 104 break; |
100 case NPCharsetRussian: | 105 case NPCharsetRussian: |
| 106 is_lgc = true; |
101 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); | 107 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); |
102 break; | 108 break; |
103 case NPCharsetShiftJIS: | 109 case NPCharsetShiftJIS: |
104 // Japanese | 110 // Japanese |
105 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); | 111 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); |
106 break; | 112 break; |
107 case NPCharsetTurkish: | 113 case NPCharsetTurkish: |
| 114 is_lgc = true; |
108 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); | 115 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); |
109 break; | 116 break; |
110 case NPCharsetVietnamese: | 117 case NPCharsetVietnamese: |
| 118 is_lgc = true; |
111 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); | 119 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); |
112 break; | 120 break; |
113 case NPCharsetArabic: | 121 case NPCharsetArabic: |
114 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); | 122 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); |
115 break; | 123 break; |
116 case NPCharsetHebrew: | 124 case NPCharsetHebrew: |
117 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); | 125 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); |
118 break; | 126 break; |
119 case NPCharsetThai: | 127 case NPCharsetThai: |
120 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); | 128 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); |
121 break; | 129 break; |
122 // default: | 130 // default: |
123 // Don't add any languages in that case that we don't recognise the | 131 // Don't add any languages in that case that we don't recognise the |
124 // constant. | 132 // constant. |
125 } | 133 } |
| 134 return is_lgc; |
126 } | 135 } |
127 | 136 |
128 } // namespace | 137 } // namespace |
129 | 138 |
130 namespace content { | 139 namespace content { |
131 | 140 |
132 SandboxIPCHandler::SandboxIPCHandler(int lifeline_fd, int browser_socket) | 141 SandboxIPCHandler::SandboxIPCHandler(int lifeline_fd, int browser_socket) |
133 : lifeline_fd_(lifeline_fd), browser_socket_(browser_socket) { | 142 : lifeline_fd_(lifeline_fd), browser_socket_(browser_socket) { |
134 // FontConfig doesn't provide a standard property to control subpixel | 143 // FontConfig doesn't provide a standard property to control subpixel |
135 // positioning, so we pass the current setting through to WebKit. | 144 // positioning, so we pass the current setting through to WebKit. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 439 |
431 if (!pickle.ReadString(&iter, &face) || face.empty() || | 440 if (!pickle.ReadString(&iter, &face) || face.empty() || |
432 !pickle.ReadBool(&iter, &is_bold) || | 441 !pickle.ReadBool(&iter, &is_bold) || |
433 !pickle.ReadBool(&iter, &is_italic) || | 442 !pickle.ReadBool(&iter, &is_italic) || |
434 !pickle.ReadUInt32(&iter, &charset) || | 443 !pickle.ReadUInt32(&iter, &charset) || |
435 !pickle.ReadUInt32(&iter, &fallback_family)) { | 444 !pickle.ReadUInt32(&iter, &fallback_family)) { |
436 return; | 445 return; |
437 } | 446 } |
438 | 447 |
439 FcLangSet* langset = FcLangSetCreate(); | 448 FcLangSet* langset = FcLangSetCreate(); |
440 MSCharSetToFontconfig(langset, charset); | 449 bool is_lgc = MSCharSetToFontconfig(langset, charset); |
441 | 450 |
442 FcPattern* pattern = FcPatternCreate(); | 451 FcPattern* pattern = FcPatternCreate(); |
443 // TODO(agl): FC_FAMILy needs to change | |
444 FcPatternAddString( | 452 FcPatternAddString( |
445 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(face.c_str())); | 453 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(face.c_str())); |
446 | 454 |
| 455 // TODO(thestig) Check if we can access Chrome's per-script font preference |
| 456 // here and select better default fonts for non-LGC case. |
447 std::string generic_font_name; | 457 std::string generic_font_name; |
448 switch (fallback_family) { | 458 if (is_lgc) { |
449 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 459 switch (fallback_family) { |
450 generic_font_name = "Times New Roman"; | 460 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
451 break; | 461 generic_font_name = "Times New Roman"; |
452 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: | 462 break; |
453 generic_font_name = "Arial"; | 463 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: |
454 break; | 464 generic_font_name = "Arial"; |
455 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: | 465 break; |
456 generic_font_name = "Courier New"; | 466 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: |
457 break; | 467 generic_font_name = "Courier New"; |
| 468 break; |
| 469 } |
458 } | 470 } |
459 if (!generic_font_name.empty()) { | 471 if (!generic_font_name.empty()) { |
460 const FcChar8* fc_generic_font_name = | 472 const FcChar8* fc_generic_font_name = |
461 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); | 473 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); |
462 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); | 474 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); |
463 } | 475 } |
464 | 476 |
465 if (is_bold) | 477 if (is_bold) |
466 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); | 478 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); |
467 if (is_italic) | 479 if (is_italic) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 } | 635 } |
624 | 636 |
625 void SandboxIPCHandler::EnsureWebKitInitialized() { | 637 void SandboxIPCHandler::EnsureWebKitInitialized() { |
626 if (webkit_platform_support_) | 638 if (webkit_platform_support_) |
627 return; | 639 return; |
628 webkit_platform_support_.reset(new BlinkPlatformImpl); | 640 webkit_platform_support_.reset(new BlinkPlatformImpl); |
629 blink::initializeWithoutV8(webkit_platform_support_.get()); | 641 blink::initializeWithoutV8(webkit_platform_support_.get()); |
630 } | 642 } |
631 | 643 |
632 } // namespace content | 644 } // namespace content |
OLD | NEW |