OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <unistd.h> | 10 #include <unistd.h> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/pickle.h" | 24 #include "base/pickle.h" |
25 #include "base/process_util.h" | 25 #include "base/process_util.h" |
26 #include "base/shared_memory.h" | 26 #include "base/shared_memory.h" |
27 #include "base/string_number_conversions.h" | 27 #include "base/string_number_conversions.h" |
28 #include "base/string_util.h" | 28 #include "base/string_util.h" |
29 #include "content/common/font_config_ipc_linux.h" | 29 #include "content/common/font_config_ipc_linux.h" |
30 #include "content/common/sandbox_methods_linux.h" | 30 #include "content/common/sandbox_methods_linux.h" |
31 #include "content/common/unix_domain_socket_posix.h" | 31 #include "content/common/unix_domain_socket_posix.h" |
32 #include "skia/ext/SkFontHost_fontconfig_direct.h" | 32 #include "skia/ext/SkFontHost_fontconfig_direct.h" |
33 #include "third_party/npapi/bindings/npapi_extensions.h" | 33 #include "third_party/npapi/bindings/npapi_extensions.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebFontInfo.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebFontInfo.h" |
| 36 #include "webkit/glue/webkitclient_impl.h" |
35 | 37 |
36 using WebKit::WebCString; | 38 using WebKit::WebCString; |
37 using WebKit::WebFontInfo; | 39 using WebKit::WebFontInfo; |
38 using WebKit::WebUChar; | 40 using WebKit::WebUChar; |
39 | 41 |
40 // http://code.google.com/p/chromium/wiki/LinuxSandboxIPC | 42 // http://code.google.com/p/chromium/wiki/LinuxSandboxIPC |
41 | 43 |
42 // BEWARE: code in this file run across *processes* (not just threads). | 44 // BEWARE: code in this file run across *processes* (not just threads). |
43 | 45 |
44 // This code runs in a child process | 46 // This code runs in a child process |
(...skipping 16 matching lines...) Expand all Loading... |
61 multimap.push_back(base::InjectionArc(0, browser_socket, false)); | 63 multimap.push_back(base::InjectionArc(0, browser_socket, false)); |
62 | 64 |
63 base::CloseSuperfluousFds(multimap); | 65 base::CloseSuperfluousFds(multimap); |
64 | 66 |
65 if (!sandbox_cmd.empty()) { | 67 if (!sandbox_cmd.empty()) { |
66 sandbox_cmd_.push_back(sandbox_cmd); | 68 sandbox_cmd_.push_back(sandbox_cmd); |
67 sandbox_cmd_.push_back(base::kFindInodeSwitch); | 69 sandbox_cmd_.push_back(base::kFindInodeSwitch); |
68 } | 70 } |
69 } | 71 } |
70 | 72 |
| 73 ~SandboxIPCProcess(); |
| 74 |
71 void Run() { | 75 void Run() { |
72 struct pollfd pfds[2]; | 76 struct pollfd pfds[2]; |
73 pfds[0].fd = lifeline_fd_; | 77 pfds[0].fd = lifeline_fd_; |
74 pfds[0].events = POLLIN; | 78 pfds[0].events = POLLIN; |
75 pfds[1].fd = browser_socket_; | 79 pfds[1].fd = browser_socket_; |
76 pfds[1].events = POLLIN; | 80 pfds[1].events = POLLIN; |
77 | 81 |
78 int failed_polls = 0; | 82 int failed_polls = 0; |
79 for (;;) { | 83 for (;;) { |
80 const int r = HANDLE_EINTR(poll(pfds, 2, -1)); | 84 const int r = HANDLE_EINTR(poll(pfds, 2, -1)); |
(...skipping 13 matching lines...) Expand all Loading... |
94 _exit(0); | 98 _exit(0); |
95 } | 99 } |
96 | 100 |
97 if (pfds[1].revents) { | 101 if (pfds[1].revents) { |
98 HandleRequestFromRenderer(browser_socket_); | 102 HandleRequestFromRenderer(browser_socket_); |
99 } | 103 } |
100 } | 104 } |
101 } | 105 } |
102 | 106 |
103 private: | 107 private: |
| 108 void EnsureWebKitInitialized(); |
| 109 |
104 // --------------------------------------------------------------------------- | 110 // --------------------------------------------------------------------------- |
105 // Requests from the renderer... | 111 // Requests from the renderer... |
106 | 112 |
107 void HandleRequestFromRenderer(int fd) { | 113 void HandleRequestFromRenderer(int fd) { |
108 std::vector<int> fds; | 114 std::vector<int> fds; |
109 | 115 |
110 // A FontConfigIPC::METHOD_MATCH message could be kMaxFontFamilyLength | 116 // A FontConfigIPC::METHOD_MATCH message could be kMaxFontFamilyLength |
111 // bytes long (this is the largest message type). | 117 // bytes long (this is the largest message type). |
112 // 128 bytes padding are necessary so recvmsg() does not return MSG_TRUNC | 118 // 128 bytes padding are necessary so recvmsg() does not return MSG_TRUNC |
113 // error for a maximum length message. | 119 // error for a maximum length message. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 244 |
239 // We don't want a corrupt renderer asking too much of us, it might | 245 // We don't want a corrupt renderer asking too much of us, it might |
240 // overflow later in the code. | 246 // overflow later in the code. |
241 static const int kMaxChars = 4096; | 247 static const int kMaxChars = 4096; |
242 if (num_chars < 1 || num_chars > kMaxChars) { | 248 if (num_chars < 1 || num_chars > kMaxChars) { |
243 LOG(WARNING) << "HandleGetFontFamilyForChars: too many chars: " | 249 LOG(WARNING) << "HandleGetFontFamilyForChars: too many chars: " |
244 << num_chars; | 250 << num_chars; |
245 return; | 251 return; |
246 } | 252 } |
247 | 253 |
| 254 EnsureWebKitInitialized(); |
248 scoped_array<WebUChar> chars(new WebUChar[num_chars]); | 255 scoped_array<WebUChar> chars(new WebUChar[num_chars]); |
249 | 256 |
250 for (int i = 0; i < num_chars; ++i) { | 257 for (int i = 0; i < num_chars; ++i) { |
251 uint32_t c; | 258 uint32_t c; |
252 if (!pickle.ReadUInt32(&iter, &c)) { | 259 if (!pickle.ReadUInt32(&iter, &c)) { |
253 return; | 260 return; |
254 } | 261 } |
255 | 262 |
256 chars[i] = c; | 263 chars[i] = c; |
257 } | 264 } |
(...skipping 18 matching lines...) Expand all Loading... |
276 void HandleGetStyleForStrike(int fd, const Pickle& pickle, void* iter, | 283 void HandleGetStyleForStrike(int fd, const Pickle& pickle, void* iter, |
277 std::vector<int>& fds) { | 284 std::vector<int>& fds) { |
278 std::string family; | 285 std::string family; |
279 int sizeAndStyle; | 286 int sizeAndStyle; |
280 | 287 |
281 if (!pickle.ReadString(&iter, &family) || | 288 if (!pickle.ReadString(&iter, &family) || |
282 !pickle.ReadInt(&iter, &sizeAndStyle)) { | 289 !pickle.ReadInt(&iter, &sizeAndStyle)) { |
283 return; | 290 return; |
284 } | 291 } |
285 | 292 |
| 293 EnsureWebKitInitialized(); |
286 WebKit::WebFontRenderStyle style; | 294 WebKit::WebFontRenderStyle style; |
287 WebFontInfo::renderStyleForStrike(family.c_str(), sizeAndStyle, &style); | 295 WebFontInfo::renderStyleForStrike(family.c_str(), sizeAndStyle, &style); |
288 | 296 |
289 Pickle reply; | 297 Pickle reply; |
290 reply.WriteInt(style.useBitmaps); | 298 reply.WriteInt(style.useBitmaps); |
291 reply.WriteInt(style.useAutoHint); | 299 reply.WriteInt(style.useAutoHint); |
292 reply.WriteInt(style.useHinting); | 300 reply.WriteInt(style.useHinting); |
293 reply.WriteInt(style.hintStyle); | 301 reply.WriteInt(style.hintStyle); |
294 reply.WriteInt(style.useAntiAlias); | 302 reply.WriteInt(style.useAntiAlias); |
295 reply.WriteInt(style.useSubpixel); | 303 reply.WriteInt(style.useSubpixel); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 if (HANDLE_EINTR(sendmsg(fds[0], &msg, MSG_DONTWAIT)) < 0) | 638 if (HANDLE_EINTR(sendmsg(fds[0], &msg, MSG_DONTWAIT)) < 0) |
631 PLOG(ERROR) << "sendmsg"; | 639 PLOG(ERROR) << "sendmsg"; |
632 } | 640 } |
633 | 641 |
634 // --------------------------------------------------------------------------- | 642 // --------------------------------------------------------------------------- |
635 | 643 |
636 const int lifeline_fd_; | 644 const int lifeline_fd_; |
637 const int browser_socket_; | 645 const int browser_socket_; |
638 FontConfigDirect* const font_config_; | 646 FontConfigDirect* const font_config_; |
639 std::vector<std::string> sandbox_cmd_; | 647 std::vector<std::string> sandbox_cmd_; |
| 648 scoped_ptr<webkit_glue::WebKitClientImpl> webkit_client_; |
640 }; | 649 }; |
641 | 650 |
| 651 SandboxIPCProcess::~SandboxIPCProcess() { |
| 652 if (webkit_client_.get()) |
| 653 WebKit::shutdown(); |
| 654 } |
| 655 |
| 656 void SandboxIPCProcess::EnsureWebKitInitialized() { |
| 657 if (webkit_client_.get()) |
| 658 return; |
| 659 webkit_client_.reset(new webkit_glue::WebKitClientImpl); |
| 660 WebKit::initialize(webkit_client_.get()); |
| 661 } |
| 662 |
642 // ----------------------------------------------------------------------------- | 663 // ----------------------------------------------------------------------------- |
643 | 664 |
644 // Runs on the main thread at startup. | 665 // Runs on the main thread at startup. |
645 RenderSandboxHostLinux::RenderSandboxHostLinux() | 666 RenderSandboxHostLinux::RenderSandboxHostLinux() |
646 : initialized_(false), | 667 : initialized_(false), |
647 renderer_socket_(0), | 668 renderer_socket_(0), |
648 childs_lifeline_fd_(0), | 669 childs_lifeline_fd_(0), |
649 pid_(0) { | 670 pid_(0) { |
650 } | 671 } |
651 | 672 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 712 } |
692 | 713 |
693 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 714 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
694 if (initialized_) { | 715 if (initialized_) { |
695 if (HANDLE_EINTR(close(renderer_socket_)) < 0) | 716 if (HANDLE_EINTR(close(renderer_socket_)) < 0) |
696 PLOG(ERROR) << "close"; | 717 PLOG(ERROR) << "close"; |
697 if (HANDLE_EINTR(close(childs_lifeline_fd_)) < 0) | 718 if (HANDLE_EINTR(close(childs_lifeline_fd_)) < 0) |
698 PLOG(ERROR) << "close"; | 719 PLOG(ERROR) << "close"; |
699 } | 720 } |
700 } | 721 } |
OLD | NEW |