Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: content/browser/renderer_host/sandbox_ipc_linux.cc

Issue 825353003: Revert of Remove deprecated methods from Pickle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sys/poll.h> 8 #include <sys/poll.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 NOTREACHED() << "Sandbox host message is larger than kMaxFontFamilyLength"; 137 NOTREACHED() << "Sandbox host message is larger than kMaxFontFamilyLength";
138 return; 138 return;
139 } 139 }
140 if (fds.empty()) 140 if (fds.empty())
141 return; 141 return;
142 142
143 Pickle pickle(buf, len); 143 Pickle pickle(buf, len);
144 PickleIterator iter(pickle); 144 PickleIterator iter(pickle);
145 145
146 int kind; 146 int kind;
147 if (!iter.ReadInt(&kind)) 147 if (!pickle.ReadInt(&iter, &kind))
148 return; 148 return;
149 149
150 if (kind == FontConfigIPC::METHOD_MATCH) { 150 if (kind == FontConfigIPC::METHOD_MATCH) {
151 HandleFontMatchRequest(fd, iter, fds.get()); 151 HandleFontMatchRequest(fd, pickle, iter, fds.get());
152 } else if (kind == FontConfigIPC::METHOD_OPEN) { 152 } else if (kind == FontConfigIPC::METHOD_OPEN) {
153 HandleFontOpenRequest(fd, iter, fds.get()); 153 HandleFontOpenRequest(fd, pickle, iter, fds.get());
154 } else if (kind == LinuxSandbox::METHOD_GET_FALLBACK_FONT_FOR_CHAR) { 154 } else if (kind == LinuxSandbox::METHOD_GET_FALLBACK_FONT_FOR_CHAR) {
155 HandleGetFallbackFontForChar(fd, iter, fds.get()); 155 HandleGetFallbackFontForChar(fd, pickle, iter, fds.get());
156 } else if (kind == LinuxSandbox::METHOD_LOCALTIME) { 156 } else if (kind == LinuxSandbox::METHOD_LOCALTIME) {
157 HandleLocaltime(fd, iter, fds.get()); 157 HandleLocaltime(fd, pickle, iter, fds.get());
158 } else if (kind == LinuxSandbox::METHOD_GET_STYLE_FOR_STRIKE) { 158 } else if (kind == LinuxSandbox::METHOD_GET_STYLE_FOR_STRIKE) {
159 HandleGetStyleForStrike(fd, iter, fds.get()); 159 HandleGetStyleForStrike(fd, pickle, iter, fds.get());
160 } else if (kind == LinuxSandbox::METHOD_MAKE_SHARED_MEMORY_SEGMENT) { 160 } else if (kind == LinuxSandbox::METHOD_MAKE_SHARED_MEMORY_SEGMENT) {
161 HandleMakeSharedMemorySegment(fd, iter, fds.get()); 161 HandleMakeSharedMemorySegment(fd, pickle, iter, fds.get());
162 } else if (kind == LinuxSandbox::METHOD_MATCH_WITH_FALLBACK) { 162 } else if (kind == LinuxSandbox::METHOD_MATCH_WITH_FALLBACK) {
163 HandleMatchWithFallback(fd, iter, fds.get()); 163 HandleMatchWithFallback(fd, pickle, iter, fds.get());
164 } 164 }
165 } 165 }
166 166
167 int SandboxIPCHandler::FindOrAddPath(const SkString& path) { 167 int SandboxIPCHandler::FindOrAddPath(const SkString& path) {
168 int count = paths_.count(); 168 int count = paths_.count();
169 for (int i = 0; i < count; ++i) { 169 for (int i = 0; i < count; ++i) {
170 if (path == *paths_[i]) 170 if (path == *paths_[i])
171 return i; 171 return i;
172 } 172 }
173 *paths_.append() = new SkString(path); 173 *paths_.append() = new SkString(path);
174 return count; 174 return count;
175 } 175 }
176 176
177 void SandboxIPCHandler::HandleFontMatchRequest( 177 void SandboxIPCHandler::HandleFontMatchRequest(
178 int fd, 178 int fd,
179 const Pickle& pickle,
179 PickleIterator iter, 180 PickleIterator iter,
180 const std::vector<base::ScopedFD*>& fds) { 181 const std::vector<base::ScopedFD*>& fds) {
181 uint32_t requested_style; 182 uint32_t requested_style;
182 std::string family; 183 std::string family;
183 if (!iter.ReadString(&family) || !iter.ReadUInt32(&requested_style)) 184 if (!pickle.ReadString(&iter, &family) ||
185 !pickle.ReadUInt32(&iter, &requested_style))
184 return; 186 return;
185 187
186 SkFontConfigInterface::FontIdentity result_identity; 188 SkFontConfigInterface::FontIdentity result_identity;
187 SkString result_family; 189 SkString result_family;
188 SkTypeface::Style result_style; 190 SkTypeface::Style result_style;
189 SkFontConfigInterface* fc = 191 SkFontConfigInterface* fc =
190 SkFontConfigInterface::GetSingletonDirectInterface(); 192 SkFontConfigInterface::GetSingletonDirectInterface();
191 const bool r = 193 const bool r =
192 fc->matchFamilyName(family.c_str(), 194 fc->matchFamilyName(family.c_str(),
193 static_cast<SkTypeface::Style>(requested_style), 195 static_cast<SkTypeface::Style>(requested_style),
(...skipping 13 matching lines...) Expand all
207 reply.WriteBool(true); 209 reply.WriteBool(true);
208 skia::WriteSkString(&reply, result_family); 210 skia::WriteSkString(&reply, result_family);
209 skia::WriteSkFontIdentity(&reply, result_identity); 211 skia::WriteSkFontIdentity(&reply, result_identity);
210 reply.WriteUInt32(result_style); 212 reply.WriteUInt32(result_style);
211 } 213 }
212 SendRendererReply(fds, reply, -1); 214 SendRendererReply(fds, reply, -1);
213 } 215 }
214 216
215 void SandboxIPCHandler::HandleFontOpenRequest( 217 void SandboxIPCHandler::HandleFontOpenRequest(
216 int fd, 218 int fd,
219 const Pickle& pickle,
217 PickleIterator iter, 220 PickleIterator iter,
218 const std::vector<base::ScopedFD*>& fds) { 221 const std::vector<base::ScopedFD*>& fds) {
219 uint32_t index; 222 uint32_t index;
220 if (!iter.ReadUInt32(&index)) 223 if (!pickle.ReadUInt32(&iter, &index))
221 return; 224 return;
222 if (index >= static_cast<uint32_t>(paths_.count())) 225 if (index >= static_cast<uint32_t>(paths_.count()))
223 return; 226 return;
224 const int result_fd = open(paths_[index]->c_str(), O_RDONLY); 227 const int result_fd = open(paths_[index]->c_str(), O_RDONLY);
225 228
226 Pickle reply; 229 Pickle reply;
227 if (result_fd == -1) { 230 if (result_fd == -1) {
228 reply.WriteBool(false); 231 reply.WriteBool(false);
229 } else { 232 } else {
230 reply.WriteBool(true); 233 reply.WriteBool(true);
231 } 234 }
232 235
233 // The receiver will have its own access to the file, so we will close it 236 // The receiver will have its own access to the file, so we will close it
234 // after this send. 237 // after this send.
235 SendRendererReply(fds, reply, result_fd); 238 SendRendererReply(fds, reply, result_fd);
236 239
237 if (result_fd >= 0) { 240 if (result_fd >= 0) {
238 int err = IGNORE_EINTR(close(result_fd)); 241 int err = IGNORE_EINTR(close(result_fd));
239 DCHECK(!err); 242 DCHECK(!err);
240 } 243 }
241 } 244 }
242 245
243 void SandboxIPCHandler::HandleGetFallbackFontForChar( 246 void SandboxIPCHandler::HandleGetFallbackFontForChar(
244 int fd, 247 int fd,
248 const Pickle& pickle,
245 PickleIterator iter, 249 PickleIterator iter,
246 const std::vector<base::ScopedFD*>& fds) { 250 const std::vector<base::ScopedFD*>& fds) {
247 // The other side of this call is 251 // The other side of this call is
248 // content/common/child_process_sandbox_support_impl_linux.cc 252 // content/common/child_process_sandbox_support_impl_linux.cc
249 253
250 EnsureWebKitInitialized(); 254 EnsureWebKitInitialized();
251 WebUChar32 c; 255 WebUChar32 c;
252 if (!iter.ReadInt(&c)) 256 if (!pickle.ReadInt(&iter, &c))
253 return; 257 return;
254 258
255 std::string preferred_locale; 259 std::string preferred_locale;
256 if (!iter.ReadString(&preferred_locale)) 260 if (!pickle.ReadString(&iter, &preferred_locale))
257 return; 261 return;
258 262
259 blink::WebFallbackFont fallbackFont; 263 blink::WebFallbackFont fallbackFont;
260 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont); 264 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont);
261 265
262 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data())); 266 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data()));
263 fallbackFont.fontconfigInterfaceId = pathIndex; 267 fallbackFont.fontconfigInterfaceId = pathIndex;
264 268
265 Pickle reply; 269 Pickle reply;
266 if (fallbackFont.name.data()) { 270 if (fallbackFont.name.data()) {
267 reply.WriteString(fallbackFont.name.data()); 271 reply.WriteString(fallbackFont.name.data());
268 } else { 272 } else {
269 reply.WriteString(std::string()); 273 reply.WriteString(std::string());
270 } 274 }
271 if (fallbackFont.filename.data()) { 275 if (fallbackFont.filename.data()) {
272 reply.WriteString(fallbackFont.filename.data()); 276 reply.WriteString(fallbackFont.filename.data());
273 } else { 277 } else {
274 reply.WriteString(std::string()); 278 reply.WriteString(std::string());
275 } 279 }
276 reply.WriteInt(fallbackFont.fontconfigInterfaceId); 280 reply.WriteInt(fallbackFont.fontconfigInterfaceId);
277 reply.WriteInt(fallbackFont.ttcIndex); 281 reply.WriteInt(fallbackFont.ttcIndex);
278 reply.WriteBool(fallbackFont.isBold); 282 reply.WriteBool(fallbackFont.isBold);
279 reply.WriteBool(fallbackFont.isItalic); 283 reply.WriteBool(fallbackFont.isItalic);
280 SendRendererReply(fds, reply, -1); 284 SendRendererReply(fds, reply, -1);
281 } 285 }
282 286
283 void SandboxIPCHandler::HandleGetStyleForStrike( 287 void SandboxIPCHandler::HandleGetStyleForStrike(
284 int fd, 288 int fd,
289 const Pickle& pickle,
285 PickleIterator iter, 290 PickleIterator iter,
286 const std::vector<base::ScopedFD*>& fds) { 291 const std::vector<base::ScopedFD*>& fds) {
287 std::string family; 292 std::string family;
288 bool bold, italic; 293 bool bold, italic;
289 uint16 pixel_size; 294 uint16 pixel_size;
290 295
291 if (!iter.ReadString(&family) || 296 if (!pickle.ReadString(&iter, &family) ||
292 !iter.ReadBool(&bold) || 297 !pickle.ReadBool(&iter, &bold) ||
293 !iter.ReadBool(&italic) || 298 !pickle.ReadBool(&iter, &italic) ||
294 !iter.ReadUInt16(&pixel_size)) { 299 !pickle.ReadUInt16(&iter, &pixel_size)) {
295 return; 300 return;
296 } 301 }
297 302
298 EnsureWebKitInitialized(); 303 EnsureWebKitInitialized();
299 304
300 gfx::FontRenderParamsQuery query(true); 305 gfx::FontRenderParamsQuery query(true);
301 query.families.push_back(family); 306 query.families.push_back(family);
302 query.pixel_size = pixel_size; 307 query.pixel_size = pixel_size;
303 query.style = gfx::Font::NORMAL | 308 query.style = gfx::Font::NORMAL |
304 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0); 309 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0);
305 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL); 310 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL);
306 311
307 // These are passed as ints since they're interpreted as tri-state chars in 312 // These are passed as ints since they're interpreted as tri-state chars in
308 // Blink. 313 // Blink.
309 Pickle reply; 314 Pickle reply;
310 reply.WriteInt(params.use_bitmaps); 315 reply.WriteInt(params.use_bitmaps);
311 reply.WriteInt(params.autohinter); 316 reply.WriteInt(params.autohinter);
312 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE); 317 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE);
313 reply.WriteInt(ConvertHinting(params.hinting)); 318 reply.WriteInt(ConvertHinting(params.hinting));
314 reply.WriteInt(params.antialiasing); 319 reply.WriteInt(params.antialiasing);
315 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering)); 320 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering));
316 reply.WriteInt(params.subpixel_positioning); 321 reply.WriteInt(params.subpixel_positioning);
317 322
318 SendRendererReply(fds, reply, -1); 323 SendRendererReply(fds, reply, -1);
319 } 324 }
320 325
321 void SandboxIPCHandler::HandleLocaltime( 326 void SandboxIPCHandler::HandleLocaltime(
322 int fd, 327 int fd,
328 const Pickle& pickle,
323 PickleIterator iter, 329 PickleIterator iter,
324 const std::vector<base::ScopedFD*>& fds) { 330 const std::vector<base::ScopedFD*>& fds) {
325 // The other side of this call is in zygote_main_linux.cc 331 // The other side of this call is in zygote_main_linux.cc
326 332
327 std::string time_string; 333 std::string time_string;
328 if (!iter.ReadString(&time_string) || time_string.size() != sizeof(time_t)) 334 if (!pickle.ReadString(&iter, &time_string) ||
335 time_string.size() != sizeof(time_t)) {
329 return; 336 return;
337 }
330 338
331 time_t time; 339 time_t time;
332 memcpy(&time, time_string.data(), sizeof(time)); 340 memcpy(&time, time_string.data(), sizeof(time));
333 // We use localtime here because we need the tm_zone field to be filled 341 // We use localtime here because we need the tm_zone field to be filled
334 // out. Since we are a single-threaded process, this is safe. 342 // out. Since we are a single-threaded process, this is safe.
335 const struct tm* expanded_time = localtime(&time); 343 const struct tm* expanded_time = localtime(&time);
336 344
337 std::string result_string; 345 std::string result_string;
338 const char* time_zone_string = ""; 346 const char* time_zone_string = "";
339 if (expanded_time != NULL) { 347 if (expanded_time != NULL) {
340 result_string = std::string(reinterpret_cast<const char*>(expanded_time), 348 result_string = std::string(reinterpret_cast<const char*>(expanded_time),
341 sizeof(struct tm)); 349 sizeof(struct tm));
342 time_zone_string = expanded_time->tm_zone; 350 time_zone_string = expanded_time->tm_zone;
343 } 351 }
344 352
345 Pickle reply; 353 Pickle reply;
346 reply.WriteString(result_string); 354 reply.WriteString(result_string);
347 reply.WriteString(time_zone_string); 355 reply.WriteString(time_zone_string);
348 SendRendererReply(fds, reply, -1); 356 SendRendererReply(fds, reply, -1);
349 } 357 }
350 358
351 void SandboxIPCHandler::HandleMakeSharedMemorySegment( 359 void SandboxIPCHandler::HandleMakeSharedMemorySegment(
352 int fd, 360 int fd,
361 const Pickle& pickle,
353 PickleIterator iter, 362 PickleIterator iter,
354 const std::vector<base::ScopedFD*>& fds) { 363 const std::vector<base::ScopedFD*>& fds) {
355 base::SharedMemoryCreateOptions options; 364 base::SharedMemoryCreateOptions options;
356 uint32_t size; 365 uint32_t size;
357 if (!iter.ReadUInt32(&size)) 366 if (!pickle.ReadUInt32(&iter, &size))
358 return; 367 return;
359 options.size = size; 368 options.size = size;
360 if (!iter.ReadBool(&options.executable)) 369 if (!pickle.ReadBool(&iter, &options.executable))
361 return; 370 return;
362 int shm_fd = -1; 371 int shm_fd = -1;
363 base::SharedMemory shm; 372 base::SharedMemory shm;
364 if (shm.Create(options)) 373 if (shm.Create(options))
365 shm_fd = shm.handle().fd; 374 shm_fd = shm.handle().fd;
366 Pickle reply; 375 Pickle reply;
367 SendRendererReply(fds, reply, shm_fd); 376 SendRendererReply(fds, reply, shm_fd);
368 } 377 }
369 378
370 void SandboxIPCHandler::HandleMatchWithFallback( 379 void SandboxIPCHandler::HandleMatchWithFallback(
371 int fd, 380 int fd,
381 const Pickle& pickle,
372 PickleIterator iter, 382 PickleIterator iter,
373 const std::vector<base::ScopedFD*>& fds) { 383 const std::vector<base::ScopedFD*>& fds) {
374 std::string face; 384 std::string face;
375 bool is_bold, is_italic; 385 bool is_bold, is_italic;
376 uint32 charset, fallback_family; 386 uint32 charset, fallback_family;
377 387
378 if (!iter.ReadString(&face) || face.empty() || 388 if (!pickle.ReadString(&iter, &face) || face.empty() ||
379 !iter.ReadBool(&is_bold) || 389 !pickle.ReadBool(&iter, &is_bold) ||
380 !iter.ReadBool(&is_italic) || 390 !pickle.ReadBool(&iter, &is_italic) ||
381 !iter.ReadUInt32(&charset) || 391 !pickle.ReadUInt32(&iter, &charset) ||
382 !iter.ReadUInt32(&fallback_family)) { 392 !pickle.ReadUInt32(&iter, &fallback_family)) {
383 return; 393 return;
384 } 394 }
385 395
386 int font_fd = MatchFontFaceWithFallback( 396 int font_fd = MatchFontFaceWithFallback(
387 face, is_bold, is_italic, charset, fallback_family); 397 face, is_bold, is_italic, charset, fallback_family);
388 398
389 Pickle reply; 399 Pickle reply;
390 SendRendererReply(fds, reply, font_fd); 400 SendRendererReply(fds, reply, font_fd);
391 401
392 if (font_fd >= 0) { 402 if (font_fd >= 0) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 453 }
444 454
445 void SandboxIPCHandler::EnsureWebKitInitialized() { 455 void SandboxIPCHandler::EnsureWebKitInitialized() {
446 if (blink_platform_impl_) 456 if (blink_platform_impl_)
447 return; 457 return;
448 blink_platform_impl_.reset(new BlinkPlatformImpl); 458 blink_platform_impl_.reset(new BlinkPlatformImpl);
449 blink::initializeWithoutV8(blink_platform_impl_.get()); 459 blink::initializeWithoutV8(blink_platform_impl_.get());
450 } 460 }
451 461
452 } // namespace content 462 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/sandbox_ipc_linux.h ('k') | content/browser/web_contents/web_contents_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698