auto merge of #4044 : zmike/servo/embedding-process, r=jdm

Fixes #4023 

@SimonSapin @jdm
This commit is contained in:
bors-servo 2014-11-20 13:06:32 -07:00
commit 133b523d2b
4 changed files with 141 additions and 1 deletions

View file

@ -6,11 +6,14 @@
use command_line::command_line_init;
use geom::size::TypedSize2D;
use glfw_app;
use libc::funcs::c95::string::strlen;
use libc::{c_int, c_void};
use native;
use servo::Browser;
use servo_util::opts;
use servo_util::opts::OpenGL;
use std::slice;
use switches::{KPROCESSTYPE, KWAITFORDEBUGGER};
use types::{cef_app_t, cef_main_args_t, cef_settings_t};
#[no_mangle]
@ -84,9 +87,31 @@ pub extern "C" fn cef_quit_message_loop() {
}
#[no_mangle]
pub extern "C" fn cef_execute_process(_args: *const cef_main_args_t,
pub extern "C" fn cef_execute_process(args: *const cef_main_args_t,
_app: *mut cef_app_t,
_windows_sandbox_info: *mut c_void)
-> c_int {
unsafe {
if args.is_null() {
println!("args must be passed");
return -1;
}
for i in range(0u, (*args).argc as uint) {
let u = (*args).argv.offset(i as int) as *const u8;
slice::raw::buf_as_slice(u, strlen(u as *const i8) as uint, |s| {
if s.starts_with("--".as_bytes()) {
if s.slice_from(2) == KWAITFORDEBUGGER.as_bytes() {
//FIXME: this is NOT functionally equivalent to chromium!
//this should be a pause() call with an installed signal
//handler callback, something which is impossible now in rust
} else if s.slice_from(2) == KPROCESSTYPE.as_bytes() {
//TODO: run other process now
}
}
});
}
}
//process type not specified, must be browser process (NOOP)
-1
}

View file

@ -54,6 +54,7 @@ pub mod string;
pub mod string_list;
pub mod string_map;
pub mod string_multimap;
pub mod switches;
pub mod task;
pub mod types;
pub mod urlrequest;

View file

@ -7,6 +7,7 @@ use eutil::slice_to_str;
use libc::{size_t, c_int, c_ushort,c_void};
use libc::types::os::arch::c95::wchar_t;
use mem::{new0,newarray0,delete,deletearray};
use std::char;
use std::mem;
use std::ptr;
use std::slice;
@ -222,3 +223,60 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp
}
return 1;
}
#[no_mangle]
pub extern "C" fn cef_string_wide_cmp(a: *const cef_string_wide_t, b: *const cef_string_wide_t) -> c_int {
unsafe {
slice::raw::buf_as_slice((*a).str as *const wchar_t, (*a).length as uint, |astr:&[wchar_t]| {
slice::raw::buf_as_slice((*b).str as *const wchar_t, (*b).length as uint, |bstr:&[wchar_t]| {
match astr.cmp(bstr) {
Less => -1,
Equal => 0,
Greater => 1
}
})
})
}
}
#[no_mangle]
pub extern "C" fn cef_string_utf8_to_wide(src: *const u8, src_len: size_t, output: *mut cef_string_wide_t) -> c_int {
if mem::size_of::<wchar_t>() == mem::size_of::<u16>() {
return cef_string_utf8_to_utf16(src, src_len, output as *mut cef_string_utf16_t);
}
slice_to_str(src, src_len as uint, |result| {
let conv = result.chars().map(|c| c as u32).collect::<Vec<u32>>();
cef_string_wide_set(conv.as_ptr() as *const wchar_t, conv.len() as size_t, output, 1)
})
}
#[no_mangle]
pub extern "C" fn cef_string_wide_to_utf8(src: *const wchar_t, src_len: size_t, output: *mut cef_string_utf8_t) -> c_int {
if mem::size_of::<wchar_t>() == mem::size_of::<u16>() {
return cef_string_utf16_to_utf8(src as *const u16, src_len, output);
}
unsafe {
slice::raw::buf_as_slice(src, src_len as uint, |ustr| {
let conv = ustr.iter().map(|&c| char::from_u32(c as u32).unwrap_or('\uFFFD')).collect::<String>();
cef_string_utf8_set(conv.as_bytes().as_ptr(), conv.len() as size_t, output, 1)
})
}
}
#[no_mangle]
pub extern "C" fn cef_string_ascii_to_utf16(src: *const u8, src_len: size_t, output: *mut cef_string_utf16_t) -> c_int {
slice_to_str(src, src_len as uint, |result| {
let conv = result.utf16_units().collect::<Vec<u16>>();
cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1)
})
}
#[no_mangle]
pub extern "C" fn cef_string_ascii_to_wide(src: *const u8, src_len: size_t, output: *mut cef_string_wide_t) -> c_int {
unsafe {
slice::raw::buf_as_slice(src, src_len as uint, |ustr| {
let conv = ustr.iter().map(|&c| c as u8).collect::<Vec<u8>>();
cef_string_wide_set(conv.as_ptr() as *const wchar_t, conv.len() as size_t, output, 1)
})
}
}

56
ports/cef/switches.rs Normal file
View file

@ -0,0 +1,56 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// values taken from chromium/base/base_switches.cc
// Disables the crash reporting.
pub static KDISABLEBREAKPAD: &'static str = "disable-breakpad";
// Indicates that crash reporting should be enabled. On platforms where helper
// processes cannot access to files needed to make this decision, this flag is
// generated internally.
pub static KENABLECRASHREPORTER: &'static str = "enable-crash-reporter";
// Generates full memory crash dump.
pub static KFULLMEMORYCRASHREPORT: &'static str = "full-memory-crash-report";
// The value of this switch determines whether the process is started as a
// renderer or plugin host. If it's empty, it's the browser.
pub static KPROCESSTYPE: &'static str = "type";
// Suppresses all error dialogs when present.
pub static KNOERRDIALOGS: &'static str = "noerrdialogs";
// When running certain tests that spawn child processes, this switch indicates
// to the test framework that the current process is a child process.
pub static KTESTCHILDPROCESS: &'static str = "test-child-process";
// Gives the default maximal active V-logging level; 0 is the default.
// Normally positive values are used for V-logging levels.
pub static KV: &'static str = "v";
// Gives the per-module maximal V-logging levels to override the value
// given by --v. E.g. "my_module=2,foo*=3" would change the logging
// level for all code in source files "my_module.*" and "foo*.*"
// ("-inl" suffixes are also disregarded for this matching).
//
// Any pattern containing a forward or backward slash will be tested
// against the whole pathname and not just the module. E.g.,
// "*/foo/bar/*=2" would change the logging level for all code in
// source files under a "foo/bar" directory.
pub static KVMODULE: &'static str = "vmodule";
// Will wait for 60 seconds for a debugger to come to attach to the process.
pub static KWAITFORDEBUGGER: &'static str = "wait-for-debugger";
// Sends a pretty-printed version of tracing info to the console.
pub static KTRACETOCONSOLE: &'static str = "trace-to-console";
// Configure whether chrome://profiler will contain timing information. This
// option is enabled by default. A value of "0" will disable profiler timing,
// while all other values will enable it.
pub static KPROFILERTIMING: &'static str = "profiler-timing";
// Value of the --profiler-timing flag that will disable timing information for
// chrome://profiler.
pub static KPROFILERTIMINGDISABLEDVALUE: &'static str = "0";