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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "skia/ext/skia_utils_base.h" | 28 #include "skia/ext/skia_utils_base.h" |
29 #include "third_party/skia/include/ports/SkFontConfigInterface.h" | 29 #include "third_party/skia/include/ports/SkFontConfigInterface.h" |
30 #include "ui/gfx/font.h" | 30 #include "ui/gfx/font.h" |
31 #include "ui/gfx/font_fallback_linux.h" | 31 #include "ui/gfx/font_fallback_linux.h" |
32 #include "ui/gfx/font_render_params.h" | 32 #include "ui/gfx/font_render_params.h" |
33 | 33 |
34 namespace content { | 34 namespace content { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
| 38 SandboxIPCHandler::TestObserver* g_test_observer = nullptr; |
| 39 |
38 // Converts gfx::FontRenderParams::Hinting to WebFontRenderStyle::hintStyle. | 40 // Converts gfx::FontRenderParams::Hinting to WebFontRenderStyle::hintStyle. |
39 // Returns an int for serialization, but the underlying Blink type is a char. | 41 // Returns an int for serialization, but the underlying Blink type is a char. |
40 int ConvertHinting(gfx::FontRenderParams::Hinting hinting) { | 42 int ConvertHinting(gfx::FontRenderParams::Hinting hinting) { |
41 switch (hinting) { | 43 switch (hinting) { |
42 case gfx::FontRenderParams::HINTING_NONE: return 0; | 44 case gfx::FontRenderParams::HINTING_NONE: return 0; |
43 case gfx::FontRenderParams::HINTING_SLIGHT: return 1; | 45 case gfx::FontRenderParams::HINTING_SLIGHT: return 1; |
44 case gfx::FontRenderParams::HINTING_MEDIUM: return 2; | 46 case gfx::FontRenderParams::HINTING_MEDIUM: return 2; |
45 case gfx::FontRenderParams::HINTING_FULL: return 3; | 47 case gfx::FontRenderParams::HINTING_FULL: return 3; |
46 } | 48 } |
47 NOTREACHED() << "Unexpected hinting value " << hinting; | 49 NOTREACHED() << "Unexpected hinting value " << hinting; |
(...skipping 11 matching lines...) Expand all Loading... |
59 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: return 1; | 61 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: return 1; |
60 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: return 1; | 62 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: return 1; |
61 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: return 1; | 63 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: return 1; |
62 } | 64 } |
63 NOTREACHED() << "Unexpected subpixel rendering value " << rendering; | 65 NOTREACHED() << "Unexpected subpixel rendering value " << rendering; |
64 return 0; | 66 return 0; |
65 } | 67 } |
66 | 68 |
67 } // namespace | 69 } // namespace |
68 | 70 |
| 71 // static |
| 72 void SandboxIPCHandler::SetObserverForTests( |
| 73 SandboxIPCHandler::TestObserver* observer) { |
| 74 g_test_observer = observer; |
| 75 } |
| 76 |
69 SandboxIPCHandler::SandboxIPCHandler(int lifeline_fd, int browser_socket) | 77 SandboxIPCHandler::SandboxIPCHandler(int lifeline_fd, int browser_socket) |
70 : lifeline_fd_(lifeline_fd), | 78 : lifeline_fd_(lifeline_fd), |
71 browser_socket_(browser_socket) { | 79 browser_socket_(browser_socket) { |
72 } | 80 } |
73 | 81 |
74 void SandboxIPCHandler::Run() { | 82 void SandboxIPCHandler::Run() { |
75 struct pollfd pfds[2]; | 83 struct pollfd pfds[2]; |
76 pfds[0].fd = lifeline_fd_; | 84 pfds[0].fd = lifeline_fd_; |
77 pfds[0].events = POLLIN; | 85 pfds[0].events = POLLIN; |
78 pfds[1].fd = browser_socket_; | 86 pfds[1].fd = browser_socket_; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 217 |
210 void SandboxIPCHandler::HandleFontOpenRequest( | 218 void SandboxIPCHandler::HandleFontOpenRequest( |
211 int fd, | 219 int fd, |
212 base::PickleIterator iter, | 220 base::PickleIterator iter, |
213 const std::vector<base::ScopedFD>& fds) { | 221 const std::vector<base::ScopedFD>& fds) { |
214 uint32_t index; | 222 uint32_t index; |
215 if (!iter.ReadUInt32(&index)) | 223 if (!iter.ReadUInt32(&index)) |
216 return; | 224 return; |
217 if (index >= static_cast<uint32_t>(paths_.size())) | 225 if (index >= static_cast<uint32_t>(paths_.size())) |
218 return; | 226 return; |
| 227 if (g_test_observer) { |
| 228 g_test_observer->OnFontOpen(index); |
| 229 } |
219 const int result_fd = open(paths_[index].c_str(), O_RDONLY); | 230 const int result_fd = open(paths_[index].c_str(), O_RDONLY); |
220 | 231 |
221 base::Pickle reply; | 232 base::Pickle reply; |
222 reply.WriteBool(result_fd != -1); | 233 reply.WriteBool(result_fd != -1); |
223 | 234 |
224 // The receiver will have its own access to the file, so we will close it | 235 // The receiver will have its own access to the file, so we will close it |
225 // after this send. | 236 // after this send. |
226 SendRendererReply(fds, reply, result_fd); | 237 SendRendererReply(fds, reply, result_fd); |
227 | 238 |
228 if (result_fd >= 0) { | 239 if (result_fd >= 0) { |
(...skipping 14 matching lines...) Expand all Loading... |
243 return; | 254 return; |
244 | 255 |
245 std::string preferred_locale; | 256 std::string preferred_locale; |
246 if (!iter.ReadString(&preferred_locale)) | 257 if (!iter.ReadString(&preferred_locale)) |
247 return; | 258 return; |
248 | 259 |
249 auto fallback_font = gfx::GetFallbackFontForChar(c, preferred_locale); | 260 auto fallback_font = gfx::GetFallbackFontForChar(c, preferred_locale); |
250 int fontconfig_interface_id = | 261 int fontconfig_interface_id = |
251 FindOrAddPath(SkString(fallback_font.filename.data())); | 262 FindOrAddPath(SkString(fallback_font.filename.data())); |
252 | 263 |
| 264 if (g_test_observer) { |
| 265 g_test_observer->OnGetFallbackFontForChar(c, fallback_font.name, |
| 266 fontconfig_interface_id); |
| 267 } |
253 base::Pickle reply; | 268 base::Pickle reply; |
254 reply.WriteString(fallback_font.name); | 269 reply.WriteString(fallback_font.name); |
255 reply.WriteString(fallback_font.filename); | 270 reply.WriteString(fallback_font.filename); |
256 reply.WriteInt(fontconfig_interface_id); | 271 reply.WriteInt(fontconfig_interface_id); |
257 reply.WriteInt(fallback_font.ttc_index); | 272 reply.WriteInt(fallback_font.ttc_index); |
258 reply.WriteBool(fallback_font.is_bold); | 273 reply.WriteBool(fallback_font.is_bold); |
259 reply.WriteBool(fallback_font.is_italic); | 274 reply.WriteBool(fallback_font.is_italic); |
260 SendRendererReply(fds, reply, -1); | 275 SendRendererReply(fds, reply, -1); |
261 } | 276 } |
262 | 277 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 428 } |
414 | 429 |
415 SandboxIPCHandler::~SandboxIPCHandler() { | 430 SandboxIPCHandler::~SandboxIPCHandler() { |
416 if (IGNORE_EINTR(close(lifeline_fd_)) < 0) | 431 if (IGNORE_EINTR(close(lifeline_fd_)) < 0) |
417 PLOG(ERROR) << "close"; | 432 PLOG(ERROR) << "close"; |
418 if (IGNORE_EINTR(close(browser_socket_)) < 0) | 433 if (IGNORE_EINTR(close(browser_socket_)) < 0) |
419 PLOG(ERROR) << "close"; | 434 PLOG(ERROR) << "close"; |
420 } | 435 } |
421 | 436 |
422 } // namespace content | 437 } // namespace content |
OLD | NEW |