servo: Merge #4044 - Embedding process (from zmike:embedding-process); r=jdm
authorMike Blumenkrantz <zmike@osg.samsung.com>
Thu, 20 Nov 2014 13:06:32 -0700
changeset 381951 d842b6782535aecb1db9a89d8cd59701f6caea4e
parent 381950 cbcb99163696e1a76bcc5550f7691f62d9521bae
child 381952 317cb5792614b6ab8a04b546d38811ac51e6649a
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #4044 - Embedding process (from zmike:embedding-process); r=jdm Fixes #4023 @SimonSapin @jdm Source-Repo: https://github.com/servo/servo Source-Revision: 133b523d2b3a95796e66e77fe6962abf79c3a4c7
servo/ports/cef/core.rs
servo/ports/cef/lib.rs
servo/ports/cef/string.rs
servo/ports/cef/switches.rs
--- a/servo/ports/cef/core.rs
+++ b/servo/ports/cef/core.rs
@@ -1,21 +1,24 @@
 /* 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/. */
 
 
 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]
 pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
                                  _settings: *mut cef_settings_t,
                                  application: *mut cef_app_t,
                                  _windows_sandbox_info: *const c_void)
                                  -> c_int {
@@ -79,14 +82,36 @@ pub extern "C" fn cef_run_message_loop()
     });
 }
 
 #[no_mangle]
 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
 }
--- a/servo/ports/cef/lib.rs
+++ b/servo/ports/cef/lib.rs
@@ -49,12 +49,13 @@ pub mod core;
 pub mod eutil;
 #[cfg(any(target_os="linux",target_os="macos"))]
 pub mod mem;
 pub mod request;
 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;
 
--- a/servo/ports/cef/string.rs
+++ b/servo/ports/cef/string.rs
@@ -2,16 +2,17 @@
  * 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/. */
 
 
 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;
 use std::string;
 use types::{cef_string_utf16_t, cef_string_utf8_t, cef_string_wide_t};
 use types::{cef_string_userfree_utf16_t, cef_string_userfree_utf8_t, cef_string_userfree_wide_t};
 
 //cef_string
@@ -217,8 +218,65 @@ pub extern "C" fn cef_string_wide_set(sr
        } else {
          (*output).str = mem::transmute(src);
          (*output).length = src_len;
          (*output).dtor = mem::transmute(0 as *const u8);
        }
     }
     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)
+        })
+    }
+}
new file mode 100644
--- /dev/null
+++ b/servo/ports/cef/switches.rs
@@ -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";