From 3bf779cd21f42f488c6590d681b61f860e635692 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 24 Nov 2014 17:23:30 -0800 Subject: [PATCH 1/5] ports/cef: Use the CEF translator tool to generate the full set of CEF bindings. This replaces hand-implemented CEF bindings with proper Rust wrappers automatically generated from the C++ headers. This means that, whenever CEF's C++ headers change, we can easily generate both the appropriate C API and the appropriate Rust API. It eliminates much of the hand-written unsafe code within the CEF port, because the CEF translator tool now knows how to generate Rust smart pointer wrappers for each class that corrently perform reference counting. Additionally, this commit adds utility macros (located in `macros.rs`) that make it easier to correctly expose Rust objects as CEF objects. They handle the marshaling of objects between Rust and CEF properly. The net result of this is that you can write mostly-natural-looking Rust in the CEF port and interact with it with a natural-looking C++ API on the embedding side. This setup relies on the branch of CEF located here: https://github.com/pcwalton/chromium-embedded-framework To regenerate, follow the instructions in `ports/cef/README.md`. For convenience, and because I don't anticipate the API to change much, I have vendored in all of the appropriate interfaces. --- ports/cef/README.md | 9 + ports/cef/browser.rs | 165 +- ports/cef/command_line.rs | 28 +- ports/cef/cookie.rs | 16 + ports/cef/core.rs | 51 +- ports/cef/drag_data.rs | 10 + ports/cef/eutil.rs | 69 +- ports/cef/interfaces/cef_app.rs | 305 ++ ports/cef/interfaces/cef_auth_callback.rs | 206 ++ ports/cef/interfaces/cef_browser.rs | 2033 ++++++++++++ .../interfaces/cef_browser_process_handler.rs | 272 ++ ports/cef/interfaces/cef_callback.rs | 336 ++ ports/cef/interfaces/cef_client.rs | 463 +++ ports/cef/interfaces/cef_command_line.rs | 643 ++++ .../interfaces/cef_context_menu_handler.rs | 825 +++++ ports/cef/interfaces/cef_cookie.rs | 560 ++++ ports/cef/interfaces/cef_dialog_handler.rs | 374 +++ ports/cef/interfaces/cef_display_handler.rs | 303 ++ ports/cef/interfaces/cef_dom.rs | 1295 ++++++++ ports/cef/interfaces/cef_download_handler.rs | 519 +++ ports/cef/interfaces/cef_download_item.rs | 495 +++ ports/cef/interfaces/cef_drag_data.rs | 653 ++++ ports/cef/interfaces/cef_drag_handler.rs | 197 ++ ports/cef/interfaces/cef_focus_handler.rs | 242 ++ ports/cef/interfaces/cef_frame.rs | 687 ++++ ports/cef/interfaces/cef_geolocation.rs | 189 ++ .../cef/interfaces/cef_geolocation_handler.rs | 377 +++ ports/cef/interfaces/cef_jsdialog_handler.rs | 455 +++ ports/cef/interfaces/cef_keyboard_handler.rs | 230 ++ ports/cef/interfaces/cef_life_span_handler.rs | 433 +++ ports/cef/interfaces/cef_load_handler.rs | 307 ++ ports/cef/interfaces/cef_menu_model.rs | 1341 ++++++++ ports/cef/interfaces/cef_origin_whitelist.rs | 46 + ports/cef/interfaces/cef_path_util.rs | 46 + ports/cef/interfaces/cef_print_handler.rs | 562 ++++ ports/cef/interfaces/cef_print_settings.rs | 668 ++++ ports/cef/interfaces/cef_process_message.rs | 279 ++ ports/cef/interfaces/cef_process_util.rs | 46 + ports/cef/interfaces/cef_render_handler.rs | 554 ++++ .../interfaces/cef_render_process_handler.rs | 492 +++ ports/cef/interfaces/cef_request.rs | 1088 +++++++ ports/cef/interfaces/cef_request_context.rs | 272 ++ .../interfaces/cef_request_context_handler.rs | 184 ++ ports/cef/interfaces/cef_request_handler.rs | 841 +++++ .../interfaces/cef_resource_bundle_handler.rs | 231 ++ ports/cef/interfaces/cef_resource_handler.rs | 340 ++ ports/cef/interfaces/cef_response.rs | 387 +++ ports/cef/interfaces/cef_scheme.rs | 434 +++ ports/cef/interfaces/cef_stream.rs | 1019 ++++++ ports/cef/interfaces/cef_string_visitor.rs | 183 ++ ports/cef/interfaces/cef_task.rs | 461 +++ ports/cef/interfaces/cef_trace.rs | 192 ++ ports/cef/interfaces/cef_url.rs | 46 + ports/cef/interfaces/cef_urlrequest.rs | 599 ++++ ports/cef/interfaces/cef_v8.rs | 2888 +++++++++++++++++ ports/cef/interfaces/cef_values.rs | 1685 ++++++++++ ports/cef/interfaces/cef_web_plugin.rs | 544 ++++ ports/cef/interfaces/cef_xml_reader.rs | 856 +++++ ports/cef/interfaces/cef_zip_reader.rs | 445 +++ ports/cef/interfaces/mod.rs | 148 + ports/cef/lib.rs | 19 +- ports/cef/macros.rs | 122 + ports/cef/mem.rs | 61 - ports/cef/print_settings.rs | 9 + ports/cef/process_message.rs | 11 + ports/cef/request.rs | 19 +- ports/cef/request_context.rs | 12 + ports/cef/response.rs | 10 + ports/cef/stream.rs | 23 + ports/cef/string.rs | 81 +- ports/cef/string_list.rs | 10 +- ports/cef/string_map.rs | 18 +- ports/cef/string_multimap.rs | 17 +- ports/cef/stubs.rs | 53 + ports/cef/task.rs | 10 +- ports/cef/types.rs | 2184 +++++-------- ports/cef/urlrequest.rs | 4 +- ports/cef/v8.rs | 29 + ports/cef/values.rs | 14 + ports/cef/wrappers.rs | 227 ++ ports/cef/xml_reader.rs | 14 + ports/cef/zip_reader.rs | 10 + 82 files changed, 30917 insertions(+), 1664 deletions(-) create mode 100644 ports/cef/cookie.rs create mode 100644 ports/cef/drag_data.rs create mode 100644 ports/cef/interfaces/cef_app.rs create mode 100644 ports/cef/interfaces/cef_auth_callback.rs create mode 100644 ports/cef/interfaces/cef_browser.rs create mode 100644 ports/cef/interfaces/cef_browser_process_handler.rs create mode 100644 ports/cef/interfaces/cef_callback.rs create mode 100644 ports/cef/interfaces/cef_client.rs create mode 100644 ports/cef/interfaces/cef_command_line.rs create mode 100644 ports/cef/interfaces/cef_context_menu_handler.rs create mode 100644 ports/cef/interfaces/cef_cookie.rs create mode 100644 ports/cef/interfaces/cef_dialog_handler.rs create mode 100644 ports/cef/interfaces/cef_display_handler.rs create mode 100644 ports/cef/interfaces/cef_dom.rs create mode 100644 ports/cef/interfaces/cef_download_handler.rs create mode 100644 ports/cef/interfaces/cef_download_item.rs create mode 100644 ports/cef/interfaces/cef_drag_data.rs create mode 100644 ports/cef/interfaces/cef_drag_handler.rs create mode 100644 ports/cef/interfaces/cef_focus_handler.rs create mode 100644 ports/cef/interfaces/cef_frame.rs create mode 100644 ports/cef/interfaces/cef_geolocation.rs create mode 100644 ports/cef/interfaces/cef_geolocation_handler.rs create mode 100644 ports/cef/interfaces/cef_jsdialog_handler.rs create mode 100644 ports/cef/interfaces/cef_keyboard_handler.rs create mode 100644 ports/cef/interfaces/cef_life_span_handler.rs create mode 100644 ports/cef/interfaces/cef_load_handler.rs create mode 100644 ports/cef/interfaces/cef_menu_model.rs create mode 100644 ports/cef/interfaces/cef_origin_whitelist.rs create mode 100644 ports/cef/interfaces/cef_path_util.rs create mode 100644 ports/cef/interfaces/cef_print_handler.rs create mode 100644 ports/cef/interfaces/cef_print_settings.rs create mode 100644 ports/cef/interfaces/cef_process_message.rs create mode 100644 ports/cef/interfaces/cef_process_util.rs create mode 100644 ports/cef/interfaces/cef_render_handler.rs create mode 100644 ports/cef/interfaces/cef_render_process_handler.rs create mode 100644 ports/cef/interfaces/cef_request.rs create mode 100644 ports/cef/interfaces/cef_request_context.rs create mode 100644 ports/cef/interfaces/cef_request_context_handler.rs create mode 100644 ports/cef/interfaces/cef_request_handler.rs create mode 100644 ports/cef/interfaces/cef_resource_bundle_handler.rs create mode 100644 ports/cef/interfaces/cef_resource_handler.rs create mode 100644 ports/cef/interfaces/cef_response.rs create mode 100644 ports/cef/interfaces/cef_scheme.rs create mode 100644 ports/cef/interfaces/cef_stream.rs create mode 100644 ports/cef/interfaces/cef_string_visitor.rs create mode 100644 ports/cef/interfaces/cef_task.rs create mode 100644 ports/cef/interfaces/cef_trace.rs create mode 100644 ports/cef/interfaces/cef_url.rs create mode 100644 ports/cef/interfaces/cef_urlrequest.rs create mode 100644 ports/cef/interfaces/cef_v8.rs create mode 100644 ports/cef/interfaces/cef_values.rs create mode 100644 ports/cef/interfaces/cef_web_plugin.rs create mode 100644 ports/cef/interfaces/cef_xml_reader.rs create mode 100644 ports/cef/interfaces/cef_zip_reader.rs create mode 100644 ports/cef/interfaces/mod.rs create mode 100644 ports/cef/macros.rs delete mode 100644 ports/cef/mem.rs create mode 100644 ports/cef/print_settings.rs create mode 100644 ports/cef/process_message.rs create mode 100644 ports/cef/request_context.rs create mode 100644 ports/cef/response.rs create mode 100644 ports/cef/stream.rs create mode 100644 ports/cef/stubs.rs create mode 100644 ports/cef/v8.rs create mode 100644 ports/cef/values.rs create mode 100644 ports/cef/wrappers.rs create mode 100644 ports/cef/xml_reader.rs create mode 100644 ports/cef/zip_reader.rs diff --git a/ports/cef/README.md b/ports/cef/README.md index a8ffd07fc82..1832ffef781 100644 --- a/ports/cef/README.md +++ b/ports/cef/README.md @@ -10,3 +10,12 @@ How to test: Notes: * Running with the Debug build in GDB is EXTREMELY slow on startup. Only use this if you are actively debugging an unimplemented CEF interaction. +* The contents of `interfaces/`, with the exception of `interfaces/mod.rs` is autogenerated. To + regenerate: + - Check out the `servo` branch of the following repository: + https://github.com/pcwalton/chromium-embedded-framework + - Change to the `tools` directory and run `./translator.sh` + - Run the following command to copy in the Rust header files, replacing `${SERVO_SRC}` with + the path to your Servo checkout: + $ cp ../libcef_dll/rust/*.rs ${SERVO_SRC}/ports/cef/interfaces/ + diff --git a/ports/cef/browser.rs b/ports/cef/browser.rs index 432228ba1d0..fa018079e2b 100644 --- a/ports/cef/browser.rs +++ b/ports/cef/browser.rs @@ -2,95 +2,102 @@ * 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 compositing::windowing::{WindowMethods}; +use interfaces::{CefBrowser, CefClient, CefRequestContext, cef_browser_t, cef_client_t}; +use interfaces::{cef_request_context_t}; +use types::{cef_browser_settings_t, cef_string_t, cef_window_info_t}; + +use eutil::Downcast; use glfw_app; -use libc::{calloc, size_t,c_int}; +use libc::c_int; use servo::Browser; use servo_util::opts; -use std::cell::RefCell; -use std::mem; +use std::cell::{Cell, RefCell}; use std::rc::Rc; -use std::string; -use types::{cef_browser_settings_t, cef_browser_t, cef_client_t, cef_request_context_t, cef_string_t, cef_window_info_t}; -pub type servo_browser_t = servo_browser; -pub struct servo_browser { - pub browser: cef_browser_t, - pub client: *mut cef_client_t, - pub servo_browser: Option>, - pub window: Rc, - pub callback_executed: bool +pub struct ServoCefBrowser { + pub client: CefClient, + pub servo_browser: RefCell>>, + pub window: RefCell>>, + pub callback_executed: Cell, } -local_data_key!(pub GLOBAL_BROWSERS: RefCell>) - -pub fn browser_callback_after_created(browser: *mut servo_browser_t) { - unsafe { - if (*browser).client.is_null() { return; } - let client = (*browser).client; - (*client).get_life_span_handler.map(|cb| { - let handler = cb(client); - if handler.is_not_null() { - (*handler).on_after_created.map(|createcb| createcb(handler, browser as *mut cef_browser_t)); - } - }); - (*browser).callback_executed = true; +impl ServoCefBrowser { + pub fn new(client: CefClient) -> ServoCefBrowser { + ServoCefBrowser { + client: client, + servo_browser: RefCell::new(None), + window: RefCell::new(None), + callback_executed: Cell::new(false), + } } } -fn browser_host_create(_window_info: *const cef_window_info_t, - client: *mut cef_client_t, - url: *const cef_string_t, - _settings: *const cef_browser_settings_t, - _request_context: *mut cef_request_context_t, - callback_executed: bool) - -> *mut cef_browser_t { - unsafe { - let mut urls = Vec::new(); - if url.is_null() || (*url).str.is_null() { - urls.push("http://s27.postimg.org/vqbtrolyr/servo.jpg".to_string()); - } else { - urls.push(string::raw::from_buf((*url).str as *const u8)); +cef_class_impl! { + ServoCefBrowser : CefBrowser, cef_browser_t {} +} + +local_data_key!(pub GLOBAL_BROWSERS: RefCell>) + +pub fn browser_callback_after_created(browser: CefBrowser) { + if browser.downcast().client.is_null_cef_object() { + return + } + let client = browser.downcast().client.clone(); + let life_span_handler = client.get_life_span_handler(); + if life_span_handler.is_not_null_cef_object() { + life_span_handler.on_after_created(browser.clone()); + } + browser.downcast().callback_executed.set(true); +} + +fn browser_host_create(client: CefClient, callback_executed: bool) -> CefBrowser { + let mut urls = Vec::new(); + urls.push("http://s27.postimg.org/vqbtrolyr/servo.jpg".to_string()); + let mut opts = opts::default_opts(); + opts.urls = urls; + let browser = ServoCefBrowser::new(client).as_cef_interface(); + if callback_executed { + browser_callback_after_created(browser.clone()); + } + match GLOBAL_BROWSERS.replace(None) { + Some(brs) => { + brs.borrow_mut().push(browser.clone()); + GLOBAL_BROWSERS.replace(Some(brs)); + }, + None => { + let brs = RefCell::new(vec!(browser.clone())); + GLOBAL_BROWSERS.replace(Some(brs)); } - let mut opts = opts::default_opts(); - opts.urls = urls; - let browser = calloc(1, mem::size_of::() as size_t) as *mut servo_browser_t; - (*browser).browser.base.size = mem::size_of::() as size_t; - (*browser).client = client; - if callback_executed { - browser_callback_after_created(browser); - } - match GLOBAL_BROWSERS.replace(None) { - Some(brs) => { - brs.borrow_mut().push(browser); - GLOBAL_BROWSERS.replace(Some(brs)); - }, - None => { - let brs = RefCell::new(vec!(browser)); - GLOBAL_BROWSERS.replace(Some(brs)); - } - } - browser as *mut cef_browser_t + } + browser +} + +cef_static_method_impls! { + fn cef_browser_host_create_browser(_window_info: *const cef_window_info_t, + client: *mut cef_client_t, + _url: *const cef_string_t, + _browser_settings: *const cef_browser_settings_t, + _request_context: *mut cef_request_context_t) + -> c_int { + let _window_info: &cef_window_info_t = _window_info; + let client: CefClient = client; + let _url: &str = _url; + let _browser_settings: &cef_browser_settings_t = _browser_settings; + let _request_context: CefRequestContext = _request_context; + browser_host_create(client, false); + 1i32 + } + fn cef_browser_host_create_browser_sync(_window_info: *const cef_window_info_t, + client: *mut cef_client_t, + _url: *const cef_string_t, + _browser_settings: *const cef_browser_settings_t, + _request_context: *mut cef_request_context_t) + -> *mut cef_browser_t { + let _window_info: &cef_window_info_t = _window_info; + let client: CefClient = client; + let _url: &str = _url; + let _browser_settings: &cef_browser_settings_t = _browser_settings; + let _request_context: CefRequestContext = _request_context; + browser_host_create(client, true) } } - -#[no_mangle] -pub extern "C" fn cef_browser_host_create_browser(window_info: *const cef_window_info_t, - client: *mut cef_client_t, - url: *const cef_string_t, - settings: *const cef_browser_settings_t, - request_context: *mut cef_request_context_t) - -> c_int { - browser_host_create(window_info, client, url, settings, request_context, false); - 1 -} - -#[no_mangle] -pub extern "C" fn cef_browser_host_create_browser_sync(window_info: *const cef_window_info_t, - client: *mut cef_client_t, - url: *const cef_string_t, - settings: *const cef_browser_settings_t, - request_context: *mut cef_request_context_t) - -> *mut cef_browser_t { - browser_host_create(window_info, client, url, settings, request_context, true) -} diff --git a/ports/cef/command_line.rs b/ports/cef/command_line.rs index f8116f762ed..ed3578dfbcd 100644 --- a/ports/cef/command_line.rs +++ b/ports/cef/command_line.rs @@ -2,12 +2,15 @@ * 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 interfaces::cef_command_line_t; + use libc::{calloc, c_int, size_t}; use std::mem; use std::string; use std::c_vec::CVec; -use string::{cef_string_userfree_utf16_alloc, cef_string_utf16_set}; -use types::{cef_command_line_t, cef_string_t, cef_string_userfree_t, cef_string_utf16_t}; +use string as cef_string; +use string::cef_string_utf16_set; +use types::{cef_string_t, cef_string_userfree_t, cef_string_utf16_t}; type command_line_t = command_line; struct command_line { @@ -41,9 +44,9 @@ pub fn command_line_init(argc: c_int, argv: *const *const u8) { } #[no_mangle] -pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, name: *const cef_string_t) -> *mut cef_string_userfree_t { +pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, name: *const cef_string_t) -> cef_string_userfree_t { if cmd.is_null() || name.is_null() { - return 0 as *mut cef_string_userfree_t; + return cef_string::empty_utf16_string() } unsafe { //technically cef_string_t can be any type of character size @@ -56,16 +59,19 @@ pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, na let o = s.as_slice().trim_left_chars('-'); //debug!("arg: {}", o); if o.as_slice().starts_with(opt.as_slice()) { - let string = cef_string_userfree_utf16_alloc() as *mut cef_string_utf16_t; + let mut string = mem::uninitialized(); let arg = o.slice_from(opt.len() + 1).as_bytes(); arg.with_c_str(|c_str| { - cef_string_utf16_set(mem::transmute(c_str), arg.len() as size_t, string, 1); + cef_string_utf16_set(mem::transmute(c_str), + arg.len() as size_t, + &mut string, + 1); }); - return string as *mut cef_string_userfree_t + return string } } } - return 0 as *mut cef_string_userfree_t; + return cef_string::empty_utf16_string() } #[no_mangle] @@ -90,3 +96,9 @@ pub extern "C" fn cef_command_line_get_global() -> *mut cef_command_line_t { } } } + +cef_stub_static_method_impls! { + fn cef_command_line_create_command_line() -> *mut cef_command_line_t; + fn cef_command_line_get_global_command_line() -> *mut cef_command_line_t; +} + diff --git a/ports/cef/cookie.rs b/ports/cef/cookie.rs new file mode 100644 index 00000000000..c1290767430 --- /dev/null +++ b/ports/cef/cookie.rs @@ -0,0 +1,16 @@ +/* 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 interfaces::cef_cookie_manager_t; +use types::cef_string_t; + +use libc::c_int; + +cef_stub_static_method_impls! { + fn cef_cookie_manager_get_global_manager() -> *mut cef_cookie_manager_t; + fn cef_cookie_manager_create_manager(path: *const cef_string_t, + persist_session_cookies: c_int) + -> *mut cef_cookie_manager_t; +} + diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 5c4d5b8f6de..bb0a92c071a 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -4,14 +4,17 @@ use browser::{GLOBAL_BROWSERS, browser_callback_after_created}; use command_line::command_line_init; +use interfaces::cef_app_t; +use eutil::Downcast; +use switches::{KPROCESSTYPE, KWAITFORDEBUGGER}; +use types::{cef_main_args_t, cef_settings_t}; + use glfw_app; use libc::funcs::c95::string::strlen; use libc::{c_int, c_void}; use native; use servo::Browser; 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, @@ -42,22 +45,36 @@ pub extern "C" fn cef_shutdown() { pub extern "C" fn cef_run_message_loop() { native::start(0, 0 as *const *const u8, proc() { GLOBAL_BROWSERS.get().map(|refcellbrowsers| { - unsafe { - let browsers = refcellbrowsers.borrow(); - let mut num = browsers.len(); - for active_browser in browsers.iter() { - (**active_browser).window = glfw_app::create_window(); - (**active_browser).servo_browser = Some(Browser::new(Some((**active_browser).window.clone()))); - if !(**active_browser).callback_executed { browser_callback_after_created(*active_browser); } + let browsers = refcellbrowsers.borrow(); + let mut num = browsers.len(); + for active_browser in browsers.iter() { + *active_browser.downcast().window.borrow_mut() = + Some(glfw_app::create_window()); + *active_browser.downcast().servo_browser.borrow_mut() = + Some(Browser::new((*active_browser.downcast() + .window + .borrow()).clone())); + if !active_browser.downcast().callback_executed.get() { + browser_callback_after_created((*active_browser).clone()); } - while num > 0 { - for active_browser in browsers.iter().filter(|&active_browser| (**active_browser).servo_browser.is_some()) { - let ref mut browser = **active_browser; - let mut servobrowser = browser.servo_browser.take().unwrap(); - if !servobrowser.handle_event(browser.window.wait_events()) { - servobrowser.shutdown(); - num -= 1; - } + } + while num > 0 { + for active_browser in browsers.iter() + .filter(|&active_browser| { + active_browser.downcast() + .servo_browser + .borrow() + .is_some() + }) { + let ref mut browser = active_browser.downcast(); + let mut servobrowser = browser.servo_browser.borrow_mut().take().unwrap(); + if !servobrowser.handle_event(browser.window + .borrow_mut() + .as_ref() + .unwrap() + .wait_events()) { + servobrowser.shutdown(); + num -= 1; } } } diff --git a/ports/cef/drag_data.rs b/ports/cef/drag_data.rs new file mode 100644 index 00000000000..4285f204b64 --- /dev/null +++ b/ports/cef/drag_data.rs @@ -0,0 +1,10 @@ +/* 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 interfaces::{cef_drag_data_t}; + +cef_stub_static_method_impls! { + fn cef_drag_data_create() -> *mut cef_drag_data_t; +} + diff --git a/ports/cef/eutil.rs b/ports/cef/eutil.rs index be0052bdfef..bde30231fcd 100644 --- a/ports/cef/eutil.rs +++ b/ports/cef/eutil.rs @@ -2,10 +2,23 @@ * 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 libc::c_int; +use types::cef_base_t; + +use libc::{mod, c_int, c_void, size_t}; +use std::mem; use std::slice; use std::str; +/// Allows you to downcast a CEF interface to a CEF class instance. +/// +/// FIXME(pcwalton): This is currently unsafe. I think the right way to make this safe is to (a) +/// forbid more than one Rust implementation of a given interface (easy to do by manufacturing an +/// impl that will conflict if there is more than one) and then (b) add a dynamic check to make +/// sure the `release` for the object is equal to `servo_release`. +pub trait Downcast { + fn downcast(&self) -> &Class; +} + pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int { unsafe { slice::raw::buf_as_slice(s, l, |result| { @@ -13,3 +26,57 @@ pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int { }) } } + +/// Creates a new raw CEF object of the given type and sets up its reference counting machinery. +/// All fields are initialized to zero. It is the caller's responsibility to ensure that the given +/// type is a CEF type with `cef_base_t` as its first member. +pub unsafe fn create_cef_object() -> *mut Base { + let size = (mem::size_of::() as size_t) + (mem::size_of::() as size_t) - 1; + println!("allocating CEF object with size {}", size); + let object = libc::calloc(1, size) as *mut cef_base_t; + (*object).size = size - mem::size_of::() as u64; // Subtract out the refcount. + (*object).add_ref = Some(servo_add_ref); + (*object).release = Some(servo_release); + *ref_count(object) = 1; + object as *mut Base +} + +/// Returns a pointer to the Servo-specific reference count for the given object. This only works +/// on objects that Servo created! +unsafe fn ref_count(object: *mut cef_base_t) -> *mut uint { + // The reference count should be the first field of the extra data. + (object as *mut u8).offset((*object).size as int) as *mut uint +} + +/// Increments the reference count on a CEF object. This only works on objects that Servo created! +extern "C" fn servo_add_ref(object: *mut cef_base_t) -> c_int { + unsafe { + let count = ref_count(object); + *count += 1; + *count as c_int + } +} + +/// Decrements the reference count on a CEF object. If zero, frees it. This only works on objects +/// that Servo created! +extern "C" fn servo_release(object: *mut cef_base_t) -> c_int { + unsafe { + let count = ref_count(object); + *count -= 1; + let new_count = *count; + if new_count == 0 { + servo_free(object); + } + (new_count == 0) as c_int + } +} + +unsafe fn servo_free(object: *mut cef_base_t) { + println!("freeing Servo-created CEF object!"); + libc::free(object as *mut c_void); +} + +pub unsafe fn add_ref(c_object: *mut cef_base_t) { + ((*c_object).add_ref.unwrap())(c_object); +} + diff --git a/ports/cef/interfaces/cef_app.rs b/ports/cef/interfaces/cef_app.rs new file mode 100644 index 00000000000..d54e42ae605 --- /dev/null +++ b/ports/cef/interfaces/cef_app.rs @@ -0,0 +1,305 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to provide handler implementations. Methods will be +// called by the process and/or thread indicated. +// +#[repr(C)] +pub struct _cef_app_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Provides an opportunity to view and/or modify command-line arguments before + // processing by CEF and Chromium. The |process_type| value will be NULL for + // the browser process. Do not keep a reference to the cef_command_line_t + // object passed to this function. The CefSettings.command_line_args_disabled + // value can be used to start with an NULL command-line object. Any values + // specified in CefSettings that equate to command-line arguments will be set + // before this function is called. Be cautious when using this function to + // modify command-line arguments for non-browser processes as this may result + // in undefined behavior including crashes. + // + pub on_before_command_line_processing: Option ()>, + + // + // Provides an opportunity to register custom schemes. Do not keep a reference + // to the |registrar| object. This function is called on the main thread for + // each process and the registered schemes should be the same across all + // processes. + // + pub on_register_custom_schemes: Option ()>, + + // + // Return the handler for resource bundle events. If + // CefSettings.pack_loading_disabled is true (1) a handler must be returned. + // If no handler is returned resources will be loaded from pack files. This + // function is called by the browser and render processes on multiple threads. + // + pub get_resource_bundle_handler: Option *mut interfaces::cef_resource_bundle_handler_t>, + + // + // Return the handler for functionality specific to the browser process. This + // function is called on multiple threads in the browser process. + // + pub get_browser_process_handler: Option *mut interfaces::cef_browser_process_handler_t>, + + // + // Return the handler for functionality specific to the render process. This + // function is called on the render process main thread. + // + pub get_render_process_handler: Option *mut interfaces::cef_render_process_handler_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_app_t = _cef_app_t; + + +// +// Implement this structure to provide handler implementations. Methods will be +// called by the process and/or thread indicated. +// +pub struct CefApp { + c_object: *mut cef_app_t, +} + +impl Clone for CefApp { + fn clone(&self) -> CefApp{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefApp { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefApp { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefApp { + pub unsafe fn from_c_object(c_object: *mut cef_app_t) -> CefApp { + CefApp { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_app_t) -> CefApp { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefApp { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_app_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_app_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Provides an opportunity to view and/or modify command-line arguments before + // processing by CEF and Chromium. The |process_type| value will be NULL for + // the browser process. Do not keep a reference to the cef_command_line_t + // object passed to this function. The CefSettings.command_line_args_disabled + // value can be used to start with an NULL command-line object. Any values + // specified in CefSettings that equate to command-line arguments will be set + // before this function is called. Be cautious when using this function to + // modify command-line arguments for non-browser processes as this may result + // in undefined behavior including crashes. + // + pub fn on_before_command_line_processing(&self, process_type: &str, + command_line: interfaces::CefCommandLine) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_command_line_processing.unwrap())( + self.c_object, + CefWrap::to_c(process_type), + CefWrap::to_c(command_line))) + } + } + + // + // Provides an opportunity to register custom schemes. Do not keep a reference + // to the |registrar| object. This function is called on the main thread for + // each process and the registered schemes should be the same across all + // processes. + // + pub fn on_register_custom_schemes(&self, + registrar: interfaces::CefSchemeRegistrar) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_register_custom_schemes.unwrap())( + self.c_object, + CefWrap::to_c(registrar))) + } + } + + // + // Return the handler for resource bundle events. If + // CefSettings.pack_loading_disabled is true (1) a handler must be returned. + // If no handler is returned resources will be loaded from pack files. This + // function is called by the browser and render processes on multiple threads. + // + pub fn get_resource_bundle_handler( + &self) -> interfaces::CefResourceBundleHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_resource_bundle_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for functionality specific to the browser process. This + // function is called on multiple threads in the browser process. + // + pub fn get_browser_process_handler( + &self) -> interfaces::CefBrowserProcessHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_browser_process_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for functionality specific to the render process. This + // function is called on the render process main thread. + // + pub fn get_render_process_handler( + &self) -> interfaces::CefRenderProcessHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_render_process_handler.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_app_t> for CefApp { + fn to_c(rust_object: CefApp) -> *mut cef_app_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_app_t) -> CefApp { + CefApp::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_app_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_app_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_app_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefApp::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_auth_callback.rs b/ports/cef/interfaces/cef_auth_callback.rs new file mode 100644 index 00000000000..3abd16d3abd --- /dev/null +++ b/ports/cef/interfaces/cef_auth_callback.rs @@ -0,0 +1,206 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure used for asynchronous continuation of authentication +// requests. +// +#[repr(C)] +pub struct _cef_auth_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue the authentication request. + // + pub cont: Option ()>, + + // + // Cancel the authentication request. + // + pub cancel: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_auth_callback_t = _cef_auth_callback_t; + + +// +// Callback structure used for asynchronous continuation of authentication +// requests. +// +pub struct CefAuthCallback { + c_object: *mut cef_auth_callback_t, +} + +impl Clone for CefAuthCallback { + fn clone(&self) -> CefAuthCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefAuthCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefAuthCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefAuthCallback { + pub unsafe fn from_c_object(c_object: *mut cef_auth_callback_t) -> CefAuthCallback { + CefAuthCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_auth_callback_t) -> CefAuthCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefAuthCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_auth_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_auth_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue the authentication request. + // + pub fn cont(&self, username: &str, password: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(username), + CefWrap::to_c(password))) + } + } + + // + // Cancel the authentication request. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_auth_callback_t> for CefAuthCallback { + fn to_c(rust_object: CefAuthCallback) -> *mut cef_auth_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_auth_callback_t) -> CefAuthCallback { + CefAuthCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_auth_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_auth_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_auth_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefAuthCallback::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_browser.rs b/ports/cef/interfaces/cef_browser.rs new file mode 100644 index 00000000000..e2f18a76d73 --- /dev/null +++ b/ports/cef/interfaces/cef_browser.rs @@ -0,0 +1,2033 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent a browser window. When used in the browser +// process the functions of this structure may be called on any thread unless +// otherwise indicated in the comments. When used in the render process the +// functions of this structure may only be called on the main thread. +// +#[repr(C)] +pub struct _cef_browser_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the browser host object. This function can only be called in the + // browser process. + // + pub get_host: Option *mut interfaces::cef_browser_host_t>, + + // + // Returns true (1) if the browser can navigate backwards. + // + pub can_go_back: Option libc::c_int>, + + // + // Navigate backwards. + // + pub go_back: Option ()>, + + // + // Returns true (1) if the browser can navigate forwards. + // + pub can_go_forward: Option libc::c_int>, + + // + // Navigate forwards. + // + pub go_forward: Option ()>, + + // + // Returns true (1) if the browser is currently loading. + // + pub is_loading: Option libc::c_int>, + + // + // Reload the current page. + // + pub reload: Option ()>, + + // + // Reload the current page ignoring any cached data. + // + pub reload_ignore_cache: Option ( + )>, + + // + // Stop loading the page. + // + pub stop_load: Option ()>, + + // + // Returns the globally unique identifier for this browser. + // + pub get_identifier: Option libc::c_int>, + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub is_same: Option libc::c_int>, + + // + // Returns true (1) if the window is a popup window. + // + pub is_popup: Option libc::c_int>, + + // + // Returns true (1) if a document has been loaded in the browser. + // + pub has_document: Option libc::c_int>, + + // + // Returns the main (top-level) frame for the browser window. + // + pub get_main_frame: Option *mut interfaces::cef_frame_t>, + + // + // Returns the focused frame for the browser window. + // + pub get_focused_frame: Option *mut interfaces::cef_frame_t>, + + // + // Returns the frame with the specified identifier, or NULL if not found. + // + pub get_frame_byident: Option *mut interfaces::cef_frame_t>, + + // + // Returns the frame with the specified name, or NULL if not found. + // + pub get_frame: Option *mut interfaces::cef_frame_t>, + + // + // Returns the number of frames that currently exist. + // + pub get_frame_count: Option libc::size_t>, + + // + // Returns the identifiers of all existing frames. + // + pub get_frame_identifiers: Option ()>, + + // + // Returns the names of all existing frames. + // + pub get_frame_names: Option ()>, + + // + // Send a message to the specified |target_process|. Returns true (1) if the + // message was sent successfully. + // + pub send_process_message: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_browser_t = _cef_browser_t; + + +// +// Structure used to represent a browser window. When used in the browser +// process the functions of this structure may be called on any thread unless +// otherwise indicated in the comments. When used in the render process the +// functions of this structure may only be called on the main thread. +// +pub struct CefBrowser { + c_object: *mut cef_browser_t, +} + +impl Clone for CefBrowser { + fn clone(&self) -> CefBrowser{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefBrowser { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefBrowser { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefBrowser { + pub unsafe fn from_c_object(c_object: *mut cef_browser_t) -> CefBrowser { + CefBrowser { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_browser_t) -> CefBrowser { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefBrowser { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_browser_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_browser_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the browser host object. This function can only be called in the + // browser process. + // + pub fn get_host(&self) -> interfaces::CefBrowserHost { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_host.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the browser can navigate backwards. + // + pub fn can_go_back(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).can_go_back.unwrap())( + self.c_object)) + } + } + + // + // Navigate backwards. + // + pub fn go_back(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).go_back.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the browser can navigate forwards. + // + pub fn can_go_forward(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).can_go_forward.unwrap())( + self.c_object)) + } + } + + // + // Navigate forwards. + // + pub fn go_forward(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).go_forward.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the browser is currently loading. + // + pub fn is_loading(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_loading.unwrap())( + self.c_object)) + } + } + + // + // Reload the current page. + // + pub fn reload(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).reload.unwrap())( + self.c_object)) + } + } + + // + // Reload the current page ignoring any cached data. + // + pub fn reload_ignore_cache(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).reload_ignore_cache.unwrap())( + self.c_object)) + } + } + + // + // Stop loading the page. + // + pub fn stop_load(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).stop_load.unwrap())( + self.c_object)) + } + } + + // + // Returns the globally unique identifier for this browser. + // + pub fn get_identifier(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_identifier.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub fn is_same(&self, that: interfaces::CefBrowser) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(that))) + } + } + + // + // Returns true (1) if the window is a popup window. + // + pub fn is_popup(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_popup.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if a document has been loaded in the browser. + // + pub fn has_document(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_document.unwrap())( + self.c_object)) + } + } + + // + // Returns the main (top-level) frame for the browser window. + // + pub fn get_main_frame(&self) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_main_frame.unwrap())( + self.c_object)) + } + } + + // + // Returns the focused frame for the browser window. + // + pub fn get_focused_frame(&self) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_focused_frame.unwrap())( + self.c_object)) + } + } + + // + // Returns the frame with the specified identifier, or NULL if not found. + // + pub fn get_frame_byident(&self, identifier: i64) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_byident.unwrap())( + self.c_object, + CefWrap::to_c(identifier))) + } + } + + // + // Returns the frame with the specified name, or NULL if not found. + // + pub fn get_frame(&self, name: &str) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Returns the number of frames that currently exist. + // + pub fn get_frame_count(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_count.unwrap())( + self.c_object)) + } + } + + // + // Returns the identifiers of all existing frames. + // + pub fn get_frame_identifiers(&self, identifiers_count: *mut libc::size_t, + identifiers: *mut i64) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_identifiers.unwrap())( + self.c_object, + CefWrap::to_c(identifiers_count), + CefWrap::to_c(identifiers))) + } + } + + // + // Returns the names of all existing frames. + // + pub fn get_frame_names(&self, names: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_names.unwrap())( + self.c_object, + CefWrap::to_c(names))) + } + } + + // + // Send a message to the specified |target_process|. Returns true (1) if the + // message was sent successfully. + // + pub fn send_process_message(&self, target_process: interfaces::CefProcessId, + message: interfaces::CefProcessMessage) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_process_message.unwrap())( + self.c_object, + CefWrap::to_c(target_process), + CefWrap::to_c(message))) + } + } +} + +impl CefWrap<*mut cef_browser_t> for CefBrowser { + fn to_c(rust_object: CefBrowser) -> *mut cef_browser_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_browser_t) -> CefBrowser { + CefBrowser::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_browser_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_browser_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_browser_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefBrowser::from_c_object_addref(c_object)) + } + } +} + + +// +// Callback structure for cef_browser_host_t::RunFileDialog. The functions of +// this structure will be called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_run_file_dialog_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called asynchronously after the file dialog is dismissed. If the selection + // was successful |file_paths| will be a single value or a list of values + // depending on the dialog mode. If the selection was cancelled |file_paths| + // will be NULL. + // + pub cont: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_run_file_dialog_callback_t = _cef_run_file_dialog_callback_t; + + +// +// Callback structure for cef_browser_host_t::RunFileDialog. The functions of +// this structure will be called on the browser process UI thread. +// +pub struct CefRunFileDialogCallback { + c_object: *mut cef_run_file_dialog_callback_t, +} + +impl Clone for CefRunFileDialogCallback { + fn clone(&self) -> CefRunFileDialogCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRunFileDialogCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRunFileDialogCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRunFileDialogCallback { + pub unsafe fn from_c_object(c_object: *mut cef_run_file_dialog_callback_t) -> CefRunFileDialogCallback { + CefRunFileDialogCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_run_file_dialog_callback_t) -> CefRunFileDialogCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRunFileDialogCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_run_file_dialog_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_run_file_dialog_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called asynchronously after the file dialog is dismissed. If the selection + // was successful |file_paths| will be a single value or a list of values + // depending on the dialog mode. If the selection was cancelled |file_paths| + // will be NULL. + // + pub fn cont(&self, browser_host: interfaces::CefBrowserHost, + file_paths: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(browser_host), + CefWrap::to_c(file_paths))) + } + } +} + +impl CefWrap<*mut cef_run_file_dialog_callback_t> for CefRunFileDialogCallback { + fn to_c(rust_object: CefRunFileDialogCallback) -> *mut cef_run_file_dialog_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_run_file_dialog_callback_t) -> CefRunFileDialogCallback { + CefRunFileDialogCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_run_file_dialog_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_run_file_dialog_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_run_file_dialog_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRunFileDialogCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to represent the browser process aspects of a browser window. +// The functions of this structure can only be called in the browser process. +// They may be called on any thread in that process unless otherwise indicated +// in the comments. +// +#[repr(C)] +pub struct _cef_browser_host_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the hosted browser object. + // + pub get_browser: Option *mut interfaces::cef_browser_t>, + + // + // Request that the browser close. The JavaScript 'onbeforeunload' event will + // be fired. If |force_close| is false (0) the event handler, if any, will be + // allowed to prompt the user and the user can optionally cancel the close. If + // |force_close| is true (1) the prompt will not be displayed and the close + // will proceed. Results in a call to cef_life_span_handler_t::do_close() if + // the event handler allows the close or if |force_close| is true (1). See + // cef_life_span_handler_t::do_close() documentation for additional usage + // information. + // + pub close_browser: Option ()>, + + // + // Set whether the browser is focused. + // + pub set_focus: Option ()>, + + // + // Set whether the window containing the browser is visible + // (minimized/unminimized, app hidden/unhidden, etc). Only used on Mac OS X. + // + pub set_window_visibility: Option ()>, + + // + // Retrieve the window handle for this browser. + // + pub get_window_handle: Option types::cef_window_handle_t>, + + // + // Retrieve the window handle of the browser that opened this browser. Will + // return NULL for non-popup windows. This function can be used in combination + // with custom handling of modal windows. + // + pub get_opener_window_handle: Option types::cef_window_handle_t>, + + // + // Returns the client for this browser. + // + pub get_client: Option *mut interfaces::cef_client_t>, + + // + // Returns the request context for this browser. + // + pub get_request_context: Option *mut interfaces::cef_request_context_t>, + + // + // Get the current zoom level. The default zoom level is 0.0. This function + // can only be called on the UI thread. + // + pub get_zoom_level: Option libc::c_double>, + + // + // Change the zoom level to the specified value. Specify 0.0 to reset the zoom + // level. If called on the UI thread the change will be applied immediately. + // Otherwise, the change will be applied asynchronously on the UI thread. + // + pub set_zoom_level: Option ()>, + + // + // Call to run a file chooser dialog. Only a single file chooser dialog may be + // pending at any given time. |mode| represents the type of dialog to display. + // |title| to the title to be used for the dialog and may be NULL to show the + // default title ("Open" or "Save" depending on the mode). |default_file_name| + // is the default file name to select in the dialog. |accept_types| is a list + // of valid lower-cased MIME types or file extensions specified in an input + // element and is used to restrict selectable files to such types. |callback| + // will be executed after the dialog is dismissed or immediately if another + // dialog is already pending. The dialog will be initiated asynchronously on + // the UI thread. + // + pub run_file_dialog: Option ()>, + + // + // Download the file at |url| using cef_download_handler_t. + // + pub start_download: Option ()>, + + // + // Print the current browser contents. + // + pub print: Option ()>, + + // + // Search for |searchText|. |identifier| can be used to have multiple searches + // running simultaniously. |forward| indicates whether to search forward or + // backward within the page. |matchCase| indicates whether the search should + // be case-sensitive. |findNext| indicates whether this is the first request + // or a follow-up. + // + pub find: Option ( + )>, + + // + // Cancel all searches that are currently going on. + // + pub stop_finding: Option ()>, + + // + // Open developer tools in its own window. If |inspect_element_at| is non- + // NULL the element at the specified (x,y) location will be inspected. + // + pub show_dev_tools: Option ()>, + + // + // Explicitly close the developer tools window if one exists for this browser + // instance. + // + pub close_dev_tools: Option ( + )>, + + // + // Set whether mouse cursor change is disabled. + // + pub set_mouse_cursor_change_disabled: Option ()>, + + // + // Returns true (1) if mouse cursor change is disabled. + // + pub is_mouse_cursor_change_disabled: Option libc::c_int>, + + // + // If a misspelled word is currently selected in an editable node calling this + // function will replace it with the specified |word|. + // + pub replace_misspelling: Option ()>, + + // + // Add the specified |word| to the spelling dictionary. + // + pub add_word_to_dictionary: Option ()>, + + // + // Returns true (1) if window rendering is disabled. + // + pub is_window_rendering_disabled: Option libc::c_int>, + + // + // Notify the browser that the widget has been resized. The browser will first + // call cef_render_handler_t::GetViewRect to get the new size and then call + // cef_render_handler_t::OnPaint asynchronously with the updated regions. This + // function is only used when window rendering is disabled. + // + pub was_resized: Option ()>, + + // + // Notify the browser that it has been hidden or shown. Layouting and + // cef_render_handler_t::OnPaint notification will stop when the browser is + // hidden. This function is only used when window rendering is disabled. + // + pub was_hidden: Option ()>, + + // + // Send a notification to the browser that the screen info has changed. The + // browser will then call cef_render_handler_t::GetScreenInfo to update the + // screen information with the new values. This simulates moving the webview + // window from one display to another, or changing the properties of the + // current display. This function is only used when window rendering is + // disabled. + // + pub notify_screen_info_changed: Option ()>, + + // + // Invalidate the view. The browser will call cef_render_handler_t::OnPaint + // asynchronously. This function is only used when window rendering is + // disabled. + // + pub invalidate: Option ()>, + + // + // Send a key event to the browser. + // + pub send_key_event: Option ()>, + + // + // Send a mouse click event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. + // + pub send_mouse_click_event: Option ()>, + + // + // Send a mouse move event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. + // + pub send_mouse_move_event: Option ()>, + + // + // Send a mouse wheel event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. The |deltaX| and |deltaY| + // values represent the movement delta in the X and Y directions respectively. + // In order to scroll inside select popups with window rendering disabled + // cef_render_handler_t::GetScreenPoint should be implemented properly. + // + pub send_mouse_wheel_event: Option ()>, + + // + // Send a focus event to the browser. + // + pub send_focus_event: Option ()>, + + // + // Send a capture lost event to the browser. + // + pub send_capture_lost_event: Option ()>, + + // + // Notify the browser that the window hosting it is about to be moved or + // resized. This function is only used on Windows and Linux. + // + pub notify_move_or_resize_started: Option ()>, + + // + // Get the NSTextInputContext implementation for enabling IME on Mac when + // window rendering is disabled. + // + pub get_nstext_input_context: Option types::cef_text_input_context_t>, + + // + // Handles a keyDown event prior to passing it through the NSTextInputClient + // machinery. + // + pub handle_key_event_before_text_input_client: Option ( + )>, + + // + // Performs any additional actions after NSTextInputClient handles the event. + // + pub handle_key_event_after_text_input_client: Option ( + )>, + + // + // Call this function when the user drags the mouse into the web view (before + // calling DragTargetDragOver/DragTargetLeave/DragTargetDrop). |drag_data| + // should not contain file contents as this type of data is not allowed to be + // dragged into the web view. File contents can be removed using + // cef_drag_data_t::ResetFileContents (for example, if |drag_data| comes from + // cef_render_handler_t::StartDragging). This function is only used when + // window rendering is disabled. + // + pub drag_target_drag_enter: Option ()>, + + // + // Call this function each time the mouse is moved across the web view during + // a drag operation (after calling DragTargetDragEnter and before calling + // DragTargetDragLeave/DragTargetDrop). This function is only used when window + // rendering is disabled. + // + pub drag_target_drag_over: Option ()>, + + // + // Call this function when the user drags the mouse out of the web view (after + // calling DragTargetDragEnter). This function is only used when window + // rendering is disabled. + // + pub drag_target_drag_leave: Option ()>, + + // + // Call this function when the user completes the drag operation by dropping + // the object onto the web view (after calling DragTargetDragEnter). The + // object being dropped is |drag_data|, given as an argument to the previous + // DragTargetDragEnter call. This function is only used when window rendering + // is disabled. + // + pub drag_target_drop: Option ()>, + + // + // Call this function when the drag operation started by a + // cef_render_handler_t::StartDragging call has ended either in a drop or by + // being cancelled. |x| and |y| are mouse coordinates relative to the upper- + // left corner of the view. If the web view is both the drag source and the + // drag target then all DragTarget* functions should be called before + // DragSource* mthods. This function is only used when window rendering is + // disabled. + // + pub drag_source_ended_at: Option ()>, + + // + // Call this function when the drag operation started by a + // cef_render_handler_t::StartDragging call has completed. This function may + // be called immediately without first calling DragSourceEndedAt to cancel a + // drag operation. If the web view is both the drag source and the drag target + // then all DragTarget* functions should be called before DragSource* mthods. + // This function is only used when window rendering is disabled. + // + pub drag_source_system_drag_ended: Option ()>, + + // + // Instructs the browser to perform an accelerated composite. The appropriate + // Direct3D or OpenGL state must have been set up before calling this + // function. + // + pub composite: Option ()>, + + // + // Instructs the browser to initialize accelerated compositing. The + // appropriate Direct3D or OpenGL state must have been set up before calling + // this function. + // + pub initialize_compositing: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_browser_host_t = _cef_browser_host_t; + + +// +// Structure used to represent the browser process aspects of a browser window. +// The functions of this structure can only be called in the browser process. +// They may be called on any thread in that process unless otherwise indicated +// in the comments. +// +pub struct CefBrowserHost { + c_object: *mut cef_browser_host_t, +} + +impl Clone for CefBrowserHost { + fn clone(&self) -> CefBrowserHost{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefBrowserHost { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefBrowserHost { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefBrowserHost { + pub unsafe fn from_c_object(c_object: *mut cef_browser_host_t) -> CefBrowserHost { + CefBrowserHost { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_browser_host_t) -> CefBrowserHost { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefBrowserHost { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_browser_host_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_browser_host_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the hosted browser object. + // + pub fn get_browser(&self) -> interfaces::CefBrowser { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_browser.unwrap())( + self.c_object)) + } + } + + // + // Request that the browser close. The JavaScript 'onbeforeunload' event will + // be fired. If |force_close| is false (0) the event handler, if any, will be + // allowed to prompt the user and the user can optionally cancel the close. If + // |force_close| is true (1) the prompt will not be displayed and the close + // will proceed. Results in a call to cef_life_span_handler_t::do_close() if + // the event handler allows the close or if |force_close| is true (1). See + // cef_life_span_handler_t::do_close() documentation for additional usage + // information. + // + pub fn close_browser(&self, force_close: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).close_browser.unwrap())( + self.c_object, + CefWrap::to_c(force_close))) + } + } + + // + // Set whether the browser is focused. + // + pub fn set_focus(&self, focus: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_focus.unwrap())( + self.c_object, + CefWrap::to_c(focus))) + } + } + + // + // Set whether the window containing the browser is visible + // (minimized/unminimized, app hidden/unhidden, etc). Only used on Mac OS X. + // + pub fn set_window_visibility(&self, visible: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_window_visibility.unwrap())( + self.c_object, + CefWrap::to_c(visible))) + } + } + + // + // Retrieve the window handle for this browser. + // + pub fn get_window_handle(&self) -> types::cef_window_handle_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_window_handle.unwrap())( + self.c_object)) + } + } + + // + // Retrieve the window handle of the browser that opened this browser. Will + // return NULL for non-popup windows. This function can be used in combination + // with custom handling of modal windows. + // + pub fn get_opener_window_handle(&self) -> types::cef_window_handle_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_opener_window_handle.unwrap())( + self.c_object)) + } + } + + // + // Returns the client for this browser. + // + pub fn get_client(&self) -> interfaces::CefClient { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_client.unwrap())( + self.c_object)) + } + } + + // + // Returns the request context for this browser. + // + pub fn get_request_context(&self) -> interfaces::CefRequestContext { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_request_context.unwrap())( + self.c_object)) + } + } + + // + // Get the current zoom level. The default zoom level is 0.0. This function + // can only be called on the UI thread. + // + pub fn get_zoom_level(&self) -> libc::c_double { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_zoom_level.unwrap())( + self.c_object)) + } + } + + // + // Change the zoom level to the specified value. Specify 0.0 to reset the zoom + // level. If called on the UI thread the change will be applied immediately. + // Otherwise, the change will be applied asynchronously on the UI thread. + // + pub fn set_zoom_level(&self, zoomLevel: libc::c_double) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_zoom_level.unwrap())( + self.c_object, + CefWrap::to_c(zoomLevel))) + } + } + + // + // Call to run a file chooser dialog. Only a single file chooser dialog may be + // pending at any given time. |mode| represents the type of dialog to display. + // |title| to the title to be used for the dialog and may be NULL to show the + // default title ("Open" or "Save" depending on the mode). |default_file_name| + // is the default file name to select in the dialog. |accept_types| is a list + // of valid lower-cased MIME types or file extensions specified in an input + // element and is used to restrict selectable files to such types. |callback| + // will be executed after the dialog is dismissed or immediately if another + // dialog is already pending. The dialog will be initiated asynchronously on + // the UI thread. + // + pub fn run_file_dialog(&self, mode: types::cef_file_dialog_mode_t, + title: &str, default_file_name: &str, accept_types: Vec, + callback: interfaces::CefRunFileDialogCallback) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).run_file_dialog.unwrap())( + self.c_object, + CefWrap::to_c(mode), + CefWrap::to_c(title), + CefWrap::to_c(default_file_name), + CefWrap::to_c(accept_types), + CefWrap::to_c(callback))) + } + } + + // + // Download the file at |url| using cef_download_handler_t. + // + pub fn start_download(&self, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).start_download.unwrap())( + self.c_object, + CefWrap::to_c(url))) + } + } + + // + // Print the current browser contents. + // + pub fn print(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).print.unwrap())( + self.c_object)) + } + } + + // + // Search for |searchText|. |identifier| can be used to have multiple searches + // running simultaniously. |forward| indicates whether to search forward or + // backward within the page. |matchCase| indicates whether the search should + // be case-sensitive. |findNext| indicates whether this is the first request + // or a follow-up. + // + pub fn find(&self, identifier: libc::c_int, searchText: &str, + forward: libc::c_int, matchCase: libc::c_int, findNext: libc::c_int) -> ( + ) { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).find.unwrap())( + self.c_object, + CefWrap::to_c(identifier), + CefWrap::to_c(searchText), + CefWrap::to_c(forward), + CefWrap::to_c(matchCase), + CefWrap::to_c(findNext))) + } + } + + // + // Cancel all searches that are currently going on. + // + pub fn stop_finding(&self, clearSelection: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).stop_finding.unwrap())( + self.c_object, + CefWrap::to_c(clearSelection))) + } + } + + // + // Open developer tools in its own window. If |inspect_element_at| is non- + // NULL the element at the specified (x,y) location will be inspected. + // + pub fn show_dev_tools(&self, windowInfo: &interfaces::CefWindowInfo, + client: interfaces::CefClient, settings: &interfaces::CefBrowserSettings, + inspect_element_at: &types::cef_point_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).show_dev_tools.unwrap())( + self.c_object, + CefWrap::to_c(windowInfo), + CefWrap::to_c(client), + CefWrap::to_c(settings), + CefWrap::to_c(inspect_element_at))) + } + } + + // + // Explicitly close the developer tools window if one exists for this browser + // instance. + // + pub fn close_dev_tools(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).close_dev_tools.unwrap())( + self.c_object)) + } + } + + // + // Set whether mouse cursor change is disabled. + // + pub fn set_mouse_cursor_change_disabled(&self, disabled: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_mouse_cursor_change_disabled.unwrap())( + self.c_object, + CefWrap::to_c(disabled))) + } + } + + // + // Returns true (1) if mouse cursor change is disabled. + // + pub fn is_mouse_cursor_change_disabled(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_mouse_cursor_change_disabled.unwrap())( + self.c_object)) + } + } + + // + // If a misspelled word is currently selected in an editable node calling this + // function will replace it with the specified |word|. + // + pub fn replace_misspelling(&self, word: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).replace_misspelling.unwrap())( + self.c_object, + CefWrap::to_c(word))) + } + } + + // + // Add the specified |word| to the spelling dictionary. + // + pub fn add_word_to_dictionary(&self, word: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_word_to_dictionary.unwrap())( + self.c_object, + CefWrap::to_c(word))) + } + } + + // + // Returns true (1) if window rendering is disabled. + // + pub fn is_window_rendering_disabled(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_window_rendering_disabled.unwrap())( + self.c_object)) + } + } + + // + // Notify the browser that the widget has been resized. The browser will first + // call cef_render_handler_t::GetViewRect to get the new size and then call + // cef_render_handler_t::OnPaint asynchronously with the updated regions. This + // function is only used when window rendering is disabled. + // + pub fn was_resized(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).was_resized.unwrap())( + self.c_object)) + } + } + + // + // Notify the browser that it has been hidden or shown. Layouting and + // cef_render_handler_t::OnPaint notification will stop when the browser is + // hidden. This function is only used when window rendering is disabled. + // + pub fn was_hidden(&self, hidden: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).was_hidden.unwrap())( + self.c_object, + CefWrap::to_c(hidden))) + } + } + + // + // Send a notification to the browser that the screen info has changed. The + // browser will then call cef_render_handler_t::GetScreenInfo to update the + // screen information with the new values. This simulates moving the webview + // window from one display to another, or changing the properties of the + // current display. This function is only used when window rendering is + // disabled. + // + pub fn notify_screen_info_changed(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).notify_screen_info_changed.unwrap())( + self.c_object)) + } + } + + // + // Invalidate the view. The browser will call cef_render_handler_t::OnPaint + // asynchronously. This function is only used when window rendering is + // disabled. + // + pub fn invalidate(&self, ty: types::cef_paint_element_type_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).invalidate.unwrap())( + self.c_object, + CefWrap::to_c(ty))) + } + } + + // + // Send a key event to the browser. + // + pub fn send_key_event(&self, event: &interfaces::CefKeyEvent) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_key_event.unwrap())( + self.c_object, + CefWrap::to_c(event))) + } + } + + // + // Send a mouse click event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. + // + pub fn send_mouse_click_event(&self, event: &interfaces::CefMouseEvent, + ty: types::cef_mouse_button_type_t, mouseUp: libc::c_int, + clickCount: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_mouse_click_event.unwrap())( + self.c_object, + CefWrap::to_c(event), + CefWrap::to_c(ty), + CefWrap::to_c(mouseUp), + CefWrap::to_c(clickCount))) + } + } + + // + // Send a mouse move event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. + // + pub fn send_mouse_move_event(&self, event: &interfaces::CefMouseEvent, + mouseLeave: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_mouse_move_event.unwrap())( + self.c_object, + CefWrap::to_c(event), + CefWrap::to_c(mouseLeave))) + } + } + + // + // Send a mouse wheel event to the browser. The |x| and |y| coordinates are + // relative to the upper-left corner of the view. The |deltaX| and |deltaY| + // values represent the movement delta in the X and Y directions respectively. + // In order to scroll inside select popups with window rendering disabled + // cef_render_handler_t::GetScreenPoint should be implemented properly. + // + pub fn send_mouse_wheel_event(&self, event: &interfaces::CefMouseEvent, + deltaX: libc::c_int, deltaY: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_mouse_wheel_event.unwrap())( + self.c_object, + CefWrap::to_c(event), + CefWrap::to_c(deltaX), + CefWrap::to_c(deltaY))) + } + } + + // + // Send a focus event to the browser. + // + pub fn send_focus_event(&self, setFocus: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_focus_event.unwrap())( + self.c_object, + CefWrap::to_c(setFocus))) + } + } + + // + // Send a capture lost event to the browser. + // + pub fn send_capture_lost_event(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).send_capture_lost_event.unwrap())( + self.c_object)) + } + } + + // + // Notify the browser that the window hosting it is about to be moved or + // resized. This function is only used on Windows and Linux. + // + pub fn notify_move_or_resize_started(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).notify_move_or_resize_started.unwrap())( + self.c_object)) + } + } + + // + // Get the NSTextInputContext implementation for enabling IME on Mac when + // window rendering is disabled. + // + pub fn get_nstext_input_context(&self) -> types::cef_text_input_context_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_nstext_input_context.unwrap())( + self.c_object)) + } + } + + // + // Handles a keyDown event prior to passing it through the NSTextInputClient + // machinery. + // + pub fn handle_key_event_before_text_input_client(&self, + keyEvent: types::cef_event_handle_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).handle_key_event_before_text_input_client.unwrap())( + self.c_object, + CefWrap::to_c(keyEvent))) + } + } + + // + // Performs any additional actions after NSTextInputClient handles the event. + // + pub fn handle_key_event_after_text_input_client(&self, + keyEvent: types::cef_event_handle_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).handle_key_event_after_text_input_client.unwrap())( + self.c_object, + CefWrap::to_c(keyEvent))) + } + } + + // + // Call this function when the user drags the mouse into the web view (before + // calling DragTargetDragOver/DragTargetLeave/DragTargetDrop). |drag_data| + // should not contain file contents as this type of data is not allowed to be + // dragged into the web view. File contents can be removed using + // cef_drag_data_t::ResetFileContents (for example, if |drag_data| comes from + // cef_render_handler_t::StartDragging). This function is only used when + // window rendering is disabled. + // + pub fn drag_target_drag_enter(&self, drag_data: interfaces::CefDragData, + event: &interfaces::CefMouseEvent, + allowed_ops: types::cef_drag_operations_mask_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_target_drag_enter.unwrap())( + self.c_object, + CefWrap::to_c(drag_data), + CefWrap::to_c(event), + CefWrap::to_c(allowed_ops))) + } + } + + // + // Call this function each time the mouse is moved across the web view during + // a drag operation (after calling DragTargetDragEnter and before calling + // DragTargetDragLeave/DragTargetDrop). This function is only used when window + // rendering is disabled. + // + pub fn drag_target_drag_over(&self, event: &interfaces::CefMouseEvent, + allowed_ops: types::cef_drag_operations_mask_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_target_drag_over.unwrap())( + self.c_object, + CefWrap::to_c(event), + CefWrap::to_c(allowed_ops))) + } + } + + // + // Call this function when the user drags the mouse out of the web view (after + // calling DragTargetDragEnter). This function is only used when window + // rendering is disabled. + // + pub fn drag_target_drag_leave(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_target_drag_leave.unwrap())( + self.c_object)) + } + } + + // + // Call this function when the user completes the drag operation by dropping + // the object onto the web view (after calling DragTargetDragEnter). The + // object being dropped is |drag_data|, given as an argument to the previous + // DragTargetDragEnter call. This function is only used when window rendering + // is disabled. + // + pub fn drag_target_drop(&self, event: &interfaces::CefMouseEvent) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_target_drop.unwrap())( + self.c_object, + CefWrap::to_c(event))) + } + } + + // + // Call this function when the drag operation started by a + // cef_render_handler_t::StartDragging call has ended either in a drop or by + // being cancelled. |x| and |y| are mouse coordinates relative to the upper- + // left corner of the view. If the web view is both the drag source and the + // drag target then all DragTarget* functions should be called before + // DragSource* mthods. This function is only used when window rendering is + // disabled. + // + pub fn drag_source_ended_at(&self, x: libc::c_int, y: libc::c_int, + op: types::cef_drag_operations_mask_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_source_ended_at.unwrap())( + self.c_object, + CefWrap::to_c(x), + CefWrap::to_c(y), + CefWrap::to_c(op))) + } + } + + // + // Call this function when the drag operation started by a + // cef_render_handler_t::StartDragging call has completed. This function may + // be called immediately without first calling DragSourceEndedAt to cancel a + // drag operation. If the web view is both the drag source and the drag target + // then all DragTarget* functions should be called before DragSource* mthods. + // This function is only used when window rendering is disabled. + // + pub fn drag_source_system_drag_ended(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).drag_source_system_drag_ended.unwrap())( + self.c_object)) + } + } + + // + // Instructs the browser to perform an accelerated composite. The appropriate + // Direct3D or OpenGL state must have been set up before calling this + // function. + // + pub fn composite(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).composite.unwrap())( + self.c_object)) + } + } + + // + // Instructs the browser to initialize accelerated compositing. The + // appropriate Direct3D or OpenGL state must have been set up before calling + // this function. + // + pub fn initialize_compositing(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).initialize_compositing.unwrap())( + self.c_object)) + } + } + + // + // Create a new browser window using the window parameters specified by + // |windowInfo|. All values will be copied internally and the actual window + // will be created on the UI thread. If |request_context| is NULL the global + // request context will be used. This function can be called on any browser + // process thread and will not block. + // + pub fn create_browser(windowInfo: &interfaces::CefWindowInfo, + client: interfaces::CefClient, url: &str, + settings: &interfaces::CefBrowserSettings, + request_context: interfaces::CefRequestContext) -> libc::c_int { + unsafe { + CefWrap::to_rust( + ::browser::cef_browser_host_create_browser( + CefWrap::to_c(windowInfo), + CefWrap::to_c(client), + CefWrap::to_c(url), + CefWrap::to_c(settings), + CefWrap::to_c(request_context))) + } + } + + // + // Create a new browser window using the window parameters specified by + // |windowInfo|. If |request_context| is NULL the global request context will + // be used. This function can only be called on the browser process UI thread. + // + pub fn create_browser_sync(windowInfo: &interfaces::CefWindowInfo, + client: interfaces::CefClient, url: &str, + settings: &interfaces::CefBrowserSettings, + request_context: interfaces::CefRequestContext) -> interfaces::CefBrowser { + unsafe { + CefWrap::to_rust( + ::browser::cef_browser_host_create_browser_sync( + CefWrap::to_c(windowInfo), + CefWrap::to_c(client), + CefWrap::to_c(url), + CefWrap::to_c(settings), + CefWrap::to_c(request_context))) + } + } +} + +impl CefWrap<*mut cef_browser_host_t> for CefBrowserHost { + fn to_c(rust_object: CefBrowserHost) -> *mut cef_browser_host_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_browser_host_t) -> CefBrowserHost { + CefBrowserHost::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_browser_host_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_browser_host_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_browser_host_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefBrowserHost::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_browser_process_handler.rs b/ports/cef/interfaces/cef_browser_process_handler.rs new file mode 100644 index 00000000000..71acc80ae8b --- /dev/null +++ b/ports/cef/interfaces/cef_browser_process_handler.rs @@ -0,0 +1,272 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to implement browser process callbacks. The functions of this +// structure will be called on the browser process main thread unless otherwise +// indicated. +// +#[repr(C)] +pub struct _cef_browser_process_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called on the browser process UI thread immediately after the CEF context + // has been initialized. + // + pub on_context_initialized: Option ()>, + + // + // Called before a child process is launched. Will be called on the browser + // process UI thread when launching a render process and on the browser + // process IO thread when launching a GPU or plugin process. Provides an + // opportunity to modify the child process command line. Do not keep a + // reference to |command_line| outside of this function. + // + pub on_before_child_process_launch: Option ()>, + + // + // Called on the browser process IO thread after the main thread has been + // created for a new render process. Provides an opportunity to specify extra + // information that will be passed to + // cef_render_process_handler_t::on_render_thread_created() in the render + // process. Do not keep a reference to |extra_info| outside of this function. + // + pub on_render_process_thread_created: Option ()>, + + // + // Return the handler for printing on Linux. If a print handler is not + // provided then printing will not be supported on the Linux platform. + // + pub get_print_handler: Option *mut interfaces::cef_print_handler_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_browser_process_handler_t = _cef_browser_process_handler_t; + + +// +// Structure used to implement browser process callbacks. The functions of this +// structure will be called on the browser process main thread unless otherwise +// indicated. +// +pub struct CefBrowserProcessHandler { + c_object: *mut cef_browser_process_handler_t, +} + +impl Clone for CefBrowserProcessHandler { + fn clone(&self) -> CefBrowserProcessHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefBrowserProcessHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefBrowserProcessHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefBrowserProcessHandler { + pub unsafe fn from_c_object(c_object: *mut cef_browser_process_handler_t) -> CefBrowserProcessHandler { + CefBrowserProcessHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_browser_process_handler_t) -> CefBrowserProcessHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefBrowserProcessHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_browser_process_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_browser_process_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called on the browser process UI thread immediately after the CEF context + // has been initialized. + // + pub fn on_context_initialized(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_context_initialized.unwrap())( + self.c_object)) + } + } + + // + // Called before a child process is launched. Will be called on the browser + // process UI thread when launching a render process and on the browser + // process IO thread when launching a GPU or plugin process. Provides an + // opportunity to modify the child process command line. Do not keep a + // reference to |command_line| outside of this function. + // + pub fn on_before_child_process_launch(&self, + command_line: interfaces::CefCommandLine) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_child_process_launch.unwrap())( + self.c_object, + CefWrap::to_c(command_line))) + } + } + + // + // Called on the browser process IO thread after the main thread has been + // created for a new render process. Provides an opportunity to specify extra + // information that will be passed to + // cef_render_process_handler_t::on_render_thread_created() in the render + // process. Do not keep a reference to |extra_info| outside of this function. + // + pub fn on_render_process_thread_created(&self, + extra_info: interfaces::CefListValue) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_render_process_thread_created.unwrap())( + self.c_object, + CefWrap::to_c(extra_info))) + } + } + + // + // Return the handler for printing on Linux. If a print handler is not + // provided then printing will not be supported on the Linux platform. + // + pub fn get_print_handler(&self) -> interfaces::CefPrintHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_print_handler.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_browser_process_handler_t> for CefBrowserProcessHandler { + fn to_c(rust_object: CefBrowserProcessHandler) -> *mut cef_browser_process_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_browser_process_handler_t) -> CefBrowserProcessHandler { + CefBrowserProcessHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_browser_process_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_browser_process_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_browser_process_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefBrowserProcessHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_callback.rs b/ports/cef/interfaces/cef_callback.rs new file mode 100644 index 00000000000..d90d58095e9 --- /dev/null +++ b/ports/cef/interfaces/cef_callback.rs @@ -0,0 +1,336 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Generic callback structure used for asynchronous continuation. +// +#[repr(C)] +pub struct _cef_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue processing. + // + pub cont: Option ()>, + + // + // Cancel processing. + // + pub cancel: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_callback_t = _cef_callback_t; + + +// +// Generic callback structure used for asynchronous continuation. +// +pub struct CefCallback { + c_object: *mut cef_callback_t, +} + +impl Clone for CefCallback { + fn clone(&self) -> CefCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefCallback { + pub unsafe fn from_c_object(c_object: *mut cef_callback_t) -> CefCallback { + CefCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_callback_t) -> CefCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue processing. + // + pub fn cont(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object)) + } + } + + // + // Cancel processing. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_callback_t> for CefCallback { + fn to_c(rust_object: CefCallback) -> *mut cef_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_callback_t) -> CefCallback { + CefCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Generic callback structure used for asynchronous completion. +// +#[repr(C)] +pub struct _cef_completion_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be called once the task is complete. + // + pub on_complete: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_completion_callback_t = _cef_completion_callback_t; + + +// +// Generic callback structure used for asynchronous completion. +// +pub struct CefCompletionCallback { + c_object: *mut cef_completion_callback_t, +} + +impl Clone for CefCompletionCallback { + fn clone(&self) -> CefCompletionCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefCompletionCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefCompletionCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefCompletionCallback { + pub unsafe fn from_c_object(c_object: *mut cef_completion_callback_t) -> CefCompletionCallback { + CefCompletionCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_completion_callback_t) -> CefCompletionCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefCompletionCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_completion_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_completion_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be called once the task is complete. + // + pub fn on_complete(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_complete.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_completion_callback_t> for CefCompletionCallback { + fn to_c(rust_object: CefCompletionCallback) -> *mut cef_completion_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_completion_callback_t) -> CefCompletionCallback { + CefCompletionCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_completion_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_completion_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_completion_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefCompletionCallback::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_client.rs b/ports/cef/interfaces/cef_client.rs new file mode 100644 index 00000000000..66a5e1ee34b --- /dev/null +++ b/ports/cef/interfaces/cef_client.rs @@ -0,0 +1,463 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to provide handler implementations. +// +#[repr(C)] +pub struct _cef_client_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Return the handler for context menus. If no handler is provided the default + // implementation will be used. + // + pub get_context_menu_handler: Option *mut interfaces::cef_context_menu_handler_t>, + + // + // Return the handler for dialogs. If no handler is provided the default + // implementation will be used. + // + pub get_dialog_handler: Option *mut interfaces::cef_dialog_handler_t>, + + // + // Return the handler for browser display state events. + // + pub get_display_handler: Option *mut interfaces::cef_display_handler_t>, + + // + // Return the handler for download events. If no handler is returned downloads + // will not be allowed. + // + pub get_download_handler: Option *mut interfaces::cef_download_handler_t>, + + // + // Return the handler for drag events. + // + pub get_drag_handler: Option *mut interfaces::cef_drag_handler_t>, + + // + // Return the handler for focus events. + // + pub get_focus_handler: Option *mut interfaces::cef_focus_handler_t>, + + // + // Return the handler for geolocation permissions requests. If no handler is + // provided geolocation access will be denied by default. + // + pub get_geolocation_handler: Option *mut interfaces::cef_geolocation_handler_t>, + + // + // Return the handler for JavaScript dialogs. If no handler is provided the + // default implementation will be used. + // + pub get_jsdialog_handler: Option *mut interfaces::cef_jsdialog_handler_t>, + + // + // Return the handler for keyboard events. + // + pub get_keyboard_handler: Option *mut interfaces::cef_keyboard_handler_t>, + + // + // Return the handler for browser life span events. + // + pub get_life_span_handler: Option *mut interfaces::cef_life_span_handler_t>, + + // + // Return the handler for browser load status events. + // + pub get_load_handler: Option *mut interfaces::cef_load_handler_t>, + + // + // Return the handler for off-screen rendering events. + // + pub get_render_handler: Option *mut interfaces::cef_render_handler_t>, + + // + // Return the handler for browser request events. + // + pub get_request_handler: Option *mut interfaces::cef_request_handler_t>, + + // + // Called when a new message is received from a different process. Return true + // (1) if the message was handled or false (0) otherwise. Do not keep a + // reference to or attempt to access the message outside of this callback. + // + pub on_process_message_received: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_client_t = _cef_client_t; + + +// +// Implement this structure to provide handler implementations. +// +pub struct CefClient { + c_object: *mut cef_client_t, +} + +impl Clone for CefClient { + fn clone(&self) -> CefClient{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefClient { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefClient { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefClient { + pub unsafe fn from_c_object(c_object: *mut cef_client_t) -> CefClient { + CefClient { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_client_t) -> CefClient { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefClient { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_client_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_client_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Return the handler for context menus. If no handler is provided the default + // implementation will be used. + // + pub fn get_context_menu_handler(&self) -> interfaces::CefContextMenuHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_context_menu_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for dialogs. If no handler is provided the default + // implementation will be used. + // + pub fn get_dialog_handler(&self) -> interfaces::CefDialogHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_dialog_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for browser display state events. + // + pub fn get_display_handler(&self) -> interfaces::CefDisplayHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_display_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for download events. If no handler is returned downloads + // will not be allowed. + // + pub fn get_download_handler(&self) -> interfaces::CefDownloadHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_download_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for drag events. + // + pub fn get_drag_handler(&self) -> interfaces::CefDragHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_drag_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for focus events. + // + pub fn get_focus_handler(&self) -> interfaces::CefFocusHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_focus_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for geolocation permissions requests. If no handler is + // provided geolocation access will be denied by default. + // + pub fn get_geolocation_handler(&self) -> interfaces::CefGeolocationHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_geolocation_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for JavaScript dialogs. If no handler is provided the + // default implementation will be used. + // + pub fn get_jsdialog_handler(&self) -> interfaces::CefJSDialogHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_jsdialog_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for keyboard events. + // + pub fn get_keyboard_handler(&self) -> interfaces::CefKeyboardHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_keyboard_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for browser life span events. + // + pub fn get_life_span_handler(&self) -> interfaces::CefLifeSpanHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_life_span_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for browser load status events. + // + pub fn get_load_handler(&self) -> interfaces::CefLoadHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_load_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for off-screen rendering events. + // + pub fn get_render_handler(&self) -> interfaces::CefRenderHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_render_handler.unwrap())( + self.c_object)) + } + } + + // + // Return the handler for browser request events. + // + pub fn get_request_handler(&self) -> interfaces::CefRequestHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_request_handler.unwrap())( + self.c_object)) + } + } + + // + // Called when a new message is received from a different process. Return true + // (1) if the message was handled or false (0) otherwise. Do not keep a + // reference to or attempt to access the message outside of this callback. + // + pub fn on_process_message_received(&self, browser: interfaces::CefBrowser, + source_process: interfaces::CefProcessId, + message: interfaces::CefProcessMessage) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_process_message_received.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(source_process), + CefWrap::to_c(message))) + } + } +} + +impl CefWrap<*mut cef_client_t> for CefClient { + fn to_c(rust_object: CefClient) -> *mut cef_client_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_client_t) -> CefClient { + CefClient::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_client_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_client_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_client_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefClient::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_command_line.rs b/ports/cef/interfaces/cef_command_line.rs new file mode 100644 index 00000000000..7cdc0b15379 --- /dev/null +++ b/ports/cef/interfaces/cef_command_line.rs @@ -0,0 +1,643 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to create and/or parse command line arguments. Arguments with +// '--', '-' and, on Windows, '/' prefixes are considered switches. Switches +// will always precede any arguments without switch prefixes. Switches can +// optionally have a value specified using the '=' delimiter (e.g. +// "-switch=value"). An argument of "--" will terminate switch parsing with all +// subsequent tokens, regardless of prefix, being interpreted as non-switch +// arguments. Switch names are considered case-insensitive. This structure can +// be used before cef_initialize() is called. +// +#[repr(C)] +pub struct _cef_command_line_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns a writable copy of this object. + // + pub copy: Option *mut interfaces::cef_command_line_t>, + + // + // Initialize the command line with the specified |argc| and |argv| values. + // The first argument must be the name of the program. This function is only + // supported on non-Windows platforms. + // + pub init_from_argv: Option ()>, + + // + // Initialize the command line with the string returned by calling + // GetCommandLineW(). This function is only supported on Windows. + // + pub init_from_string: Option ()>, + + // + // Reset the command-line switches and arguments but leave the program + // component unchanged. + // + pub reset: Option ()>, + + // + // Retrieve the original command line string as a vector of strings. The argv + // array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* } + // + pub get_argv: Option ()>, + + // + // Constructs and returns the represented command line string. Use this + // function cautiously because quoting behavior is unclear. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_command_line_string: Option types::cef_string_userfree_t>, + + // + // Get the program part of the command line string (the first item). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_program: Option types::cef_string_userfree_t>, + + // + // Set the program part of the command line string (the first item). + // + pub set_program: Option ()>, + + // + // Returns true (1) if the command line has switches. + // + pub has_switches: Option libc::c_int>, + + // + // Returns true (1) if the command line contains the given switch. + // + pub has_switch: Option libc::c_int>, + + // + // Returns the value associated with the given switch. If the switch has no + // value or isn't present this function returns the NULL string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_switch_value: Option types::cef_string_userfree_t>, + + // + // Returns the map of switch names and values. If a switch has no value an + // NULL string is returned. + // + pub get_switches: Option ()>, + + // + // Add a switch to the end of the command line. If the switch has no value + // pass an NULL value string. + // + pub append_switch: Option ()>, + + // + // Add a switch with the specified value to the end of the command line. + // + pub append_switch_with_value: Option ()>, + + // + // True if there are remaining command line arguments. + // + pub has_arguments: Option libc::c_int>, + + // + // Get the remaining command line arguments. + // + pub get_arguments: Option ()>, + + // + // Add an argument to the end of the command line. + // + pub append_argument: Option ()>, + + // + // Insert a command before the current command. Common for debuggers, like + // "valgrind" or "gdb --args". + // + pub prepend_wrapper: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_command_line_t = _cef_command_line_t; + + +// +// Structure used to create and/or parse command line arguments. Arguments with +// '--', '-' and, on Windows, '/' prefixes are considered switches. Switches +// will always precede any arguments without switch prefixes. Switches can +// optionally have a value specified using the '=' delimiter (e.g. +// "-switch=value"). An argument of "--" will terminate switch parsing with all +// subsequent tokens, regardless of prefix, being interpreted as non-switch +// arguments. Switch names are considered case-insensitive. This structure can +// be used before cef_initialize() is called. +// +pub struct CefCommandLine { + c_object: *mut cef_command_line_t, +} + +impl Clone for CefCommandLine { + fn clone(&self) -> CefCommandLine{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefCommandLine { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefCommandLine { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefCommandLine { + pub unsafe fn from_c_object(c_object: *mut cef_command_line_t) -> CefCommandLine { + CefCommandLine { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_command_line_t) -> CefCommandLine { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefCommandLine { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_command_line_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_command_line_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns a writable copy of this object. + // + pub fn copy(&self) -> interfaces::CefCommandLine { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Initialize the command line with the specified |argc| and |argv| values. + // The first argument must be the name of the program. This function is only + // supported on non-Windows platforms. + // + pub fn init_from_argv(&self, argc: libc::c_int, argv: &&str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).init_from_argv.unwrap())( + self.c_object, + CefWrap::to_c(argc), + CefWrap::to_c(argv))) + } + } + + // + // Initialize the command line with the string returned by calling + // GetCommandLineW(). This function is only supported on Windows. + // + pub fn init_from_string(&self, command_line: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).init_from_string.unwrap())( + self.c_object, + CefWrap::to_c(command_line))) + } + } + + // + // Reset the command-line switches and arguments but leave the program + // component unchanged. + // + pub fn reset(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).reset.unwrap())( + self.c_object)) + } + } + + // + // Retrieve the original command line string as a vector of strings. The argv + // array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* } + // + pub fn get_argv(&self, argv: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_argv.unwrap())( + self.c_object, + CefWrap::to_c(argv))) + } + } + + // + // Constructs and returns the represented command line string. Use this + // function cautiously because quoting behavior is unclear. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_command_line_string(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_command_line_string.unwrap())( + self.c_object)) + } + } + + // + // Get the program part of the command line string (the first item). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_program(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_program.unwrap())( + self.c_object)) + } + } + + // + // Set the program part of the command line string (the first item). + // + pub fn set_program(&self, program: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_program.unwrap())( + self.c_object, + CefWrap::to_c(program))) + } + } + + // + // Returns true (1) if the command line has switches. + // + pub fn has_switches(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_switches.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the command line contains the given switch. + // + pub fn has_switch(&self, name: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_switch.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Returns the value associated with the given switch. If the switch has no + // value or isn't present this function returns the NULL string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_switch_value(&self, name: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_switch_value.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Returns the map of switch names and values. If a switch has no value an + // NULL string is returned. + // + pub fn get_switches(&self, switches: HashMap) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_switches.unwrap())( + self.c_object, + CefWrap::to_c(switches))) + } + } + + // + // Add a switch to the end of the command line. If the switch has no value + // pass an NULL value string. + // + pub fn append_switch(&self, name: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).append_switch.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Add a switch with the specified value to the end of the command line. + // + pub fn append_switch_with_value(&self, name: &str, value: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).append_switch_with_value.unwrap())( + self.c_object, + CefWrap::to_c(name), + CefWrap::to_c(value))) + } + } + + // + // True if there are remaining command line arguments. + // + pub fn has_arguments(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_arguments.unwrap())( + self.c_object)) + } + } + + // + // Get the remaining command line arguments. + // + pub fn get_arguments(&self, arguments: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_arguments.unwrap())( + self.c_object, + CefWrap::to_c(arguments))) + } + } + + // + // Add an argument to the end of the command line. + // + pub fn append_argument(&self, argument: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).append_argument.unwrap())( + self.c_object, + CefWrap::to_c(argument))) + } + } + + // + // Insert a command before the current command. Common for debuggers, like + // "valgrind" or "gdb --args". + // + pub fn prepend_wrapper(&self, wrapper: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).prepend_wrapper.unwrap())( + self.c_object, + CefWrap::to_c(wrapper))) + } + } + + // + // Create a new cef_command_line_t instance. + // + pub fn create_command_line() -> interfaces::CefCommandLine { + unsafe { + CefWrap::to_rust( + ::command_line::cef_command_line_create_command_line( +)) + } + } + + // + // Returns the singleton global cef_command_line_t object. The returned object + // will be read-only. + // + pub fn get_global_command_line() -> interfaces::CefCommandLine { + unsafe { + CefWrap::to_rust( + ::command_line::cef_command_line_get_global_command_line( +)) + } + } +} + +impl CefWrap<*mut cef_command_line_t> for CefCommandLine { + fn to_c(rust_object: CefCommandLine) -> *mut cef_command_line_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_command_line_t) -> CefCommandLine { + CefCommandLine::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_command_line_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_command_line_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_command_line_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefCommandLine::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_context_menu_handler.rs b/ports/cef/interfaces/cef_context_menu_handler.rs new file mode 100644 index 00000000000..3017851eb1c --- /dev/null +++ b/ports/cef/interfaces/cef_context_menu_handler.rs @@ -0,0 +1,825 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle context menu events. The functions of this +// structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_context_menu_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called before a context menu is displayed. |params| provides information + // about the context menu state. |model| initially contains the default + // context menu. The |model| can be cleared to show no context menu or + // modified to show a custom menu. Do not keep references to |params| or + // |model| outside of this callback. + // + pub on_before_context_menu: Option ()>, + + // + // Called to execute a command selected from the context menu. Return true (1) + // if the command was handled or false (0) for the default implementation. See + // cef_menu_id_t for the command ids that have default implementations. All + // user-defined command ids should be between MENU_ID_USER_FIRST and + // MENU_ID_USER_LAST. |params| will have the same values as what was passed to + // on_before_context_menu(). Do not keep a reference to |params| outside of + // this callback. + // + pub on_context_menu_command: Option libc::c_int>, + + // + // Called when the context menu is dismissed irregardless of whether the menu + // was NULL or a command was selected. + // + pub on_context_menu_dismissed: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_context_menu_handler_t = _cef_context_menu_handler_t; + + +// +// Implement this structure to handle context menu events. The functions of this +// structure will be called on the UI thread. +// +pub struct CefContextMenuHandler { + c_object: *mut cef_context_menu_handler_t, +} + +impl Clone for CefContextMenuHandler { + fn clone(&self) -> CefContextMenuHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefContextMenuHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefContextMenuHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefContextMenuHandler { + pub unsafe fn from_c_object(c_object: *mut cef_context_menu_handler_t) -> CefContextMenuHandler { + CefContextMenuHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_context_menu_handler_t) -> CefContextMenuHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefContextMenuHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_context_menu_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_context_menu_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called before a context menu is displayed. |params| provides information + // about the context menu state. |model| initially contains the default + // context menu. The |model| can be cleared to show no context menu or + // modified to show a custom menu. Do not keep references to |params| or + // |model| outside of this callback. + // + pub fn on_before_context_menu(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, params: interfaces::CefContextMenuParams, + model: interfaces::CefMenuModel) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_context_menu.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(params), + CefWrap::to_c(model))) + } + } + + // + // Called to execute a command selected from the context menu. Return true (1) + // if the command was handled or false (0) for the default implementation. See + // cef_menu_id_t for the command ids that have default implementations. All + // user-defined command ids should be between MENU_ID_USER_FIRST and + // MENU_ID_USER_LAST. |params| will have the same values as what was passed to + // on_before_context_menu(). Do not keep a reference to |params| outside of + // this callback. + // + pub fn on_context_menu_command(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, params: interfaces::CefContextMenuParams, + command_id: libc::c_int, + event_flags: types::cef_event_flags_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_context_menu_command.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(params), + CefWrap::to_c(command_id), + CefWrap::to_c(event_flags))) + } + } + + // + // Called when the context menu is dismissed irregardless of whether the menu + // was NULL or a command was selected. + // + pub fn on_context_menu_dismissed(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_context_menu_dismissed.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame))) + } + } +} + +impl CefWrap<*mut cef_context_menu_handler_t> for CefContextMenuHandler { + fn to_c(rust_object: CefContextMenuHandler) -> *mut cef_context_menu_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_context_menu_handler_t) -> CefContextMenuHandler { + CefContextMenuHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_context_menu_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_context_menu_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_context_menu_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefContextMenuHandler::from_c_object_addref(c_object)) + } + } +} + + +// +// Provides information about the context menu state. The ethods of this +// structure can only be accessed on browser process the UI thread. +// +#[repr(C)] +pub struct _cef_context_menu_params_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the X coordinate of the mouse where the context menu was invoked. + // Coords are relative to the associated RenderView's origin. + // + pub get_xcoord: Option libc::c_int>, + + // + // Returns the Y coordinate of the mouse where the context menu was invoked. + // Coords are relative to the associated RenderView's origin. + // + pub get_ycoord: Option libc::c_int>, + + // + // Returns flags representing the type of node that the context menu was + // invoked on. + // + pub get_type_flags: Option types::cef_context_menu_type_flags_t>, + + // + // Returns the URL of the link, if any, that encloses the node that the + // context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_link_url: Option types::cef_string_userfree_t>, + + // + // Returns the link URL, if any, to be used ONLY for "copy link address". We + // don't validate this field in the frontend process. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_unfiltered_link_url: Option types::cef_string_userfree_t>, + + // + // Returns the source URL, if any, for the element that the context menu was + // invoked on. Example of elements with source URLs are img, audio, and video. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_source_url: Option types::cef_string_userfree_t>, + + // + // Returns true (1) if the context menu was invoked on an image which has non- + // NULL contents. + // + pub has_image_contents: Option libc::c_int>, + + // + // Returns the URL of the top level page that the context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_page_url: Option types::cef_string_userfree_t>, + + // + // Returns the URL of the subframe that the context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_frame_url: Option types::cef_string_userfree_t>, + + // + // Returns the character encoding of the subframe that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_frame_charset: Option types::cef_string_userfree_t>, + + // + // Returns the type of context node that the context menu was invoked on. + // + pub get_media_type: Option types::cef_context_menu_media_type_t>, + + // + // Returns flags representing the actions supported by the media element, if + // any, that the context menu was invoked on. + // + pub get_media_state_flags: Option types::cef_context_menu_media_state_flags_t>, + + // + // Returns the text of the selection, if any, that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_selection_text: Option types::cef_string_userfree_t>, + + // + // Returns the text of the misspelled word, if any, that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_misspelled_word: Option types::cef_string_userfree_t>, + + // + // Returns the hash of the misspelled word, if any, that the context menu was + // invoked on. + // + pub get_misspelling_hash: Option libc::c_int>, + + // + // Returns true (1) if suggestions exist, false (0) otherwise. Fills in + // |suggestions| from the spell check service for the misspelled word if there + // is one. + // + pub get_dictionary_suggestions: Option libc::c_int>, + + // + // Returns true (1) if the context menu was invoked on an editable node. + // + pub is_editable: Option libc::c_int>, + + // + // Returns true (1) if the context menu was invoked on an editable node where + // spell-check is enabled. + // + pub is_spell_check_enabled: Option libc::c_int>, + + // + // Returns flags representing the actions supported by the editable node, if + // any, that the context menu was invoked on. + // + pub get_edit_state_flags: Option types::cef_context_menu_edit_state_flags_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_context_menu_params_t = _cef_context_menu_params_t; + + +// +// Provides information about the context menu state. The ethods of this +// structure can only be accessed on browser process the UI thread. +// +pub struct CefContextMenuParams { + c_object: *mut cef_context_menu_params_t, +} + +impl Clone for CefContextMenuParams { + fn clone(&self) -> CefContextMenuParams{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefContextMenuParams { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefContextMenuParams { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefContextMenuParams { + pub unsafe fn from_c_object(c_object: *mut cef_context_menu_params_t) -> CefContextMenuParams { + CefContextMenuParams { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_context_menu_params_t) -> CefContextMenuParams { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefContextMenuParams { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_context_menu_params_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_context_menu_params_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the X coordinate of the mouse where the context menu was invoked. + // Coords are relative to the associated RenderView's origin. + // + pub fn get_xcoord(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_xcoord.unwrap())( + self.c_object)) + } + } + + // + // Returns the Y coordinate of the mouse where the context menu was invoked. + // Coords are relative to the associated RenderView's origin. + // + pub fn get_ycoord(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_ycoord.unwrap())( + self.c_object)) + } + } + + // + // Returns flags representing the type of node that the context menu was + // invoked on. + // + pub fn get_type_flags(&self) -> types::cef_context_menu_type_flags_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type_flags.unwrap())( + self.c_object)) + } + } + + // + // Returns the URL of the link, if any, that encloses the node that the + // context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_link_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_link_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the link URL, if any, to be used ONLY for "copy link address". We + // don't validate this field in the frontend process. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_unfiltered_link_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_unfiltered_link_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the source URL, if any, for the element that the context menu was + // invoked on. Example of elements with source URLs are img, audio, and video. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_source_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_source_url.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the context menu was invoked on an image which has non- + // NULL contents. + // + pub fn has_image_contents(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_image_contents.unwrap())( + self.c_object)) + } + } + + // + // Returns the URL of the top level page that the context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_page_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_page_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the URL of the subframe that the context menu was invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_frame_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the character encoding of the subframe that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_frame_charset(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_charset.unwrap())( + self.c_object)) + } + } + + // + // Returns the type of context node that the context menu was invoked on. + // + pub fn get_media_type(&self) -> types::cef_context_menu_media_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_media_type.unwrap())( + self.c_object)) + } + } + + // + // Returns flags representing the actions supported by the media element, if + // any, that the context menu was invoked on. + // + pub fn get_media_state_flags( + &self) -> types::cef_context_menu_media_state_flags_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_media_state_flags.unwrap())( + self.c_object)) + } + } + + // + // Returns the text of the selection, if any, that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_selection_text(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_text.unwrap())( + self.c_object)) + } + } + + // + // Returns the text of the misspelled word, if any, that the context menu was + // invoked on. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_misspelled_word(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_misspelled_word.unwrap())( + self.c_object)) + } + } + + // + // Returns the hash of the misspelled word, if any, that the context menu was + // invoked on. + // + pub fn get_misspelling_hash(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_misspelling_hash.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if suggestions exist, false (0) otherwise. Fills in + // |suggestions| from the spell check service for the misspelled word if there + // is one. + // + pub fn get_dictionary_suggestions(&self, + suggestions: Vec) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_dictionary_suggestions.unwrap())( + self.c_object, + CefWrap::to_c(suggestions))) + } + } + + // + // Returns true (1) if the context menu was invoked on an editable node. + // + pub fn is_editable(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_editable.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the context menu was invoked on an editable node where + // spell-check is enabled. + // + pub fn is_spell_check_enabled(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_spell_check_enabled.unwrap())( + self.c_object)) + } + } + + // + // Returns flags representing the actions supported by the editable node, if + // any, that the context menu was invoked on. + // + pub fn get_edit_state_flags( + &self) -> types::cef_context_menu_edit_state_flags_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_edit_state_flags.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_context_menu_params_t> for CefContextMenuParams { + fn to_c(rust_object: CefContextMenuParams) -> *mut cef_context_menu_params_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_context_menu_params_t) -> CefContextMenuParams { + CefContextMenuParams::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_context_menu_params_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_context_menu_params_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_context_menu_params_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefContextMenuParams::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_cookie.rs b/ports/cef/interfaces/cef_cookie.rs new file mode 100644 index 00000000000..62a970482c0 --- /dev/null +++ b/ports/cef/interfaces/cef_cookie.rs @@ -0,0 +1,560 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used for managing cookies. The functions of this structure may be +// called on any thread unless otherwise indicated. +// +#[repr(C)] +pub struct _cef_cookie_manager_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Set the schemes supported by this manager. By default only "http" and + // "https" schemes are supported. Must be called before any cookies are + // accessed. + // + pub set_supported_schemes: Option ( + )>, + + // + // Visit all cookies. The returned cookies are ordered by longest path, then + // by earliest creation date. Returns false (0) if cookies cannot be accessed. + // + pub visit_all_cookies: Option libc::c_int>, + + // + // Visit a subset of cookies. The results are filtered by the given url + // scheme, host, domain and path. If |includeHttpOnly| is true (1) HTTP-only + // cookies will also be included in the results. The returned cookies are + // ordered by longest path, then by earliest creation date. Returns false (0) + // if cookies cannot be accessed. + // + pub visit_url_cookies: Option libc::c_int>, + + // + // Sets a cookie given a valid URL and explicit user-provided cookie + // attributes. This function expects each attribute to be well-formed. It will + // check for disallowed characters (e.g. the ';' character is disallowed + // within the cookie value attribute) and will return false (0) without + // setting the cookie if such characters are found. This function must be + // called on the IO thread. + // + pub set_cookie: Option libc::c_int>, + + // + // Delete all cookies that match the specified parameters. If both |url| and + // values |cookie_name| are specified all host and domain cookies matching + // both will be deleted. If only |url| is specified all host cookies (but not + // domain cookies) irrespective of path will be deleted. If |url| is NULL all + // cookies for all hosts and domains will be deleted. Returns false (0) if a + // non- NULL invalid URL is specified or if cookies cannot be accessed. This + // function must be called on the IO thread. + // + pub delete_cookies: Option libc::c_int>, + + // + // Sets the directory path that will be used for storing cookie data. If + // |path| is NULL data will be stored in memory only. Otherwise, data will be + // stored at the specified |path|. To persist session cookies (cookies without + // an expiry date or validity interval) set |persist_session_cookies| to true + // (1). Session cookies are generally intended to be transient and most Web + // browsers do not persist them. Returns false (0) if cookies cannot be + // accessed. + // + pub set_storage_path: Option libc::c_int>, + + // + // Flush the backing store (if any) to disk and execute the specified + // |callback| on the IO thread when done. Returns false (0) if cookies cannot + // be accessed. + // + pub flush_store: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_cookie_manager_t = _cef_cookie_manager_t; + + +// +// Structure used for managing cookies. The functions of this structure may be +// called on any thread unless otherwise indicated. +// +pub struct CefCookieManager { + c_object: *mut cef_cookie_manager_t, +} + +impl Clone for CefCookieManager { + fn clone(&self) -> CefCookieManager{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefCookieManager { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefCookieManager { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefCookieManager { + pub unsafe fn from_c_object(c_object: *mut cef_cookie_manager_t) -> CefCookieManager { + CefCookieManager { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_cookie_manager_t) -> CefCookieManager { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefCookieManager { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_cookie_manager_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_cookie_manager_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Set the schemes supported by this manager. By default only "http" and + // "https" schemes are supported. Must be called before any cookies are + // accessed. + // + pub fn set_supported_schemes(&self, schemes: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_supported_schemes.unwrap())( + self.c_object, + CefWrap::to_c(schemes))) + } + } + + // + // Visit all cookies. The returned cookies are ordered by longest path, then + // by earliest creation date. Returns false (0) if cookies cannot be accessed. + // + pub fn visit_all_cookies(&self, + visitor: interfaces::CefCookieVisitor) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit_all_cookies.unwrap())( + self.c_object, + CefWrap::to_c(visitor))) + } + } + + // + // Visit a subset of cookies. The results are filtered by the given url + // scheme, host, domain and path. If |includeHttpOnly| is true (1) HTTP-only + // cookies will also be included in the results. The returned cookies are + // ordered by longest path, then by earliest creation date. Returns false (0) + // if cookies cannot be accessed. + // + pub fn visit_url_cookies(&self, url: &str, includeHttpOnly: libc::c_int, + visitor: interfaces::CefCookieVisitor) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit_url_cookies.unwrap())( + self.c_object, + CefWrap::to_c(url), + CefWrap::to_c(includeHttpOnly), + CefWrap::to_c(visitor))) + } + } + + // + // Sets a cookie given a valid URL and explicit user-provided cookie + // attributes. This function expects each attribute to be well-formed. It will + // check for disallowed characters (e.g. the ';' character is disallowed + // within the cookie value attribute) and will return false (0) without + // setting the cookie if such characters are found. This function must be + // called on the IO thread. + // + pub fn set_cookie(&self, url: &str, + cookie: &interfaces::CefCookie) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_cookie.unwrap())( + self.c_object, + CefWrap::to_c(url), + CefWrap::to_c(cookie))) + } + } + + // + // Delete all cookies that match the specified parameters. If both |url| and + // values |cookie_name| are specified all host and domain cookies matching + // both will be deleted. If only |url| is specified all host cookies (but not + // domain cookies) irrespective of path will be deleted. If |url| is NULL all + // cookies for all hosts and domains will be deleted. Returns false (0) if a + // non- NULL invalid URL is specified or if cookies cannot be accessed. This + // function must be called on the IO thread. + // + pub fn delete_cookies(&self, url: &str, cookie_name: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).delete_cookies.unwrap())( + self.c_object, + CefWrap::to_c(url), + CefWrap::to_c(cookie_name))) + } + } + + // + // Sets the directory path that will be used for storing cookie data. If + // |path| is NULL data will be stored in memory only. Otherwise, data will be + // stored at the specified |path|. To persist session cookies (cookies without + // an expiry date or validity interval) set |persist_session_cookies| to true + // (1). Session cookies are generally intended to be transient and most Web + // browsers do not persist them. Returns false (0) if cookies cannot be + // accessed. + // + pub fn set_storage_path(&self, path: &str, + persist_session_cookies: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_storage_path.unwrap())( + self.c_object, + CefWrap::to_c(path), + CefWrap::to_c(persist_session_cookies))) + } + } + + // + // Flush the backing store (if any) to disk and execute the specified + // |callback| on the IO thread when done. Returns false (0) if cookies cannot + // be accessed. + // + pub fn flush_store(&self, + callback: interfaces::CefCompletionCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).flush_store.unwrap())( + self.c_object, + CefWrap::to_c(callback))) + } + } + + // + // Returns the global cookie manager. By default data will be stored at + // CefSettings.cache_path if specified or in memory otherwise. + // + pub fn get_global_manager() -> interfaces::CefCookieManager { + unsafe { + CefWrap::to_rust( + ::cookie::cef_cookie_manager_get_global_manager( +)) + } + } + + // + // Creates a new cookie manager. If |path| is NULL data will be stored in + // memory only. Otherwise, data will be stored at the specified |path|. To + // persist session cookies (cookies without an expiry date or validity + // interval) set |persist_session_cookies| to true (1). Session cookies are + // generally intended to be transient and most Web browsers do not persist + // them. Returns NULL if creation fails. + // + pub fn create_manager(path: &str, + persist_session_cookies: libc::c_int) -> interfaces::CefCookieManager { + unsafe { + CefWrap::to_rust( + ::cookie::cef_cookie_manager_create_manager( + CefWrap::to_c(path), + CefWrap::to_c(persist_session_cookies))) + } + } +} + +impl CefWrap<*mut cef_cookie_manager_t> for CefCookieManager { + fn to_c(rust_object: CefCookieManager) -> *mut cef_cookie_manager_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_cookie_manager_t) -> CefCookieManager { + CefCookieManager::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_cookie_manager_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_cookie_manager_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_cookie_manager_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefCookieManager::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure to implement for visiting cookie values. The functions of this +// structure will always be called on the IO thread. +// +#[repr(C)] +pub struct _cef_cookie_visitor_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be called once for each cookie. |count| is the 0-based + // index for the current cookie. |total| is the total number of cookies. Set + // |deleteCookie| to true (1) to delete the cookie currently being visited. + // Return false (0) to stop visiting cookies. This function may never be + // called if no cookies are found. + // + pub visit: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_cookie_visitor_t = _cef_cookie_visitor_t; + + +// +// Structure to implement for visiting cookie values. The functions of this +// structure will always be called on the IO thread. +// +pub struct CefCookieVisitor { + c_object: *mut cef_cookie_visitor_t, +} + +impl Clone for CefCookieVisitor { + fn clone(&self) -> CefCookieVisitor{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefCookieVisitor { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefCookieVisitor { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefCookieVisitor { + pub unsafe fn from_c_object(c_object: *mut cef_cookie_visitor_t) -> CefCookieVisitor { + CefCookieVisitor { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_cookie_visitor_t) -> CefCookieVisitor { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefCookieVisitor { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_cookie_visitor_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_cookie_visitor_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be called once for each cookie. |count| is the 0-based + // index for the current cookie. |total| is the total number of cookies. Set + // |deleteCookie| to true (1) to delete the cookie currently being visited. + // Return false (0) to stop visiting cookies. This function may never be + // called if no cookies are found. + // + pub fn visit(&self, cookie: &interfaces::CefCookie, count: libc::c_int, + total: libc::c_int, deleteCookie: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit.unwrap())( + self.c_object, + CefWrap::to_c(cookie), + CefWrap::to_c(count), + CefWrap::to_c(total), + CefWrap::to_c(deleteCookie))) + } + } +} + +impl CefWrap<*mut cef_cookie_visitor_t> for CefCookieVisitor { + fn to_c(rust_object: CefCookieVisitor) -> *mut cef_cookie_visitor_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_cookie_visitor_t) -> CefCookieVisitor { + CefCookieVisitor::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_cookie_visitor_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_cookie_visitor_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_cookie_visitor_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefCookieVisitor::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_dialog_handler.rs b/ports/cef/interfaces/cef_dialog_handler.rs new file mode 100644 index 00000000000..04660cbf16b --- /dev/null +++ b/ports/cef/interfaces/cef_dialog_handler.rs @@ -0,0 +1,374 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure for asynchronous continuation of file dialog requests. +// +#[repr(C)] +pub struct _cef_file_dialog_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue the file selection with the specified |file_paths|. This may be a + // single value or a list of values depending on the dialog mode. An NULL + // value is treated the same as calling cancel(). + // + pub cont: Option ()>, + + // + // Cancel the file selection. + // + pub cancel: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_file_dialog_callback_t = _cef_file_dialog_callback_t; + + +// +// Callback structure for asynchronous continuation of file dialog requests. +// +pub struct CefFileDialogCallback { + c_object: *mut cef_file_dialog_callback_t, +} + +impl Clone for CefFileDialogCallback { + fn clone(&self) -> CefFileDialogCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefFileDialogCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefFileDialogCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefFileDialogCallback { + pub unsafe fn from_c_object(c_object: *mut cef_file_dialog_callback_t) -> CefFileDialogCallback { + CefFileDialogCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_file_dialog_callback_t) -> CefFileDialogCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefFileDialogCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_file_dialog_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_file_dialog_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue the file selection with the specified |file_paths|. This may be a + // single value or a list of values depending on the dialog mode. An NULL + // value is treated the same as calling cancel(). + // + pub fn cont(&self, file_paths: Vec) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(file_paths))) + } + } + + // + // Cancel the file selection. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_file_dialog_callback_t> for CefFileDialogCallback { + fn to_c(rust_object: CefFileDialogCallback) -> *mut cef_file_dialog_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_file_dialog_callback_t) -> CefFileDialogCallback { + CefFileDialogCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_file_dialog_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_file_dialog_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_file_dialog_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefFileDialogCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Implement this structure to handle dialog events. The functions of this +// structure will be called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_dialog_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called to run a file chooser dialog. |mode| represents the type of dialog + // to display. |title| to the title to be used for the dialog and may be NULL + // to show the default title ("Open" or "Save" depending on the mode). + // |default_file_name| is the default file name to select in the dialog. + // |accept_types| is a list of valid lower-cased MIME types or file extensions + // specified in an input element and is used to restrict selectable files to + // such types. To display a custom dialog return true (1) and execute + // |callback| either inline or at a later time. To display the default dialog + // return false (0). + // + pub on_file_dialog: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_dialog_handler_t = _cef_dialog_handler_t; + + +// +// Implement this structure to handle dialog events. The functions of this +// structure will be called on the browser process UI thread. +// +pub struct CefDialogHandler { + c_object: *mut cef_dialog_handler_t, +} + +impl Clone for CefDialogHandler { + fn clone(&self) -> CefDialogHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDialogHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDialogHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDialogHandler { + pub unsafe fn from_c_object(c_object: *mut cef_dialog_handler_t) -> CefDialogHandler { + CefDialogHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_dialog_handler_t) -> CefDialogHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDialogHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_dialog_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_dialog_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called to run a file chooser dialog. |mode| represents the type of dialog + // to display. |title| to the title to be used for the dialog and may be NULL + // to show the default title ("Open" or "Save" depending on the mode). + // |default_file_name| is the default file name to select in the dialog. + // |accept_types| is a list of valid lower-cased MIME types or file extensions + // specified in an input element and is used to restrict selectable files to + // such types. To display a custom dialog return true (1) and execute + // |callback| either inline or at a later time. To display the default dialog + // return false (0). + // + pub fn on_file_dialog(&self, browser: interfaces::CefBrowser, + mode: types::cef_file_dialog_mode_t, title: &str, + default_file_name: &str, accept_types: Vec, + callback: interfaces::CefFileDialogCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_file_dialog.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(mode), + CefWrap::to_c(title), + CefWrap::to_c(default_file_name), + CefWrap::to_c(accept_types), + CefWrap::to_c(callback))) + } + } +} + +impl CefWrap<*mut cef_dialog_handler_t> for CefDialogHandler { + fn to_c(rust_object: CefDialogHandler) -> *mut cef_dialog_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_dialog_handler_t) -> CefDialogHandler { + CefDialogHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_dialog_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_dialog_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_dialog_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDialogHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_display_handler.rs b/ports/cef/interfaces/cef_display_handler.rs new file mode 100644 index 00000000000..bb26a50b4b5 --- /dev/null +++ b/ports/cef/interfaces/cef_display_handler.rs @@ -0,0 +1,303 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to browser display state. +// The functions of this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_display_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called when a frame's address has changed. + // + pub on_address_change: Option ()>, + + // + // Called when the page title changes. + // + pub on_title_change: Option ()>, + + // + // Called when the browser is about to display a tooltip. |text| contains the + // text that will be displayed in the tooltip. To handle the display of the + // tooltip yourself return true (1). Otherwise, you can optionally modify + // |text| and then return false (0) to allow the browser to display the + // tooltip. When window rendering is disabled the application is responsible + // for drawing tooltips and the return value is ignored. + // + pub on_tooltip: Option libc::c_int>, + + // + // Called when the browser receives a status message. |value| contains the + // text that will be displayed in the status message. + // + pub on_status_message: Option ()>, + + // + // Called to display a console message. Return true (1) to stop the message + // from being output to the console. + // + pub on_console_message: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_display_handler_t = _cef_display_handler_t; + + +// +// Implement this structure to handle events related to browser display state. +// The functions of this structure will be called on the UI thread. +// +pub struct CefDisplayHandler { + c_object: *mut cef_display_handler_t, +} + +impl Clone for CefDisplayHandler { + fn clone(&self) -> CefDisplayHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDisplayHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDisplayHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDisplayHandler { + pub unsafe fn from_c_object(c_object: *mut cef_display_handler_t) -> CefDisplayHandler { + CefDisplayHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_display_handler_t) -> CefDisplayHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDisplayHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_display_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_display_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called when a frame's address has changed. + // + pub fn on_address_change(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_address_change.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(url))) + } + } + + // + // Called when the page title changes. + // + pub fn on_title_change(&self, browser: interfaces::CefBrowser, + title: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_title_change.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(title))) + } + } + + // + // Called when the browser is about to display a tooltip. |text| contains the + // text that will be displayed in the tooltip. To handle the display of the + // tooltip yourself return true (1). Otherwise, you can optionally modify + // |text| and then return false (0) to allow the browser to display the + // tooltip. When window rendering is disabled the application is responsible + // for drawing tooltips and the return value is ignored. + // + pub fn on_tooltip(&self, browser: interfaces::CefBrowser, + text: *mut types::cef_string_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_tooltip.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(text))) + } + } + + // + // Called when the browser receives a status message. |value| contains the + // text that will be displayed in the status message. + // + pub fn on_status_message(&self, browser: interfaces::CefBrowser, + value: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_status_message.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(value))) + } + } + + // + // Called to display a console message. Return true (1) to stop the message + // from being output to the console. + // + pub fn on_console_message(&self, browser: interfaces::CefBrowser, + message: &str, source: &str, line: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_console_message.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(message), + CefWrap::to_c(source), + CefWrap::to_c(line))) + } + } +} + +impl CefWrap<*mut cef_display_handler_t> for CefDisplayHandler { + fn to_c(rust_object: CefDisplayHandler) -> *mut cef_display_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_display_handler_t) -> CefDisplayHandler { + CefDisplayHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_display_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_display_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_display_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDisplayHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_dom.rs b/ports/cef/interfaces/cef_dom.rs new file mode 100644 index 00000000000..ef12b54d21d --- /dev/null +++ b/ports/cef/interfaces/cef_dom.rs @@ -0,0 +1,1295 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure to implement for visiting the DOM. The functions of this structure +// will be called on the render process main thread. +// +#[repr(C)] +pub struct _cef_domvisitor_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method executed for visiting the DOM. The document object passed to this + // function represents a snapshot of the DOM at the time this function is + // executed. DOM objects are only valid for the scope of this function. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this function. + // + pub visit: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_domvisitor_t = _cef_domvisitor_t; + + +// +// Structure to implement for visiting the DOM. The functions of this structure +// will be called on the render process main thread. +// +pub struct CefDOMVisitor { + c_object: *mut cef_domvisitor_t, +} + +impl Clone for CefDOMVisitor { + fn clone(&self) -> CefDOMVisitor{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDOMVisitor { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDOMVisitor { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDOMVisitor { + pub unsafe fn from_c_object(c_object: *mut cef_domvisitor_t) -> CefDOMVisitor { + CefDOMVisitor { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_domvisitor_t) -> CefDOMVisitor { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDOMVisitor { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_domvisitor_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_domvisitor_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method executed for visiting the DOM. The document object passed to this + // function represents a snapshot of the DOM at the time this function is + // executed. DOM objects are only valid for the scope of this function. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this function. + // + pub fn visit(&self, document: interfaces::CefDOMDocument) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit.unwrap())( + self.c_object, + CefWrap::to_c(document))) + } + } +} + +impl CefWrap<*mut cef_domvisitor_t> for CefDOMVisitor { + fn to_c(rust_object: CefDOMVisitor) -> *mut cef_domvisitor_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_domvisitor_t) -> CefDOMVisitor { + CefDOMVisitor::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_domvisitor_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_domvisitor_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_domvisitor_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDOMVisitor::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to represent a DOM document. The functions of this structure +// should only be called on the render process main thread thread. +// +#[repr(C)] +pub struct _cef_domdocument_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the document type. + // + pub get_type: Option types::cef_dom_document_type_t>, + + // + // Returns the root document node. + // + pub get_document: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the BODY node of an HTML document. + // + pub get_body: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the HEAD node of an HTML document. + // + pub get_head: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the title of an HTML document. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_title: Option types::cef_string_userfree_t>, + + // + // Returns the document element with the specified ID value. + // + pub get_element_by_id: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the node that currently has keyboard focus. + // + pub get_focused_node: Option *mut interfaces::cef_domnode_t>, + + // + // Returns true (1) if a portion of the document is selected. + // + pub has_selection: Option libc::c_int>, + + // + // Returns the selection start node. + // + pub get_selection_start_node: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the selection offset within the start node. + // + pub get_selection_start_offset: Option libc::c_int>, + + // + // Returns the selection end node. + // + pub get_selection_end_node: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the selection offset within the end node. + // + pub get_selection_end_offset: Option libc::c_int>, + + // + // Returns the contents of this selection as markup. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_selection_as_markup: Option types::cef_string_userfree_t>, + + // + // Returns the contents of this selection as text. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_selection_as_text: Option types::cef_string_userfree_t>, + + // + // Returns the base URL for the document. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_base_url: Option types::cef_string_userfree_t>, + + // + // Returns a complete URL based on the document base URL and the specified + // partial URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_complete_url: Option types::cef_string_userfree_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_domdocument_t = _cef_domdocument_t; + + +// +// Structure used to represent a DOM document. The functions of this structure +// should only be called on the render process main thread thread. +// +pub struct CefDOMDocument { + c_object: *mut cef_domdocument_t, +} + +impl Clone for CefDOMDocument { + fn clone(&self) -> CefDOMDocument{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDOMDocument { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDOMDocument { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDOMDocument { + pub unsafe fn from_c_object(c_object: *mut cef_domdocument_t) -> CefDOMDocument { + CefDOMDocument { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_domdocument_t) -> CefDOMDocument { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDOMDocument { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_domdocument_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_domdocument_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the document type. + // + pub fn get_type(&self) -> types::cef_dom_document_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object)) + } + } + + // + // Returns the root document node. + // + pub fn get_document(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_document.unwrap())( + self.c_object)) + } + } + + // + // Returns the BODY node of an HTML document. + // + pub fn get_body(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_body.unwrap())( + self.c_object)) + } + } + + // + // Returns the HEAD node of an HTML document. + // + pub fn get_head(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_head.unwrap())( + self.c_object)) + } + } + + // + // Returns the title of an HTML document. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_title(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_title.unwrap())( + self.c_object)) + } + } + + // + // Returns the document element with the specified ID value. + // + pub fn get_element_by_id(&self, id: &str) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_by_id.unwrap())( + self.c_object, + CefWrap::to_c(id))) + } + } + + // + // Returns the node that currently has keyboard focus. + // + pub fn get_focused_node(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_focused_node.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if a portion of the document is selected. + // + pub fn has_selection(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_selection.unwrap())( + self.c_object)) + } + } + + // + // Returns the selection start node. + // + pub fn get_selection_start_node(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_start_node.unwrap())( + self.c_object)) + } + } + + // + // Returns the selection offset within the start node. + // + pub fn get_selection_start_offset(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_start_offset.unwrap())( + self.c_object)) + } + } + + // + // Returns the selection end node. + // + pub fn get_selection_end_node(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_end_node.unwrap())( + self.c_object)) + } + } + + // + // Returns the selection offset within the end node. + // + pub fn get_selection_end_offset(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_end_offset.unwrap())( + self.c_object)) + } + } + + // + // Returns the contents of this selection as markup. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_selection_as_markup(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_as_markup.unwrap())( + self.c_object)) + } + } + + // + // Returns the contents of this selection as text. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_selection_as_text(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_selection_as_text.unwrap())( + self.c_object)) + } + } + + // + // Returns the base URL for the document. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_base_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_base_url.unwrap())( + self.c_object)) + } + } + + // + // Returns a complete URL based on the document base URL and the specified + // partial URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_complete_url(&self, partialURL: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_complete_url.unwrap())( + self.c_object, + CefWrap::to_c(partialURL))) + } + } +} + +impl CefWrap<*mut cef_domdocument_t> for CefDOMDocument { + fn to_c(rust_object: CefDOMDocument) -> *mut cef_domdocument_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_domdocument_t) -> CefDOMDocument { + CefDOMDocument::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_domdocument_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_domdocument_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_domdocument_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDOMDocument::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to represent a DOM node. The functions of this structure +// should only be called on the render process main thread. +// +#[repr(C)] +pub struct _cef_domnode_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the type for this node. + // + pub get_type: Option types::cef_dom_node_type_t>, + + // + // Returns true (1) if this is a text node. + // + pub is_text: Option libc::c_int>, + + // + // Returns true (1) if this is an element node. + // + pub is_element: Option libc::c_int>, + + // + // Returns true (1) if this is an editable node. + // + pub is_editable: Option libc::c_int>, + + // + // Returns true (1) if this is a form control element node. + // + pub is_form_control_element: Option libc::c_int>, + + // + // Returns the type of this form control element node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_form_control_element_type: Option types::cef_string_userfree_t>, + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub is_same: Option libc::c_int>, + + // + // Returns the name of this node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_name: Option types::cef_string_userfree_t>, + + // + // Returns the value of this node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_value: Option types::cef_string_userfree_t>, + + // + // Set the value of this node. Returns true (1) on success. + // + pub set_value: Option libc::c_int>, + + // + // Returns the contents of this node as markup. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_as_markup: Option types::cef_string_userfree_t>, + + // + // Returns the document associated with this node. + // + pub get_document: Option *mut interfaces::cef_domdocument_t>, + + // + // Returns the parent node. + // + pub get_parent: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the previous sibling node. + // + pub get_previous_sibling: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the next sibling node. + // + pub get_next_sibling: Option *mut interfaces::cef_domnode_t>, + + // + // Returns true (1) if this node has child nodes. + // + pub has_children: Option libc::c_int>, + + // + // Return the first child node. + // + pub get_first_child: Option *mut interfaces::cef_domnode_t>, + + // + // Returns the last child node. + // + pub get_last_child: Option *mut interfaces::cef_domnode_t>, + + + // The following functions are valid only for element nodes. + + // + // Returns the tag name of this element. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_element_tag_name: Option types::cef_string_userfree_t>, + + // + // Returns true (1) if this element has attributes. + // + pub has_element_attributes: Option libc::c_int>, + + // + // Returns true (1) if this element has an attribute named |attrName|. + // + pub has_element_attribute: Option libc::c_int>, + + // + // Returns the element attribute named |attrName|. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_element_attribute: Option types::cef_string_userfree_t>, + + // + // Returns a map of all element attributes. + // + pub get_element_attributes: Option ()>, + + // + // Set the value for the element attribute named |attrName|. Returns true (1) + // on success. + // + pub set_element_attribute: Option libc::c_int>, + + // + // Returns the inner text of the element. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_element_inner_text: Option types::cef_string_userfree_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_domnode_t = _cef_domnode_t; + + +// +// Structure used to represent a DOM node. The functions of this structure +// should only be called on the render process main thread. +// +pub struct CefDOMNode { + c_object: *mut cef_domnode_t, +} + +impl Clone for CefDOMNode { + fn clone(&self) -> CefDOMNode{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDOMNode { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDOMNode { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDOMNode { + pub unsafe fn from_c_object(c_object: *mut cef_domnode_t) -> CefDOMNode { + CefDOMNode { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_domnode_t) -> CefDOMNode { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDOMNode { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_domnode_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_domnode_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the type for this node. + // + pub fn get_type(&self) -> types::cef_dom_node_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this is a text node. + // + pub fn is_text(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_text.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this is an element node. + // + pub fn is_element(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_element.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this is an editable node. + // + pub fn is_editable(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_editable.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this is a form control element node. + // + pub fn is_form_control_element(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_form_control_element.unwrap())( + self.c_object)) + } + } + + // + // Returns the type of this form control element node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_form_control_element_type(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_form_control_element_type.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub fn is_same(&self, that: interfaces::CefDOMNode) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(that))) + } + } + + // + // Returns the name of this node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the value of this node. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_value(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_value.unwrap())( + self.c_object)) + } + } + + // + // Set the value of this node. Returns true (1) on success. + // + pub fn set_value(&self, value: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_value.unwrap())( + self.c_object, + CefWrap::to_c(value))) + } + } + + // + // Returns the contents of this node as markup. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_as_markup(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_as_markup.unwrap())( + self.c_object)) + } + } + + // + // Returns the document associated with this node. + // + pub fn get_document(&self) -> interfaces::CefDOMDocument { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_document.unwrap())( + self.c_object)) + } + } + + // + // Returns the parent node. + // + pub fn get_parent(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_parent.unwrap())( + self.c_object)) + } + } + + // + // Returns the previous sibling node. + // + pub fn get_previous_sibling(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_previous_sibling.unwrap())( + self.c_object)) + } + } + + // + // Returns the next sibling node. + // + pub fn get_next_sibling(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_next_sibling.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this node has child nodes. + // + pub fn has_children(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_children.unwrap())( + self.c_object)) + } + } + + // + // Return the first child node. + // + pub fn get_first_child(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_first_child.unwrap())( + self.c_object)) + } + } + + // + // Returns the last child node. + // + pub fn get_last_child(&self) -> interfaces::CefDOMNode { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_last_child.unwrap())( + self.c_object)) + } + } + + + // The following functions are valid only for element nodes. + + // + // Returns the tag name of this element. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_element_tag_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_tag_name.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this element has attributes. + // + pub fn has_element_attributes(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_element_attributes.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this element has an attribute named |attrName|. + // + pub fn has_element_attribute(&self, attrName: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_element_attribute.unwrap())( + self.c_object, + CefWrap::to_c(attrName))) + } + } + + // + // Returns the element attribute named |attrName|. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_element_attribute(&self, attrName: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_attribute.unwrap())( + self.c_object, + CefWrap::to_c(attrName))) + } + } + + // + // Returns a map of all element attributes. + // + pub fn get_element_attributes(&self, attrMap: HashMap) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_attributes.unwrap())( + self.c_object, + CefWrap::to_c(attrMap))) + } + } + + // + // Set the value for the element attribute named |attrName|. Returns true (1) + // on success. + // + pub fn set_element_attribute(&self, attrName: &str, + value: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_element_attribute.unwrap())( + self.c_object, + CefWrap::to_c(attrName), + CefWrap::to_c(value))) + } + } + + // + // Returns the inner text of the element. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_element_inner_text(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_inner_text.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_domnode_t> for CefDOMNode { + fn to_c(rust_object: CefDOMNode) -> *mut cef_domnode_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_domnode_t) -> CefDOMNode { + CefDOMNode::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_domnode_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_domnode_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_domnode_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDOMNode::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_download_handler.rs b/ports/cef/interfaces/cef_download_handler.rs new file mode 100644 index 00000000000..78cdcf83d66 --- /dev/null +++ b/ports/cef/interfaces/cef_download_handler.rs @@ -0,0 +1,519 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure used to asynchronously continue a download. +// +#[repr(C)] +pub struct _cef_before_download_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Call to continue the download. Set |download_path| to the full file path + // for the download including the file name or leave blank to use the + // suggested name and the default temp directory. Set |show_dialog| to true + // (1) if you do wish to show the default "Save As" dialog. + // + pub cont: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_before_download_callback_t = _cef_before_download_callback_t; + + +// +// Callback structure used to asynchronously continue a download. +// +pub struct CefBeforeDownloadCallback { + c_object: *mut cef_before_download_callback_t, +} + +impl Clone for CefBeforeDownloadCallback { + fn clone(&self) -> CefBeforeDownloadCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefBeforeDownloadCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefBeforeDownloadCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefBeforeDownloadCallback { + pub unsafe fn from_c_object(c_object: *mut cef_before_download_callback_t) -> CefBeforeDownloadCallback { + CefBeforeDownloadCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_before_download_callback_t) -> CefBeforeDownloadCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefBeforeDownloadCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_before_download_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_before_download_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Call to continue the download. Set |download_path| to the full file path + // for the download including the file name or leave blank to use the + // suggested name and the default temp directory. Set |show_dialog| to true + // (1) if you do wish to show the default "Save As" dialog. + // + pub fn cont(&self, download_path: &str, show_dialog: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(download_path), + CefWrap::to_c(show_dialog))) + } + } +} + +impl CefWrap<*mut cef_before_download_callback_t> for CefBeforeDownloadCallback { + fn to_c(rust_object: CefBeforeDownloadCallback) -> *mut cef_before_download_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_before_download_callback_t) -> CefBeforeDownloadCallback { + CefBeforeDownloadCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_before_download_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_before_download_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_before_download_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefBeforeDownloadCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Callback structure used to asynchronously cancel a download. +// +#[repr(C)] +pub struct _cef_download_item_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Call to cancel the download. + // + pub cancel: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_download_item_callback_t = _cef_download_item_callback_t; + + +// +// Callback structure used to asynchronously cancel a download. +// +pub struct CefDownloadItemCallback { + c_object: *mut cef_download_item_callback_t, +} + +impl Clone for CefDownloadItemCallback { + fn clone(&self) -> CefDownloadItemCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDownloadItemCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDownloadItemCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDownloadItemCallback { + pub unsafe fn from_c_object(c_object: *mut cef_download_item_callback_t) -> CefDownloadItemCallback { + CefDownloadItemCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_download_item_callback_t) -> CefDownloadItemCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDownloadItemCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_download_item_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_download_item_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Call to cancel the download. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_download_item_callback_t> for CefDownloadItemCallback { + fn to_c(rust_object: CefDownloadItemCallback) -> *mut cef_download_item_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_download_item_callback_t) -> CefDownloadItemCallback { + CefDownloadItemCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_download_item_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_download_item_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_download_item_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDownloadItemCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to handle file downloads. The functions of this structure will +// called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_download_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called before a download begins. |suggested_name| is the suggested name for + // the download file. By default the download will be canceled. Execute + // |callback| either asynchronously or in this function to continue the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + // + pub on_before_download: Option ()>, + + // + // Called when a download's status or progress information has been updated. + // This may be called multiple times before and after on_before_download(). + // Execute |callback| either asynchronously or in this function to cancel the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + // + pub on_download_updated: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_download_handler_t = _cef_download_handler_t; + + +// +// Structure used to handle file downloads. The functions of this structure will +// called on the browser process UI thread. +// +pub struct CefDownloadHandler { + c_object: *mut cef_download_handler_t, +} + +impl Clone for CefDownloadHandler { + fn clone(&self) -> CefDownloadHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDownloadHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDownloadHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDownloadHandler { + pub unsafe fn from_c_object(c_object: *mut cef_download_handler_t) -> CefDownloadHandler { + CefDownloadHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_download_handler_t) -> CefDownloadHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDownloadHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_download_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_download_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called before a download begins. |suggested_name| is the suggested name for + // the download file. By default the download will be canceled. Execute + // |callback| either asynchronously or in this function to continue the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + // + pub fn on_before_download(&self, browser: interfaces::CefBrowser, + download_item: interfaces::CefDownloadItem, suggested_name: &str, + callback: interfaces::CefBeforeDownloadCallback) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_download.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(download_item), + CefWrap::to_c(suggested_name), + CefWrap::to_c(callback))) + } + } + + // + // Called when a download's status or progress information has been updated. + // This may be called multiple times before and after on_before_download(). + // Execute |callback| either asynchronously or in this function to cancel the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + // + pub fn on_download_updated(&self, browser: interfaces::CefBrowser, + download_item: interfaces::CefDownloadItem, + callback: interfaces::CefDownloadItemCallback) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_download_updated.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(download_item), + CefWrap::to_c(callback))) + } + } +} + +impl CefWrap<*mut cef_download_handler_t> for CefDownloadHandler { + fn to_c(rust_object: CefDownloadHandler) -> *mut cef_download_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_download_handler_t) -> CefDownloadHandler { + CefDownloadHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_download_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_download_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_download_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDownloadHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_download_item.rs b/ports/cef/interfaces/cef_download_item.rs new file mode 100644 index 00000000000..c8e893cf73e --- /dev/null +++ b/ports/cef/interfaces/cef_download_item.rs @@ -0,0 +1,495 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent a download item. +// +#[repr(C)] +pub struct _cef_download_item_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if the download is in progress. + // + pub is_in_progress: Option libc::c_int>, + + // + // Returns true (1) if the download is complete. + // + pub is_complete: Option libc::c_int>, + + // + // Returns true (1) if the download has been canceled or interrupted. + // + pub is_canceled: Option libc::c_int>, + + // + // Returns a simple speed estimate in bytes/s. + // + pub get_current_speed: Option i64>, + + // + // Returns the rough percent complete or -1 if the receive total size is + // unknown. + // + pub get_percent_complete: Option libc::c_int>, + + // + // Returns the total number of bytes. + // + pub get_total_bytes: Option i64>, + + // + // Returns the number of received bytes. + // + pub get_received_bytes: Option i64>, + + // + // Returns the time that the download started. + // + pub get_start_time: Option types::cef_time_t>, + + // + // Returns the time that the download ended. + // + pub get_end_time: Option types::cef_time_t>, + + // + // Returns the full path to the downloaded or downloading file. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_full_path: Option types::cef_string_userfree_t>, + + // + // Returns the unique identifier for this download. + // + pub get_id: Option u32>, + + // + // Returns the URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_url: Option types::cef_string_userfree_t>, + + // + // Returns the suggested file name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_suggested_file_name: Option types::cef_string_userfree_t>, + + // + // Returns the content disposition. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_content_disposition: Option types::cef_string_userfree_t>, + + // + // Returns the mime type. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_mime_type: Option types::cef_string_userfree_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_download_item_t = _cef_download_item_t; + + +// +// Structure used to represent a download item. +// +pub struct CefDownloadItem { + c_object: *mut cef_download_item_t, +} + +impl Clone for CefDownloadItem { + fn clone(&self) -> CefDownloadItem{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDownloadItem { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDownloadItem { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDownloadItem { + pub unsafe fn from_c_object(c_object: *mut cef_download_item_t) -> CefDownloadItem { + CefDownloadItem { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_download_item_t) -> CefDownloadItem { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDownloadItem { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_download_item_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_download_item_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the download is in progress. + // + pub fn is_in_progress(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_in_progress.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the download is complete. + // + pub fn is_complete(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_complete.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the download has been canceled or interrupted. + // + pub fn is_canceled(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_canceled.unwrap())( + self.c_object)) + } + } + + // + // Returns a simple speed estimate in bytes/s. + // + pub fn get_current_speed(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_current_speed.unwrap())( + self.c_object)) + } + } + + // + // Returns the rough percent complete or -1 if the receive total size is + // unknown. + // + pub fn get_percent_complete(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_percent_complete.unwrap())( + self.c_object)) + } + } + + // + // Returns the total number of bytes. + // + pub fn get_total_bytes(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_total_bytes.unwrap())( + self.c_object)) + } + } + + // + // Returns the number of received bytes. + // + pub fn get_received_bytes(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_received_bytes.unwrap())( + self.c_object)) + } + } + + // + // Returns the time that the download started. + // + pub fn get_start_time(&self) -> types::cef_time_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_start_time.unwrap())( + self.c_object)) + } + } + + // + // Returns the time that the download ended. + // + pub fn get_end_time(&self) -> types::cef_time_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_end_time.unwrap())( + self.c_object)) + } + } + + // + // Returns the full path to the downloaded or downloading file. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_full_path(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_full_path.unwrap())( + self.c_object)) + } + } + + // + // Returns the unique identifier for this download. + // + pub fn get_id(&self) -> u32 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_id.unwrap())( + self.c_object)) + } + } + + // + // Returns the URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the suggested file name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_suggested_file_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_suggested_file_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the content disposition. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_content_disposition(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_content_disposition.unwrap())( + self.c_object)) + } + } + + // + // Returns the mime type. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_mime_type(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_mime_type.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_download_item_t> for CefDownloadItem { + fn to_c(rust_object: CefDownloadItem) -> *mut cef_download_item_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_download_item_t) -> CefDownloadItem { + CefDownloadItem::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_download_item_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_download_item_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_download_item_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDownloadItem::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_drag_data.rs b/ports/cef/interfaces/cef_drag_data.rs new file mode 100644 index 00000000000..2fd56c027d6 --- /dev/null +++ b/ports/cef/interfaces/cef_drag_data.rs @@ -0,0 +1,653 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent drag data. The functions of this structure may be +// called on any thread. +// +#[repr(C)] +pub struct _cef_drag_data_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns a copy of the current object. + // + pub clone: Option *mut interfaces::cef_drag_data_t>, + + // + // Returns true (1) if this object is read-only. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns true (1) if the drag data is a link. + // + pub is_link: Option libc::c_int>, + + // + // Returns true (1) if the drag data is a text or html fragment. + // + pub is_fragment: Option libc::c_int>, + + // + // Returns true (1) if the drag data is a file. + // + pub is_file: Option libc::c_int>, + + // + // Return the link URL that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_link_url: Option types::cef_string_userfree_t>, + + // + // Return the title associated with the link being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_link_title: Option types::cef_string_userfree_t>, + + // + // Return the metadata, if any, associated with the link being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_link_metadata: Option types::cef_string_userfree_t>, + + // + // Return the plain text fragment that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_fragment_text: Option types::cef_string_userfree_t>, + + // + // Return the text/html fragment that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_fragment_html: Option types::cef_string_userfree_t>, + + // + // Return the base URL that the fragment came from. This value is used for + // resolving relative URLs and may be NULL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_fragment_base_url: Option types::cef_string_userfree_t>, + + // + // Return the name of the file being dragged out of the browser window. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_file_name: Option types::cef_string_userfree_t>, + + // + // Write the contents of the file being dragged out of the web view into + // |writer|. Returns the number of bytes sent to |writer|. If |writer| is NULL + // this function will return the size of the file contents in bytes. Call + // get_file_name() to get a suggested name for the file. + // + pub get_file_contents: Option libc::size_t>, + + // + // Retrieve the list of file names that are being dragged into the browser + // window. + // + pub get_file_names: Option libc::c_int>, + + // + // Set the link URL that is being dragged. + // + pub set_link_url: Option ()>, + + // + // Set the title associated with the link being dragged. + // + pub set_link_title: Option ()>, + + // + // Set the metadata associated with the link being dragged. + // + pub set_link_metadata: Option ()>, + + // + // Set the plain text fragment that is being dragged. + // + pub set_fragment_text: Option ()>, + + // + // Set the text/html fragment that is being dragged. + // + pub set_fragment_html: Option ()>, + + // + // Set the base URL that the fragment came from. + // + pub set_fragment_base_url: Option ()>, + + // + // Reset the file contents. You should do this before calling + // cef_browser_host_t::DragTargetDragEnter as the web view does not allow us + // to drag in this kind of data. + // + pub reset_file_contents: Option ( + )>, + + // + // Add a file that is being dragged into the webview. + // + pub add_file: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_drag_data_t = _cef_drag_data_t; + + +// +// Structure used to represent drag data. The functions of this structure may be +// called on any thread. +// +pub struct CefDragData { + c_object: *mut cef_drag_data_t, +} + +impl Clone for CefDragData { + fn clone(&self) -> CefDragData{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDragData { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDragData { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDragData { + pub unsafe fn from_c_object(c_object: *mut cef_drag_data_t) -> CefDragData { + CefDragData { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_drag_data_t) -> CefDragData { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDragData { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_drag_data_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_drag_data_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns a copy of the current object. + // + pub fn clone(&self) -> interfaces::CefDragData { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).clone.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is read-only. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the drag data is a link. + // + pub fn is_link(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_link.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the drag data is a text or html fragment. + // + pub fn is_fragment(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_fragment.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the drag data is a file. + // + pub fn is_file(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_file.unwrap())( + self.c_object)) + } + } + + // + // Return the link URL that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_link_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_link_url.unwrap())( + self.c_object)) + } + } + + // + // Return the title associated with the link being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_link_title(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_link_title.unwrap())( + self.c_object)) + } + } + + // + // Return the metadata, if any, associated with the link being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_link_metadata(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_link_metadata.unwrap())( + self.c_object)) + } + } + + // + // Return the plain text fragment that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_fragment_text(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_fragment_text.unwrap())( + self.c_object)) + } + } + + // + // Return the text/html fragment that is being dragged. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_fragment_html(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_fragment_html.unwrap())( + self.c_object)) + } + } + + // + // Return the base URL that the fragment came from. This value is used for + // resolving relative URLs and may be NULL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_fragment_base_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_fragment_base_url.unwrap())( + self.c_object)) + } + } + + // + // Return the name of the file being dragged out of the browser window. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_file_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_name.unwrap())( + self.c_object)) + } + } + + // + // Write the contents of the file being dragged out of the web view into + // |writer|. Returns the number of bytes sent to |writer|. If |writer| is NULL + // this function will return the size of the file contents in bytes. Call + // get_file_name() to get a suggested name for the file. + // + pub fn get_file_contents(&self, + writer: interfaces::CefStreamWriter) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_contents.unwrap())( + self.c_object, + CefWrap::to_c(writer))) + } + } + + // + // Retrieve the list of file names that are being dragged into the browser + // window. + // + pub fn get_file_names(&self, names: Vec) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_names.unwrap())( + self.c_object, + CefWrap::to_c(names))) + } + } + + // + // Set the link URL that is being dragged. + // + pub fn set_link_url(&self, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_link_url.unwrap())( + self.c_object, + CefWrap::to_c(url))) + } + } + + // + // Set the title associated with the link being dragged. + // + pub fn set_link_title(&self, title: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_link_title.unwrap())( + self.c_object, + CefWrap::to_c(title))) + } + } + + // + // Set the metadata associated with the link being dragged. + // + pub fn set_link_metadata(&self, data: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_link_metadata.unwrap())( + self.c_object, + CefWrap::to_c(data))) + } + } + + // + // Set the plain text fragment that is being dragged. + // + pub fn set_fragment_text(&self, text: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_fragment_text.unwrap())( + self.c_object, + CefWrap::to_c(text))) + } + } + + // + // Set the text/html fragment that is being dragged. + // + pub fn set_fragment_html(&self, html: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_fragment_html.unwrap())( + self.c_object, + CefWrap::to_c(html))) + } + } + + // + // Set the base URL that the fragment came from. + // + pub fn set_fragment_base_url(&self, base_url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_fragment_base_url.unwrap())( + self.c_object, + CefWrap::to_c(base_url))) + } + } + + // + // Reset the file contents. You should do this before calling + // cef_browser_host_t::DragTargetDragEnter as the web view does not allow us + // to drag in this kind of data. + // + pub fn reset_file_contents(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).reset_file_contents.unwrap())( + self.c_object)) + } + } + + // + // Add a file that is being dragged into the webview. + // + pub fn add_file(&self, path: &str, display_name: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_file.unwrap())( + self.c_object, + CefWrap::to_c(path), + CefWrap::to_c(display_name))) + } + } + + // + // Create a new cef_drag_data_t object. + // + pub fn create() -> interfaces::CefDragData { + unsafe { + CefWrap::to_rust( + ::drag_data::cef_drag_data_create( +)) + } + } +} + +impl CefWrap<*mut cef_drag_data_t> for CefDragData { + fn to_c(rust_object: CefDragData) -> *mut cef_drag_data_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_drag_data_t) -> CefDragData { + CefDragData::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_drag_data_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_drag_data_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_drag_data_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDragData::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_drag_handler.rs b/ports/cef/interfaces/cef_drag_handler.rs new file mode 100644 index 00000000000..cd50c65b119 --- /dev/null +++ b/ports/cef/interfaces/cef_drag_handler.rs @@ -0,0 +1,197 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to dragging. The functions +// of this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_drag_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called when an external drag event enters the browser window. |dragData| + // contains the drag event data and |mask| represents the type of drag + // operation. Return false (0) for default drag handling behavior or true (1) + // to cancel the drag event. + // + pub on_drag_enter: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_drag_handler_t = _cef_drag_handler_t; + + +// +// Implement this structure to handle events related to dragging. The functions +// of this structure will be called on the UI thread. +// +pub struct CefDragHandler { + c_object: *mut cef_drag_handler_t, +} + +impl Clone for CefDragHandler { + fn clone(&self) -> CefDragHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDragHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDragHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDragHandler { + pub unsafe fn from_c_object(c_object: *mut cef_drag_handler_t) -> CefDragHandler { + CefDragHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_drag_handler_t) -> CefDragHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDragHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_drag_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_drag_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called when an external drag event enters the browser window. |dragData| + // contains the drag event data and |mask| represents the type of drag + // operation. Return false (0) for default drag handling behavior or true (1) + // to cancel the drag event. + // + pub fn on_drag_enter(&self, browser: interfaces::CefBrowser, + dragData: interfaces::CefDragData, + mask: types::cef_drag_operations_mask_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_drag_enter.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(dragData), + CefWrap::to_c(mask))) + } + } +} + +impl CefWrap<*mut cef_drag_handler_t> for CefDragHandler { + fn to_c(rust_object: CefDragHandler) -> *mut cef_drag_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_drag_handler_t) -> CefDragHandler { + CefDragHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_drag_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_drag_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_drag_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDragHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_focus_handler.rs b/ports/cef/interfaces/cef_focus_handler.rs new file mode 100644 index 00000000000..37f63af58e3 --- /dev/null +++ b/ports/cef/interfaces/cef_focus_handler.rs @@ -0,0 +1,242 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to focus. The functions of +// this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_focus_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called when the browser component is about to loose focus. For instance, if + // focus was on the last HTML element and the user pressed the TAB key. |next| + // will be true (1) if the browser is giving focus to the next component and + // false (0) if the browser is giving focus to the previous component. + // + pub on_take_focus: Option ()>, + + // + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false (0) to allow the + // focus to be set or true (1) to cancel setting the focus. + // + pub on_set_focus: Option libc::c_int>, + + // + // Called when the browser component has received focus. + // + pub on_got_focus: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_focus_handler_t = _cef_focus_handler_t; + + +// +// Implement this structure to handle events related to focus. The functions of +// this structure will be called on the UI thread. +// +pub struct CefFocusHandler { + c_object: *mut cef_focus_handler_t, +} + +impl Clone for CefFocusHandler { + fn clone(&self) -> CefFocusHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefFocusHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefFocusHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefFocusHandler { + pub unsafe fn from_c_object(c_object: *mut cef_focus_handler_t) -> CefFocusHandler { + CefFocusHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_focus_handler_t) -> CefFocusHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefFocusHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_focus_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_focus_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called when the browser component is about to loose focus. For instance, if + // focus was on the last HTML element and the user pressed the TAB key. |next| + // will be true (1) if the browser is giving focus to the next component and + // false (0) if the browser is giving focus to the previous component. + // + pub fn on_take_focus(&self, browser: interfaces::CefBrowser, + next: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_take_focus.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(next))) + } + } + + // + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false (0) to allow the + // focus to be set or true (1) to cancel setting the focus. + // + pub fn on_set_focus(&self, browser: interfaces::CefBrowser, + source: types::cef_focus_source_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_set_focus.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(source))) + } + } + + // + // Called when the browser component has received focus. + // + pub fn on_got_focus(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_got_focus.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } +} + +impl CefWrap<*mut cef_focus_handler_t> for CefFocusHandler { + fn to_c(rust_object: CefFocusHandler) -> *mut cef_focus_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_focus_handler_t) -> CefFocusHandler { + CefFocusHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_focus_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_focus_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_focus_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefFocusHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_frame.rs b/ports/cef/interfaces/cef_frame.rs new file mode 100644 index 00000000000..0c237d98dff --- /dev/null +++ b/ports/cef/interfaces/cef_frame.rs @@ -0,0 +1,687 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent a frame in the browser window. When used in the +// browser process the functions of this structure may be called on any thread +// unless otherwise indicated in the comments. When used in the render process +// the functions of this structure may only be called on the main thread. +// +#[repr(C)] +pub struct _cef_frame_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // True if this object is currently attached to a valid frame. + // + pub is_valid: Option libc::c_int>, + + // + // Execute undo in this frame. + // + pub undo: Option ()>, + + // + // Execute redo in this frame. + // + pub redo: Option ()>, + + // + // Execute cut in this frame. + // + pub cut: Option ()>, + + // + // Execute copy in this frame. + // + pub copy: Option ()>, + + // + // Execute paste in this frame. + // + pub paste: Option ()>, + + // + // Execute delete in this frame. + // + pub del: Option ()>, + + // + // Execute select all in this frame. + // + pub select_all: Option ()>, + + // + // Save this frame's HTML source to a temporary file and open it in the + // default text viewing application. This function can only be called from the + // browser process. + // + pub view_source: Option ()>, + + // + // Retrieve this frame's HTML source as a string sent to the specified + // visitor. + // + pub get_source: Option ()>, + + // + // Retrieve this frame's display text as a string sent to the specified + // visitor. + // + pub get_text: Option ()>, + + // + // Load the request represented by the |request| object. + // + pub load_request: Option ()>, + + // + // Load the specified |url|. + // + pub load_url: Option ()>, + + // + // Load the contents of |string_val| with the specified dummy |url|. |url| + // should have a standard scheme (for example, http scheme) or behaviors like + // link clicks and web security restrictions may not behave as expected. + // + pub load_string: Option ()>, + + // + // Execute a string of JavaScript code in this frame. The |script_url| + // parameter is the URL where the script in question can be found, if any. The + // renderer may request this URL to show the developer the source of the + // error. The |start_line| parameter is the base line number to use for error + // reporting. + // + pub execute_java_script: Option ()>, + + // + // Returns true (1) if this is the main (top-level) frame. + // + pub is_main: Option libc::c_int>, + + // + // Returns true (1) if this is the focused frame. + // + pub is_focused: Option libc::c_int>, + + // + // Returns the name for this frame. If the frame has an assigned name (for + // example, set via the iframe "name" attribute) then that value will be + // returned. Otherwise a unique name will be constructed based on the frame + // parent hierarchy. The main (top-level) frame will always have an NULL name + // value. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_name: Option types::cef_string_userfree_t>, + + // + // Returns the globally unique identifier for this frame. + // + pub get_identifier: Option i64>, + + // + // Returns the parent of this frame or NULL if this is the main (top-level) + // frame. + // + pub get_parent: Option *mut interfaces::cef_frame_t>, + + // + // Returns the URL currently loaded in this frame. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_url: Option types::cef_string_userfree_t>, + + // + // Returns the browser that this frame belongs to. + // + pub get_browser: Option *mut interfaces::cef_browser_t>, + + // + // Get the V8 context associated with the frame. This function can only be + // called from the render process. + // + pub get_v8context: Option *mut interfaces::cef_v8context_t>, + + // + // Visit the DOM document. This function can only be called from the render + // process. + // + pub visit_dom: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_frame_t = _cef_frame_t; + + +// +// Structure used to represent a frame in the browser window. When used in the +// browser process the functions of this structure may be called on any thread +// unless otherwise indicated in the comments. When used in the render process +// the functions of this structure may only be called on the main thread. +// +pub struct CefFrame { + c_object: *mut cef_frame_t, +} + +impl Clone for CefFrame { + fn clone(&self) -> CefFrame{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefFrame { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefFrame { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefFrame { + pub unsafe fn from_c_object(c_object: *mut cef_frame_t) -> CefFrame { + CefFrame { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_frame_t) -> CefFrame { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefFrame { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_frame_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_frame_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // True if this object is currently attached to a valid frame. + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Execute undo in this frame. + // + pub fn undo(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).undo.unwrap())( + self.c_object)) + } + } + + // + // Execute redo in this frame. + // + pub fn redo(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).redo.unwrap())( + self.c_object)) + } + } + + // + // Execute cut in this frame. + // + pub fn cut(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cut.unwrap())( + self.c_object)) + } + } + + // + // Execute copy in this frame. + // + pub fn copy(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Execute paste in this frame. + // + pub fn paste(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).paste.unwrap())( + self.c_object)) + } + } + + // + // Execute delete in this frame. + // + pub fn del(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).del.unwrap())( + self.c_object)) + } + } + + // + // Execute select all in this frame. + // + pub fn select_all(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).select_all.unwrap())( + self.c_object)) + } + } + + // + // Save this frame's HTML source to a temporary file and open it in the + // default text viewing application. This function can only be called from the + // browser process. + // + pub fn view_source(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).view_source.unwrap())( + self.c_object)) + } + } + + // + // Retrieve this frame's HTML source as a string sent to the specified + // visitor. + // + pub fn get_source(&self, visitor: interfaces::CefStringVisitor) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_source.unwrap())( + self.c_object, + CefWrap::to_c(visitor))) + } + } + + // + // Retrieve this frame's display text as a string sent to the specified + // visitor. + // + pub fn get_text(&self, visitor: interfaces::CefStringVisitor) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_text.unwrap())( + self.c_object, + CefWrap::to_c(visitor))) + } + } + + // + // Load the request represented by the |request| object. + // + pub fn load_request(&self, request: interfaces::CefRequest) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).load_request.unwrap())( + self.c_object, + CefWrap::to_c(request))) + } + } + + // + // Load the specified |url|. + // + pub fn load_url(&self, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).load_url.unwrap())( + self.c_object, + CefWrap::to_c(url))) + } + } + + // + // Load the contents of |string_val| with the specified dummy |url|. |url| + // should have a standard scheme (for example, http scheme) or behaviors like + // link clicks and web security restrictions may not behave as expected. + // + pub fn load_string(&self, string_val: &str, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).load_string.unwrap())( + self.c_object, + CefWrap::to_c(string_val), + CefWrap::to_c(url))) + } + } + + // + // Execute a string of JavaScript code in this frame. The |script_url| + // parameter is the URL where the script in question can be found, if any. The + // renderer may request this URL to show the developer the source of the + // error. The |start_line| parameter is the base line number to use for error + // reporting. + // + pub fn execute_java_script(&self, code: &str, script_url: &str, + start_line: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).execute_java_script.unwrap())( + self.c_object, + CefWrap::to_c(code), + CefWrap::to_c(script_url), + CefWrap::to_c(start_line))) + } + } + + // + // Returns true (1) if this is the main (top-level) frame. + // + pub fn is_main(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_main.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this is the focused frame. + // + pub fn is_focused(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_focused.unwrap())( + self.c_object)) + } + } + + // + // Returns the name for this frame. If the frame has an assigned name (for + // example, set via the iframe "name" attribute) then that value will be + // returned. Otherwise a unique name will be constructed based on the frame + // parent hierarchy. The main (top-level) frame will always have an NULL name + // value. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the globally unique identifier for this frame. + // + pub fn get_identifier(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_identifier.unwrap())( + self.c_object)) + } + } + + // + // Returns the parent of this frame or NULL if this is the main (top-level) + // frame. + // + pub fn get_parent(&self) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_parent.unwrap())( + self.c_object)) + } + } + + // + // Returns the URL currently loaded in this frame. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the browser that this frame belongs to. + // + pub fn get_browser(&self) -> interfaces::CefBrowser { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_browser.unwrap())( + self.c_object)) + } + } + + // + // Get the V8 context associated with the frame. This function can only be + // called from the render process. + // + pub fn get_v8context(&self) -> interfaces::CefV8Context { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_v8context.unwrap())( + self.c_object)) + } + } + + // + // Visit the DOM document. This function can only be called from the render + // process. + // + pub fn visit_dom(&self, visitor: interfaces::CefDOMVisitor) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit_dom.unwrap())( + self.c_object, + CefWrap::to_c(visitor))) + } + } +} + +impl CefWrap<*mut cef_frame_t> for CefFrame { + fn to_c(rust_object: CefFrame) -> *mut cef_frame_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_frame_t) -> CefFrame { + CefFrame::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_frame_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_frame_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_frame_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefFrame::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_geolocation.rs b/ports/cef/interfaces/cef_geolocation.rs new file mode 100644 index 00000000000..0872cf91b35 --- /dev/null +++ b/ports/cef/interfaces/cef_geolocation.rs @@ -0,0 +1,189 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to receive geolocation updates. The functions of +// this structure will be called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_get_geolocation_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called with the 'best available' location information or, if the location + // update failed, with error information. + // + pub on_location_update: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_get_geolocation_callback_t = _cef_get_geolocation_callback_t; + + +// +// Implement this structure to receive geolocation updates. The functions of +// this structure will be called on the browser process UI thread. +// +pub struct CefGetGeolocationCallback { + c_object: *mut cef_get_geolocation_callback_t, +} + +impl Clone for CefGetGeolocationCallback { + fn clone(&self) -> CefGetGeolocationCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefGetGeolocationCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefGetGeolocationCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefGetGeolocationCallback { + pub unsafe fn from_c_object(c_object: *mut cef_get_geolocation_callback_t) -> CefGetGeolocationCallback { + CefGetGeolocationCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_get_geolocation_callback_t) -> CefGetGeolocationCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefGetGeolocationCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_get_geolocation_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_get_geolocation_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called with the 'best available' location information or, if the location + // update failed, with error information. + // + pub fn on_location_update(&self, position: &interfaces::CefGeoposition) -> ( + ) { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_location_update.unwrap())( + self.c_object, + CefWrap::to_c(position))) + } + } +} + +impl CefWrap<*mut cef_get_geolocation_callback_t> for CefGetGeolocationCallback { + fn to_c(rust_object: CefGetGeolocationCallback) -> *mut cef_get_geolocation_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_get_geolocation_callback_t) -> CefGetGeolocationCallback { + CefGetGeolocationCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_get_geolocation_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_get_geolocation_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_get_geolocation_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefGetGeolocationCallback::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_geolocation_handler.rs b/ports/cef/interfaces/cef_geolocation_handler.rs new file mode 100644 index 00000000000..73fe9d842fa --- /dev/null +++ b/ports/cef/interfaces/cef_geolocation_handler.rs @@ -0,0 +1,377 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure used for asynchronous continuation of geolocation +// permission requests. +// +#[repr(C)] +pub struct _cef_geolocation_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Call to allow or deny geolocation access. + // + pub cont: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_geolocation_callback_t = _cef_geolocation_callback_t; + + +// +// Callback structure used for asynchronous continuation of geolocation +// permission requests. +// +pub struct CefGeolocationCallback { + c_object: *mut cef_geolocation_callback_t, +} + +impl Clone for CefGeolocationCallback { + fn clone(&self) -> CefGeolocationCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefGeolocationCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefGeolocationCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefGeolocationCallback { + pub unsafe fn from_c_object(c_object: *mut cef_geolocation_callback_t) -> CefGeolocationCallback { + CefGeolocationCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_geolocation_callback_t) -> CefGeolocationCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefGeolocationCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_geolocation_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_geolocation_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Call to allow or deny geolocation access. + // + pub fn cont(&self, allow: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(allow))) + } + } +} + +impl CefWrap<*mut cef_geolocation_callback_t> for CefGeolocationCallback { + fn to_c(rust_object: CefGeolocationCallback) -> *mut cef_geolocation_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_geolocation_callback_t) -> CefGeolocationCallback { + CefGeolocationCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_geolocation_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_geolocation_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_geolocation_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefGeolocationCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Implement this structure to handle events related to geolocation permission +// requests. The functions of this structure will be called on the browser +// process UI thread. +// +#[repr(C)] +pub struct _cef_geolocation_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called when a page requests permission to access geolocation information. + // |requesting_url| is the URL requesting permission and |request_id| is the + // unique ID for the permission request. Return true (1) and call + // cef_geolocation_callback_t::cont() either in this function or at a later + // time to continue or cancel the request. Return false (0) to cancel the + // request immediately. + // + pub on_request_geolocation_permission: Option libc::c_int>, + + // + // Called when a geolocation access request is canceled. |requesting_url| is + // the URL that originally requested permission and |request_id| is the unique + // ID for the permission request. + // + pub on_cancel_geolocation_permission: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_geolocation_handler_t = _cef_geolocation_handler_t; + + +// +// Implement this structure to handle events related to geolocation permission +// requests. The functions of this structure will be called on the browser +// process UI thread. +// +pub struct CefGeolocationHandler { + c_object: *mut cef_geolocation_handler_t, +} + +impl Clone for CefGeolocationHandler { + fn clone(&self) -> CefGeolocationHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefGeolocationHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefGeolocationHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefGeolocationHandler { + pub unsafe fn from_c_object(c_object: *mut cef_geolocation_handler_t) -> CefGeolocationHandler { + CefGeolocationHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_geolocation_handler_t) -> CefGeolocationHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefGeolocationHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_geolocation_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_geolocation_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called when a page requests permission to access geolocation information. + // |requesting_url| is the URL requesting permission and |request_id| is the + // unique ID for the permission request. Return true (1) and call + // cef_geolocation_callback_t::cont() either in this function or at a later + // time to continue or cancel the request. Return false (0) to cancel the + // request immediately. + // + pub fn on_request_geolocation_permission(&self, + browser: interfaces::CefBrowser, requesting_url: &str, + request_id: libc::c_int, + callback: interfaces::CefGeolocationCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_request_geolocation_permission.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(requesting_url), + CefWrap::to_c(request_id), + CefWrap::to_c(callback))) + } + } + + // + // Called when a geolocation access request is canceled. |requesting_url| is + // the URL that originally requested permission and |request_id| is the unique + // ID for the permission request. + // + pub fn on_cancel_geolocation_permission(&self, + browser: interfaces::CefBrowser, requesting_url: &str, + request_id: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_cancel_geolocation_permission.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(requesting_url), + CefWrap::to_c(request_id))) + } + } +} + +impl CefWrap<*mut cef_geolocation_handler_t> for CefGeolocationHandler { + fn to_c(rust_object: CefGeolocationHandler) -> *mut cef_geolocation_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_geolocation_handler_t) -> CefGeolocationHandler { + CefGeolocationHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_geolocation_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_geolocation_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_geolocation_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefGeolocationHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_jsdialog_handler.rs b/ports/cef/interfaces/cef_jsdialog_handler.rs new file mode 100644 index 00000000000..ca0353e57a8 --- /dev/null +++ b/ports/cef/interfaces/cef_jsdialog_handler.rs @@ -0,0 +1,455 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure used for asynchronous continuation of JavaScript dialog +// requests. +// +#[repr(C)] +pub struct _cef_jsdialog_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue the JS dialog request. Set |success| to true (1) if the OK button + // was pressed. The |user_input| value should be specified for prompt dialogs. + // + pub cont: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_jsdialog_callback_t = _cef_jsdialog_callback_t; + + +// +// Callback structure used for asynchronous continuation of JavaScript dialog +// requests. +// +pub struct CefJSDialogCallback { + c_object: *mut cef_jsdialog_callback_t, +} + +impl Clone for CefJSDialogCallback { + fn clone(&self) -> CefJSDialogCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefJSDialogCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefJSDialogCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefJSDialogCallback { + pub unsafe fn from_c_object(c_object: *mut cef_jsdialog_callback_t) -> CefJSDialogCallback { + CefJSDialogCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_jsdialog_callback_t) -> CefJSDialogCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefJSDialogCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_jsdialog_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_jsdialog_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue the JS dialog request. Set |success| to true (1) if the OK button + // was pressed. The |user_input| value should be specified for prompt dialogs. + // + pub fn cont(&self, success: libc::c_int, user_input: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(success), + CefWrap::to_c(user_input))) + } + } +} + +impl CefWrap<*mut cef_jsdialog_callback_t> for CefJSDialogCallback { + fn to_c(rust_object: CefJSDialogCallback) -> *mut cef_jsdialog_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_jsdialog_callback_t) -> CefJSDialogCallback { + CefJSDialogCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_jsdialog_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_jsdialog_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_jsdialog_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefJSDialogCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Implement this structure to handle events related to JavaScript dialogs. The +// functions of this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_jsdialog_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called to run a JavaScript dialog. The |default_prompt_text| value will be + // specified for prompt dialogs only. Set |suppress_message| to true (1) and + // return false (0) to suppress the message (suppressing messages is + // preferable to immediately executing the callback as this is used to detect + // presumably malicious behavior like spamming alert messages in + // onbeforeunload). Set |suppress_message| to false (0) and return false (0) + // to use the default implementation (the default implementation will show one + // modal dialog at a time and suppress any additional dialog requests until + // the displayed dialog is dismissed). Return true (1) if the application will + // use a custom dialog or if the callback has been executed immediately. + // Custom dialogs may be either modal or modeless. If a custom dialog is used + // the application must execute |callback| once the custom dialog is + // dismissed. + // + pub on_jsdialog: Option libc::c_int>, + + // + // Called to run a dialog asking the user if they want to leave a page. Return + // false (0) to use the default dialog implementation. Return true (1) if the + // application will use a custom dialog or if the callback has been executed + // immediately. Custom dialogs may be either modal or modeless. If a custom + // dialog is used the application must execute |callback| once the custom + // dialog is dismissed. + // + pub on_before_unload_dialog: Option libc::c_int>, + + // + // Called to cancel any pending dialogs and reset any saved dialog state. Will + // be called due to events like page navigation irregardless of whether any + // dialogs are currently pending. + // + pub on_reset_dialog_state: Option ()>, + + // + // Called when the default implementation dialog is closed. + // + pub on_dialog_closed: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_jsdialog_handler_t = _cef_jsdialog_handler_t; + + +// +// Implement this structure to handle events related to JavaScript dialogs. The +// functions of this structure will be called on the UI thread. +// +pub struct CefJSDialogHandler { + c_object: *mut cef_jsdialog_handler_t, +} + +impl Clone for CefJSDialogHandler { + fn clone(&self) -> CefJSDialogHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefJSDialogHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefJSDialogHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefJSDialogHandler { + pub unsafe fn from_c_object(c_object: *mut cef_jsdialog_handler_t) -> CefJSDialogHandler { + CefJSDialogHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_jsdialog_handler_t) -> CefJSDialogHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefJSDialogHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_jsdialog_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_jsdialog_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called to run a JavaScript dialog. The |default_prompt_text| value will be + // specified for prompt dialogs only. Set |suppress_message| to true (1) and + // return false (0) to suppress the message (suppressing messages is + // preferable to immediately executing the callback as this is used to detect + // presumably malicious behavior like spamming alert messages in + // onbeforeunload). Set |suppress_message| to false (0) and return false (0) + // to use the default implementation (the default implementation will show one + // modal dialog at a time and suppress any additional dialog requests until + // the displayed dialog is dismissed). Return true (1) if the application will + // use a custom dialog or if the callback has been executed immediately. + // Custom dialogs may be either modal or modeless. If a custom dialog is used + // the application must execute |callback| once the custom dialog is + // dismissed. + // + pub fn on_jsdialog(&self, browser: interfaces::CefBrowser, origin_url: &str, + accept_lang: &str, dialog_type: types::cef_jsdialog_type_t, + message_text: &str, default_prompt_text: &str, + callback: interfaces::CefJSDialogCallback, + suppress_message: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_jsdialog.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(origin_url), + CefWrap::to_c(accept_lang), + CefWrap::to_c(dialog_type), + CefWrap::to_c(message_text), + CefWrap::to_c(default_prompt_text), + CefWrap::to_c(callback), + CefWrap::to_c(suppress_message))) + } + } + + // + // Called to run a dialog asking the user if they want to leave a page. Return + // false (0) to use the default dialog implementation. Return true (1) if the + // application will use a custom dialog or if the callback has been executed + // immediately. Custom dialogs may be either modal or modeless. If a custom + // dialog is used the application must execute |callback| once the custom + // dialog is dismissed. + // + pub fn on_before_unload_dialog(&self, browser: interfaces::CefBrowser, + message_text: &str, is_reload: libc::c_int, + callback: interfaces::CefJSDialogCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_unload_dialog.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(message_text), + CefWrap::to_c(is_reload), + CefWrap::to_c(callback))) + } + } + + // + // Called to cancel any pending dialogs and reset any saved dialog state. Will + // be called due to events like page navigation irregardless of whether any + // dialogs are currently pending. + // + pub fn on_reset_dialog_state(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_reset_dialog_state.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called when the default implementation dialog is closed. + // + pub fn on_dialog_closed(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_dialog_closed.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } +} + +impl CefWrap<*mut cef_jsdialog_handler_t> for CefJSDialogHandler { + fn to_c(rust_object: CefJSDialogHandler) -> *mut cef_jsdialog_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_jsdialog_handler_t) -> CefJSDialogHandler { + CefJSDialogHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_jsdialog_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_jsdialog_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_jsdialog_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefJSDialogHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_keyboard_handler.rs b/ports/cef/interfaces/cef_keyboard_handler.rs new file mode 100644 index 00000000000..78be704e22b --- /dev/null +++ b/ports/cef/interfaces/cef_keyboard_handler.rs @@ -0,0 +1,230 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to keyboard input. The +// functions of this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_keyboard_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // Called before a keyboard event is sent to the renderer. |event| contains + // information about the keyboard event. |os_event| is the operating system + // event message, if any. Return true (1) if the event was handled or false + // (0) otherwise. If the event will be handled in on_key_event() as a keyboard + // shortcut set |is_keyboard_shortcut| to true (1) and return false (0). + pub on_pre_key_event: Option libc::c_int>, + + // + // Called after the renderer and JavaScript in the page has had a chance to + // handle the event. |event| contains information about the keyboard event. + // |os_event| is the operating system event message, if any. Return true (1) + // if the keyboard event was handled or false (0) otherwise. + // + pub on_key_event: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_keyboard_handler_t = _cef_keyboard_handler_t; + + +// +// Implement this structure to handle events related to keyboard input. The +// functions of this structure will be called on the UI thread. +// +pub struct CefKeyboardHandler { + c_object: *mut cef_keyboard_handler_t, +} + +impl Clone for CefKeyboardHandler { + fn clone(&self) -> CefKeyboardHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefKeyboardHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefKeyboardHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefKeyboardHandler { + pub unsafe fn from_c_object(c_object: *mut cef_keyboard_handler_t) -> CefKeyboardHandler { + CefKeyboardHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_keyboard_handler_t) -> CefKeyboardHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefKeyboardHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_keyboard_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_keyboard_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // Called before a keyboard event is sent to the renderer. |event| contains + // information about the keyboard event. |os_event| is the operating system + // event message, if any. Return true (1) if the event was handled or false + // (0) otherwise. If the event will be handled in on_key_event() as a keyboard + // shortcut set |is_keyboard_shortcut| to true (1) and return false (0). + pub fn on_pre_key_event(&self, browser: interfaces::CefBrowser, + event: &interfaces::CefKeyEvent, os_event: types::cef_event_handle_t, + is_keyboard_shortcut: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_pre_key_event.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(event), + CefWrap::to_c(os_event), + CefWrap::to_c(is_keyboard_shortcut))) + } + } + + // + // Called after the renderer and JavaScript in the page has had a chance to + // handle the event. |event| contains information about the keyboard event. + // |os_event| is the operating system event message, if any. Return true (1) + // if the keyboard event was handled or false (0) otherwise. + // + pub fn on_key_event(&self, browser: interfaces::CefBrowser, + event: &interfaces::CefKeyEvent, + os_event: types::cef_event_handle_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_key_event.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(event), + CefWrap::to_c(os_event))) + } + } +} + +impl CefWrap<*mut cef_keyboard_handler_t> for CefKeyboardHandler { + fn to_c(rust_object: CefKeyboardHandler) -> *mut cef_keyboard_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_keyboard_handler_t) -> CefKeyboardHandler { + CefKeyboardHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_keyboard_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_keyboard_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_keyboard_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefKeyboardHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_life_span_handler.rs b/ports/cef/interfaces/cef_life_span_handler.rs new file mode 100644 index 00000000000..453bacf111e --- /dev/null +++ b/ports/cef/interfaces/cef_life_span_handler.rs @@ -0,0 +1,433 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to browser life span. The +// functions of this structure will be called on the UI thread unless otherwise +// indicated. +// +#[repr(C)] +pub struct _cef_life_span_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called on the IO thread before a new popup window is created. The |browser| + // and |frame| parameters represent the source of the popup request. The + // |target_url| and |target_frame_name| values may be NULL if none were + // specified with the request. The |popupFeatures| structure contains + // information about the requested popup window. To allow creation of the + // popup window optionally modify |windowInfo|, |client|, |settings| and + // |no_javascript_access| and return false (0). To cancel creation of the + // popup window return true (1). The |client| and |settings| values will + // default to the source browser's values. The |no_javascript_access| value + // indicates whether the new browser window should be scriptable and in the + // same process as the source browser. + pub on_before_popup: Option libc::c_int>, + + // + // Called after a new browser is created. + // + pub on_after_created: Option ()>, + + // + // Called when a modal window is about to display and the modal loop should + // begin running. Return false (0) to use the default modal loop + // implementation or true (1) to use a custom implementation. + // + pub run_modal: Option libc::c_int>, + + // + // Called when a browser has recieved a request to close. This may result + // directly from a call to cef_browser_host_t::close_browser() or indirectly + // if the browser is a top-level OS window created by CEF and the user + // attempts to close the window. This function will be called after the + // JavaScript 'onunload' event has been fired. It will not be called for + // browsers after the associated OS window has been destroyed (for those + // browsers it is no longer possible to cancel the close). + // + // If CEF created an OS window for the browser returning false (0) will send + // an OS close notification to the browser window's top-level owner (e.g. + // WM_CLOSE on Windows, performClose: on OS-X and "delete_event" on Linux). If + // no OS window exists (window rendering disabled) returning false (0) will + // cause the browser object to be destroyed immediately. Return true (1) if + // the browser is parented to another window and that other window needs to + // receive close notification via some non-standard technique. + // + // If an application provides its own top-level window it should handle OS + // close notifications by calling cef_browser_host_t::CloseBrowser(false (0)) + // instead of immediately closing (see the example below). This gives CEF an + // opportunity to process the 'onbeforeunload' event and optionally cancel the + // close before do_close() is called. + // + // The cef_life_span_handler_t::on_before_close() function will be called + // immediately before the browser object is destroyed. The application should + // only exit after on_before_close() has been called for all existing + // browsers. + // + // If the browser represents a modal window and a custom modal loop + // implementation was provided in cef_life_span_handler_t::run_modal() this + // callback should be used to restore the opener window to a usable state. + // + // By way of example consider what should happen during window close when the + // browser is parented to an application-provided top-level OS window. 1. + // User clicks the window close button which sends an OS close + // notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and + // "delete_event" on Linux). + // 2. Application's top-level window receives the close notification and: + // A. Calls CefBrowserHost::CloseBrowser(false). + // B. Cancels the window close. + // 3. JavaScript 'onbeforeunload' handler executes and shows the close + // confirmation dialog (which can be overridden via + // CefJSDialogHandler::OnBeforeUnloadDialog()). + // 4. User approves the close. 5. JavaScript 'onunload' handler executes. 6. + // Application's do_close() handler is called. Application will: + // A. Set a flag to indicate that the next close attempt will be allowed. + // B. Return false. + // 7. CEF sends an OS close notification. 8. Application's top-level window + // receives the OS close notification and + // allows the window to close based on the flag from #6B. + // 9. Browser OS window is destroyed. 10. Application's + // cef_life_span_handler_t::on_before_close() handler is called and + // the browser object is destroyed. + // 11. Application exits by calling cef_quit_message_loop() if no other + // browsers + // exist. + // + pub do_close: Option libc::c_int>, + + // + // Called just before a browser is destroyed. Release all references to the + // browser object and do not attempt to execute any functions on the browser + // object after this callback returns. If this is a modal window and a custom + // modal loop implementation was provided in run_modal() this callback should + // be used to exit the custom modal loop. See do_close() documentation for + // additional usage information. + // + pub on_before_close: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_life_span_handler_t = _cef_life_span_handler_t; + + +// +// Implement this structure to handle events related to browser life span. The +// functions of this structure will be called on the UI thread unless otherwise +// indicated. +// +pub struct CefLifeSpanHandler { + c_object: *mut cef_life_span_handler_t, +} + +impl Clone for CefLifeSpanHandler { + fn clone(&self) -> CefLifeSpanHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefLifeSpanHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefLifeSpanHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefLifeSpanHandler { + pub unsafe fn from_c_object(c_object: *mut cef_life_span_handler_t) -> CefLifeSpanHandler { + CefLifeSpanHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_life_span_handler_t) -> CefLifeSpanHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefLifeSpanHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_life_span_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_life_span_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called on the IO thread before a new popup window is created. The |browser| + // and |frame| parameters represent the source of the popup request. The + // |target_url| and |target_frame_name| values may be NULL if none were + // specified with the request. The |popupFeatures| structure contains + // information about the requested popup window. To allow creation of the + // popup window optionally modify |windowInfo|, |client|, |settings| and + // |no_javascript_access| and return false (0). To cancel creation of the + // popup window return true (1). The |client| and |settings| values will + // default to the source browser's values. The |no_javascript_access| value + // indicates whether the new browser window should be scriptable and in the + // same process as the source browser. + pub fn on_before_popup(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, target_url: &str, target_frame_name: &str, + popupFeatures: &interfaces::CefPopupFeatures, + windowInfo: &mut interfaces::CefWindowInfo, + client: interfaces::CefClient, + settings: &mut interfaces::CefBrowserSettings, + no_javascript_access: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_popup.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(target_url), + CefWrap::to_c(target_frame_name), + CefWrap::to_c(popupFeatures), + CefWrap::to_c(windowInfo), + CefWrap::to_c(client), + CefWrap::to_c(settings), + CefWrap::to_c(no_javascript_access))) + } + } + + // + // Called after a new browser is created. + // + pub fn on_after_created(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_after_created.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called when a modal window is about to display and the modal loop should + // begin running. Return false (0) to use the default modal loop + // implementation or true (1) to use a custom implementation. + // + pub fn run_modal(&self, browser: interfaces::CefBrowser) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).run_modal.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called when a browser has recieved a request to close. This may result + // directly from a call to cef_browser_host_t::close_browser() or indirectly + // if the browser is a top-level OS window created by CEF and the user + // attempts to close the window. This function will be called after the + // JavaScript 'onunload' event has been fired. It will not be called for + // browsers after the associated OS window has been destroyed (for those + // browsers it is no longer possible to cancel the close). + // + // If CEF created an OS window for the browser returning false (0) will send + // an OS close notification to the browser window's top-level owner (e.g. + // WM_CLOSE on Windows, performClose: on OS-X and "delete_event" on Linux). If + // no OS window exists (window rendering disabled) returning false (0) will + // cause the browser object to be destroyed immediately. Return true (1) if + // the browser is parented to another window and that other window needs to + // receive close notification via some non-standard technique. + // + // If an application provides its own top-level window it should handle OS + // close notifications by calling cef_browser_host_t::CloseBrowser(false (0)) + // instead of immediately closing (see the example below). This gives CEF an + // opportunity to process the 'onbeforeunload' event and optionally cancel the + // close before do_close() is called. + // + // The cef_life_span_handler_t::on_before_close() function will be called + // immediately before the browser object is destroyed. The application should + // only exit after on_before_close() has been called for all existing + // browsers. + // + // If the browser represents a modal window and a custom modal loop + // implementation was provided in cef_life_span_handler_t::run_modal() this + // callback should be used to restore the opener window to a usable state. + // + // By way of example consider what should happen during window close when the + // browser is parented to an application-provided top-level OS window. 1. + // User clicks the window close button which sends an OS close + // notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and + // "delete_event" on Linux). + // 2. Application's top-level window receives the close notification and: + // A. Calls CefBrowserHost::CloseBrowser(false). + // B. Cancels the window close. + // 3. JavaScript 'onbeforeunload' handler executes and shows the close + // confirmation dialog (which can be overridden via + // CefJSDialogHandler::OnBeforeUnloadDialog()). + // 4. User approves the close. 5. JavaScript 'onunload' handler executes. 6. + // Application's do_close() handler is called. Application will: + // A. Set a flag to indicate that the next close attempt will be allowed. + // B. Return false. + // 7. CEF sends an OS close notification. 8. Application's top-level window + // receives the OS close notification and + // allows the window to close based on the flag from #6B. + // 9. Browser OS window is destroyed. 10. Application's + // cef_life_span_handler_t::on_before_close() handler is called and + // the browser object is destroyed. + // 11. Application exits by calling cef_quit_message_loop() if no other + // browsers + // exist. + // + pub fn do_close(&self, browser: interfaces::CefBrowser) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).do_close.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called just before a browser is destroyed. Release all references to the + // browser object and do not attempt to execute any functions on the browser + // object after this callback returns. If this is a modal window and a custom + // modal loop implementation was provided in run_modal() this callback should + // be used to exit the custom modal loop. See do_close() documentation for + // additional usage information. + // + pub fn on_before_close(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_close.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } +} + +impl CefWrap<*mut cef_life_span_handler_t> for CefLifeSpanHandler { + fn to_c(rust_object: CefLifeSpanHandler) -> *mut cef_life_span_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_life_span_handler_t) -> CefLifeSpanHandler { + CefLifeSpanHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_life_span_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_life_span_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_life_span_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefLifeSpanHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_load_handler.rs b/ports/cef/interfaces/cef_load_handler.rs new file mode 100644 index 00000000000..989302d3691 --- /dev/null +++ b/ports/cef/interfaces/cef_load_handler.rs @@ -0,0 +1,307 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events related to browser load status. The +// functions of this structure will be called on the browser process UI thread +// or render process main thread (TID_RENDERER). +// +#[repr(C)] +pub struct _cef_load_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called when the loading state has changed. This callback will be executed + // twice -- once when loading is initiated either programmatically or by user + // action, and once when loading is terminated due to completion, cancellation + // of failure. + // + pub on_loading_state_change: Option ()>, + + // + // Called when the browser begins loading a frame. The |frame| value will + // never be NULL -- call the is_main() function to check if this frame is the + // main frame. Multiple frames may be loading at the same time. Sub-frames may + // start or continue loading after the main frame load has ended. This + // function may not be called for a particular frame if the load request for + // that frame fails. For notification of overall browser load status use + // OnLoadingStateChange instead. + // + pub on_load_start: Option ()>, + + // + // Called when the browser is done loading a frame. The |frame| value will + // never be NULL -- call the is_main() function to check if this frame is the + // main frame. Multiple frames may be loading at the same time. Sub-frames may + // start or continue loading after the main frame load has ended. This + // function will always be called for all frames irrespective of whether the + // request completes successfully. + // + pub on_load_end: Option ()>, + + // + // Called when the resource load for a navigation fails or is canceled. + // |errorCode| is the error code number, |errorText| is the error text and + // |failedUrl| is the URL that failed to load. See net\base\net_error_list.h + // for complete descriptions of the error codes. + // + pub on_load_error: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_load_handler_t = _cef_load_handler_t; + + +// +// Implement this structure to handle events related to browser load status. The +// functions of this structure will be called on the browser process UI thread +// or render process main thread (TID_RENDERER). +// +pub struct CefLoadHandler { + c_object: *mut cef_load_handler_t, +} + +impl Clone for CefLoadHandler { + fn clone(&self) -> CefLoadHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefLoadHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefLoadHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefLoadHandler { + pub unsafe fn from_c_object(c_object: *mut cef_load_handler_t) -> CefLoadHandler { + CefLoadHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_load_handler_t) -> CefLoadHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefLoadHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_load_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_load_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called when the loading state has changed. This callback will be executed + // twice -- once when loading is initiated either programmatically or by user + // action, and once when loading is terminated due to completion, cancellation + // of failure. + // + pub fn on_loading_state_change(&self, browser: interfaces::CefBrowser, + isLoading: libc::c_int, canGoBack: libc::c_int, + canGoForward: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_loading_state_change.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(isLoading), + CefWrap::to_c(canGoBack), + CefWrap::to_c(canGoForward))) + } + } + + // + // Called when the browser begins loading a frame. The |frame| value will + // never be NULL -- call the is_main() function to check if this frame is the + // main frame. Multiple frames may be loading at the same time. Sub-frames may + // start or continue loading after the main frame load has ended. This + // function may not be called for a particular frame if the load request for + // that frame fails. For notification of overall browser load status use + // OnLoadingStateChange instead. + // + pub fn on_load_start(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_load_start.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame))) + } + } + + // + // Called when the browser is done loading a frame. The |frame| value will + // never be NULL -- call the is_main() function to check if this frame is the + // main frame. Multiple frames may be loading at the same time. Sub-frames may + // start or continue loading after the main frame load has ended. This + // function will always be called for all frames irrespective of whether the + // request completes successfully. + // + pub fn on_load_end(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, httpStatusCode: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_load_end.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(httpStatusCode))) + } + } + + // + // Called when the resource load for a navigation fails or is canceled. + // |errorCode| is the error code number, |errorText| is the error text and + // |failedUrl| is the URL that failed to load. See net\base\net_error_list.h + // for complete descriptions of the error codes. + // + pub fn on_load_error(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, errorCode: types::cef_errorcode_t, + errorText: &str, failedUrl: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_load_error.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(errorCode), + CefWrap::to_c(errorText), + CefWrap::to_c(failedUrl))) + } + } +} + +impl CefWrap<*mut cef_load_handler_t> for CefLoadHandler { + fn to_c(rust_object: CefLoadHandler) -> *mut cef_load_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_load_handler_t) -> CefLoadHandler { + CefLoadHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_load_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_load_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_load_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefLoadHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_menu_model.rs b/ports/cef/interfaces/cef_menu_model.rs new file mode 100644 index 00000000000..2d45ad335c6 --- /dev/null +++ b/ports/cef/interfaces/cef_menu_model.rs @@ -0,0 +1,1341 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Supports creation and modification of menus. See cef_menu_id_t for the +// command ids that have default implementations. All user-defined command ids +// should be between MENU_ID_USER_FIRST and MENU_ID_USER_LAST. The functions of +// this structure can only be accessed on the browser process the UI thread. +// +#[repr(C)] +pub struct _cef_menu_model_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Clears the menu. Returns true (1) on success. + // + pub clear: Option libc::c_int>, + + // + // Returns the number of items in this menu. + // + pub get_count: Option libc::c_int>, + + // + // Add a separator to the menu. Returns true (1) on success. + // + pub add_separator: Option libc::c_int>, + + // + // Add an item to the menu. Returns true (1) on success. + // + pub add_item: Option libc::c_int>, + + // + // Add a check item to the menu. Returns true (1) on success. + // + pub add_check_item: Option libc::c_int>, + + // + // Add a radio item to the menu. Only a single item with the specified + // |group_id| can be checked at a time. Returns true (1) on success. + // + pub add_radio_item: Option libc::c_int>, + + // + // Add a sub-menu to the menu. The new sub-menu is returned. + // + pub add_sub_menu: Option *mut interfaces::cef_menu_model_t>, + + // + // Insert a separator in the menu at the specified |index|. Returns true (1) + // on success. + // + pub insert_separator_at: Option libc::c_int>, + + // + // Insert an item in the menu at the specified |index|. Returns true (1) on + // success. + // + pub insert_item_at: Option libc::c_int>, + + // + // Insert a check item in the menu at the specified |index|. Returns true (1) + // on success. + // + pub insert_check_item_at: Option libc::c_int>, + + // + // Insert a radio item in the menu at the specified |index|. Only a single + // item with the specified |group_id| can be checked at a time. Returns true + // (1) on success. + // + pub insert_radio_item_at: Option libc::c_int>, + + // + // Insert a sub-menu in the menu at the specified |index|. The new sub-menu is + // returned. + // + pub insert_sub_menu_at: Option *mut interfaces::cef_menu_model_t>, + + // + // Removes the item with the specified |command_id|. Returns true (1) on + // success. + // + pub remove: Option libc::c_int>, + + // + // Removes the item at the specified |index|. Returns true (1) on success. + // + pub remove_at: Option libc::c_int>, + + // + // Returns the index associated with the specified |command_id| or -1 if not + // found due to the command id not existing in the menu. + // + pub get_index_of: Option libc::c_int>, + + // + // Returns the command id at the specified |index| or -1 if not found due to + // invalid range or the index being a separator. + // + pub get_command_id_at: Option libc::c_int>, + + // + // Sets the command id at the specified |index|. Returns true (1) on success. + // + pub set_command_id_at: Option libc::c_int>, + + // + // Returns the label for the specified |command_id| or NULL if not found. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_label: Option types::cef_string_userfree_t>, + + // + // Returns the label at the specified |index| or NULL if not found due to + // invalid range or the index being a separator. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_label_at: Option types::cef_string_userfree_t>, + + // + // Sets the label for the specified |command_id|. Returns true (1) on success. + // + pub set_label: Option libc::c_int>, + + // + // Set the label at the specified |index|. Returns true (1) on success. + // + pub set_label_at: Option libc::c_int>, + + // + // Returns the item type for the specified |command_id|. + // + pub get_type: Option types::cef_menu_item_type_t>, + + // + // Returns the item type at the specified |index|. + // + pub get_type_at: Option types::cef_menu_item_type_t>, + + // + // Returns the group id for the specified |command_id| or -1 if invalid. + // + pub get_group_id: Option libc::c_int>, + + // + // Returns the group id at the specified |index| or -1 if invalid. + // + pub get_group_id_at: Option libc::c_int>, + + // + // Sets the group id for the specified |command_id|. Returns true (1) on + // success. + // + pub set_group_id: Option libc::c_int>, + + // + // Sets the group id at the specified |index|. Returns true (1) on success. + // + pub set_group_id_at: Option libc::c_int>, + + // + // Returns the submenu for the specified |command_id| or NULL if invalid. + // + pub get_sub_menu: Option *mut interfaces::cef_menu_model_t>, + + // + // Returns the submenu at the specified |index| or NULL if invalid. + // + pub get_sub_menu_at: Option *mut interfaces::cef_menu_model_t>, + + // + // Returns true (1) if the specified |command_id| is visible. + // + pub is_visible: Option libc::c_int>, + + // + // Returns true (1) if the specified |index| is visible. + // + pub is_visible_at: Option libc::c_int>, + + // + // Change the visibility of the specified |command_id|. Returns true (1) on + // success. + // + pub set_visible: Option libc::c_int>, + + // + // Change the visibility at the specified |index|. Returns true (1) on + // success. + // + pub set_visible_at: Option libc::c_int>, + + // + // Returns true (1) if the specified |command_id| is enabled. + // + pub is_enabled: Option libc::c_int>, + + // + // Returns true (1) if the specified |index| is enabled. + // + pub is_enabled_at: Option libc::c_int>, + + // + // Change the enabled status of the specified |command_id|. Returns true (1) + // on success. + // + pub set_enabled: Option libc::c_int>, + + // + // Change the enabled status at the specified |index|. Returns true (1) on + // success. + // + pub set_enabled_at: Option libc::c_int>, + + // + // Returns true (1) if the specified |command_id| is checked. Only applies to + // check and radio items. + // + pub is_checked: Option libc::c_int>, + + // + // Returns true (1) if the specified |index| is checked. Only applies to check + // and radio items. + // + pub is_checked_at: Option libc::c_int>, + + // + // Check the specified |command_id|. Only applies to check and radio items. + // Returns true (1) on success. + // + pub set_checked: Option libc::c_int>, + + // + // Check the specified |index|. Only applies to check and radio items. Returns + // true (1) on success. + // + pub set_checked_at: Option libc::c_int>, + + // + // Returns true (1) if the specified |command_id| has a keyboard accelerator + // assigned. + // + pub has_accelerator: Option libc::c_int>, + + // + // Returns true (1) if the specified |index| has a keyboard accelerator + // assigned. + // + pub has_accelerator_at: Option libc::c_int>, + + // + // Set the keyboard accelerator for the specified |command_id|. |key_code| can + // be any virtual key or character value. Returns true (1) on success. + // + pub set_accelerator: Option libc::c_int>, + + // + // Set the keyboard accelerator at the specified |index|. |key_code| can be + // any virtual key or character value. Returns true (1) on success. + // + pub set_accelerator_at: Option libc::c_int>, + + // + // Remove the keyboard accelerator for the specified |command_id|. Returns + // true (1) on success. + // + pub remove_accelerator: Option libc::c_int>, + + // + // Remove the keyboard accelerator at the specified |index|. Returns true (1) + // on success. + // + pub remove_accelerator_at: Option libc::c_int>, + + // + // Retrieves the keyboard accelerator for the specified |command_id|. Returns + // true (1) on success. + // + pub get_accelerator: Option libc::c_int>, + + // + // Retrieves the keyboard accelerator for the specified |index|. Returns true + // (1) on success. + // + pub get_accelerator_at: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_menu_model_t = _cef_menu_model_t; + + +// +// Supports creation and modification of menus. See cef_menu_id_t for the +// command ids that have default implementations. All user-defined command ids +// should be between MENU_ID_USER_FIRST and MENU_ID_USER_LAST. The functions of +// this structure can only be accessed on the browser process the UI thread. +// +pub struct CefMenuModel { + c_object: *mut cef_menu_model_t, +} + +impl Clone for CefMenuModel { + fn clone(&self) -> CefMenuModel{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefMenuModel { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefMenuModel { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefMenuModel { + pub unsafe fn from_c_object(c_object: *mut cef_menu_model_t) -> CefMenuModel { + CefMenuModel { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_menu_model_t) -> CefMenuModel { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefMenuModel { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_menu_model_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_menu_model_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Clears the menu. Returns true (1) on success. + // + pub fn clear(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).clear.unwrap())( + self.c_object)) + } + } + + // + // Returns the number of items in this menu. + // + pub fn get_count(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_count.unwrap())( + self.c_object)) + } + } + + // + // Add a separator to the menu. Returns true (1) on success. + // + pub fn add_separator(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_separator.unwrap())( + self.c_object)) + } + } + + // + // Add an item to the menu. Returns true (1) on success. + // + pub fn add_item(&self, command_id: libc::c_int, label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_item.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Add a check item to the menu. Returns true (1) on success. + // + pub fn add_check_item(&self, command_id: libc::c_int, + label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_check_item.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Add a radio item to the menu. Only a single item with the specified + // |group_id| can be checked at a time. Returns true (1) on success. + // + pub fn add_radio_item(&self, command_id: libc::c_int, label: &str, + group_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_radio_item.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(label), + CefWrap::to_c(group_id))) + } + } + + // + // Add a sub-menu to the menu. The new sub-menu is returned. + // + pub fn add_sub_menu(&self, command_id: libc::c_int, + label: &str) -> interfaces::CefMenuModel { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_sub_menu.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Insert a separator in the menu at the specified |index|. Returns true (1) + // on success. + // + pub fn insert_separator_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).insert_separator_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Insert an item in the menu at the specified |index|. Returns true (1) on + // success. + // + pub fn insert_item_at(&self, index: libc::c_int, command_id: libc::c_int, + label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).insert_item_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Insert a check item in the menu at the specified |index|. Returns true (1) + // on success. + // + pub fn insert_check_item_at(&self, index: libc::c_int, + command_id: libc::c_int, label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).insert_check_item_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Insert a radio item in the menu at the specified |index|. Only a single + // item with the specified |group_id| can be checked at a time. Returns true + // (1) on success. + // + pub fn insert_radio_item_at(&self, index: libc::c_int, + command_id: libc::c_int, label: &str, + group_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).insert_radio_item_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(command_id), + CefWrap::to_c(label), + CefWrap::to_c(group_id))) + } + } + + // + // Insert a sub-menu in the menu at the specified |index|. The new sub-menu is + // returned. + // + pub fn insert_sub_menu_at(&self, index: libc::c_int, command_id: libc::c_int, + label: &str) -> interfaces::CefMenuModel { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).insert_sub_menu_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Removes the item with the specified |command_id|. Returns true (1) on + // success. + // + pub fn remove(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Removes the item at the specified |index|. Returns true (1) on success. + // + pub fn remove_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the index associated with the specified |command_id| or -1 if not + // found due to the command id not existing in the menu. + // + pub fn get_index_of(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_index_of.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns the command id at the specified |index| or -1 if not found due to + // invalid range or the index being a separator. + // + pub fn get_command_id_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_command_id_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Sets the command id at the specified |index|. Returns true (1) on success. + // + pub fn set_command_id_at(&self, index: libc::c_int, + command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_command_id_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(command_id))) + } + } + + // + // Returns the label for the specified |command_id| or NULL if not found. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_label(&self, command_id: libc::c_int) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_label.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns the label at the specified |index| or NULL if not found due to + // invalid range or the index being a separator. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_label_at(&self, index: libc::c_int) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_label_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Sets the label for the specified |command_id|. Returns true (1) on success. + // + pub fn set_label(&self, command_id: libc::c_int, label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_label.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(label))) + } + } + + // + // Set the label at the specified |index|. Returns true (1) on success. + // + pub fn set_label_at(&self, index: libc::c_int, label: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_label_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(label))) + } + } + + // + // Returns the item type for the specified |command_id|. + // + pub fn get_type(&self, + command_id: libc::c_int) -> types::cef_menu_item_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns the item type at the specified |index|. + // + pub fn get_type_at(&self, index: libc::c_int) -> types::cef_menu_item_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the group id for the specified |command_id| or -1 if invalid. + // + pub fn get_group_id(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_group_id.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns the group id at the specified |index| or -1 if invalid. + // + pub fn get_group_id_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_group_id_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Sets the group id for the specified |command_id|. Returns true (1) on + // success. + // + pub fn set_group_id(&self, command_id: libc::c_int, + group_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_group_id.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(group_id))) + } + } + + // + // Sets the group id at the specified |index|. Returns true (1) on success. + // + pub fn set_group_id_at(&self, index: libc::c_int, + group_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_group_id_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(group_id))) + } + } + + // + // Returns the submenu for the specified |command_id| or NULL if invalid. + // + pub fn get_sub_menu(&self, + command_id: libc::c_int) -> interfaces::CefMenuModel { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_sub_menu.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns the submenu at the specified |index| or NULL if invalid. + // + pub fn get_sub_menu_at(&self, + index: libc::c_int) -> interfaces::CefMenuModel { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_sub_menu_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns true (1) if the specified |command_id| is visible. + // + pub fn is_visible(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_visible.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns true (1) if the specified |index| is visible. + // + pub fn is_visible_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_visible_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Change the visibility of the specified |command_id|. Returns true (1) on + // success. + // + pub fn set_visible(&self, command_id: libc::c_int, + visible: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_visible.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(visible))) + } + } + + // + // Change the visibility at the specified |index|. Returns true (1) on + // success. + // + pub fn set_visible_at(&self, index: libc::c_int, + visible: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_visible_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(visible))) + } + } + + // + // Returns true (1) if the specified |command_id| is enabled. + // + pub fn is_enabled(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_enabled.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns true (1) if the specified |index| is enabled. + // + pub fn is_enabled_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_enabled_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Change the enabled status of the specified |command_id|. Returns true (1) + // on success. + // + pub fn set_enabled(&self, command_id: libc::c_int, + enabled: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_enabled.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(enabled))) + } + } + + // + // Change the enabled status at the specified |index|. Returns true (1) on + // success. + // + pub fn set_enabled_at(&self, index: libc::c_int, + enabled: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_enabled_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(enabled))) + } + } + + // + // Returns true (1) if the specified |command_id| is checked. Only applies to + // check and radio items. + // + pub fn is_checked(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_checked.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns true (1) if the specified |index| is checked. Only applies to check + // and radio items. + // + pub fn is_checked_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_checked_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Check the specified |command_id|. Only applies to check and radio items. + // Returns true (1) on success. + // + pub fn set_checked(&self, command_id: libc::c_int, + checked: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_checked.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(checked))) + } + } + + // + // Check the specified |index|. Only applies to check and radio items. Returns + // true (1) on success. + // + pub fn set_checked_at(&self, index: libc::c_int, + checked: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_checked_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(checked))) + } + } + + // + // Returns true (1) if the specified |command_id| has a keyboard accelerator + // assigned. + // + pub fn has_accelerator(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_accelerator.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Returns true (1) if the specified |index| has a keyboard accelerator + // assigned. + // + pub fn has_accelerator_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_accelerator_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Set the keyboard accelerator for the specified |command_id|. |key_code| can + // be any virtual key or character value. Returns true (1) on success. + // + pub fn set_accelerator(&self, command_id: libc::c_int, key_code: libc::c_int, + shift_pressed: libc::c_int, ctrl_pressed: libc::c_int, + alt_pressed: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_accelerator.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(key_code), + CefWrap::to_c(shift_pressed), + CefWrap::to_c(ctrl_pressed), + CefWrap::to_c(alt_pressed))) + } + } + + // + // Set the keyboard accelerator at the specified |index|. |key_code| can be + // any virtual key or character value. Returns true (1) on success. + // + pub fn set_accelerator_at(&self, index: libc::c_int, key_code: libc::c_int, + shift_pressed: libc::c_int, ctrl_pressed: libc::c_int, + alt_pressed: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_accelerator_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(key_code), + CefWrap::to_c(shift_pressed), + CefWrap::to_c(ctrl_pressed), + CefWrap::to_c(alt_pressed))) + } + } + + // + // Remove the keyboard accelerator for the specified |command_id|. Returns + // true (1) on success. + // + pub fn remove_accelerator(&self, command_id: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove_accelerator.unwrap())( + self.c_object, + CefWrap::to_c(command_id))) + } + } + + // + // Remove the keyboard accelerator at the specified |index|. Returns true (1) + // on success. + // + pub fn remove_accelerator_at(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove_accelerator_at.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Retrieves the keyboard accelerator for the specified |command_id|. Returns + // true (1) on success. + // + pub fn get_accelerator(&self, command_id: libc::c_int, + key_code: &mut libc::c_int, shift_pressed: &mut libc::c_int, + ctrl_pressed: &mut libc::c_int, + alt_pressed: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_accelerator.unwrap())( + self.c_object, + CefWrap::to_c(command_id), + CefWrap::to_c(key_code), + CefWrap::to_c(shift_pressed), + CefWrap::to_c(ctrl_pressed), + CefWrap::to_c(alt_pressed))) + } + } + + // + // Retrieves the keyboard accelerator for the specified |index|. Returns true + // (1) on success. + // + pub fn get_accelerator_at(&self, index: libc::c_int, + key_code: &mut libc::c_int, shift_pressed: &mut libc::c_int, + ctrl_pressed: &mut libc::c_int, + alt_pressed: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_accelerator_at.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(key_code), + CefWrap::to_c(shift_pressed), + CefWrap::to_c(ctrl_pressed), + CefWrap::to_c(alt_pressed))) + } + } +} + +impl CefWrap<*mut cef_menu_model_t> for CefMenuModel { + fn to_c(rust_object: CefMenuModel) -> *mut cef_menu_model_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_menu_model_t) -> CefMenuModel { + CefMenuModel::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_menu_model_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_menu_model_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_menu_model_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefMenuModel::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_origin_whitelist.rs b/ports/cef/interfaces/cef_origin_whitelist.rs new file mode 100644 index 00000000000..c8622bc9cc9 --- /dev/null +++ b/ports/cef/interfaces/cef_origin_whitelist.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; diff --git a/ports/cef/interfaces/cef_path_util.rs b/ports/cef/interfaces/cef_path_util.rs new file mode 100644 index 00000000000..c8622bc9cc9 --- /dev/null +++ b/ports/cef/interfaces/cef_path_util.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; diff --git a/ports/cef/interfaces/cef_print_handler.rs b/ports/cef/interfaces/cef_print_handler.rs new file mode 100644 index 00000000000..ec794b50f2f --- /dev/null +++ b/ports/cef/interfaces/cef_print_handler.rs @@ -0,0 +1,562 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure for asynchronous continuation of print dialog requests. +// +#[repr(C)] +pub struct _cef_print_dialog_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue printing with the specified |settings|. + // + pub cont: Option ()>, + + // + // Cancel the printing. + // + pub cancel: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_print_dialog_callback_t = _cef_print_dialog_callback_t; + + +// +// Callback structure for asynchronous continuation of print dialog requests. +// +pub struct CefPrintDialogCallback { + c_object: *mut cef_print_dialog_callback_t, +} + +impl Clone for CefPrintDialogCallback { + fn clone(&self) -> CefPrintDialogCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPrintDialogCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPrintDialogCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPrintDialogCallback { + pub unsafe fn from_c_object(c_object: *mut cef_print_dialog_callback_t) -> CefPrintDialogCallback { + CefPrintDialogCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_print_dialog_callback_t) -> CefPrintDialogCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPrintDialogCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_print_dialog_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_print_dialog_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue printing with the specified |settings|. + // + pub fn cont(&self, settings: interfaces::CefPrintSettings) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(settings))) + } + } + + // + // Cancel the printing. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_print_dialog_callback_t> for CefPrintDialogCallback { + fn to_c(rust_object: CefPrintDialogCallback) -> *mut cef_print_dialog_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_print_dialog_callback_t) -> CefPrintDialogCallback { + CefPrintDialogCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_print_dialog_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_print_dialog_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_print_dialog_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPrintDialogCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Callback structure for asynchronous continuation of print job requests. +// +#[repr(C)] +pub struct _cef_print_job_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Indicate completion of the print job. + // + pub cont: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_print_job_callback_t = _cef_print_job_callback_t; + + +// +// Callback structure for asynchronous continuation of print job requests. +// +pub struct CefPrintJobCallback { + c_object: *mut cef_print_job_callback_t, +} + +impl Clone for CefPrintJobCallback { + fn clone(&self) -> CefPrintJobCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPrintJobCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPrintJobCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPrintJobCallback { + pub unsafe fn from_c_object(c_object: *mut cef_print_job_callback_t) -> CefPrintJobCallback { + CefPrintJobCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_print_job_callback_t) -> CefPrintJobCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPrintJobCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_print_job_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_print_job_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Indicate completion of the print job. + // + pub fn cont(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_print_job_callback_t> for CefPrintJobCallback { + fn to_c(rust_object: CefPrintJobCallback) -> *mut cef_print_job_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_print_job_callback_t) -> CefPrintJobCallback { + CefPrintJobCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_print_job_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_print_job_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_print_job_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPrintJobCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Implement this structure to handle printing on Linux. The functions of this +// structure will be called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_print_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Synchronize |settings| with client state. If |get_defaults| is true (1) + // then populate |settings| with the default print settings. Do not keep a + // reference to |settings| outside of this callback. + // + pub on_print_settings: Option ()>, + + // + // Show the print dialog. Execute |callback| once the dialog is dismissed. + // Return true (1) if the dialog will be displayed or false (0) to cancel the + // printing immediately. + // + pub on_print_dialog: Option libc::c_int>, + + // + // Send the print job to the printer. Execute |callback| once the job is + // completed. Return true (1) if the job will proceed or false (0) to cancel + // the job immediately. + // + pub on_print_job: Option libc::c_int>, + + // + // Reset client state related to printing. + // + pub on_print_reset: Option ( + )>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_print_handler_t = _cef_print_handler_t; + + +// +// Implement this structure to handle printing on Linux. The functions of this +// structure will be called on the browser process UI thread. +// +pub struct CefPrintHandler { + c_object: *mut cef_print_handler_t, +} + +impl Clone for CefPrintHandler { + fn clone(&self) -> CefPrintHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPrintHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPrintHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPrintHandler { + pub unsafe fn from_c_object(c_object: *mut cef_print_handler_t) -> CefPrintHandler { + CefPrintHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_print_handler_t) -> CefPrintHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPrintHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_print_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_print_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Synchronize |settings| with client state. If |get_defaults| is true (1) + // then populate |settings| with the default print settings. Do not keep a + // reference to |settings| outside of this callback. + // + pub fn on_print_settings(&self, settings: interfaces::CefPrintSettings, + get_defaults: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_print_settings.unwrap())( + self.c_object, + CefWrap::to_c(settings), + CefWrap::to_c(get_defaults))) + } + } + + // + // Show the print dialog. Execute |callback| once the dialog is dismissed. + // Return true (1) if the dialog will be displayed or false (0) to cancel the + // printing immediately. + // + pub fn on_print_dialog(&self, has_selection: libc::c_int, + callback: interfaces::CefPrintDialogCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_print_dialog.unwrap())( + self.c_object, + CefWrap::to_c(has_selection), + CefWrap::to_c(callback))) + } + } + + // + // Send the print job to the printer. Execute |callback| once the job is + // completed. Return true (1) if the job will proceed or false (0) to cancel + // the job immediately. + // + pub fn on_print_job(&self, document_name: &str, pdf_file_path: &str, + callback: interfaces::CefPrintJobCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_print_job.unwrap())( + self.c_object, + CefWrap::to_c(document_name), + CefWrap::to_c(pdf_file_path), + CefWrap::to_c(callback))) + } + } + + // + // Reset client state related to printing. + // + pub fn on_print_reset(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_print_reset.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_print_handler_t> for CefPrintHandler { + fn to_c(rust_object: CefPrintHandler) -> *mut cef_print_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_print_handler_t) -> CefPrintHandler { + CefPrintHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_print_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_print_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_print_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPrintHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_print_settings.rs b/ports/cef/interfaces/cef_print_settings.rs new file mode 100644 index 00000000000..ef81ec47fdb --- /dev/null +++ b/ports/cef/interfaces/cef_print_settings.rs @@ -0,0 +1,668 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure representing print settings. +// +#[repr(C)] +pub struct _cef_print_settings_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns a writable copy of this object. + // + pub copy: Option *mut interfaces::cef_print_settings_t>, + + // + // Set the page orientation. + // + pub set_orientation: Option ()>, + + // + // Returns true (1) if the orientation is landscape. + // + pub is_landscape: Option libc::c_int>, + + // + // Set the printer printable area in device units. Some platforms already + // provide flipped area. Set |landscape_needs_flip| to false (0) on those + // platforms to avoid double flipping. + // + pub set_printer_printable_area: Option ()>, + + // + // Set the device name. + // + pub set_device_name: Option ()>, + + // + // Get the device name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_device_name: Option types::cef_string_userfree_t>, + + // + // Set the DPI (dots per inch). + // + pub set_dpi: Option ()>, + + // + // Get the DPI (dots per inch). + // + pub get_dpi: Option libc::c_int>, + + // + // Set the page ranges. + // + pub set_page_ranges: Option ( + )>, + + // + // Returns the number of page ranges that currently exist. + // + pub get_page_ranges_count: Option libc::size_t>, + + // + // Retrieve the page ranges. + // + pub get_page_ranges: Option ()>, + + // + // Set whether only the selection will be printed. + // + pub set_selection_only: Option ()>, + + // + // Returns true (1) if only the selection will be printed. + // + pub is_selection_only: Option libc::c_int>, + + // + // Set whether pages will be collated. + // + pub set_collate: Option ()>, + + // + // Returns true (1) if pages will be collated. + // + pub will_collate: Option libc::c_int>, + + // + // Set the color model. + // + pub set_color_model: Option ()>, + + // + // Get the color model. + // + pub get_color_model: Option types::cef_color_model_t>, + + // + // Set the number of copies. + // + pub set_copies: Option ()>, + + // + // Get the number of copies. + // + pub get_copies: Option libc::c_int>, + + // + // Set the duplex mode. + // + pub set_duplex_mode: Option ()>, + + // + // Get the duplex mode. + // + pub get_duplex_mode: Option types::cef_duplex_mode_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_print_settings_t = _cef_print_settings_t; + + +// +// Structure representing print settings. +// +pub struct CefPrintSettings { + c_object: *mut cef_print_settings_t, +} + +impl Clone for CefPrintSettings { + fn clone(&self) -> CefPrintSettings{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPrintSettings { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPrintSettings { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPrintSettings { + pub unsafe fn from_c_object(c_object: *mut cef_print_settings_t) -> CefPrintSettings { + CefPrintSettings { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_print_settings_t) -> CefPrintSettings { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPrintSettings { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_print_settings_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_print_settings_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns a writable copy of this object. + // + pub fn copy(&self) -> interfaces::CefPrintSettings { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Set the page orientation. + // + pub fn set_orientation(&self, landscape: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_orientation.unwrap())( + self.c_object, + CefWrap::to_c(landscape))) + } + } + + // + // Returns true (1) if the orientation is landscape. + // + pub fn is_landscape(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_landscape.unwrap())( + self.c_object)) + } + } + + // + // Set the printer printable area in device units. Some platforms already + // provide flipped area. Set |landscape_needs_flip| to false (0) on those + // platforms to avoid double flipping. + // + pub fn set_printer_printable_area(&self, + physical_size_device_units: &types::cef_size_t, + printable_area_device_units: &types::cef_rect_t, + landscape_needs_flip: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_printer_printable_area.unwrap())( + self.c_object, + CefWrap::to_c(physical_size_device_units), + CefWrap::to_c(printable_area_device_units), + CefWrap::to_c(landscape_needs_flip))) + } + } + + // + // Set the device name. + // + pub fn set_device_name(&self, name: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_device_name.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Get the device name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_device_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_device_name.unwrap())( + self.c_object)) + } + } + + // + // Set the DPI (dots per inch). + // + pub fn set_dpi(&self, dpi: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_dpi.unwrap())( + self.c_object, + CefWrap::to_c(dpi))) + } + } + + // + // Get the DPI (dots per inch). + // + pub fn get_dpi(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_dpi.unwrap())( + self.c_object)) + } + } + + // + // Set the page ranges. + // + pub fn set_page_ranges(&self, ranges_count: libc::size_t, + ranges: *const types::cef_page_range_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_page_ranges.unwrap())( + self.c_object, + CefWrap::to_c(ranges_count), + CefWrap::to_c(ranges))) + } + } + + // + // Returns the number of page ranges that currently exist. + // + pub fn get_page_ranges_count(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_page_ranges_count.unwrap())( + self.c_object)) + } + } + + // + // Retrieve the page ranges. + // + pub fn get_page_ranges(&self, ranges_count: *mut libc::size_t, + ranges: *mut types::cef_page_range_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_page_ranges.unwrap())( + self.c_object, + CefWrap::to_c(ranges_count), + CefWrap::to_c(ranges))) + } + } + + // + // Set whether only the selection will be printed. + // + pub fn set_selection_only(&self, selection_only: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_selection_only.unwrap())( + self.c_object, + CefWrap::to_c(selection_only))) + } + } + + // + // Returns true (1) if only the selection will be printed. + // + pub fn is_selection_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_selection_only.unwrap())( + self.c_object)) + } + } + + // + // Set whether pages will be collated. + // + pub fn set_collate(&self, collate: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_collate.unwrap())( + self.c_object, + CefWrap::to_c(collate))) + } + } + + // + // Returns true (1) if pages will be collated. + // + pub fn will_collate(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).will_collate.unwrap())( + self.c_object)) + } + } + + // + // Set the color model. + // + pub fn set_color_model(&self, model: types::cef_color_model_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_color_model.unwrap())( + self.c_object, + CefWrap::to_c(model))) + } + } + + // + // Get the color model. + // + pub fn get_color_model(&self) -> types::cef_color_model_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_color_model.unwrap())( + self.c_object)) + } + } + + // + // Set the number of copies. + // + pub fn set_copies(&self, copies: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_copies.unwrap())( + self.c_object, + CefWrap::to_c(copies))) + } + } + + // + // Get the number of copies. + // + pub fn get_copies(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_copies.unwrap())( + self.c_object)) + } + } + + // + // Set the duplex mode. + // + pub fn set_duplex_mode(&self, mode: types::cef_duplex_mode_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_duplex_mode.unwrap())( + self.c_object, + CefWrap::to_c(mode))) + } + } + + // + // Get the duplex mode. + // + pub fn get_duplex_mode(&self) -> types::cef_duplex_mode_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_duplex_mode.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_print_settings_t object. + // + pub fn create() -> interfaces::CefPrintSettings { + unsafe { + CefWrap::to_rust( + ::print_settings::cef_print_settings_create( +)) + } + } +} + +impl CefWrap<*mut cef_print_settings_t> for CefPrintSettings { + fn to_c(rust_object: CefPrintSettings) -> *mut cef_print_settings_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_print_settings_t) -> CefPrintSettings { + CefPrintSettings::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_print_settings_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_print_settings_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_print_settings_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPrintSettings::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_process_message.rs b/ports/cef/interfaces/cef_process_message.rs new file mode 100644 index 00000000000..5d5ab1ce3f7 --- /dev/null +++ b/ports/cef/interfaces/cef_process_message.rs @@ -0,0 +1,279 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure representing a message. Can be used on any process and thread. +// +#[repr(C)] +pub struct _cef_process_message_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns a writable copy of this object. + // + pub copy: Option *mut interfaces::cef_process_message_t>, + + // + // Returns the message name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_name: Option types::cef_string_userfree_t>, + + // + // Returns the list of arguments. + // + pub get_argument_list: Option *mut interfaces::cef_list_value_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_process_message_t = _cef_process_message_t; + + +// +// Structure representing a message. Can be used on any process and thread. +// +pub struct CefProcessMessage { + c_object: *mut cef_process_message_t, +} + +impl Clone for CefProcessMessage { + fn clone(&self) -> CefProcessMessage{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefProcessMessage { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefProcessMessage { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefProcessMessage { + pub unsafe fn from_c_object(c_object: *mut cef_process_message_t) -> CefProcessMessage { + CefProcessMessage { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_process_message_t) -> CefProcessMessage { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefProcessMessage { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_process_message_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_process_message_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns a writable copy of this object. + // + pub fn copy(&self) -> interfaces::CefProcessMessage { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Returns the message name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the list of arguments. + // + pub fn get_argument_list(&self) -> interfaces::CefListValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_argument_list.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_process_message_t object with the specified name. + // + pub fn create(name: &str) -> interfaces::CefProcessMessage { + unsafe { + CefWrap::to_rust( + ::process_message::cef_process_message_create( + CefWrap::to_c(name))) + } + } +} + +impl CefWrap<*mut cef_process_message_t> for CefProcessMessage { + fn to_c(rust_object: CefProcessMessage) -> *mut cef_process_message_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_process_message_t) -> CefProcessMessage { + CefProcessMessage::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_process_message_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_process_message_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_process_message_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefProcessMessage::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_process_util.rs b/ports/cef/interfaces/cef_process_util.rs new file mode 100644 index 00000000000..c8622bc9cc9 --- /dev/null +++ b/ports/cef/interfaces/cef_process_util.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; diff --git a/ports/cef/interfaces/cef_render_handler.rs b/ports/cef/interfaces/cef_render_handler.rs new file mode 100644 index 00000000000..0ab5bf7e6e5 --- /dev/null +++ b/ports/cef/interfaces/cef_render_handler.rs @@ -0,0 +1,554 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to handle events when window rendering is disabled. +// The functions of this structure will be called on the UI thread. +// +#[repr(C)] +pub struct _cef_render_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called to retrieve the root window rectangle in screen coordinates. Return + // true (1) if the rectangle was provided. + // + pub get_root_screen_rect: Option libc::c_int>, + + // + // Called to retrieve the view rectangle which is relative to screen + // coordinates. Return true (1) if the rectangle was provided. + // + pub get_view_rect: Option libc::c_int>, + + // + // Called to retrieve the translation from view coordinates to actual screen + // coordinates. Return true (1) if the screen coordinates were provided. + // + pub get_screen_point: Option libc::c_int>, + + // + // Called to allow the client to fill in the CefScreenInfo object with + // appropriate values. Return true (1) if the |screen_info| structure has been + // modified. + // + // If the screen info rectangle is left NULL the rectangle from GetViewRect + // will be used. If the rectangle is still NULL or invalid popups may not be + // drawn correctly. + // + pub get_screen_info: Option libc::c_int>, + + // + // Called when the browser wants to show or hide the popup widget. The popup + // should be shown if |show| is true (1) and hidden if |show| is false (0). + // + pub on_popup_show: Option ()>, + + // + // Called when the browser wants to move or resize the popup widget. |rect| + // contains the new location and size. + // + pub on_popup_size: Option ()>, + + // + // Called when an element should be painted. |type| indicates whether the + // element is the view or the popup widget. |buffer| contains the pixel data + // for the whole image. |dirtyRects| contains the set of rectangles that need + // to be repainted. On Windows |buffer| will be |width|*|height|*4 bytes in + // size and represents a BGRA image with an upper-left origin. + // + pub on_paint: Option ()>, + + // + // Called when the browser window's cursor has changed. + // + pub on_cursor_change: Option ()>, + + // + // Called when the user starts dragging content in the web view. Contextual + // information about the dragged content is supplied by |drag_data|. OS APIs + // that run a system message loop may be used within the StartDragging call. + // + // Return false (0) to abort the drag operation. Don't call any of + // cef_browser_host_t::DragSource*Ended* functions after returning false (0). + // + // Return true (1) to handle the drag operation. Call + // cef_browser_host_t::DragSourceEndedAt and DragSourceSystemDragEnded either + // synchronously or asynchronously to inform the web view that the drag + // operation has ended. + // + pub start_dragging: Option libc::c_int>, + + // + // Called when the web view wants to update the mouse cursor during a drag & + // drop operation. |operation| describes the allowed operation (none, move, + // copy, link). + // + pub update_drag_cursor: Option ()>, + + // + // Called when the scroll offset has changed. + // + pub on_scroll_offset_changed: Option ()>, + + // + // Called to retrieve the backing size of the view rectangle which is relative + // to screen coordinates. On HiDPI displays, the backing size can differ from + // the view size as returned by |GetViewRect|. Return true (1) if the + // rectangle was provided. + // + pub get_backing_rect: Option libc::c_int>, + + // + // Called when an element should be presented (e.g. double buffers should page + // flip). This is called only during accelerated compositing. + // + pub on_present: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_render_handler_t = _cef_render_handler_t; + + +// +// Implement this structure to handle events when window rendering is disabled. +// The functions of this structure will be called on the UI thread. +// +pub struct CefRenderHandler { + c_object: *mut cef_render_handler_t, +} + +impl Clone for CefRenderHandler { + fn clone(&self) -> CefRenderHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRenderHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRenderHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRenderHandler { + pub unsafe fn from_c_object(c_object: *mut cef_render_handler_t) -> CefRenderHandler { + CefRenderHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_render_handler_t) -> CefRenderHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRenderHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_render_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_render_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called to retrieve the root window rectangle in screen coordinates. Return + // true (1) if the rectangle was provided. + // + pub fn get_root_screen_rect(&self, browser: interfaces::CefBrowser, + rect: &mut types::cef_rect_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_root_screen_rect.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(rect))) + } + } + + // + // Called to retrieve the view rectangle which is relative to screen + // coordinates. Return true (1) if the rectangle was provided. + // + pub fn get_view_rect(&self, browser: interfaces::CefBrowser, + rect: &mut types::cef_rect_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_view_rect.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(rect))) + } + } + + // + // Called to retrieve the translation from view coordinates to actual screen + // coordinates. Return true (1) if the screen coordinates were provided. + // + pub fn get_screen_point(&self, browser: interfaces::CefBrowser, + viewX: libc::c_int, viewY: libc::c_int, screenX: &mut libc::c_int, + screenY: &mut libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_screen_point.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(viewX), + CefWrap::to_c(viewY), + CefWrap::to_c(screenX), + CefWrap::to_c(screenY))) + } + } + + // + // Called to allow the client to fill in the CefScreenInfo object with + // appropriate values. Return true (1) if the |screen_info| structure has been + // modified. + // + // If the screen info rectangle is left NULL the rectangle from GetViewRect + // will be used. If the rectangle is still NULL or invalid popups may not be + // drawn correctly. + // + pub fn get_screen_info(&self, browser: interfaces::CefBrowser, + screen_info: &mut interfaces::CefScreenInfo) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_screen_info.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(screen_info))) + } + } + + // + // Called when the browser wants to show or hide the popup widget. The popup + // should be shown if |show| is true (1) and hidden if |show| is false (0). + // + pub fn on_popup_show(&self, browser: interfaces::CefBrowser, + show: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_popup_show.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(show))) + } + } + + // + // Called when the browser wants to move or resize the popup widget. |rect| + // contains the new location and size. + // + pub fn on_popup_size(&self, browser: interfaces::CefBrowser, + rect: &types::cef_rect_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_popup_size.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(rect))) + } + } + + // + // Called when an element should be painted. |type| indicates whether the + // element is the view or the popup widget. |buffer| contains the pixel data + // for the whole image. |dirtyRects| contains the set of rectangles that need + // to be repainted. On Windows |buffer| will be |width|*|height|*4 bytes in + // size and represents a BGRA image with an upper-left origin. + // + pub fn on_paint(&self, browser: interfaces::CefBrowser, + ty: types::cef_paint_element_type_t, dirtyRects_count: libc::size_t, + dirtyRects: *const types::cef_rect_t, buffer: &(), width: libc::c_int, + height: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_paint.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(ty), + CefWrap::to_c(dirtyRects_count), + CefWrap::to_c(dirtyRects), + CefWrap::to_c(buffer), + CefWrap::to_c(width), + CefWrap::to_c(height))) + } + } + + // + // Called when the browser window's cursor has changed. + // + pub fn on_cursor_change(&self, browser: interfaces::CefBrowser, + cursor: types::cef_cursor_handle_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_cursor_change.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(cursor))) + } + } + + // + // Called when the user starts dragging content in the web view. Contextual + // information about the dragged content is supplied by |drag_data|. OS APIs + // that run a system message loop may be used within the StartDragging call. + // + // Return false (0) to abort the drag operation. Don't call any of + // cef_browser_host_t::DragSource*Ended* functions after returning false (0). + // + // Return true (1) to handle the drag operation. Call + // cef_browser_host_t::DragSourceEndedAt and DragSourceSystemDragEnded either + // synchronously or asynchronously to inform the web view that the drag + // operation has ended. + // + pub fn start_dragging(&self, browser: interfaces::CefBrowser, + drag_data: interfaces::CefDragData, + allowed_ops: types::cef_drag_operations_mask_t, x: libc::c_int, + y: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).start_dragging.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(drag_data), + CefWrap::to_c(allowed_ops), + CefWrap::to_c(x), + CefWrap::to_c(y))) + } + } + + // + // Called when the web view wants to update the mouse cursor during a drag & + // drop operation. |operation| describes the allowed operation (none, move, + // copy, link). + // + pub fn update_drag_cursor(&self, browser: interfaces::CefBrowser, + operation: types::cef_drag_operations_mask_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).update_drag_cursor.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(operation))) + } + } + + // + // Called when the scroll offset has changed. + // + pub fn on_scroll_offset_changed(&self, browser: interfaces::CefBrowser) -> ( + ) { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_scroll_offset_changed.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called to retrieve the backing size of the view rectangle which is relative + // to screen coordinates. On HiDPI displays, the backing size can differ from + // the view size as returned by |GetViewRect|. Return true (1) if the + // rectangle was provided. + // + pub fn get_backing_rect(&self, browser: interfaces::CefBrowser, + rect: &mut types::cef_rect_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_backing_rect.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(rect))) + } + } + + // + // Called when an element should be presented (e.g. double buffers should page + // flip). This is called only during accelerated compositing. + // + pub fn on_present(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_present.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } +} + +impl CefWrap<*mut cef_render_handler_t> for CefRenderHandler { + fn to_c(rust_object: CefRenderHandler) -> *mut cef_render_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_render_handler_t) -> CefRenderHandler { + CefRenderHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_render_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_render_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_render_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRenderHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_render_process_handler.rs b/ports/cef/interfaces/cef_render_process_handler.rs new file mode 100644 index 00000000000..a9a8f92352a --- /dev/null +++ b/ports/cef/interfaces/cef_render_process_handler.rs @@ -0,0 +1,492 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to implement render process callbacks. The functions of this +// structure will be called on the render process main thread (TID_RENDERER) +// unless otherwise indicated. +// +#[repr(C)] +pub struct _cef_render_process_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called after the render process main thread has been created. |extra_info| + // is a read-only value originating from + // cef_browser_process_handler_t::on_render_process_thread_created(). Do not + // keep a reference to |extra_info| outside of this function. + // + pub on_render_thread_created: Option ()>, + + // + // Called after WebKit has been initialized. + // + pub on_web_kit_initialized: Option ()>, + + // + // Called after a browser has been created. When browsing cross-origin a new + // browser will be created before the old browser with the same identifier is + // destroyed. + // + pub on_browser_created: Option ()>, + + // + // Called before a browser is destroyed. + // + pub on_browser_destroyed: Option ()>, + + // + // Return the handler for browser load status events. + // + pub get_load_handler: Option *mut interfaces::cef_load_handler_t>, + + // + // Called before browser navigation. Return true (1) to cancel the navigation + // or false (0) to allow the navigation to proceed. The |request| object + // cannot be modified in this callback. + // + pub on_before_navigation: Option libc::c_int>, + + // + // Called immediately after the V8 context for a frame has been created. To + // retrieve the JavaScript 'window' object use the + // cef_v8context_t::get_global() function. V8 handles can only be accessed + // from the thread on which they are created. A task runner for posting tasks + // on the associated thread can be retrieved via the + // cef_v8context_t::get_task_runner() function. + // + pub on_context_created: Option ()>, + + // + // Called immediately before the V8 context for a frame is released. No + // references to the context should be kept after this function is called. + // + pub on_context_released: Option ()>, + + // + // Called for global uncaught exceptions in a frame. Execution of this + // callback is disabled by default. To enable set + // CefSettings.uncaught_exception_stack_size > 0. + // + pub on_uncaught_exception: Option ()>, + + // + // Called when a new node in the the browser gets focus. The |node| value may + // be NULL if no specific node has gained focus. The node object passed to + // this function represents a snapshot of the DOM at the time this function is + // executed. DOM objects are only valid for the scope of this function. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this function. + // + pub on_focused_node_changed: Option ()>, + + // + // Called when a new message is received from a different process. Return true + // (1) if the message was handled or false (0) otherwise. Do not keep a + // reference to or attempt to access the message outside of this callback. + // + pub on_process_message_received: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_render_process_handler_t = _cef_render_process_handler_t; + + +// +// Structure used to implement render process callbacks. The functions of this +// structure will be called on the render process main thread (TID_RENDERER) +// unless otherwise indicated. +// +pub struct CefRenderProcessHandler { + c_object: *mut cef_render_process_handler_t, +} + +impl Clone for CefRenderProcessHandler { + fn clone(&self) -> CefRenderProcessHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRenderProcessHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRenderProcessHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRenderProcessHandler { + pub unsafe fn from_c_object(c_object: *mut cef_render_process_handler_t) -> CefRenderProcessHandler { + CefRenderProcessHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_render_process_handler_t) -> CefRenderProcessHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRenderProcessHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_render_process_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_render_process_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called after the render process main thread has been created. |extra_info| + // is a read-only value originating from + // cef_browser_process_handler_t::on_render_process_thread_created(). Do not + // keep a reference to |extra_info| outside of this function. + // + pub fn on_render_thread_created(&self, + extra_info: interfaces::CefListValue) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_render_thread_created.unwrap())( + self.c_object, + CefWrap::to_c(extra_info))) + } + } + + // + // Called after WebKit has been initialized. + // + pub fn on_web_kit_initialized(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_web_kit_initialized.unwrap())( + self.c_object)) + } + } + + // + // Called after a browser has been created. When browsing cross-origin a new + // browser will be created before the old browser with the same identifier is + // destroyed. + // + pub fn on_browser_created(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_browser_created.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Called before a browser is destroyed. + // + pub fn on_browser_destroyed(&self, browser: interfaces::CefBrowser) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_browser_destroyed.unwrap())( + self.c_object, + CefWrap::to_c(browser))) + } + } + + // + // Return the handler for browser load status events. + // + pub fn get_load_handler(&self) -> interfaces::CefLoadHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_load_handler.unwrap())( + self.c_object)) + } + } + + // + // Called before browser navigation. Return true (1) to cancel the navigation + // or false (0) to allow the navigation to proceed. The |request| object + // cannot be modified in this callback. + // + pub fn on_before_navigation(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, request: interfaces::CefRequest, + navigation_type: types::cef_navigation_type_t, + is_redirect: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_navigation.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(request), + CefWrap::to_c(navigation_type), + CefWrap::to_c(is_redirect))) + } + } + + // + // Called immediately after the V8 context for a frame has been created. To + // retrieve the JavaScript 'window' object use the + // cef_v8context_t::get_global() function. V8 handles can only be accessed + // from the thread on which they are created. A task runner for posting tasks + // on the associated thread can be retrieved via the + // cef_v8context_t::get_task_runner() function. + // + pub fn on_context_created(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, context: interfaces::CefV8Context) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_context_created.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(context))) + } + } + + // + // Called immediately before the V8 context for a frame is released. No + // references to the context should be kept after this function is called. + // + pub fn on_context_released(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, context: interfaces::CefV8Context) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_context_released.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(context))) + } + } + + // + // Called for global uncaught exceptions in a frame. Execution of this + // callback is disabled by default. To enable set + // CefSettings.uncaught_exception_stack_size > 0. + // + pub fn on_uncaught_exception(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, context: interfaces::CefV8Context, + exception: interfaces::CefV8Exception, + stackTrace: interfaces::CefV8StackTrace) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_uncaught_exception.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(context), + CefWrap::to_c(exception), + CefWrap::to_c(stackTrace))) + } + } + + // + // Called when a new node in the the browser gets focus. The |node| value may + // be NULL if no specific node has gained focus. The node object passed to + // this function represents a snapshot of the DOM at the time this function is + // executed. DOM objects are only valid for the scope of this function. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this function. + // + pub fn on_focused_node_changed(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, node: interfaces::CefDOMNode) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_focused_node_changed.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(node))) + } + } + + // + // Called when a new message is received from a different process. Return true + // (1) if the message was handled or false (0) otherwise. Do not keep a + // reference to or attempt to access the message outside of this callback. + // + pub fn on_process_message_received(&self, browser: interfaces::CefBrowser, + source_process: interfaces::CefProcessId, + message: interfaces::CefProcessMessage) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_process_message_received.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(source_process), + CefWrap::to_c(message))) + } + } +} + +impl CefWrap<*mut cef_render_process_handler_t> for CefRenderProcessHandler { + fn to_c(rust_object: CefRenderProcessHandler) -> *mut cef_render_process_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_render_process_handler_t) -> CefRenderProcessHandler { + CefRenderProcessHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_render_process_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_render_process_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_render_process_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRenderProcessHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_request.rs b/ports/cef/interfaces/cef_request.rs new file mode 100644 index 00000000000..8f490ac26bf --- /dev/null +++ b/ports/cef/interfaces/cef_request.rs @@ -0,0 +1,1088 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent a web request. The functions of this structure +// may be called on any thread. +// +#[repr(C)] +pub struct _cef_request_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is read-only. + // + pub is_read_only: Option libc::c_int>, + + // + // Get the fully qualified URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_url: Option types::cef_string_userfree_t>, + + // + // Set the fully qualified URL. + // + pub set_url: Option ()>, + + // + // Get the request function type. The value will default to POST if post data + // is provided and GET otherwise. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_method: Option types::cef_string_userfree_t>, + + // + // Set the request function type. + // + pub set_method: Option ()>, + + // + // Get the post data. + // + pub get_post_data: Option *mut interfaces::cef_post_data_t>, + + // + // Set the post data. + // + pub set_post_data: Option ()>, + + // + // Get the header values. + // + pub get_header_map: Option ()>, + + // + // Set the header values. + // + pub set_header_map: Option ()>, + + // + // Set all values at one time. + // + pub set: Option ()>, + + // + // Get the flags used in combination with cef_urlrequest_t. See + // cef_urlrequest_flags_t for supported values. + // + pub get_flags: Option libc::c_int>, + + // + // Set the flags used in combination with cef_urlrequest_t. See + // cef_urlrequest_flags_t for supported values. + // + pub set_flags: Option ()>, + + // + // Set the URL to the first party for cookies used in combination with + // cef_urlrequest_t. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_first_party_for_cookies: Option types::cef_string_userfree_t>, + + // + // Get the URL to the first party for cookies used in combination with + // cef_urlrequest_t. + // + pub set_first_party_for_cookies: Option ()>, + + // + // Get the resource type for this request. Only available in the browser + // process. + // + pub get_resource_type: Option types::cef_resource_type_t>, + + // + // Get the transition type for this request. Only available in the browser + // process and only applies to requests that represent a main frame or sub- + // frame navigation. + // + pub get_transition_type: Option types::cef_transition_type_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_request_t = _cef_request_t; + + +// +// Structure used to represent a web request. The functions of this structure +// may be called on any thread. +// +pub struct CefRequest { + c_object: *mut cef_request_t, +} + +impl Clone for CefRequest { + fn clone(&self) -> CefRequest{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRequest { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRequest { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRequest { + pub unsafe fn from_c_object(c_object: *mut cef_request_t) -> CefRequest { + CefRequest { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_request_t) -> CefRequest { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRequest { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_request_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_request_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is read-only. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Get the fully qualified URL. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_url.unwrap())( + self.c_object)) + } + } + + // + // Set the fully qualified URL. + // + pub fn set_url(&self, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_url.unwrap())( + self.c_object, + CefWrap::to_c(url))) + } + } + + // + // Get the request function type. The value will default to POST if post data + // is provided and GET otherwise. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_method(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_method.unwrap())( + self.c_object)) + } + } + + // + // Set the request function type. + // + pub fn set_method(&self, method: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_method.unwrap())( + self.c_object, + CefWrap::to_c(method))) + } + } + + // + // Get the post data. + // + pub fn get_post_data(&self) -> interfaces::CefPostData { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_post_data.unwrap())( + self.c_object)) + } + } + + // + // Set the post data. + // + pub fn set_post_data(&self, postData: interfaces::CefPostData) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_post_data.unwrap())( + self.c_object, + CefWrap::to_c(postData))) + } + } + + // + // Get the header values. + // + pub fn get_header_map(&self, headerMap: HashMap>) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_header_map.unwrap())( + self.c_object, + CefWrap::to_c(headerMap))) + } + } + + // + // Set the header values. + // + pub fn set_header_map(&self, headerMap: HashMap>) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_header_map.unwrap())( + self.c_object, + CefWrap::to_c(headerMap))) + } + } + + // + // Set all values at one time. + // + pub fn set(&self, url: &str, method: &str, postData: interfaces::CefPostData, + headerMap: HashMap>) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set.unwrap())( + self.c_object, + CefWrap::to_c(url), + CefWrap::to_c(method), + CefWrap::to_c(postData), + CefWrap::to_c(headerMap))) + } + } + + // + // Get the flags used in combination with cef_urlrequest_t. See + // cef_urlrequest_flags_t for supported values. + // + pub fn get_flags(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_flags.unwrap())( + self.c_object)) + } + } + + // + // Set the flags used in combination with cef_urlrequest_t. See + // cef_urlrequest_flags_t for supported values. + // + pub fn set_flags(&self, flags: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_flags.unwrap())( + self.c_object, + CefWrap::to_c(flags))) + } + } + + // + // Set the URL to the first party for cookies used in combination with + // cef_urlrequest_t. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_first_party_for_cookies(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_first_party_for_cookies.unwrap())( + self.c_object)) + } + } + + // + // Get the URL to the first party for cookies used in combination with + // cef_urlrequest_t. + // + pub fn set_first_party_for_cookies(&self, url: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_first_party_for_cookies.unwrap())( + self.c_object, + CefWrap::to_c(url))) + } + } + + // + // Get the resource type for this request. Only available in the browser + // process. + // + pub fn get_resource_type(&self) -> types::cef_resource_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_resource_type.unwrap())( + self.c_object)) + } + } + + // + // Get the transition type for this request. Only available in the browser + // process and only applies to requests that represent a main frame or sub- + // frame navigation. + // + pub fn get_transition_type(&self) -> types::cef_transition_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_transition_type.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_request_t object. + // + pub fn create() -> interfaces::CefRequest { + unsafe { + CefWrap::to_rust( + ::request::cef_request_create( +)) + } + } +} + +impl CefWrap<*mut cef_request_t> for CefRequest { + fn to_c(rust_object: CefRequest) -> *mut cef_request_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_request_t) -> CefRequest { + CefRequest::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_request_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_request_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_request_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRequest::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to represent post data for a web request. The functions of +// this structure may be called on any thread. +// +#[repr(C)] +pub struct _cef_post_data_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is read-only. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns the number of existing post data elements. + // + pub get_element_count: Option libc::size_t>, + + // + // Retrieve the post data elements. + // + pub get_elements: Option ()>, + + // + // Remove the specified post data element. Returns true (1) if the removal + // succeeds. + // + pub remove_element: Option libc::c_int>, + + // + // Add the specified post data element. Returns true (1) if the add succeeds. + // + pub add_element: Option libc::c_int>, + + // + // Remove all existing post data elements. + // + pub remove_elements: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_post_data_t = _cef_post_data_t; + + +// +// Structure used to represent post data for a web request. The functions of +// this structure may be called on any thread. +// +pub struct CefPostData { + c_object: *mut cef_post_data_t, +} + +impl Clone for CefPostData { + fn clone(&self) -> CefPostData{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPostData { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPostData { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPostData { + pub unsafe fn from_c_object(c_object: *mut cef_post_data_t) -> CefPostData { + CefPostData { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_post_data_t) -> CefPostData { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPostData { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_post_data_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_post_data_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is read-only. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns the number of existing post data elements. + // + pub fn get_element_count(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_element_count.unwrap())( + self.c_object)) + } + } + + // + // Retrieve the post data elements. + // + pub fn get_elements(&self, elements_count: *mut libc::size_t, + elements: *mut interfaces::CefPostDataElement) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_elements.unwrap())( + self.c_object, + CefWrap::to_c(elements_count), + CefWrap::to_c(elements))) + } + } + + // + // Remove the specified post data element. Returns true (1) if the removal + // succeeds. + // + pub fn remove_element(&self, + element: interfaces::CefPostDataElement) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove_element.unwrap())( + self.c_object, + CefWrap::to_c(element))) + } + } + + // + // Add the specified post data element. Returns true (1) if the add succeeds. + // + pub fn add_element(&self, + element: interfaces::CefPostDataElement) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_element.unwrap())( + self.c_object, + CefWrap::to_c(element))) + } + } + + // + // Remove all existing post data elements. + // + pub fn remove_elements(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove_elements.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_post_data_t object. + // + pub fn create() -> interfaces::CefPostData { + unsafe { + CefWrap::to_rust( + ::request::cef_post_data_create( +)) + } + } +} + +impl CefWrap<*mut cef_post_data_t> for CefPostData { + fn to_c(rust_object: CefPostData) -> *mut cef_post_data_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_post_data_t) -> CefPostData { + CefPostData::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_post_data_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_post_data_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_post_data_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPostData::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to represent a single element in the request post data. The +// functions of this structure may be called on any thread. +// +#[repr(C)] +pub struct _cef_post_data_element_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is read-only. + // + pub is_read_only: Option libc::c_int>, + + // + // Remove all contents from the post data element. + // + pub set_to_empty: Option ()>, + + // + // The post data element will represent a file. + // + pub set_to_file: Option ()>, + + // + // The post data element will represent bytes. The bytes passed in will be + // copied. + // + pub set_to_bytes: Option ()>, + + // + // Return the type of this post data element. + // + pub get_type: Option types::cef_postdataelement_type_t>, + + // + // Return the file name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_file: Option types::cef_string_userfree_t>, + + // + // Return the number of bytes. + // + pub get_bytes_count: Option libc::size_t>, + + // + // Read up to |size| bytes into |bytes| and return the number of bytes + // actually read. + // + pub get_bytes: Option libc::size_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_post_data_element_t = _cef_post_data_element_t; + + +// +// Structure used to represent a single element in the request post data. The +// functions of this structure may be called on any thread. +// +pub struct CefPostDataElement { + c_object: *mut cef_post_data_element_t, +} + +impl Clone for CefPostDataElement { + fn clone(&self) -> CefPostDataElement{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefPostDataElement { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefPostDataElement { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefPostDataElement { + pub unsafe fn from_c_object(c_object: *mut cef_post_data_element_t) -> CefPostDataElement { + CefPostDataElement { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_post_data_element_t) -> CefPostDataElement { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefPostDataElement { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_post_data_element_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_post_data_element_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is read-only. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Remove all contents from the post data element. + // + pub fn set_to_empty(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_to_empty.unwrap())( + self.c_object)) + } + } + + // + // The post data element will represent a file. + // + pub fn set_to_file(&self, fileName: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_to_file.unwrap())( + self.c_object, + CefWrap::to_c(fileName))) + } + } + + // + // The post data element will represent bytes. The bytes passed in will be + // copied. + // + pub fn set_to_bytes(&self, size: libc::size_t, bytes: &()) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_to_bytes.unwrap())( + self.c_object, + CefWrap::to_c(size), + CefWrap::to_c(bytes))) + } + } + + // + // Return the type of this post data element. + // + pub fn get_type(&self) -> types::cef_postdataelement_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object)) + } + } + + // + // Return the file name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_file(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file.unwrap())( + self.c_object)) + } + } + + // + // Return the number of bytes. + // + pub fn get_bytes_count(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_bytes_count.unwrap())( + self.c_object)) + } + } + + // + // Read up to |size| bytes into |bytes| and return the number of bytes + // actually read. + // + pub fn get_bytes(&self, size: libc::size_t, bytes: &mut ()) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_bytes.unwrap())( + self.c_object, + CefWrap::to_c(size), + CefWrap::to_c(bytes))) + } + } + + // + // Create a new cef_post_data_element_t object. + // + pub fn create() -> interfaces::CefPostDataElement { + unsafe { + CefWrap::to_rust( + ::request::cef_post_data_element_create( +)) + } + } +} + +impl CefWrap<*mut cef_post_data_element_t> for CefPostDataElement { + fn to_c(rust_object: CefPostDataElement) -> *mut cef_post_data_element_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_post_data_element_t) -> CefPostDataElement { + CefPostDataElement::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_post_data_element_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_post_data_element_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_post_data_element_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefPostDataElement::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_request_context.rs b/ports/cef/interfaces/cef_request_context.rs new file mode 100644 index 00000000000..84a10d44c3f --- /dev/null +++ b/ports/cef/interfaces/cef_request_context.rs @@ -0,0 +1,272 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// A request context provides request handling for a set of related browser +// objects. A request context is specified when creating a new browser object +// via the cef_browser_host_t static factory functions. Browser objects with +// different request contexts will never be hosted in the same render process. +// Browser objects with the same request context may or may not be hosted in the +// same render process depending on the process model. Browser objects created +// indirectly via the JavaScript window.open function or targeted links will +// share the same render process and the same request context as the source +// browser. When running in single-process mode there is only a single render +// process (the main process) and so all browsers created in single-process mode +// will share the same request context. This will be the first request context +// passed into a cef_browser_host_t static factory function and all other +// request context objects will be ignored. +// +#[repr(C)] +pub struct _cef_request_context_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is pointing to the same context as |that| + // object. + // + pub is_same: Option libc::c_int>, + + // + // Returns true (1) if this object is the global context. + // + pub is_global: Option libc::c_int>, + + // + // Returns the handler for this context if any. + // + pub get_handler: Option *mut interfaces::cef_request_context_handler_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_request_context_t = _cef_request_context_t; + + +// +// A request context provides request handling for a set of related browser +// objects. A request context is specified when creating a new browser object +// via the cef_browser_host_t static factory functions. Browser objects with +// different request contexts will never be hosted in the same render process. +// Browser objects with the same request context may or may not be hosted in the +// same render process depending on the process model. Browser objects created +// indirectly via the JavaScript window.open function or targeted links will +// share the same render process and the same request context as the source +// browser. When running in single-process mode there is only a single render +// process (the main process) and so all browsers created in single-process mode +// will share the same request context. This will be the first request context +// passed into a cef_browser_host_t static factory function and all other +// request context objects will be ignored. +// +pub struct CefRequestContext { + c_object: *mut cef_request_context_t, +} + +impl Clone for CefRequestContext { + fn clone(&self) -> CefRequestContext{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRequestContext { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRequestContext { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRequestContext { + pub unsafe fn from_c_object(c_object: *mut cef_request_context_t) -> CefRequestContext { + CefRequestContext { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_request_context_t) -> CefRequestContext { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRequestContext { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_request_context_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_request_context_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is pointing to the same context as |that| + // object. + // + pub fn is_same(&self, other: interfaces::CefRequestContext) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(other))) + } + } + + // + // Returns true (1) if this object is the global context. + // + pub fn is_global(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_global.unwrap())( + self.c_object)) + } + } + + // + // Returns the handler for this context if any. + // + pub fn get_handler(&self) -> interfaces::CefRequestContextHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_handler.unwrap())( + self.c_object)) + } + } + + // + // Returns the global context object. + // + pub fn get_global_context() -> interfaces::CefRequestContext { + unsafe { + CefWrap::to_rust( + ::request_context::cef_request_context_get_global_context( +)) + } + } + + // + // Creates a new context object with the specified handler. + // + pub fn create_context( + handler: interfaces::CefRequestContextHandler) -> interfaces::CefRequestContext { + unsafe { + CefWrap::to_rust( + ::request_context::cef_request_context_create_context( + CefWrap::to_c(handler))) + } + } +} + +impl CefWrap<*mut cef_request_context_t> for CefRequestContext { + fn to_c(rust_object: CefRequestContext) -> *mut cef_request_context_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_request_context_t) -> CefRequestContext { + CefRequestContext::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_request_context_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_request_context_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_request_context_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRequestContext::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_request_context_handler.rs b/ports/cef/interfaces/cef_request_context_handler.rs new file mode 100644 index 00000000000..7a0425302c7 --- /dev/null +++ b/ports/cef/interfaces/cef_request_context_handler.rs @@ -0,0 +1,184 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to provide handler implementations. +// +#[repr(C)] +pub struct _cef_request_context_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called on the IO thread to retrieve the cookie manager. The global cookie + // manager will be used if this function returns NULL. + // + pub get_cookie_manager: Option *mut interfaces::cef_cookie_manager_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_request_context_handler_t = _cef_request_context_handler_t; + + +// +// Implement this structure to provide handler implementations. +// +pub struct CefRequestContextHandler { + c_object: *mut cef_request_context_handler_t, +} + +impl Clone for CefRequestContextHandler { + fn clone(&self) -> CefRequestContextHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRequestContextHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRequestContextHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRequestContextHandler { + pub unsafe fn from_c_object(c_object: *mut cef_request_context_handler_t) -> CefRequestContextHandler { + CefRequestContextHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_request_context_handler_t) -> CefRequestContextHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRequestContextHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_request_context_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_request_context_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called on the IO thread to retrieve the cookie manager. The global cookie + // manager will be used if this function returns NULL. + // + pub fn get_cookie_manager(&self) -> interfaces::CefCookieManager { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_cookie_manager.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_request_context_handler_t> for CefRequestContextHandler { + fn to_c(rust_object: CefRequestContextHandler) -> *mut cef_request_context_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_request_context_handler_t) -> CefRequestContextHandler { + CefRequestContextHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_request_context_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_request_context_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_request_context_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRequestContextHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_request_handler.rs b/ports/cef/interfaces/cef_request_handler.rs new file mode 100644 index 00000000000..68c60a6eb60 --- /dev/null +++ b/ports/cef/interfaces/cef_request_handler.rs @@ -0,0 +1,841 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Callback structure used for asynchronous continuation of quota requests. +// +#[repr(C)] +pub struct _cef_quota_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue the quota request. If |allow| is true (1) the request will be + // allowed. Otherwise, the request will be denied. + // + pub cont: Option ()>, + + // + // Cancel the quota request. + // + pub cancel: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_quota_callback_t = _cef_quota_callback_t; + + +// +// Callback structure used for asynchronous continuation of quota requests. +// +pub struct CefQuotaCallback { + c_object: *mut cef_quota_callback_t, +} + +impl Clone for CefQuotaCallback { + fn clone(&self) -> CefQuotaCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefQuotaCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefQuotaCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefQuotaCallback { + pub unsafe fn from_c_object(c_object: *mut cef_quota_callback_t) -> CefQuotaCallback { + CefQuotaCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_quota_callback_t) -> CefQuotaCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefQuotaCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_quota_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_quota_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue the quota request. If |allow| is true (1) the request will be + // allowed. Otherwise, the request will be denied. + // + pub fn cont(&self, allow: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(allow))) + } + } + + // + // Cancel the quota request. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_quota_callback_t> for CefQuotaCallback { + fn to_c(rust_object: CefQuotaCallback) -> *mut cef_quota_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_quota_callback_t) -> CefQuotaCallback { + CefQuotaCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_quota_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_quota_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_quota_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefQuotaCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Callback structure used for asynchronous continuation of url requests when +// invalid SSL certificates are encountered. +// +#[repr(C)] +pub struct _cef_allow_certificate_error_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Continue the url request. If |allow| is true (1) the request will be + // continued. Otherwise, the request will be canceled. + // + pub cont: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_allow_certificate_error_callback_t = _cef_allow_certificate_error_callback_t; + + +// +// Callback structure used for asynchronous continuation of url requests when +// invalid SSL certificates are encountered. +// +pub struct CefAllowCertificateErrorCallback { + c_object: *mut cef_allow_certificate_error_callback_t, +} + +impl Clone for CefAllowCertificateErrorCallback { + fn clone(&self) -> CefAllowCertificateErrorCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefAllowCertificateErrorCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefAllowCertificateErrorCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefAllowCertificateErrorCallback { + pub unsafe fn from_c_object(c_object: *mut cef_allow_certificate_error_callback_t) -> CefAllowCertificateErrorCallback { + CefAllowCertificateErrorCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_allow_certificate_error_callback_t) -> CefAllowCertificateErrorCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefAllowCertificateErrorCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_allow_certificate_error_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_allow_certificate_error_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Continue the url request. If |allow| is true (1) the request will be + // continued. Otherwise, the request will be canceled. + // + pub fn cont(&self, allow: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cont.unwrap())( + self.c_object, + CefWrap::to_c(allow))) + } + } +} + +impl CefWrap<*mut cef_allow_certificate_error_callback_t> for CefAllowCertificateErrorCallback { + fn to_c(rust_object: CefAllowCertificateErrorCallback) -> *mut cef_allow_certificate_error_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_allow_certificate_error_callback_t) -> CefAllowCertificateErrorCallback { + CefAllowCertificateErrorCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_allow_certificate_error_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_allow_certificate_error_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_allow_certificate_error_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefAllowCertificateErrorCallback::from_c_object_addref(c_object)) + } + } +} + + +// +// Implement this structure to handle events related to browser requests. The +// functions of this structure will be called on the thread indicated. +// +#[repr(C)] +pub struct _cef_request_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called on the UI thread before browser navigation. Return true (1) to + // cancel the navigation or false (0) to allow the navigation to proceed. The + // |request| object cannot be modified in this callback. + // cef_load_handler_t::OnLoadingStateChange will be called twice in all cases. + // If the navigation is allowed cef_load_handler_t::OnLoadStart and + // cef_load_handler_t::OnLoadEnd will be called. If the navigation is canceled + // cef_load_handler_t::OnLoadError will be called with an |errorCode| value of + // ERR_ABORTED. + // + pub on_before_browse: Option libc::c_int>, + + // + // Called on the IO thread before a resource request is loaded. The |request| + // object may be modified. To cancel the request return true (1) otherwise + // return false (0). + // + pub on_before_resource_load: Option libc::c_int>, + + // + // Called on the IO thread before a resource is loaded. To allow the resource + // to load normally return NULL. To specify a handler for the resource return + // a cef_resource_handler_t object. The |request| object should not be + // modified in this callback. + // + pub get_resource_handler: Option *mut interfaces::cef_resource_handler_t>, + + // + // Called on the IO thread when a resource load is redirected. The |old_url| + // parameter will contain the old URL. The |new_url| parameter will contain + // the new URL and can be changed if desired. + // + pub on_resource_redirect: Option ()>, + + // + // Called on the IO thread when the browser needs credentials from the user. + // |isProxy| indicates whether the host is a proxy server. |host| contains the + // hostname and |port| contains the port number. Return true (1) to continue + // the request and call cef_auth_callback_t::cont() when the authentication + // information is available. Return false (0) to cancel the request. + // + pub get_auth_credentials: Option libc::c_int>, + + // + // Called on the IO thread when JavaScript requests a specific storage quota + // size via the webkitStorageInfo.requestQuota function. |origin_url| is the + // origin of the page making the request. |new_size| is the requested quota + // size in bytes. Return true (1) and call cef_quota_callback_t::cont() either + // in this function or at a later time to grant or deny the request. Return + // false (0) to cancel the request. + // + pub on_quota_request: Option libc::c_int>, + + // + // Called on the UI thread to handle requests for URLs with an unknown + // protocol component. Set |allow_os_execution| to true (1) to attempt + // execution via the registered OS protocol handler, if any. SECURITY WARNING: + // YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED ON SCHEME, HOST OR + // OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION. + // + pub on_protocol_execution: Option ()>, + + // + // Called on the UI thread to handle requests for URLs with an invalid SSL + // certificate. Return true (1) and call + // cef_allow_certificate_error_callback_t:: cont() either in this function or + // at a later time to continue or cancel the request. Return false (0) to + // cancel the request immediately. If |callback| is NULL the error cannot be + // recovered from and the request will be canceled automatically. If + // CefSettings.ignore_certificate_errors is set all invalid certificates will + // be accepted without calling this function. + // + pub on_certificate_error: Option libc::c_int>, + + // + // Called on the browser process IO thread before a plugin is loaded. Return + // true (1) to block loading of the plugin. + // + pub on_before_plugin_load: Option libc::c_int>, + + // + // Called on the browser process UI thread when a plugin has crashed. + // |plugin_path| is the path of the plugin that crashed. + // + pub on_plugin_crashed: Option ()>, + + // + // Called on the browser process UI thread when the render process terminates + // unexpectedly. |status| indicates how the process terminated. + // + pub on_render_process_terminated: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_request_handler_t = _cef_request_handler_t; + + +// +// Implement this structure to handle events related to browser requests. The +// functions of this structure will be called on the thread indicated. +// +pub struct CefRequestHandler { + c_object: *mut cef_request_handler_t, +} + +impl Clone for CefRequestHandler { + fn clone(&self) -> CefRequestHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefRequestHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefRequestHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefRequestHandler { + pub unsafe fn from_c_object(c_object: *mut cef_request_handler_t) -> CefRequestHandler { + CefRequestHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_request_handler_t) -> CefRequestHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefRequestHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_request_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_request_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called on the UI thread before browser navigation. Return true (1) to + // cancel the navigation or false (0) to allow the navigation to proceed. The + // |request| object cannot be modified in this callback. + // cef_load_handler_t::OnLoadingStateChange will be called twice in all cases. + // If the navigation is allowed cef_load_handler_t::OnLoadStart and + // cef_load_handler_t::OnLoadEnd will be called. If the navigation is canceled + // cef_load_handler_t::OnLoadError will be called with an |errorCode| value of + // ERR_ABORTED. + // + pub fn on_before_browse(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, request: interfaces::CefRequest, + is_redirect: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_browse.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(request), + CefWrap::to_c(is_redirect))) + } + } + + // + // Called on the IO thread before a resource request is loaded. The |request| + // object may be modified. To cancel the request return true (1) otherwise + // return false (0). + // + pub fn on_before_resource_load(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, + request: interfaces::CefRequest) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_resource_load.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(request))) + } + } + + // + // Called on the IO thread before a resource is loaded. To allow the resource + // to load normally return NULL. To specify a handler for the resource return + // a cef_resource_handler_t object. The |request| object should not be + // modified in this callback. + // + pub fn get_resource_handler(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, + request: interfaces::CefRequest) -> interfaces::CefResourceHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_resource_handler.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(request))) + } + } + + // + // Called on the IO thread when a resource load is redirected. The |old_url| + // parameter will contain the old URL. The |new_url| parameter will contain + // the new URL and can be changed if desired. + // + pub fn on_resource_redirect(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, old_url: &str, + new_url: *mut types::cef_string_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_resource_redirect.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(old_url), + CefWrap::to_c(new_url))) + } + } + + // + // Called on the IO thread when the browser needs credentials from the user. + // |isProxy| indicates whether the host is a proxy server. |host| contains the + // hostname and |port| contains the port number. Return true (1) to continue + // the request and call cef_auth_callback_t::cont() when the authentication + // information is available. Return false (0) to cancel the request. + // + pub fn get_auth_credentials(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, isProxy: libc::c_int, host: &str, + port: libc::c_int, realm: &str, scheme: &str, + callback: interfaces::CefAuthCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_auth_credentials.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(isProxy), + CefWrap::to_c(host), + CefWrap::to_c(port), + CefWrap::to_c(realm), + CefWrap::to_c(scheme), + CefWrap::to_c(callback))) + } + } + + // + // Called on the IO thread when JavaScript requests a specific storage quota + // size via the webkitStorageInfo.requestQuota function. |origin_url| is the + // origin of the page making the request. |new_size| is the requested quota + // size in bytes. Return true (1) and call cef_quota_callback_t::cont() either + // in this function or at a later time to grant or deny the request. Return + // false (0) to cancel the request. + // + pub fn on_quota_request(&self, browser: interfaces::CefBrowser, + origin_url: &str, new_size: i64, + callback: interfaces::CefQuotaCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_quota_request.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(origin_url), + CefWrap::to_c(new_size), + CefWrap::to_c(callback))) + } + } + + // + // Called on the UI thread to handle requests for URLs with an unknown + // protocol component. Set |allow_os_execution| to true (1) to attempt + // execution via the registered OS protocol handler, if any. SECURITY WARNING: + // YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED ON SCHEME, HOST OR + // OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION. + // + pub fn on_protocol_execution(&self, browser: interfaces::CefBrowser, + url: &str, allow_os_execution: &mut libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_protocol_execution.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(url), + CefWrap::to_c(allow_os_execution))) + } + } + + // + // Called on the UI thread to handle requests for URLs with an invalid SSL + // certificate. Return true (1) and call + // cef_allow_certificate_error_callback_t:: cont() either in this function or + // at a later time to continue or cancel the request. Return false (0) to + // cancel the request immediately. If |callback| is NULL the error cannot be + // recovered from and the request will be canceled automatically. If + // CefSettings.ignore_certificate_errors is set all invalid certificates will + // be accepted without calling this function. + // + pub fn on_certificate_error(&self, cert_error: types::cef_errorcode_t, + request_url: &str, + callback: interfaces::CefAllowCertificateErrorCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_certificate_error.unwrap())( + self.c_object, + CefWrap::to_c(cert_error), + CefWrap::to_c(request_url), + CefWrap::to_c(callback))) + } + } + + // + // Called on the browser process IO thread before a plugin is loaded. Return + // true (1) to block loading of the plugin. + // + pub fn on_before_plugin_load(&self, browser: interfaces::CefBrowser, + url: &str, policy_url: &str, + info: interfaces::CefWebPluginInfo) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_before_plugin_load.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(url), + CefWrap::to_c(policy_url), + CefWrap::to_c(info))) + } + } + + // + // Called on the browser process UI thread when a plugin has crashed. + // |plugin_path| is the path of the plugin that crashed. + // + pub fn on_plugin_crashed(&self, browser: interfaces::CefBrowser, + plugin_path: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_plugin_crashed.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(plugin_path))) + } + } + + // + // Called on the browser process UI thread when the render process terminates + // unexpectedly. |status| indicates how the process terminated. + // + pub fn on_render_process_terminated(&self, browser: interfaces::CefBrowser, + status: types::cef_termination_status_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_render_process_terminated.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(status))) + } + } +} + +impl CefWrap<*mut cef_request_handler_t> for CefRequestHandler { + fn to_c(rust_object: CefRequestHandler) -> *mut cef_request_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_request_handler_t) -> CefRequestHandler { + CefRequestHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_request_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_request_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_request_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefRequestHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_resource_bundle_handler.rs b/ports/cef/interfaces/cef_resource_bundle_handler.rs new file mode 100644 index 00000000000..3551a0d06e1 --- /dev/null +++ b/ports/cef/interfaces/cef_resource_bundle_handler.rs @@ -0,0 +1,231 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to implement a custom resource bundle structure. The functions +// of this structure may be called on multiple threads. +// +#[repr(C)] +pub struct _cef_resource_bundle_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called to retrieve a localized translation for the string specified by + // |message_id|. To provide the translation set |string| to the translation + // string and return true (1). To use the default translation return false + // (0). Supported message IDs are listed in cef_pack_strings.h. + // + pub get_localized_string: Option libc::c_int>, + + // + // Called to retrieve data for the resource specified by |resource_id|. To + // provide the resource data set |data| and |data_size| to the data pointer + // and size respectively and return true (1). To use the default resource data + // return false (0). The resource data will not be copied and must remain + // resident in memory. Supported resource IDs are listed in + // cef_pack_resources.h. + // + pub get_data_resource: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_resource_bundle_handler_t = _cef_resource_bundle_handler_t; + + +// +// Structure used to implement a custom resource bundle structure. The functions +// of this structure may be called on multiple threads. +// +pub struct CefResourceBundleHandler { + c_object: *mut cef_resource_bundle_handler_t, +} + +impl Clone for CefResourceBundleHandler { + fn clone(&self) -> CefResourceBundleHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefResourceBundleHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefResourceBundleHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefResourceBundleHandler { + pub unsafe fn from_c_object(c_object: *mut cef_resource_bundle_handler_t) -> CefResourceBundleHandler { + CefResourceBundleHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_resource_bundle_handler_t) -> CefResourceBundleHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefResourceBundleHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_resource_bundle_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_resource_bundle_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called to retrieve a localized translation for the string specified by + // |message_id|. To provide the translation set |string| to the translation + // string and return true (1). To use the default translation return false + // (0). Supported message IDs are listed in cef_pack_strings.h. + // + pub fn get_localized_string(&self, message_id: libc::c_int, + string: *mut types::cef_string_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_localized_string.unwrap())( + self.c_object, + CefWrap::to_c(message_id), + CefWrap::to_c(string))) + } + } + + // + // Called to retrieve data for the resource specified by |resource_id|. To + // provide the resource data set |data| and |data_size| to the data pointer + // and size respectively and return true (1). To use the default resource data + // return false (0). The resource data will not be copied and must remain + // resident in memory. Supported resource IDs are listed in + // cef_pack_resources.h. + // + pub fn get_data_resource(&self, resource_id: libc::c_int, + data: &mut *mut libc::c_void, + data_size: &mut libc::size_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_data_resource.unwrap())( + self.c_object, + CefWrap::to_c(resource_id), + CefWrap::to_c(data), + CefWrap::to_c(data_size))) + } + } +} + +impl CefWrap<*mut cef_resource_bundle_handler_t> for CefResourceBundleHandler { + fn to_c(rust_object: CefResourceBundleHandler) -> *mut cef_resource_bundle_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_resource_bundle_handler_t) -> CefResourceBundleHandler { + CefResourceBundleHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_resource_bundle_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_resource_bundle_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_resource_bundle_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefResourceBundleHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_resource_handler.rs b/ports/cef/interfaces/cef_resource_handler.rs new file mode 100644 index 00000000000..63cc82fb070 --- /dev/null +++ b/ports/cef/interfaces/cef_resource_handler.rs @@ -0,0 +1,340 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to implement a custom request handler structure. The functions +// of this structure will always be called on the IO thread. +// +#[repr(C)] +pub struct _cef_resource_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Begin processing the request. To handle the request return true (1) and + // call cef_callback_t::cont() once the response header information is + // available (cef_callback_t::cont() can also be called from inside this + // function if header information is available immediately). To cancel the + // request return false (0). + // + pub process_request: Option libc::c_int>, + + // + // Retrieve response header information. If the response length is not known + // set |response_length| to -1 and read_response() will be called until it + // returns false (0). If the response length is known set |response_length| to + // a positive value and read_response() will be called until it returns false + // (0) or the specified number of bytes have been read. Use the |response| + // object to set the mime type, http status code and other optional header + // values. To redirect the request to a new URL set |redirectUrl| to the new + // URL. + // + pub get_response_headers: Option ()>, + + // + // Read response data. If data is available immediately copy up to + // |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of + // bytes copied, and return true (1). To read the data at a later time set + // |bytes_read| to 0, return true (1) and call cef_callback_t::cont() when the + // data is available. To indicate response completion return false (0). + // + pub read_response: Option libc::c_int>, + + // + // Return true (1) if the specified cookie can be sent with the request or + // false (0) otherwise. If false (0) is returned for any cookie then no + // cookies will be sent with the request. + // + pub can_get_cookie: Option libc::c_int>, + + // + // Return true (1) if the specified cookie returned with the response can be + // set or false (0) otherwise. + // + pub can_set_cookie: Option libc::c_int>, + + // + // Request processing has been canceled. + // + pub cancel: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_resource_handler_t = _cef_resource_handler_t; + + +// +// Structure used to implement a custom request handler structure. The functions +// of this structure will always be called on the IO thread. +// +pub struct CefResourceHandler { + c_object: *mut cef_resource_handler_t, +} + +impl Clone for CefResourceHandler { + fn clone(&self) -> CefResourceHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefResourceHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefResourceHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefResourceHandler { + pub unsafe fn from_c_object(c_object: *mut cef_resource_handler_t) -> CefResourceHandler { + CefResourceHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_resource_handler_t) -> CefResourceHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefResourceHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_resource_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_resource_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Begin processing the request. To handle the request return true (1) and + // call cef_callback_t::cont() once the response header information is + // available (cef_callback_t::cont() can also be called from inside this + // function if header information is available immediately). To cancel the + // request return false (0). + // + pub fn process_request(&self, request: interfaces::CefRequest, + callback: interfaces::CefCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).process_request.unwrap())( + self.c_object, + CefWrap::to_c(request), + CefWrap::to_c(callback))) + } + } + + // + // Retrieve response header information. If the response length is not known + // set |response_length| to -1 and read_response() will be called until it + // returns false (0). If the response length is known set |response_length| to + // a positive value and read_response() will be called until it returns false + // (0) or the specified number of bytes have been read. Use the |response| + // object to set the mime type, http status code and other optional header + // values. To redirect the request to a new URL set |redirectUrl| to the new + // URL. + // + pub fn get_response_headers(&self, response: interfaces::CefResponse, + response_length: &mut i64, redirectUrl: *mut types::cef_string_t) -> ( + ) { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_response_headers.unwrap())( + self.c_object, + CefWrap::to_c(response), + CefWrap::to_c(response_length), + CefWrap::to_c(redirectUrl))) + } + } + + // + // Read response data. If data is available immediately copy up to + // |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of + // bytes copied, and return true (1). To read the data at a later time set + // |bytes_read| to 0, return true (1) and call cef_callback_t::cont() when the + // data is available. To indicate response completion return false (0). + // + pub fn read_response(&self, data_out: &mut (), bytes_to_read: libc::c_int, + bytes_read: &mut libc::c_int, + callback: interfaces::CefCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).read_response.unwrap())( + self.c_object, + CefWrap::to_c(data_out), + CefWrap::to_c(bytes_to_read), + CefWrap::to_c(bytes_read), + CefWrap::to_c(callback))) + } + } + + // + // Return true (1) if the specified cookie can be sent with the request or + // false (0) otherwise. If false (0) is returned for any cookie then no + // cookies will be sent with the request. + // + pub fn can_get_cookie(&self, cookie: &interfaces::CefCookie) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).can_get_cookie.unwrap())( + self.c_object, + CefWrap::to_c(cookie))) + } + } + + // + // Return true (1) if the specified cookie returned with the response can be + // set or false (0) otherwise. + // + pub fn can_set_cookie(&self, cookie: &interfaces::CefCookie) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).can_set_cookie.unwrap())( + self.c_object, + CefWrap::to_c(cookie))) + } + } + + // + // Request processing has been canceled. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_resource_handler_t> for CefResourceHandler { + fn to_c(rust_object: CefResourceHandler) -> *mut cef_resource_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_resource_handler_t) -> CefResourceHandler { + CefResourceHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_resource_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_resource_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_resource_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefResourceHandler::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_response.rs b/ports/cef/interfaces/cef_response.rs new file mode 100644 index 00000000000..d2599c4f8c0 --- /dev/null +++ b/ports/cef/interfaces/cef_response.rs @@ -0,0 +1,387 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to represent a web response. The functions of this structure +// may be called on any thread. +// +#[repr(C)] +pub struct _cef_response_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is read-only. + // + pub is_read_only: Option libc::c_int>, + + // + // Get the response status code. + // + pub get_status: Option libc::c_int>, + + // + // Set the response status code. + // + pub set_status: Option ()>, + + // + // Get the response status text. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_status_text: Option types::cef_string_userfree_t>, + + // + // Set the response status text. + // + pub set_status_text: Option ()>, + + // + // Get the response mime type. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_mime_type: Option types::cef_string_userfree_t>, + + // + // Set the response mime type. + // + pub set_mime_type: Option ()>, + + // + // Get the value for the specified response header field. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_header: Option types::cef_string_userfree_t>, + + // + // Get all response header fields. + // + pub get_header_map: Option ()>, + + // + // Set all response header fields. + // + pub set_header_map: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_response_t = _cef_response_t; + + +// +// Structure used to represent a web response. The functions of this structure +// may be called on any thread. +// +pub struct CefResponse { + c_object: *mut cef_response_t, +} + +impl Clone for CefResponse { + fn clone(&self) -> CefResponse{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefResponse { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefResponse { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefResponse { + pub unsafe fn from_c_object(c_object: *mut cef_response_t) -> CefResponse { + CefResponse { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_response_t) -> CefResponse { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefResponse { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_response_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_response_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is read-only. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Get the response status code. + // + pub fn get_status(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_status.unwrap())( + self.c_object)) + } + } + + // + // Set the response status code. + // + pub fn set_status(&self, status: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_status.unwrap())( + self.c_object, + CefWrap::to_c(status))) + } + } + + // + // Get the response status text. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_status_text(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_status_text.unwrap())( + self.c_object)) + } + } + + // + // Set the response status text. + // + pub fn set_status_text(&self, statusText: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_status_text.unwrap())( + self.c_object, + CefWrap::to_c(statusText))) + } + } + + // + // Get the response mime type. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_mime_type(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_mime_type.unwrap())( + self.c_object)) + } + } + + // + // Set the response mime type. + // + pub fn set_mime_type(&self, mimeType: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_mime_type.unwrap())( + self.c_object, + CefWrap::to_c(mimeType))) + } + } + + // + // Get the value for the specified response header field. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_header(&self, name: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_header.unwrap())( + self.c_object, + CefWrap::to_c(name))) + } + } + + // + // Get all response header fields. + // + pub fn get_header_map(&self, headerMap: HashMap>) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_header_map.unwrap())( + self.c_object, + CefWrap::to_c(headerMap))) + } + } + + // + // Set all response header fields. + // + pub fn set_header_map(&self, headerMap: HashMap>) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_header_map.unwrap())( + self.c_object, + CefWrap::to_c(headerMap))) + } + } + + // + // Create a new cef_response_t object. + // + pub fn create() -> interfaces::CefResponse { + unsafe { + CefWrap::to_rust( + ::response::cef_response_create( +)) + } + } +} + +impl CefWrap<*mut cef_response_t> for CefResponse { + fn to_c(rust_object: CefResponse) -> *mut cef_response_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_response_t) -> CefResponse { + CefResponse::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_response_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_response_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_response_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefResponse::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_scheme.rs b/ports/cef/interfaces/cef_scheme.rs new file mode 100644 index 00000000000..3391b9fd119 --- /dev/null +++ b/ports/cef/interfaces/cef_scheme.rs @@ -0,0 +1,434 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure that manages custom scheme registrations. +// +#[repr(C)] +pub struct _cef_scheme_registrar_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Register a custom scheme. This function should not be called for the built- + // in HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes. + // + // If |is_standard| is true (1) the scheme will be treated as a standard + // scheme. Standard schemes are subject to URL canonicalization and parsing + // rules as defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 + // available at http://www.ietf.org/rfc/rfc1738.txt + // + // In particular, the syntax for standard scheme URLs must be of the form: + //
+  //  [scheme]://[username]:[password]@[host]:[port]/[url-path]
+  // 
Standard scheme URLs must have a host component that is a fully + // qualified domain name as defined in Section 3.5 of RFC 1034 [13] and + // Section 2.1 of RFC 1123. These URLs will be canonicalized to + // "scheme://host/path" in the simplest case and + // "scheme://username:password@host:port/path" in the most explicit case. For + // example, "scheme:host/path" and "scheme:///host/path" will both be + // canonicalized to "scheme://host/path". The origin of a standard scheme URL + // is the combination of scheme, host and port (i.e., "scheme://host:port" in + // the most explicit case). + // + // For non-standard scheme URLs only the "scheme:" component is parsed and + // canonicalized. The remainder of the URL will be passed to the handler as- + // is. For example, "scheme:///some%20text" will remain the same. Non-standard + // scheme URLs cannot be used as a target for form submission. + // + // If |is_local| is true (1) the scheme will be treated as local (i.e., with + // the same security rules as those applied to "file" URLs). Normal pages + // cannot link to or access local URLs. Also, by default, local URLs can only + // perform XMLHttpRequest calls to the same URL (origin + path) that + // originated the request. To allow XMLHttpRequest calls from a local URL to + // other URLs with the same origin set the + // CefSettings.file_access_from_file_urls_allowed value to true (1). To allow + // XMLHttpRequest calls from a local URL to all origins set the + // CefSettings.universal_access_from_file_urls_allowed value to true (1). + // + // If |is_display_isolated| is true (1) the scheme will be treated as display- + // isolated. This means that pages cannot display these URLs unless they are + // from the same scheme. For example, pages in another origin cannot create + // iframes or hyperlinks to URLs with this scheme. + // + // This function may be called on any thread. It should only be called once + // per unique |scheme_name| value. If |scheme_name| is already registered or + // if an error occurs this function will return false (0). + // + pub add_custom_scheme: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_scheme_registrar_t = _cef_scheme_registrar_t; + + +// +// Structure that manages custom scheme registrations. +// +pub struct CefSchemeRegistrar { + c_object: *mut cef_scheme_registrar_t, +} + +impl Clone for CefSchemeRegistrar { + fn clone(&self) -> CefSchemeRegistrar{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefSchemeRegistrar { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefSchemeRegistrar { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefSchemeRegistrar { + pub unsafe fn from_c_object(c_object: *mut cef_scheme_registrar_t) -> CefSchemeRegistrar { + CefSchemeRegistrar { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_scheme_registrar_t) -> CefSchemeRegistrar { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefSchemeRegistrar { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_scheme_registrar_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_scheme_registrar_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Register a custom scheme. This function should not be called for the built- + // in HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes. + // + // If |is_standard| is true (1) the scheme will be treated as a standard + // scheme. Standard schemes are subject to URL canonicalization and parsing + // rules as defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 + // available at http://www.ietf.org/rfc/rfc1738.txt + // + // In particular, the syntax for standard scheme URLs must be of the form: + //
+  //  [scheme]://[username]:[password]@[host]:[port]/[url-path]
+  // 
Standard scheme URLs must have a host component that is a fully + // qualified domain name as defined in Section 3.5 of RFC 1034 [13] and + // Section 2.1 of RFC 1123. These URLs will be canonicalized to + // "scheme://host/path" in the simplest case and + // "scheme://username:password@host:port/path" in the most explicit case. For + // example, "scheme:host/path" and "scheme:///host/path" will both be + // canonicalized to "scheme://host/path". The origin of a standard scheme URL + // is the combination of scheme, host and port (i.e., "scheme://host:port" in + // the most explicit case). + // + // For non-standard scheme URLs only the "scheme:" component is parsed and + // canonicalized. The remainder of the URL will be passed to the handler as- + // is. For example, "scheme:///some%20text" will remain the same. Non-standard + // scheme URLs cannot be used as a target for form submission. + // + // If |is_local| is true (1) the scheme will be treated as local (i.e., with + // the same security rules as those applied to "file" URLs). Normal pages + // cannot link to or access local URLs. Also, by default, local URLs can only + // perform XMLHttpRequest calls to the same URL (origin + path) that + // originated the request. To allow XMLHttpRequest calls from a local URL to + // other URLs with the same origin set the + // CefSettings.file_access_from_file_urls_allowed value to true (1). To allow + // XMLHttpRequest calls from a local URL to all origins set the + // CefSettings.universal_access_from_file_urls_allowed value to true (1). + // + // If |is_display_isolated| is true (1) the scheme will be treated as display- + // isolated. This means that pages cannot display these URLs unless they are + // from the same scheme. For example, pages in another origin cannot create + // iframes or hyperlinks to URLs with this scheme. + // + // This function may be called on any thread. It should only be called once + // per unique |scheme_name| value. If |scheme_name| is already registered or + // if an error occurs this function will return false (0). + // + pub fn add_custom_scheme(&self, scheme_name: &str, is_standard: libc::c_int, + is_local: libc::c_int, + is_display_isolated: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).add_custom_scheme.unwrap())( + self.c_object, + CefWrap::to_c(scheme_name), + CefWrap::to_c(is_standard), + CefWrap::to_c(is_local), + CefWrap::to_c(is_display_isolated))) + } + } +} + +impl CefWrap<*mut cef_scheme_registrar_t> for CefSchemeRegistrar { + fn to_c(rust_object: CefSchemeRegistrar) -> *mut cef_scheme_registrar_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_scheme_registrar_t) -> CefSchemeRegistrar { + CefSchemeRegistrar::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_scheme_registrar_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_scheme_registrar_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_scheme_registrar_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefSchemeRegistrar::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure that creates cef_resource_handler_t instances for handling scheme +// requests. The functions of this structure will always be called on the IO +// thread. +// +#[repr(C)] +pub struct _cef_scheme_handler_factory_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Return a new resource handler instance to handle the request or an NULL + // reference to allow default handling of the request. |browser| and |frame| + // will be the browser window and frame respectively that originated the + // request or NULL if the request did not originate from a browser window (for + // example, if the request came from cef_urlrequest_t). The |request| object + // passed to this function will not contain cookie data. + // + pub create: Option *mut interfaces::cef_resource_handler_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_scheme_handler_factory_t = _cef_scheme_handler_factory_t; + + +// +// Structure that creates cef_resource_handler_t instances for handling scheme +// requests. The functions of this structure will always be called on the IO +// thread. +// +pub struct CefSchemeHandlerFactory { + c_object: *mut cef_scheme_handler_factory_t, +} + +impl Clone for CefSchemeHandlerFactory { + fn clone(&self) -> CefSchemeHandlerFactory{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefSchemeHandlerFactory { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefSchemeHandlerFactory { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefSchemeHandlerFactory { + pub unsafe fn from_c_object(c_object: *mut cef_scheme_handler_factory_t) -> CefSchemeHandlerFactory { + CefSchemeHandlerFactory { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_scheme_handler_factory_t) -> CefSchemeHandlerFactory { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefSchemeHandlerFactory { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_scheme_handler_factory_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_scheme_handler_factory_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Return a new resource handler instance to handle the request or an NULL + // reference to allow default handling of the request. |browser| and |frame| + // will be the browser window and frame respectively that originated the + // request or NULL if the request did not originate from a browser window (for + // example, if the request came from cef_urlrequest_t). The |request| object + // passed to this function will not contain cookie data. + // + pub fn create(&self, browser: interfaces::CefBrowser, + frame: interfaces::CefFrame, scheme_name: &str, + request: interfaces::CefRequest) -> interfaces::CefResourceHandler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).create.unwrap())( + self.c_object, + CefWrap::to_c(browser), + CefWrap::to_c(frame), + CefWrap::to_c(scheme_name), + CefWrap::to_c(request))) + } + } +} + +impl CefWrap<*mut cef_scheme_handler_factory_t> for CefSchemeHandlerFactory { + fn to_c(rust_object: CefSchemeHandlerFactory) -> *mut cef_scheme_handler_factory_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_scheme_handler_factory_t) -> CefSchemeHandlerFactory { + CefSchemeHandlerFactory::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_scheme_handler_factory_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_scheme_handler_factory_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_scheme_handler_factory_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefSchemeHandlerFactory::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_stream.rs b/ports/cef/interfaces/cef_stream.rs new file mode 100644 index 00000000000..ecae891aa17 --- /dev/null +++ b/ports/cef/interfaces/cef_stream.rs @@ -0,0 +1,1019 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure the client can implement to provide a custom stream reader. The +// functions of this structure may be called on any thread. +// +#[repr(C)] +pub struct _cef_read_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Read raw binary data. + // + pub read: Option libc::size_t>, + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Return zero on success and non-zero on failure. + // + pub seek: Option libc::c_int>, + + // + // Return the current offset position. + // + pub tell: Option i64>, + + // + // Return non-zero if at end of file. + // + pub eof: Option libc::c_int>, + + // + // Return true (1) if this handler performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the handler from. + // + pub may_block: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_read_handler_t = _cef_read_handler_t; + + +// +// Structure the client can implement to provide a custom stream reader. The +// functions of this structure may be called on any thread. +// +pub struct CefReadHandler { + c_object: *mut cef_read_handler_t, +} + +impl Clone for CefReadHandler { + fn clone(&self) -> CefReadHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefReadHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefReadHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefReadHandler { + pub unsafe fn from_c_object(c_object: *mut cef_read_handler_t) -> CefReadHandler { + CefReadHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_read_handler_t) -> CefReadHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefReadHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_read_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_read_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Read raw binary data. + // + pub fn read(&self, ptr: &mut (), size: libc::size_t, + n: libc::size_t) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).read.unwrap())( + self.c_object, + CefWrap::to_c(ptr), + CefWrap::to_c(size), + CefWrap::to_c(n))) + } + } + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Return zero on success and non-zero on failure. + // + pub fn seek(&self, offset: i64, whence: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).seek.unwrap())( + self.c_object, + CefWrap::to_c(offset), + CefWrap::to_c(whence))) + } + } + + // + // Return the current offset position. + // + pub fn tell(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).tell.unwrap())( + self.c_object)) + } + } + + // + // Return non-zero if at end of file. + // + pub fn eof(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).eof.unwrap())( + self.c_object)) + } + } + + // + // Return true (1) if this handler performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the handler from. + // + pub fn may_block(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).may_block.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_read_handler_t> for CefReadHandler { + fn to_c(rust_object: CefReadHandler) -> *mut cef_read_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_read_handler_t) -> CefReadHandler { + CefReadHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_read_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_read_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_read_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefReadHandler::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to read data from a stream. The functions of this structure +// may be called on any thread. +// +#[repr(C)] +pub struct _cef_stream_reader_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Read raw binary data. + // + pub read: Option libc::size_t>, + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Returns zero on success and non-zero on failure. + // + pub seek: Option libc::c_int>, + + // + // Return the current offset position. + // + pub tell: Option i64>, + + // + // Return non-zero if at end of file. + // + pub eof: Option libc::c_int>, + + // + // Returns true (1) if this reader performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the reader from. + // + pub may_block: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_stream_reader_t = _cef_stream_reader_t; + + +// +// Structure used to read data from a stream. The functions of this structure +// may be called on any thread. +// +pub struct CefStreamReader { + c_object: *mut cef_stream_reader_t, +} + +impl Clone for CefStreamReader { + fn clone(&self) -> CefStreamReader{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefStreamReader { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefStreamReader { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefStreamReader { + pub unsafe fn from_c_object(c_object: *mut cef_stream_reader_t) -> CefStreamReader { + CefStreamReader { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_stream_reader_t) -> CefStreamReader { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefStreamReader { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_stream_reader_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_stream_reader_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Read raw binary data. + // + pub fn read(&self, ptr: &mut (), size: libc::size_t, + n: libc::size_t) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).read.unwrap())( + self.c_object, + CefWrap::to_c(ptr), + CefWrap::to_c(size), + CefWrap::to_c(n))) + } + } + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Returns zero on success and non-zero on failure. + // + pub fn seek(&self, offset: i64, whence: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).seek.unwrap())( + self.c_object, + CefWrap::to_c(offset), + CefWrap::to_c(whence))) + } + } + + // + // Return the current offset position. + // + pub fn tell(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).tell.unwrap())( + self.c_object)) + } + } + + // + // Return non-zero if at end of file. + // + pub fn eof(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).eof.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this reader performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the reader from. + // + pub fn may_block(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).may_block.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_stream_reader_t object from a file. + // + pub fn create_for_file(fileName: &str) -> interfaces::CefStreamReader { + unsafe { + CefWrap::to_rust( + ::stream::cef_stream_reader_create_for_file( + CefWrap::to_c(fileName))) + } + } + + // + // Create a new cef_stream_reader_t object from data. + // + pub fn create_for_data(data: &mut (), + size: libc::size_t) -> interfaces::CefStreamReader { + unsafe { + CefWrap::to_rust( + ::stream::cef_stream_reader_create_for_data( + CefWrap::to_c(data), + CefWrap::to_c(size))) + } + } + + // + // Create a new cef_stream_reader_t object from a custom handler. + // + pub fn create_for_handler( + handler: interfaces::CefReadHandler) -> interfaces::CefStreamReader { + unsafe { + CefWrap::to_rust( + ::stream::cef_stream_reader_create_for_handler( + CefWrap::to_c(handler))) + } + } +} + +impl CefWrap<*mut cef_stream_reader_t> for CefStreamReader { + fn to_c(rust_object: CefStreamReader) -> *mut cef_stream_reader_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_stream_reader_t) -> CefStreamReader { + CefStreamReader::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_stream_reader_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_stream_reader_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_stream_reader_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefStreamReader::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure the client can implement to provide a custom stream writer. The +// functions of this structure may be called on any thread. +// +#[repr(C)] +pub struct _cef_write_handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Write raw binary data. + // + pub write: Option libc::size_t>, + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Return zero on success and non-zero on failure. + // + pub seek: Option libc::c_int>, + + // + // Return the current offset position. + // + pub tell: Option i64>, + + // + // Flush the stream. + // + pub flush: Option libc::c_int>, + + // + // Return true (1) if this handler performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the handler from. + // + pub may_block: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_write_handler_t = _cef_write_handler_t; + + +// +// Structure the client can implement to provide a custom stream writer. The +// functions of this structure may be called on any thread. +// +pub struct CefWriteHandler { + c_object: *mut cef_write_handler_t, +} + +impl Clone for CefWriteHandler { + fn clone(&self) -> CefWriteHandler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefWriteHandler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefWriteHandler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefWriteHandler { + pub unsafe fn from_c_object(c_object: *mut cef_write_handler_t) -> CefWriteHandler { + CefWriteHandler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_write_handler_t) -> CefWriteHandler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefWriteHandler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_write_handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_write_handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Write raw binary data. + // + pub fn write(&self, ptr: &(), size: libc::size_t, + n: libc::size_t) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).write.unwrap())( + self.c_object, + CefWrap::to_c(ptr), + CefWrap::to_c(size), + CefWrap::to_c(n))) + } + } + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Return zero on success and non-zero on failure. + // + pub fn seek(&self, offset: i64, whence: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).seek.unwrap())( + self.c_object, + CefWrap::to_c(offset), + CefWrap::to_c(whence))) + } + } + + // + // Return the current offset position. + // + pub fn tell(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).tell.unwrap())( + self.c_object)) + } + } + + // + // Flush the stream. + // + pub fn flush(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).flush.unwrap())( + self.c_object)) + } + } + + // + // Return true (1) if this handler performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the handler from. + // + pub fn may_block(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).may_block.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_write_handler_t> for CefWriteHandler { + fn to_c(rust_object: CefWriteHandler) -> *mut cef_write_handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_write_handler_t) -> CefWriteHandler { + CefWriteHandler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_write_handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_write_handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_write_handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefWriteHandler::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure used to write data to a stream. The functions of this structure may +// be called on any thread. +// +#[repr(C)] +pub struct _cef_stream_writer_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Write raw binary data. + // + pub write: Option libc::size_t>, + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Returns zero on success and non-zero on failure. + // + pub seek: Option libc::c_int>, + + // + // Return the current offset position. + // + pub tell: Option i64>, + + // + // Flush the stream. + // + pub flush: Option libc::c_int>, + + // + // Returns true (1) if this writer performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the writer from. + // + pub may_block: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_stream_writer_t = _cef_stream_writer_t; + + +// +// Structure used to write data to a stream. The functions of this structure may +// be called on any thread. +// +pub struct CefStreamWriter { + c_object: *mut cef_stream_writer_t, +} + +impl Clone for CefStreamWriter { + fn clone(&self) -> CefStreamWriter{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefStreamWriter { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefStreamWriter { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefStreamWriter { + pub unsafe fn from_c_object(c_object: *mut cef_stream_writer_t) -> CefStreamWriter { + CefStreamWriter { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_stream_writer_t) -> CefStreamWriter { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefStreamWriter { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_stream_writer_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_stream_writer_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Write raw binary data. + // + pub fn write(&self, ptr: &(), size: libc::size_t, + n: libc::size_t) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).write.unwrap())( + self.c_object, + CefWrap::to_c(ptr), + CefWrap::to_c(size), + CefWrap::to_c(n))) + } + } + + // + // Seek to the specified offset position. |whence| may be any one of SEEK_CUR, + // SEEK_END or SEEK_SET. Returns zero on success and non-zero on failure. + // + pub fn seek(&self, offset: i64, whence: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).seek.unwrap())( + self.c_object, + CefWrap::to_c(offset), + CefWrap::to_c(whence))) + } + } + + // + // Return the current offset position. + // + pub fn tell(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).tell.unwrap())( + self.c_object)) + } + } + + // + // Flush the stream. + // + pub fn flush(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).flush.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this writer performs work like accessing the file + // system which may block. Used as a hint for determining the thread to access + // the writer from. + // + pub fn may_block(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).may_block.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_stream_writer_t object for a file. + // + pub fn create_for_file(fileName: &str) -> interfaces::CefStreamWriter { + unsafe { + CefWrap::to_rust( + ::stream::cef_stream_writer_create_for_file( + CefWrap::to_c(fileName))) + } + } + + // + // Create a new cef_stream_writer_t object for a custom handler. + // + pub fn create_for_handler( + handler: interfaces::CefWriteHandler) -> interfaces::CefStreamWriter { + unsafe { + CefWrap::to_rust( + ::stream::cef_stream_writer_create_for_handler( + CefWrap::to_c(handler))) + } + } +} + +impl CefWrap<*mut cef_stream_writer_t> for CefStreamWriter { + fn to_c(rust_object: CefStreamWriter) -> *mut cef_stream_writer_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_stream_writer_t) -> CefStreamWriter { + CefStreamWriter::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_stream_writer_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_stream_writer_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_stream_writer_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefStreamWriter::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_string_visitor.rs b/ports/cef/interfaces/cef_string_visitor.rs new file mode 100644 index 00000000000..26fc75997e0 --- /dev/null +++ b/ports/cef/interfaces/cef_string_visitor.rs @@ -0,0 +1,183 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to receive string values asynchronously. +// +#[repr(C)] +pub struct _cef_string_visitor_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be executed. + // + pub visit: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_string_visitor_t = _cef_string_visitor_t; + + +// +// Implement this structure to receive string values asynchronously. +// +pub struct CefStringVisitor { + c_object: *mut cef_string_visitor_t, +} + +impl Clone for CefStringVisitor { + fn clone(&self) -> CefStringVisitor{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefStringVisitor { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefStringVisitor { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefStringVisitor { + pub unsafe fn from_c_object(c_object: *mut cef_string_visitor_t) -> CefStringVisitor { + CefStringVisitor { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_string_visitor_t) -> CefStringVisitor { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefStringVisitor { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_string_visitor_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_string_visitor_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be executed. + // + pub fn visit(&self, string: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit.unwrap())( + self.c_object, + CefWrap::to_c(string))) + } + } +} + +impl CefWrap<*mut cef_string_visitor_t> for CefStringVisitor { + fn to_c(rust_object: CefStringVisitor) -> *mut cef_string_visitor_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_string_visitor_t) -> CefStringVisitor { + CefStringVisitor::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_string_visitor_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_string_visitor_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_string_visitor_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefStringVisitor::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_task.rs b/ports/cef/interfaces/cef_task.rs new file mode 100644 index 00000000000..5f8aa5cb19e --- /dev/null +++ b/ports/cef/interfaces/cef_task.rs @@ -0,0 +1,461 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure for asynchronous task execution. If the task is +// posted successfully and if the associated message loop is still running then +// the execute() function will be called on the target thread. If the task fails +// to post then the task object may be destroyed on the source thread instead of +// the target thread. For this reason be cautious when performing work in the +// task object destructor. +// +#[repr(C)] +pub struct _cef_task_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be executed on the target thread. + // + pub execute: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_task_t = _cef_task_t; + + +// +// Implement this structure for asynchronous task execution. If the task is +// posted successfully and if the associated message loop is still running then +// the execute() function will be called on the target thread. If the task fails +// to post then the task object may be destroyed on the source thread instead of +// the target thread. For this reason be cautious when performing work in the +// task object destructor. +// +pub struct CefTask { + c_object: *mut cef_task_t, +} + +impl Clone for CefTask { + fn clone(&self) -> CefTask{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefTask { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefTask { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefTask { + pub unsafe fn from_c_object(c_object: *mut cef_task_t) -> CefTask { + CefTask { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_task_t) -> CefTask { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefTask { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_task_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_task_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be executed on the target thread. + // + pub fn execute(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).execute.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_task_t> for CefTask { + fn to_c(rust_object: CefTask) -> *mut cef_task_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_task_t) -> CefTask { + CefTask::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_task_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_task_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_task_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefTask::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure that asynchronously executes tasks on the associated thread. It is +// safe to call the functions of this structure on any thread. +// +// CEF maintains multiple internal threads that are used for handling different +// types of tasks in different processes. The cef_thread_id_t definitions in +// cef_types.h list the common CEF threads. Task runners are also available for +// other CEF threads as appropriate (for example, V8 WebWorker threads). +// +#[repr(C)] +pub struct _cef_task_runner_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is pointing to the same task runner as + // |that| object. + // + pub is_same: Option libc::c_int>, + + // + // Returns true (1) if this task runner belongs to the current thread. + // + pub belongs_to_current_thread: Option libc::c_int>, + + // + // Returns true (1) if this task runner is for the specified CEF thread. + // + pub belongs_to_thread: Option libc::c_int>, + + // + // Post a task for execution on the thread associated with this task runner. + // Execution will occur asynchronously. + // + pub post_task: Option libc::c_int>, + + // + // Post a task for delayed execution on the thread associated with this task + // runner. Execution will occur asynchronously. Delayed tasks are not + // supported on V8 WebWorker threads and will be executed without the + // specified delay. + // + pub post_delayed_task: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_task_runner_t = _cef_task_runner_t; + + +// +// Structure that asynchronously executes tasks on the associated thread. It is +// safe to call the functions of this structure on any thread. +// +// CEF maintains multiple internal threads that are used for handling different +// types of tasks in different processes. The cef_thread_id_t definitions in +// cef_types.h list the common CEF threads. Task runners are also available for +// other CEF threads as appropriate (for example, V8 WebWorker threads). +// +pub struct CefTaskRunner { + c_object: *mut cef_task_runner_t, +} + +impl Clone for CefTaskRunner { + fn clone(&self) -> CefTaskRunner{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefTaskRunner { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefTaskRunner { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefTaskRunner { + pub unsafe fn from_c_object(c_object: *mut cef_task_runner_t) -> CefTaskRunner { + CefTaskRunner { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_task_runner_t) -> CefTaskRunner { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefTaskRunner { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_task_runner_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_task_runner_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is pointing to the same task runner as + // |that| object. + // + pub fn is_same(&self, that: interfaces::CefTaskRunner) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(that))) + } + } + + // + // Returns true (1) if this task runner belongs to the current thread. + // + pub fn belongs_to_current_thread(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).belongs_to_current_thread.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this task runner is for the specified CEF thread. + // + pub fn belongs_to_thread(&self, + threadId: types::cef_thread_id_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).belongs_to_thread.unwrap())( + self.c_object, + CefWrap::to_c(threadId))) + } + } + + // + // Post a task for execution on the thread associated with this task runner. + // Execution will occur asynchronously. + // + pub fn post_task(&self, task: interfaces::CefTask) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).post_task.unwrap())( + self.c_object, + CefWrap::to_c(task))) + } + } + + // + // Post a task for delayed execution on the thread associated with this task + // runner. Execution will occur asynchronously. Delayed tasks are not + // supported on V8 WebWorker threads and will be executed without the + // specified delay. + // + pub fn post_delayed_task(&self, task: interfaces::CefTask, + delay_ms: i64) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).post_delayed_task.unwrap())( + self.c_object, + CefWrap::to_c(task), + CefWrap::to_c(delay_ms))) + } + } + + // + // Returns the task runner for the current thread. Only CEF threads will have + // task runners. An NULL reference will be returned if this function is called + // on an invalid thread. + // + pub fn get_for_current_thread() -> interfaces::CefTaskRunner { + unsafe { + CefWrap::to_rust( + ::task::cef_task_runner_get_for_current_thread( +)) + } + } + + // + // Returns the task runner for the specified CEF thread. + // + pub fn get_for_thread( + threadId: types::cef_thread_id_t) -> interfaces::CefTaskRunner { + unsafe { + CefWrap::to_rust( + ::task::cef_task_runner_get_for_thread( + CefWrap::to_c(threadId))) + } + } +} + +impl CefWrap<*mut cef_task_runner_t> for CefTaskRunner { + fn to_c(rust_object: CefTaskRunner) -> *mut cef_task_runner_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_task_runner_t) -> CefTaskRunner { + CefTaskRunner::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_task_runner_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_task_runner_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_task_runner_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefTaskRunner::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_trace.rs b/ports/cef/interfaces/cef_trace.rs new file mode 100644 index 00000000000..7cccbb1135d --- /dev/null +++ b/ports/cef/interfaces/cef_trace.rs @@ -0,0 +1,192 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Implement this structure to receive notification when tracing has completed. +// The functions of this structure will be called on the browser process UI +// thread. +// +#[repr(C)] +pub struct _cef_end_tracing_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Called after all processes have sent their trace data. |tracing_file| is + // the path at which tracing data was written. The client is responsible for + // deleting |tracing_file|. + // + pub on_end_tracing_complete: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_end_tracing_callback_t = _cef_end_tracing_callback_t; + + +// +// Implement this structure to receive notification when tracing has completed. +// The functions of this structure will be called on the browser process UI +// thread. +// +pub struct CefEndTracingCallback { + c_object: *mut cef_end_tracing_callback_t, +} + +impl Clone for CefEndTracingCallback { + fn clone(&self) -> CefEndTracingCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefEndTracingCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefEndTracingCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefEndTracingCallback { + pub unsafe fn from_c_object(c_object: *mut cef_end_tracing_callback_t) -> CefEndTracingCallback { + CefEndTracingCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_end_tracing_callback_t) -> CefEndTracingCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefEndTracingCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_end_tracing_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_end_tracing_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Called after all processes have sent their trace data. |tracing_file| is + // the path at which tracing data was written. The client is responsible for + // deleting |tracing_file|. + // + pub fn on_end_tracing_complete(&self, tracing_file: &str) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_end_tracing_complete.unwrap())( + self.c_object, + CefWrap::to_c(tracing_file))) + } + } +} + +impl CefWrap<*mut cef_end_tracing_callback_t> for CefEndTracingCallback { + fn to_c(rust_object: CefEndTracingCallback) -> *mut cef_end_tracing_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_end_tracing_callback_t) -> CefEndTracingCallback { + CefEndTracingCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_end_tracing_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_end_tracing_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_end_tracing_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefEndTracingCallback::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_url.rs b/ports/cef/interfaces/cef_url.rs new file mode 100644 index 00000000000..c8622bc9cc9 --- /dev/null +++ b/ports/cef/interfaces/cef_url.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; diff --git a/ports/cef/interfaces/cef_urlrequest.rs b/ports/cef/interfaces/cef_urlrequest.rs new file mode 100644 index 00000000000..73189180f4d --- /dev/null +++ b/ports/cef/interfaces/cef_urlrequest.rs @@ -0,0 +1,599 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure used to make a URL request. URL requests are not associated with a +// browser instance so no cef_client_t callbacks will be executed. URL requests +// can be created on any valid CEF thread in either the browser or render +// process. Once created the functions of the URL request object must be +// accessed on the same thread that created it. +// +#[repr(C)] +pub struct _cef_urlrequest_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the request object used to create this URL request. The returned + // object is read-only and should not be modified. + // + pub get_request: Option *mut interfaces::cef_request_t>, + + // + // Returns the client. + // + pub get_client: Option *mut interfaces::cef_urlrequest_client_t>, + + // + // Returns the request status. + // + pub get_request_status: Option types::cef_urlrequest_status_t>, + + // + // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0 + // otherwise. + // + pub get_request_error: Option types::cef_errorcode_t>, + + // + // Returns the response, or NULL if no response information is available. + // Response information will only be available after the upload has completed. + // The returned object is read-only and should not be modified. + // + pub get_response: Option *mut interfaces::cef_response_t>, + + // + // Cancel the request. + // + pub cancel: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_urlrequest_t = _cef_urlrequest_t; + + +// +// Structure used to make a URL request. URL requests are not associated with a +// browser instance so no cef_client_t callbacks will be executed. URL requests +// can be created on any valid CEF thread in either the browser or render +// process. Once created the functions of the URL request object must be +// accessed on the same thread that created it. +// +pub struct CefURLRequest { + c_object: *mut cef_urlrequest_t, +} + +impl Clone for CefURLRequest { + fn clone(&self) -> CefURLRequest{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefURLRequest { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefURLRequest { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefURLRequest { + pub unsafe fn from_c_object(c_object: *mut cef_urlrequest_t) -> CefURLRequest { + CefURLRequest { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_urlrequest_t) -> CefURLRequest { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefURLRequest { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_urlrequest_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_urlrequest_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the request object used to create this URL request. The returned + // object is read-only and should not be modified. + // + pub fn get_request(&self) -> interfaces::CefRequest { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_request.unwrap())( + self.c_object)) + } + } + + // + // Returns the client. + // + pub fn get_client(&self) -> interfaces::CefURLRequestClient { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_client.unwrap())( + self.c_object)) + } + } + + // + // Returns the request status. + // + pub fn get_request_status(&self) -> types::cef_urlrequest_status_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_request_status.unwrap())( + self.c_object)) + } + } + + // + // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0 + // otherwise. + // + pub fn get_request_error(&self) -> types::cef_errorcode_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_request_error.unwrap())( + self.c_object)) + } + } + + // + // Returns the response, or NULL if no response information is available. + // Response information will only be available after the upload has completed. + // The returned object is read-only and should not be modified. + // + pub fn get_response(&self) -> interfaces::CefResponse { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_response.unwrap())( + self.c_object)) + } + } + + // + // Cancel the request. + // + pub fn cancel(&self) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).cancel.unwrap())( + self.c_object)) + } + } + + // + // Create a new URL request. Only GET, POST, HEAD, DELETE and PUT request + // functions are supported. Multiple post data elements are not supported and + // elements of type PDE_TYPE_FILE are only supported for requests originating + // from the browser process. Requests originating from the render process will + // receive the same handling as requests originating from Web content -- if + // the response contains Content-Disposition or Mime-Type header values that + // would not normally be rendered then the response may receive special + // handling inside the browser (for example, via the file download code path + // instead of the URL request code path). The |request| object will be marked + // as read-only after calling this function. + // + pub fn create(request: interfaces::CefRequest, + client: interfaces::CefURLRequestClient) -> interfaces::CefURLRequest { + unsafe { + CefWrap::to_rust( + ::urlrequest::cef_urlrequest_create( + CefWrap::to_c(request), + CefWrap::to_c(client))) + } + } +} + +impl CefWrap<*mut cef_urlrequest_t> for CefURLRequest { + fn to_c(rust_object: CefURLRequest) -> *mut cef_urlrequest_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_urlrequest_t) -> CefURLRequest { + CefURLRequest::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_urlrequest_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_urlrequest_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_urlrequest_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefURLRequest::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure that should be implemented by the cef_urlrequest_t client. The +// functions of this structure will be called on the same thread that created +// the request unless otherwise documented. +// +#[repr(C)] +pub struct _cef_urlrequest_client_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Notifies the client that the request has completed. Use the + // cef_urlrequest_t::GetRequestStatus function to determine if the request was + // successful or not. + // + pub on_request_complete: Option ()>, + + // + // Notifies the client of upload progress. |current| denotes the number of + // bytes sent so far and |total| is the total size of uploading data (or -1 if + // chunked upload is enabled). This function will only be called if the + // UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request. + // + pub on_upload_progress: Option ()>, + + // + // Notifies the client of download progress. |current| denotes the number of + // bytes received up to the call and |total| is the expected total size of the + // response (or -1 if not determined). + // + pub on_download_progress: Option ()>, + + // + // Called when some part of the response is read. |data| contains the current + // bytes received since the last call. This function will not be called if the + // UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request. + // + pub on_download_data: Option ()>, + + // + // Called on the IO thread when the browser needs credentials from the user. + // |isProxy| indicates whether the host is a proxy server. |host| contains the + // hostname and |port| contains the port number. Return true (1) to continue + // the request and call cef_auth_callback_t::cont() when the authentication + // information is available. Return false (0) to cancel the request. This + // function will only be called for requests initiated from the browser + // process. + // + pub get_auth_credentials: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_urlrequest_client_t = _cef_urlrequest_client_t; + + +// +// Structure that should be implemented by the cef_urlrequest_t client. The +// functions of this structure will be called on the same thread that created +// the request unless otherwise documented. +// +pub struct CefURLRequestClient { + c_object: *mut cef_urlrequest_client_t, +} + +impl Clone for CefURLRequestClient { + fn clone(&self) -> CefURLRequestClient{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefURLRequestClient { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefURLRequestClient { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefURLRequestClient { + pub unsafe fn from_c_object(c_object: *mut cef_urlrequest_client_t) -> CefURLRequestClient { + CefURLRequestClient { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_urlrequest_client_t) -> CefURLRequestClient { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefURLRequestClient { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_urlrequest_client_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_urlrequest_client_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Notifies the client that the request has completed. Use the + // cef_urlrequest_t::GetRequestStatus function to determine if the request was + // successful or not. + // + pub fn on_request_complete(&self, request: interfaces::CefURLRequest) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_request_complete.unwrap())( + self.c_object, + CefWrap::to_c(request))) + } + } + + // + // Notifies the client of upload progress. |current| denotes the number of + // bytes sent so far and |total| is the total size of uploading data (or -1 if + // chunked upload is enabled). This function will only be called if the + // UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request. + // + pub fn on_upload_progress(&self, request: interfaces::CefURLRequest, + current: u64, total: u64) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_upload_progress.unwrap())( + self.c_object, + CefWrap::to_c(request), + CefWrap::to_c(current), + CefWrap::to_c(total))) + } + } + + // + // Notifies the client of download progress. |current| denotes the number of + // bytes received up to the call and |total| is the expected total size of the + // response (or -1 if not determined). + // + pub fn on_download_progress(&self, request: interfaces::CefURLRequest, + current: u64, total: u64) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_download_progress.unwrap())( + self.c_object, + CefWrap::to_c(request), + CefWrap::to_c(current), + CefWrap::to_c(total))) + } + } + + // + // Called when some part of the response is read. |data| contains the current + // bytes received since the last call. This function will not be called if the + // UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request. + // + pub fn on_download_data(&self, request: interfaces::CefURLRequest, data: &(), + data_length: libc::size_t) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).on_download_data.unwrap())( + self.c_object, + CefWrap::to_c(request), + CefWrap::to_c(data), + CefWrap::to_c(data_length))) + } + } + + // + // Called on the IO thread when the browser needs credentials from the user. + // |isProxy| indicates whether the host is a proxy server. |host| contains the + // hostname and |port| contains the port number. Return true (1) to continue + // the request and call cef_auth_callback_t::cont() when the authentication + // information is available. Return false (0) to cancel the request. This + // function will only be called for requests initiated from the browser + // process. + // + pub fn get_auth_credentials(&self, isProxy: libc::c_int, host: &str, + port: libc::c_int, realm: &str, scheme: &str, + callback: interfaces::CefAuthCallback) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_auth_credentials.unwrap())( + self.c_object, + CefWrap::to_c(isProxy), + CefWrap::to_c(host), + CefWrap::to_c(port), + CefWrap::to_c(realm), + CefWrap::to_c(scheme), + CefWrap::to_c(callback))) + } + } +} + +impl CefWrap<*mut cef_urlrequest_client_t> for CefURLRequestClient { + fn to_c(rust_object: CefURLRequestClient) -> *mut cef_urlrequest_client_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_urlrequest_client_t) -> CefURLRequestClient { + CefURLRequestClient::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_urlrequest_client_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_urlrequest_client_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_urlrequest_client_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefURLRequestClient::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_v8.rs b/ports/cef/interfaces/cef_v8.rs new file mode 100644 index 00000000000..fd69ec4fa42 --- /dev/null +++ b/ports/cef/interfaces/cef_v8.rs @@ -0,0 +1,2888 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure representing a V8 context handle. V8 handles can only be accessed +// from the thread on which they are created. Valid threads for creating a V8 +// handle include the render process main thread (TID_RENDERER) and WebWorker +// threads. A task runner for posting tasks on the associated thread can be +// retrieved via the cef_v8context_t::get_task_runner() function. +// +#[repr(C)] +pub struct _cef_v8context_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the task runner associated with this context. V8 handles can only + // be accessed from the thread on which they are created. This function can be + // called on any render process thread. + // + pub get_task_runner: Option *mut interfaces::cef_task_runner_t>, + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns the browser for this context. This function will return an NULL + // reference for WebWorker contexts. + // + pub get_browser: Option *mut interfaces::cef_browser_t>, + + // + // Returns the frame for this context. This function will return an NULL + // reference for WebWorker contexts. + // + pub get_frame: Option *mut interfaces::cef_frame_t>, + + // + // Returns the global object for this context. The context must be entered + // before calling this function. + // + pub get_global: Option *mut interfaces::cef_v8value_t>, + + // + // Enter this context. A context must be explicitly entered before creating a + // V8 Object, Array, Function or Date asynchronously. exit() must be called + // the same number of times as enter() before releasing this context. V8 + // objects belong to the context in which they are created. Returns true (1) + // if the scope was entered successfully. + // + pub enter: Option libc::c_int>, + + // + // Exit this context. Call this function only after calling enter(). Returns + // true (1) if the scope was exited successfully. + // + pub exit: Option libc::c_int>, + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub is_same: Option libc::c_int>, + + // + // Evaluates the specified JavaScript code using this context's global object. + // On success |retval| will be set to the return value, if any, and the + // function will return true (1). On failure |exception| will be set to the + // exception, if any, and the function will return false (0). + // + pub eval: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8context_t = _cef_v8context_t; + + +// +// Structure representing a V8 context handle. V8 handles can only be accessed +// from the thread on which they are created. Valid threads for creating a V8 +// handle include the render process main thread (TID_RENDERER) and WebWorker +// threads. A task runner for posting tasks on the associated thread can be +// retrieved via the cef_v8context_t::get_task_runner() function. +// +pub struct CefV8Context { + c_object: *mut cef_v8context_t, +} + +impl Clone for CefV8Context { + fn clone(&self) -> CefV8Context{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8Context { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8Context { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8Context { + pub unsafe fn from_c_object(c_object: *mut cef_v8context_t) -> CefV8Context { + CefV8Context { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8context_t) -> CefV8Context { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8Context { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8context_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8context_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the task runner associated with this context. V8 handles can only + // be accessed from the thread on which they are created. This function can be + // called on any render process thread. + // + pub fn get_task_runner(&self) -> interfaces::CefTaskRunner { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_task_runner.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns the browser for this context. This function will return an NULL + // reference for WebWorker contexts. + // + pub fn get_browser(&self) -> interfaces::CefBrowser { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_browser.unwrap())( + self.c_object)) + } + } + + // + // Returns the frame for this context. This function will return an NULL + // reference for WebWorker contexts. + // + pub fn get_frame(&self) -> interfaces::CefFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame.unwrap())( + self.c_object)) + } + } + + // + // Returns the global object for this context. The context must be entered + // before calling this function. + // + pub fn get_global(&self) -> interfaces::CefV8Value { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_global.unwrap())( + self.c_object)) + } + } + + // + // Enter this context. A context must be explicitly entered before creating a + // V8 Object, Array, Function or Date asynchronously. exit() must be called + // the same number of times as enter() before releasing this context. V8 + // objects belong to the context in which they are created. Returns true (1) + // if the scope was entered successfully. + // + pub fn enter(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).enter.unwrap())( + self.c_object)) + } + } + + // + // Exit this context. Call this function only after calling enter(). Returns + // true (1) if the scope was exited successfully. + // + pub fn exit(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).exit.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub fn is_same(&self, that: interfaces::CefV8Context) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(that))) + } + } + + // + // Evaluates the specified JavaScript code using this context's global object. + // On success |retval| will be set to the return value, if any, and the + // function will return true (1). On failure |exception| will be set to the + // exception, if any, and the function will return false (0). + // + pub fn eval(&self, code: &str, retval: interfaces::CefV8Value, + exception: interfaces::CefV8Exception) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).eval.unwrap())( + self.c_object, + CefWrap::to_c(code), + CefWrap::to_c(retval), + CefWrap::to_c(exception))) + } + } + + // + // Returns the current (top) context object in the V8 context stack. + // + pub fn get_current_context() -> interfaces::CefV8Context { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8context_get_current_context( +)) + } + } + + // + // Returns the entered (bottom) context object in the V8 context stack. + // + pub fn get_entered_context() -> interfaces::CefV8Context { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8context_get_entered_context( +)) + } + } + + // + // Returns true (1) if V8 is currently inside a context. + // + pub fn in_context() -> libc::c_int { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8context_in_context( +)) + } + } +} + +impl CefWrap<*mut cef_v8context_t> for CefV8Context { + fn to_c(rust_object: CefV8Context) -> *mut cef_v8context_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8context_t) -> CefV8Context { + CefV8Context::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8context_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8context_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8context_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8Context::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure that should be implemented to handle V8 function calls. The +// functions of this structure will be called on the thread associated with the +// V8 function. +// +#[repr(C)] +pub struct _cef_v8handler_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Handle execution of the function identified by |name|. |object| is the + // receiver ('this' object) of the function. |arguments| is the list of + // arguments passed to the function. If execution succeeds set |retval| to the + // function return value. If execution fails set |exception| to the exception + // that will be thrown. Return true (1) if execution was handled. + // + pub execute: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8handler_t = _cef_v8handler_t; + + +// +// Structure that should be implemented to handle V8 function calls. The +// functions of this structure will be called on the thread associated with the +// V8 function. +// +pub struct CefV8Handler { + c_object: *mut cef_v8handler_t, +} + +impl Clone for CefV8Handler { + fn clone(&self) -> CefV8Handler{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8Handler { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8Handler { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8Handler { + pub unsafe fn from_c_object(c_object: *mut cef_v8handler_t) -> CefV8Handler { + CefV8Handler { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8handler_t) -> CefV8Handler { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8Handler { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8handler_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8handler_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Handle execution of the function identified by |name|. |object| is the + // receiver ('this' object) of the function. |arguments| is the list of + // arguments passed to the function. If execution succeeds set |retval| to the + // function return value. If execution fails set |exception| to the exception + // that will be thrown. Return true (1) if execution was handled. + // + pub fn execute(&self, name: &str, object: interfaces::CefV8Value, + arguments_count: libc::size_t, arguments: *const interfaces::CefV8Value, + retval: interfaces::CefV8Value, + exception: *mut types::cef_string_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).execute.unwrap())( + self.c_object, + CefWrap::to_c(name), + CefWrap::to_c(object), + CefWrap::to_c(arguments_count), + CefWrap::to_c(arguments), + CefWrap::to_c(retval), + CefWrap::to_c(exception))) + } + } +} + +impl CefWrap<*mut cef_v8handler_t> for CefV8Handler { + fn to_c(rust_object: CefV8Handler) -> *mut cef_v8handler_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8handler_t) -> CefV8Handler { + CefV8Handler::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8handler_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8handler_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8handler_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8Handler::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure that should be implemented to handle V8 accessor calls. Accessor +// identifiers are registered by calling cef_v8value_t::set_value_byaccessor(). +// The functions of this structure will be called on the thread associated with +// the V8 accessor. +// +#[repr(C)] +pub struct _cef_v8accessor_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Handle retrieval the accessor value identified by |name|. |object| is the + // receiver ('this' object) of the accessor. If retrieval succeeds set + // |retval| to the return value. If retrieval fails set |exception| to the + // exception that will be thrown. Return true (1) if accessor retrieval was + // handled. + // + pub get: Option libc::c_int>, + + // + // Handle assignment of the accessor value identified by |name|. |object| is + // the receiver ('this' object) of the accessor. |value| is the new value + // being assigned to the accessor. If assignment fails set |exception| to the + // exception that will be thrown. Return true (1) if accessor assignment was + // handled. + // + pub set: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8accessor_t = _cef_v8accessor_t; + + +// +// Structure that should be implemented to handle V8 accessor calls. Accessor +// identifiers are registered by calling cef_v8value_t::set_value_byaccessor(). +// The functions of this structure will be called on the thread associated with +// the V8 accessor. +// +pub struct CefV8Accessor { + c_object: *mut cef_v8accessor_t, +} + +impl Clone for CefV8Accessor { + fn clone(&self) -> CefV8Accessor{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8Accessor { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8Accessor { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8Accessor { + pub unsafe fn from_c_object(c_object: *mut cef_v8accessor_t) -> CefV8Accessor { + CefV8Accessor { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8accessor_t) -> CefV8Accessor { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8Accessor { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8accessor_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8accessor_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Handle retrieval the accessor value identified by |name|. |object| is the + // receiver ('this' object) of the accessor. If retrieval succeeds set + // |retval| to the return value. If retrieval fails set |exception| to the + // exception that will be thrown. Return true (1) if accessor retrieval was + // handled. + // + pub fn get(&self, name: &str, object: interfaces::CefV8Value, + retval: interfaces::CefV8Value, + exception: *mut types::cef_string_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get.unwrap())( + self.c_object, + CefWrap::to_c(name), + CefWrap::to_c(object), + CefWrap::to_c(retval), + CefWrap::to_c(exception))) + } + } + + // + // Handle assignment of the accessor value identified by |name|. |object| is + // the receiver ('this' object) of the accessor. |value| is the new value + // being assigned to the accessor. If assignment fails set |exception| to the + // exception that will be thrown. Return true (1) if accessor assignment was + // handled. + // + pub fn set(&self, name: &str, object: interfaces::CefV8Value, + value: interfaces::CefV8Value, + exception: *mut types::cef_string_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set.unwrap())( + self.c_object, + CefWrap::to_c(name), + CefWrap::to_c(object), + CefWrap::to_c(value), + CefWrap::to_c(exception))) + } + } +} + +impl CefWrap<*mut cef_v8accessor_t> for CefV8Accessor { + fn to_c(rust_object: CefV8Accessor) -> *mut cef_v8accessor_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8accessor_t) -> CefV8Accessor { + CefV8Accessor::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8accessor_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8accessor_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8accessor_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8Accessor::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a V8 exception. The functions of this structure may be +// called on any render process thread. +// +#[repr(C)] +pub struct _cef_v8exception_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the exception message. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_message: Option types::cef_string_userfree_t>, + + // + // Returns the line of source code that the exception occurred within. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_source_line: Option types::cef_string_userfree_t>, + + // + // Returns the resource name for the script from where the function causing + // the error originates. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_script_resource_name: Option types::cef_string_userfree_t>, + + // + // Returns the 1-based number of the line where the error occurred or 0 if the + // line number is unknown. + // + pub get_line_number: Option libc::c_int>, + + // + // Returns the index within the script of the first character where the error + // occurred. + // + pub get_start_position: Option libc::c_int>, + + // + // Returns the index within the script of the last character where the error + // occurred. + // + pub get_end_position: Option libc::c_int>, + + // + // Returns the index within the line of the first character where the error + // occurred. + // + pub get_start_column: Option libc::c_int>, + + // + // Returns the index within the line of the last character where the error + // occurred. + // + pub get_end_column: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8exception_t = _cef_v8exception_t; + + +// +// Structure representing a V8 exception. The functions of this structure may be +// called on any render process thread. +// +pub struct CefV8Exception { + c_object: *mut cef_v8exception_t, +} + +impl Clone for CefV8Exception { + fn clone(&self) -> CefV8Exception{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8Exception { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8Exception { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8Exception { + pub unsafe fn from_c_object(c_object: *mut cef_v8exception_t) -> CefV8Exception { + CefV8Exception { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8exception_t) -> CefV8Exception { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8Exception { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8exception_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8exception_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the exception message. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_message(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_message.unwrap())( + self.c_object)) + } + } + + // + // Returns the line of source code that the exception occurred within. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_source_line(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_source_line.unwrap())( + self.c_object)) + } + } + + // + // Returns the resource name for the script from where the function causing + // the error originates. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_script_resource_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_script_resource_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the 1-based number of the line where the error occurred or 0 if the + // line number is unknown. + // + pub fn get_line_number(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_line_number.unwrap())( + self.c_object)) + } + } + + // + // Returns the index within the script of the first character where the error + // occurred. + // + pub fn get_start_position(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_start_position.unwrap())( + self.c_object)) + } + } + + // + // Returns the index within the script of the last character where the error + // occurred. + // + pub fn get_end_position(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_end_position.unwrap())( + self.c_object)) + } + } + + // + // Returns the index within the line of the first character where the error + // occurred. + // + pub fn get_start_column(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_start_column.unwrap())( + self.c_object)) + } + } + + // + // Returns the index within the line of the last character where the error + // occurred. + // + pub fn get_end_column(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_end_column.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_v8exception_t> for CefV8Exception { + fn to_c(rust_object: CefV8Exception) -> *mut cef_v8exception_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8exception_t) -> CefV8Exception { + CefV8Exception::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8exception_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8exception_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8exception_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8Exception::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a V8 value handle. V8 handles can only be accessed +// from the thread on which they are created. Valid threads for creating a V8 +// handle include the render process main thread (TID_RENDERER) and WebWorker +// threads. A task runner for posting tasks on the associated thread can be +// retrieved via the cef_v8context_t::get_task_runner() function. +// +#[repr(C)] +pub struct _cef_v8value_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // True if the value type is undefined. + // + pub is_undefined: Option libc::c_int>, + + // + // True if the value type is null. + // + pub is_null: Option libc::c_int>, + + // + // True if the value type is bool. + // + pub is_bool: Option libc::c_int>, + + // + // True if the value type is int. + // + pub is_int: Option libc::c_int>, + + // + // True if the value type is unsigned int. + // + pub is_uint: Option libc::c_int>, + + // + // True if the value type is double. + // + pub is_double: Option libc::c_int>, + + // + // True if the value type is Date. + // + pub is_date: Option libc::c_int>, + + // + // True if the value type is string. + // + pub is_string: Option libc::c_int>, + + // + // True if the value type is object. + // + pub is_object: Option libc::c_int>, + + // + // True if the value type is array. + // + pub is_array: Option libc::c_int>, + + // + // True if the value type is function. + // + pub is_function: Option libc::c_int>, + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub is_same: Option libc::c_int>, + + // + // Return a bool value. The underlying data will be converted to if + // necessary. + // + pub get_bool_value: Option libc::c_int>, + + // + // Return an int value. The underlying data will be converted to if + // necessary. + // + pub get_int_value: Option i32>, + + // + // Return an unisgned int value. The underlying data will be converted to if + // necessary. + // + pub get_uint_value: Option u32>, + + // + // Return a double value. The underlying data will be converted to if + // necessary. + // + pub get_double_value: Option libc::c_double>, + + // + // Return a Date value. The underlying data will be converted to if + // necessary. + // + pub get_date_value: Option types::cef_time_t>, + + // + // Return a string value. The underlying data will be converted to if + // necessary. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_string_value: Option types::cef_string_userfree_t>, + + + // OBJECT METHODS - These functions are only available on objects. Arrays and + // functions are also objects. String- and integer-based keys can be used + // interchangably with the framework converting between them as necessary. + + // + // Returns true (1) if this is a user created object. + // + pub is_user_created: Option libc::c_int>, + + // + // Returns true (1) if the last function call resulted in an exception. This + // attribute exists only in the scope of the current CEF value object. + // + pub has_exception: Option libc::c_int>, + + // + // Returns the exception resulting from the last function call. This attribute + // exists only in the scope of the current CEF value object. + // + pub get_exception: Option *mut interfaces::cef_v8exception_t>, + + // + // Clears the last exception and returns true (1) on success. + // + pub clear_exception: Option libc::c_int>, + + // + // Returns true (1) if this object will re-throw future exceptions. This + // attribute exists only in the scope of the current CEF value object. + // + pub will_rethrow_exceptions: Option libc::c_int>, + + // + // Set whether this object will re-throw future exceptions. By default + // exceptions are not re-thrown. If a exception is re-thrown the current + // context should not be accessed again until after the exception has been + // caught and not re-thrown. Returns true (1) on success. This attribute + // exists only in the scope of the current CEF value object. + // + pub set_rethrow_exceptions: Option libc::c_int>, + + // + // Returns true (1) if the object has a value with the specified identifier. + // + pub has_value_bykey: Option libc::c_int>, + + // + // Returns true (1) if the object has a value with the specified identifier. + // + pub has_value_byindex: Option libc::c_int>, + + // + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only and don't-delete values this function + // will return true (1) even though deletion failed. + // + pub delete_value_bykey: Option libc::c_int>, + + // + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly, deletion + // fails or an exception is thrown. For read-only and don't-delete values this + // function will return true (1) even though deletion failed. + // + pub delete_value_byindex: Option libc::c_int>, + + // + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. + // + pub get_value_bykey: Option *mut interfaces::cef_v8value_t>, + + // + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. + // + pub get_value_byindex: Option *mut interfaces::cef_v8value_t>, + + // + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. + // + pub set_value_bykey: Option libc::c_int>, + + // + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. + // + pub set_value_byindex: Option libc::c_int>, + + // + // Registers an identifier and returns true (1) on success. Access to the + // identifier will be forwarded to the cef_v8accessor_t instance passed to + // cef_v8value_t::cef_v8value_create_object(). Returns false (0) if this + // function is called incorrectly or an exception is thrown. For read-only + // values this function will return true (1) even though assignment failed. + // + pub set_value_byaccessor: Option libc::c_int>, + + // + // Read the keys for the object's values into the specified vector. Integer- + // based keys will also be returned as strings. + // + pub get_keys: Option libc::c_int>, + + // + // Sets the user data for this object and returns true (1) on success. Returns + // false (0) if this function is called incorrectly. This function can only be + // called on user created objects. + // + pub set_user_data: Option libc::c_int>, + + // + // Returns the user data, if any, assigned to this object. + // + pub get_user_data: Option *mut interfaces::cef_base_t>, + + // + // Returns the amount of externally allocated memory registered for the + // object. + // + pub get_externally_allocated_memory: Option libc::c_int>, + + // + // Adjusts the amount of registered external memory for the object. Used to + // give V8 an indication of the amount of externally allocated memory that is + // kept alive by JavaScript objects. V8 uses this information to decide when + // to perform global garbage collection. Each cef_v8value_t tracks the amount + // of external memory associated with it and automatically decreases the + // global total by the appropriate amount on its destruction. + // |change_in_bytes| specifies the number of bytes to adjust by. This function + // returns the number of bytes associated with the object after the + // adjustment. This function can only be called on user created objects. + // + pub adjust_externally_allocated_memory: Option libc::c_int>, + + + // ARRAY METHODS - These functions are only available on arrays. + + // + // Returns the number of elements in the array. + // + pub get_array_length: Option libc::c_int>, + + + // FUNCTION METHODS - These functions are only available on functions. + + // + // Returns the function name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_function_name: Option types::cef_string_userfree_t>, + + // + // Returns the function handler or NULL if not a CEF-created function. + // + pub get_function_handler: Option *mut interfaces::cef_v8handler_t>, + + // + // Execute the function using the current V8 context. This function should + // only be called from within the scope of a cef_v8handler_t or + // cef_v8accessor_t callback, or in combination with calling enter() and + // exit() on a stored cef_v8context_t reference. |object| is the receiver + // ('this' object) of the function. If |object| is NULL the current context's + // global object will be used. |arguments| is the list of arguments that will + // be passed to the function. Returns the function return value on success. + // Returns NULL if this function is called incorrectly or an exception is + // thrown. + // + pub execute_function: Option *mut interfaces::cef_v8value_t>, + + // + // Execute the function using the specified V8 context. |object| is the + // receiver ('this' object) of the function. If |object| is NULL the specified + // context's global object will be used. |arguments| is the list of arguments + // that will be passed to the function. Returns the function return value on + // success. Returns NULL if this function is called incorrectly or an + // exception is thrown. + // + pub execute_function_with_context: Option *mut interfaces::cef_v8value_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8value_t = _cef_v8value_t; + + +// +// Structure representing a V8 value handle. V8 handles can only be accessed +// from the thread on which they are created. Valid threads for creating a V8 +// handle include the render process main thread (TID_RENDERER) and WebWorker +// threads. A task runner for posting tasks on the associated thread can be +// retrieved via the cef_v8context_t::get_task_runner() function. +// +pub struct CefV8Value { + c_object: *mut cef_v8value_t, +} + +impl Clone for CefV8Value { + fn clone(&self) -> CefV8Value{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8Value { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8Value { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8Value { + pub unsafe fn from_c_object(c_object: *mut cef_v8value_t) -> CefV8Value { + CefV8Value { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8value_t) -> CefV8Value { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8Value { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8value_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8value_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is undefined. + // + pub fn is_undefined(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_undefined.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is null. + // + pub fn is_null(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_null.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is bool. + // + pub fn is_bool(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_bool.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is int. + // + pub fn is_int(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_int.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is unsigned int. + // + pub fn is_uint(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_uint.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is double. + // + pub fn is_double(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_double.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is Date. + // + pub fn is_date(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_date.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is string. + // + pub fn is_string(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_string.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is object. + // + pub fn is_object(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_object.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is array. + // + pub fn is_array(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_array.unwrap())( + self.c_object)) + } + } + + // + // True if the value type is function. + // + pub fn is_function(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_function.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + // + pub fn is_same(&self, that: interfaces::CefV8Value) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_same.unwrap())( + self.c_object, + CefWrap::to_c(that))) + } + } + + // + // Return a bool value. The underlying data will be converted to if + // necessary. + // + pub fn get_bool_value(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_bool_value.unwrap())( + self.c_object)) + } + } + + // + // Return an int value. The underlying data will be converted to if + // necessary. + // + pub fn get_int_value(&self) -> i32 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_int_value.unwrap())( + self.c_object)) + } + } + + // + // Return an unisgned int value. The underlying data will be converted to if + // necessary. + // + pub fn get_uint_value(&self) -> u32 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_uint_value.unwrap())( + self.c_object)) + } + } + + // + // Return a double value. The underlying data will be converted to if + // necessary. + // + pub fn get_double_value(&self) -> libc::c_double { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_double_value.unwrap())( + self.c_object)) + } + } + + // + // Return a Date value. The underlying data will be converted to if + // necessary. + // + pub fn get_date_value(&self) -> types::cef_time_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_date_value.unwrap())( + self.c_object)) + } + } + + // + // Return a string value. The underlying data will be converted to if + // necessary. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_string_value(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_string_value.unwrap())( + self.c_object)) + } + } + + + // OBJECT METHODS - These functions are only available on objects. Arrays and + // functions are also objects. String- and integer-based keys can be used + // interchangably with the framework converting between them as necessary. + + // + // Returns true (1) if this is a user created object. + // + pub fn is_user_created(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_user_created.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the last function call resulted in an exception. This + // attribute exists only in the scope of the current CEF value object. + // + pub fn has_exception(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_exception.unwrap())( + self.c_object)) + } + } + + // + // Returns the exception resulting from the last function call. This attribute + // exists only in the scope of the current CEF value object. + // + pub fn get_exception(&self) -> interfaces::CefV8Exception { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_exception.unwrap())( + self.c_object)) + } + } + + // + // Clears the last exception and returns true (1) on success. + // + pub fn clear_exception(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).clear_exception.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object will re-throw future exceptions. This + // attribute exists only in the scope of the current CEF value object. + // + pub fn will_rethrow_exceptions(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).will_rethrow_exceptions.unwrap())( + self.c_object)) + } + } + + // + // Set whether this object will re-throw future exceptions. By default + // exceptions are not re-thrown. If a exception is re-thrown the current + // context should not be accessed again until after the exception has been + // caught and not re-thrown. Returns true (1) on success. This attribute + // exists only in the scope of the current CEF value object. + // + pub fn set_rethrow_exceptions(&self, rethrow: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_rethrow_exceptions.unwrap())( + self.c_object, + CefWrap::to_c(rethrow))) + } + } + + // + // Returns true (1) if the object has a value with the specified identifier. + // + pub fn has_value_bykey(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_value_bykey.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns true (1) if the object has a value with the specified identifier. + // + pub fn has_value_byindex(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_value_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only and don't-delete values this function + // will return true (1) even though deletion failed. + // + pub fn delete_value_bykey(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).delete_value_bykey.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly, deletion + // fails or an exception is thrown. For read-only and don't-delete values this + // function will return true (1) even though deletion failed. + // + pub fn delete_value_byindex(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).delete_value_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. + // + pub fn get_value_bykey(&self, key: &str) -> interfaces::CefV8Value { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_value_bykey.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. + // + pub fn get_value_byindex(&self, + index: libc::c_int) -> interfaces::CefV8Value { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_value_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. + // + pub fn set_value_bykey(&self, key: &str, value: interfaces::CefV8Value, + attribute: types::cef_v8_propertyattribute_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_value_bykey.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value), + CefWrap::to_c(attribute))) + } + } + + // + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. + // + pub fn set_value_byindex(&self, index: libc::c_int, + value: interfaces::CefV8Value) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_value_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Registers an identifier and returns true (1) on success. Access to the + // identifier will be forwarded to the cef_v8accessor_t instance passed to + // cef_v8value_t::cef_v8value_create_object(). Returns false (0) if this + // function is called incorrectly or an exception is thrown. For read-only + // values this function will return true (1) even though assignment failed. + // + pub fn set_value_byaccessor(&self, key: &str, + settings: types::cef_v8_accesscontrol_t, + attribute: types::cef_v8_propertyattribute_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_value_byaccessor.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(settings), + CefWrap::to_c(attribute))) + } + } + + // + // Read the keys for the object's values into the specified vector. Integer- + // based keys will also be returned as strings. + // + pub fn get_keys(&self, keys: Vec) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_keys.unwrap())( + self.c_object, + CefWrap::to_c(keys))) + } + } + + // + // Sets the user data for this object and returns true (1) on success. Returns + // false (0) if this function is called incorrectly. This function can only be + // called on user created objects. + // + pub fn set_user_data(&self, user_data: interfaces::CefBase) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_user_data.unwrap())( + self.c_object, + CefWrap::to_c(user_data))) + } + } + + // + // Returns the user data, if any, assigned to this object. + // + pub fn get_user_data(&self) -> interfaces::CefBase { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_user_data.unwrap())( + self.c_object)) + } + } + + // + // Returns the amount of externally allocated memory registered for the + // object. + // + pub fn get_externally_allocated_memory(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_externally_allocated_memory.unwrap())( + self.c_object)) + } + } + + // + // Adjusts the amount of registered external memory for the object. Used to + // give V8 an indication of the amount of externally allocated memory that is + // kept alive by JavaScript objects. V8 uses this information to decide when + // to perform global garbage collection. Each cef_v8value_t tracks the amount + // of external memory associated with it and automatically decreases the + // global total by the appropriate amount on its destruction. + // |change_in_bytes| specifies the number of bytes to adjust by. This function + // returns the number of bytes associated with the object after the + // adjustment. This function can only be called on user created objects. + // + pub fn adjust_externally_allocated_memory(&self, + change_in_bytes: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).adjust_externally_allocated_memory.unwrap())( + self.c_object, + CefWrap::to_c(change_in_bytes))) + } + } + + + // ARRAY METHODS - These functions are only available on arrays. + + // + // Returns the number of elements in the array. + // + pub fn get_array_length(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_array_length.unwrap())( + self.c_object)) + } + } + + + // FUNCTION METHODS - These functions are only available on functions. + + // + // Returns the function name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_function_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_function_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the function handler or NULL if not a CEF-created function. + // + pub fn get_function_handler(&self) -> interfaces::CefV8Handler { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_function_handler.unwrap())( + self.c_object)) + } + } + + // + // Execute the function using the current V8 context. This function should + // only be called from within the scope of a cef_v8handler_t or + // cef_v8accessor_t callback, or in combination with calling enter() and + // exit() on a stored cef_v8context_t reference. |object| is the receiver + // ('this' object) of the function. If |object| is NULL the current context's + // global object will be used. |arguments| is the list of arguments that will + // be passed to the function. Returns the function return value on success. + // Returns NULL if this function is called incorrectly or an exception is + // thrown. + // + pub fn execute_function(&self, object: interfaces::CefV8Value, + arguments_count: libc::size_t, + arguments: *const interfaces::CefV8Value) -> interfaces::CefV8Value { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).execute_function.unwrap())( + self.c_object, + CefWrap::to_c(object), + CefWrap::to_c(arguments_count), + CefWrap::to_c(arguments))) + } + } + + // + // Execute the function using the specified V8 context. |object| is the + // receiver ('this' object) of the function. If |object| is NULL the specified + // context's global object will be used. |arguments| is the list of arguments + // that will be passed to the function. Returns the function return value on + // success. Returns NULL if this function is called incorrectly or an + // exception is thrown. + // + pub fn execute_function_with_context(&self, context: interfaces::CefV8Context, + object: interfaces::CefV8Value, arguments_count: libc::size_t, + arguments: *const interfaces::CefV8Value) -> interfaces::CefV8Value { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).execute_function_with_context.unwrap())( + self.c_object, + CefWrap::to_c(context), + CefWrap::to_c(object), + CefWrap::to_c(arguments_count), + CefWrap::to_c(arguments))) + } + } + + // + // Create a new cef_v8value_t object of type undefined. + // + pub fn create_undefined() -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_undefined( +)) + } + } + + // + // Create a new cef_v8value_t object of type null. + // + pub fn create_null() -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_null( +)) + } + } + + // + // Create a new cef_v8value_t object of type bool. + // + pub fn create_bool(value: libc::c_int) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_bool( + CefWrap::to_c(value))) + } + } + + // + // Create a new cef_v8value_t object of type int. + // + pub fn create_int(value: i32) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_int( + CefWrap::to_c(value))) + } + } + + // + // Create a new cef_v8value_t object of type unsigned int. + // + pub fn create_uint(value: u32) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_uint( + CefWrap::to_c(value))) + } + } + + // + // Create a new cef_v8value_t object of type double. + // + pub fn create_double(value: libc::c_double) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_double( + CefWrap::to_c(value))) + } + } + + // + // Create a new cef_v8value_t object of type Date. This function should only + // be called from within the scope of a cef_v8context_tHandler, + // cef_v8handler_t or cef_v8accessor_t callback, or in combination with + // calling enter() and exit() on a stored cef_v8context_t reference. + // + pub fn create_date(date: &types::cef_time_t) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_date( + CefWrap::to_c(date))) + } + } + + // + // Create a new cef_v8value_t object of type string. + // + pub fn create_string(value: &str) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_string( + CefWrap::to_c(value))) + } + } + + // + // Create a new cef_v8value_t object of type object with optional accessor. + // This function should only be called from within the scope of a + // cef_v8context_tHandler, cef_v8handler_t or cef_v8accessor_t callback, or in + // combination with calling enter() and exit() on a stored cef_v8context_t + // reference. + // + pub fn create_object( + accessor: interfaces::CefV8Accessor) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_object( + CefWrap::to_c(accessor))) + } + } + + // + // Create a new cef_v8value_t object of type array with the specified + // |length|. If |length| is negative the returned array will have length 0. + // This function should only be called from within the scope of a + // cef_v8context_tHandler, cef_v8handler_t or cef_v8accessor_t callback, or in + // combination with calling enter() and exit() on a stored cef_v8context_t + // reference. + // + pub fn create_array(length: libc::c_int) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_array( + CefWrap::to_c(length))) + } + } + + // + // Create a new cef_v8value_t object of type function. This function should + // only be called from within the scope of a cef_v8context_tHandler, + // cef_v8handler_t or cef_v8accessor_t callback, or in combination with + // calling enter() and exit() on a stored cef_v8context_t reference. + // + pub fn create_function(name: &str, + handler: interfaces::CefV8Handler) -> interfaces::CefV8Value { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8value_create_function( + CefWrap::to_c(name), + CefWrap::to_c(handler))) + } + } +} + +impl CefWrap<*mut cef_v8value_t> for CefV8Value { + fn to_c(rust_object: CefV8Value) -> *mut cef_v8value_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8value_t) -> CefV8Value { + CefV8Value::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8value_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8value_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8value_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8Value::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a V8 stack trace handle. V8 handles can only be +// accessed from the thread on which they are created. Valid threads for +// creating a V8 handle include the render process main thread (TID_RENDERER) +// and WebWorker threads. A task runner for posting tasks on the associated +// thread can be retrieved via the cef_v8context_t::get_task_runner() function. +// +#[repr(C)] +pub struct _cef_v8stack_trace_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns the number of stack frames. + // + pub get_frame_count: Option libc::c_int>, + + // + // Returns the stack frame at the specified 0-based index. + // + pub get_frame: Option *mut interfaces::cef_v8stack_frame_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8stack_trace_t = _cef_v8stack_trace_t; + + +// +// Structure representing a V8 stack trace handle. V8 handles can only be +// accessed from the thread on which they are created. Valid threads for +// creating a V8 handle include the render process main thread (TID_RENDERER) +// and WebWorker threads. A task runner for posting tasks on the associated +// thread can be retrieved via the cef_v8context_t::get_task_runner() function. +// +pub struct CefV8StackTrace { + c_object: *mut cef_v8stack_trace_t, +} + +impl Clone for CefV8StackTrace { + fn clone(&self) -> CefV8StackTrace{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8StackTrace { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8StackTrace { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8StackTrace { + pub unsafe fn from_c_object(c_object: *mut cef_v8stack_trace_t) -> CefV8StackTrace { + CefV8StackTrace { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8stack_trace_t) -> CefV8StackTrace { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8StackTrace { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8stack_trace_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8stack_trace_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns the number of stack frames. + // + pub fn get_frame_count(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame_count.unwrap())( + self.c_object)) + } + } + + // + // Returns the stack frame at the specified 0-based index. + // + pub fn get_frame(&self, index: libc::c_int) -> interfaces::CefV8StackFrame { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_frame.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the stack trace for the currently active context. |frame_limit| is + // the maximum number of frames that will be captured. + // + pub fn get_current(frame_limit: libc::c_int) -> interfaces::CefV8StackTrace { + unsafe { + CefWrap::to_rust( + ::v8::cef_v8stack_trace_get_current( + CefWrap::to_c(frame_limit))) + } + } +} + +impl CefWrap<*mut cef_v8stack_trace_t> for CefV8StackTrace { + fn to_c(rust_object: CefV8StackTrace) -> *mut cef_v8stack_trace_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8stack_trace_t) -> CefV8StackTrace { + CefV8StackTrace::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8stack_trace_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8stack_trace_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8stack_trace_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8StackTrace::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a V8 stack frame handle. V8 handles can only be +// accessed from the thread on which they are created. Valid threads for +// creating a V8 handle include the render process main thread (TID_RENDERER) +// and WebWorker threads. A task runner for posting tasks on the associated +// thread can be retrieved via the cef_v8context_t::get_task_runner() function. +// +#[repr(C)] +pub struct _cef_v8stack_frame_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns the name of the resource script that contains the function. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_script_name: Option types::cef_string_userfree_t>, + + // + // Returns the name of the resource script that contains the function or the + // sourceURL value if the script name is undefined and its source ends with a + // "//@ sourceURL=..." string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_script_name_or_source_url: Option types::cef_string_userfree_t>, + + // + // Returns the name of the function. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_function_name: Option types::cef_string_userfree_t>, + + // + // Returns the 1-based line number for the function call or 0 if unknown. + // + pub get_line_number: Option libc::c_int>, + + // + // Returns the 1-based column offset on the line for the function call or 0 if + // unknown. + // + pub get_column: Option libc::c_int>, + + // + // Returns true (1) if the function was compiled using eval(). + // + pub is_eval: Option libc::c_int>, + + // + // Returns true (1) if the function was called as a constructor via "new". + // + pub is_constructor: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_v8stack_frame_t = _cef_v8stack_frame_t; + + +// +// Structure representing a V8 stack frame handle. V8 handles can only be +// accessed from the thread on which they are created. Valid threads for +// creating a V8 handle include the render process main thread (TID_RENDERER) +// and WebWorker threads. A task runner for posting tasks on the associated +// thread can be retrieved via the cef_v8context_t::get_task_runner() function. +// +pub struct CefV8StackFrame { + c_object: *mut cef_v8stack_frame_t, +} + +impl Clone for CefV8StackFrame { + fn clone(&self) -> CefV8StackFrame{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefV8StackFrame { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefV8StackFrame { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefV8StackFrame { + pub unsafe fn from_c_object(c_object: *mut cef_v8stack_frame_t) -> CefV8StackFrame { + CefV8StackFrame { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_v8stack_frame_t) -> CefV8StackFrame { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefV8StackFrame { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_v8stack_frame_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_v8stack_frame_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if the underlying handle is valid and it can be accessed + // on the current thread. Do not call any other functions if this function + // returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns the name of the resource script that contains the function. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_script_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_script_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the name of the resource script that contains the function or the + // sourceURL value if the script name is undefined and its source ends with a + // "//@ sourceURL=..." string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_script_name_or_source_url(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_script_name_or_source_url.unwrap())( + self.c_object)) + } + } + + // + // Returns the name of the function. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_function_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_function_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the 1-based line number for the function call or 0 if unknown. + // + pub fn get_line_number(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_line_number.unwrap())( + self.c_object)) + } + } + + // + // Returns the 1-based column offset on the line for the function call or 0 if + // unknown. + // + pub fn get_column(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_column.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the function was compiled using eval(). + // + pub fn is_eval(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_eval.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the function was called as a constructor via "new". + // + pub fn is_constructor(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_constructor.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_v8stack_frame_t> for CefV8StackFrame { + fn to_c(rust_object: CefV8StackFrame) -> *mut cef_v8stack_frame_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_v8stack_frame_t) -> CefV8StackFrame { + CefV8StackFrame::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_v8stack_frame_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_v8stack_frame_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_v8stack_frame_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefV8StackFrame::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_values.rs b/ports/cef/interfaces/cef_values.rs new file mode 100644 index 00000000000..e4b2a95736b --- /dev/null +++ b/ports/cef/interfaces/cef_values.rs @@ -0,0 +1,1685 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure representing a binary value. Can be used on any process and thread. +// +#[repr(C)] +pub struct _cef_binary_value_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if this object is currently owned by another object. + // + pub is_owned: Option libc::c_int>, + + // + // Returns a copy of this object. The data in this object will also be copied. + // + pub copy: Option *mut interfaces::cef_binary_value_t>, + + // + // Returns the data size. + // + pub get_size: Option libc::size_t>, + + // + // Read up to |buffer_size| number of bytes into |buffer|. Reading begins at + // the specified byte |data_offset|. Returns the number of bytes read. + // + pub get_data: Option libc::size_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_binary_value_t = _cef_binary_value_t; + + +// +// Structure representing a binary value. Can be used on any process and thread. +// +pub struct CefBinaryValue { + c_object: *mut cef_binary_value_t, +} + +impl Clone for CefBinaryValue { + fn clone(&self) -> CefBinaryValue{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefBinaryValue { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefBinaryValue { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefBinaryValue { + pub unsafe fn from_c_object(c_object: *mut cef_binary_value_t) -> CefBinaryValue { + CefBinaryValue { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_binary_value_t) -> CefBinaryValue { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefBinaryValue { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_binary_value_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_binary_value_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is currently owned by another object. + // + pub fn is_owned(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_owned.unwrap())( + self.c_object)) + } + } + + // + // Returns a copy of this object. The data in this object will also be copied. + // + pub fn copy(&self) -> interfaces::CefBinaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Returns the data size. + // + pub fn get_size(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_size.unwrap())( + self.c_object)) + } + } + + // + // Read up to |buffer_size| number of bytes into |buffer|. Reading begins at + // the specified byte |data_offset|. Returns the number of bytes read. + // + pub fn get_data(&self, buffer: &mut (), buffer_size: libc::size_t, + data_offset: libc::size_t) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_data.unwrap())( + self.c_object, + CefWrap::to_c(buffer), + CefWrap::to_c(buffer_size), + CefWrap::to_c(data_offset))) + } + } + + // + // Creates a new object that is not owned by any other object. The specified + // |data| will be copied. + // + pub fn create(data: &(), + data_size: libc::size_t) -> interfaces::CefBinaryValue { + unsafe { + CefWrap::to_rust( + ::values::cef_binary_value_create( + CefWrap::to_c(data), + CefWrap::to_c(data_size))) + } + } +} + +impl CefWrap<*mut cef_binary_value_t> for CefBinaryValue { + fn to_c(rust_object: CefBinaryValue) -> *mut cef_binary_value_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_binary_value_t) -> CefBinaryValue { + CefBinaryValue::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_binary_value_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_binary_value_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_binary_value_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefBinaryValue::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a dictionary value. Can be used on any process and +// thread. +// +#[repr(C)] +pub struct _cef_dictionary_value_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if this object is currently owned by another object. + // + pub is_owned: Option libc::c_int>, + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns a writable copy of this object. If |exclude_NULL_children| is true + // (1) any NULL dictionaries or lists will be excluded from the copy. + // + pub copy: Option *mut interfaces::cef_dictionary_value_t>, + + // + // Returns the number of values. + // + pub get_size: Option libc::size_t>, + + // + // Removes all values. Returns true (1) on success. + // + pub clear: Option libc::c_int>, + + // + // Returns true (1) if the current dictionary has a value for the given key. + // + pub has_key: Option libc::c_int>, + + // + // Reads all keys for this dictionary into the specified vector. + // + pub get_keys: Option libc::c_int>, + + // + // Removes the value at the specified key. Returns true (1) is the value was + // removed successfully. + // + pub remove: Option libc::c_int>, + + // + // Returns the value type for the specified key. + // + pub get_type: Option interfaces::cef_value_type_t>, + + // + // Returns the value at the specified key as type bool. + // + pub get_bool: Option libc::c_int>, + + // + // Returns the value at the specified key as type int. + // + pub get_int: Option libc::c_int>, + + // + // Returns the value at the specified key as type double. + // + pub get_double: Option libc::c_double>, + + // + // Returns the value at the specified key as type string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_string: Option types::cef_string_userfree_t>, + + // + // Returns the value at the specified key as type binary. + // + pub get_binary: Option *mut interfaces::cef_binary_value_t>, + + // + // Returns the value at the specified key as type dictionary. + // + pub get_dictionary: Option *mut interfaces::cef_dictionary_value_t>, + + // + // Returns the value at the specified key as type list. + // + pub get_list: Option *mut interfaces::cef_list_value_t>, + + // + // Sets the value at the specified key as type null. Returns true (1) if the + // value was set successfully. + // + pub set_null: Option libc::c_int>, + + // + // Sets the value at the specified key as type bool. Returns true (1) if the + // value was set successfully. + // + pub set_bool: Option libc::c_int>, + + // + // Sets the value at the specified key as type int. Returns true (1) if the + // value was set successfully. + // + pub set_int: Option libc::c_int>, + + // + // Sets the value at the specified key as type double. Returns true (1) if the + // value was set successfully. + // + pub set_double: Option libc::c_int>, + + // + // Sets the value at the specified key as type string. Returns true (1) if the + // value was set successfully. + // + pub set_string: Option libc::c_int>, + + // + // Sets the value at the specified key as type binary. Returns true (1) if the + // value was set successfully. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub set_binary: Option libc::c_int>, + + // + // Sets the value at the specified key as type dict. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub set_dictionary: Option libc::c_int>, + + // + // Sets the value at the specified key as type list. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub set_list: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_dictionary_value_t = _cef_dictionary_value_t; + + +// +// Structure representing a dictionary value. Can be used on any process and +// thread. +// +pub struct CefDictionaryValue { + c_object: *mut cef_dictionary_value_t, +} + +impl Clone for CefDictionaryValue { + fn clone(&self) -> CefDictionaryValue{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefDictionaryValue { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefDictionaryValue { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefDictionaryValue { + pub unsafe fn from_c_object(c_object: *mut cef_dictionary_value_t) -> CefDictionaryValue { + CefDictionaryValue { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_dictionary_value_t) -> CefDictionaryValue { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefDictionaryValue { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_dictionary_value_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_dictionary_value_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is currently owned by another object. + // + pub fn is_owned(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_owned.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns a writable copy of this object. If |exclude_NULL_children| is true + // (1) any NULL dictionaries or lists will be excluded from the copy. + // + pub fn copy(&self, + exclude_empty_children: libc::c_int) -> interfaces::CefDictionaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object, + CefWrap::to_c(exclude_empty_children))) + } + } + + // + // Returns the number of values. + // + pub fn get_size(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_size.unwrap())( + self.c_object)) + } + } + + // + // Removes all values. Returns true (1) on success. + // + pub fn clear(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).clear.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the current dictionary has a value for the given key. + // + pub fn has_key(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_key.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Reads all keys for this dictionary into the specified vector. + // + pub fn get_keys(&self, keys: Vec) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_keys.unwrap())( + self.c_object, + CefWrap::to_c(keys))) + } + } + + // + // Removes the value at the specified key. Returns true (1) is the value was + // removed successfully. + // + pub fn remove(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value type for the specified key. + // + pub fn get_type(&self, key: &str) -> interfaces::CefValueType { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type bool. + // + pub fn get_bool(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_bool.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type int. + // + pub fn get_int(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_int.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type double. + // + pub fn get_double(&self, key: &str) -> libc::c_double { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_double.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_string(&self, key: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_string.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type binary. + // + pub fn get_binary(&self, key: &str) -> interfaces::CefBinaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_binary.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type dictionary. + // + pub fn get_dictionary(&self, key: &str) -> interfaces::CefDictionaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_dictionary.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Returns the value at the specified key as type list. + // + pub fn get_list(&self, key: &str) -> interfaces::CefListValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_list.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Sets the value at the specified key as type null. Returns true (1) if the + // value was set successfully. + // + pub fn set_null(&self, key: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_null.unwrap())( + self.c_object, + CefWrap::to_c(key))) + } + } + + // + // Sets the value at the specified key as type bool. Returns true (1) if the + // value was set successfully. + // + pub fn set_bool(&self, key: &str, value: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_bool.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type int. Returns true (1) if the + // value was set successfully. + // + pub fn set_int(&self, key: &str, value: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_int.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type double. Returns true (1) if the + // value was set successfully. + // + pub fn set_double(&self, key: &str, value: libc::c_double) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_double.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type string. Returns true (1) if the + // value was set successfully. + // + pub fn set_string(&self, key: &str, value: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_string.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type binary. Returns true (1) if the + // value was set successfully. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub fn set_binary(&self, key: &str, + value: interfaces::CefBinaryValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_binary.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type dict. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub fn set_dictionary(&self, key: &str, + value: interfaces::CefDictionaryValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_dictionary.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified key as type list. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub fn set_list(&self, key: &str, + value: interfaces::CefListValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_list.unwrap())( + self.c_object, + CefWrap::to_c(key), + CefWrap::to_c(value))) + } + } + + // + // Creates a new object that is not owned by any other object. + // + pub fn create() -> interfaces::CefDictionaryValue { + unsafe { + CefWrap::to_rust( + ::values::cef_dictionary_value_create( +)) + } + } +} + +impl CefWrap<*mut cef_dictionary_value_t> for CefDictionaryValue { + fn to_c(rust_object: CefDictionaryValue) -> *mut cef_dictionary_value_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_dictionary_value_t) -> CefDictionaryValue { + CefDictionaryValue::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_dictionary_value_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_dictionary_value_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_dictionary_value_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefDictionaryValue::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure representing a list value. Can be used on any process and thread. +// +#[repr(C)] +pub struct _cef_list_value_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub is_valid: Option libc::c_int>, + + // + // Returns true (1) if this object is currently owned by another object. + // + pub is_owned: Option libc::c_int>, + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub is_read_only: Option libc::c_int>, + + // + // Returns a writable copy of this object. + // + pub copy: Option *mut interfaces::cef_list_value_t>, + + // + // Sets the number of values. If the number of values is expanded all new + // value slots will default to type null. Returns true (1) on success. + // + pub set_size: Option libc::c_int>, + + // + // Returns the number of values. + // + pub get_size: Option libc::size_t>, + + // + // Removes all values. Returns true (1) on success. + // + pub clear: Option libc::c_int>, + + // + // Removes the value at the specified index. + // + pub remove: Option libc::c_int>, + + // + // Returns the value type at the specified index. + // + pub get_type: Option interfaces::cef_value_type_t>, + + // + // Returns the value at the specified index as type bool. + // + pub get_bool: Option libc::c_int>, + + // + // Returns the value at the specified index as type int. + // + pub get_int: Option libc::c_int>, + + // + // Returns the value at the specified index as type double. + // + pub get_double: Option libc::c_double>, + + // + // Returns the value at the specified index as type string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_string: Option types::cef_string_userfree_t>, + + // + // Returns the value at the specified index as type binary. + // + pub get_binary: Option *mut interfaces::cef_binary_value_t>, + + // + // Returns the value at the specified index as type dictionary. + // + pub get_dictionary: Option *mut interfaces::cef_dictionary_value_t>, + + // + // Returns the value at the specified index as type list. + // + pub get_list: Option *mut interfaces::cef_list_value_t>, + + // + // Sets the value at the specified index as type null. Returns true (1) if the + // value was set successfully. + // + pub set_null: Option libc::c_int>, + + // + // Sets the value at the specified index as type bool. Returns true (1) if the + // value was set successfully. + // + pub set_bool: Option libc::c_int>, + + // + // Sets the value at the specified index as type int. Returns true (1) if the + // value was set successfully. + // + pub set_int: Option libc::c_int>, + + // + // Sets the value at the specified index as type double. Returns true (1) if + // the value was set successfully. + // + pub set_double: Option libc::c_int>, + + // + // Sets the value at the specified index as type string. Returns true (1) if + // the value was set successfully. + // + pub set_string: Option libc::c_int>, + + // + // Sets the value at the specified index as type binary. Returns true (1) if + // the value was set successfully. After calling this function the |value| + // object will no longer be valid. If |value| is currently owned by another + // object then the value will be copied and the |value| reference will not + // change. Otherwise, ownership will be transferred to this object and the + // |value| reference will be invalidated. + // + pub set_binary: Option libc::c_int>, + + // + // Sets the value at the specified index as type dict. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub set_dictionary: Option libc::c_int>, + + // + // Sets the value at the specified index as type list. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub set_list: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_list_value_t = _cef_list_value_t; + + +// +// Structure representing a list value. Can be used on any process and thread. +// +pub struct CefListValue { + c_object: *mut cef_list_value_t, +} + +impl Clone for CefListValue { + fn clone(&self) -> CefListValue{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefListValue { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefListValue { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefListValue { + pub unsafe fn from_c_object(c_object: *mut cef_list_value_t) -> CefListValue { + CefListValue { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_list_value_t) -> CefListValue { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefListValue { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_list_value_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_list_value_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + // + pub fn is_valid(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_valid.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if this object is currently owned by another object. + // + pub fn is_owned(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_owned.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the values of this object are read-only. Some APIs may + // expose read-only objects. + // + pub fn is_read_only(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_read_only.unwrap())( + self.c_object)) + } + } + + // + // Returns a writable copy of this object. + // + pub fn copy(&self) -> interfaces::CefListValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).copy.unwrap())( + self.c_object)) + } + } + + // + // Sets the number of values. If the number of values is expanded all new + // value slots will default to type null. Returns true (1) on success. + // + pub fn set_size(&self, size: libc::size_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_size.unwrap())( + self.c_object, + CefWrap::to_c(size))) + } + } + + // + // Returns the number of values. + // + pub fn get_size(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_size.unwrap())( + self.c_object)) + } + } + + // + // Removes all values. Returns true (1) on success. + // + pub fn clear(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).clear.unwrap())( + self.c_object)) + } + } + + // + // Removes the value at the specified index. + // + pub fn remove(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).remove.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value type at the specified index. + // + pub fn get_type(&self, index: libc::c_int) -> interfaces::CefValueType { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type bool. + // + pub fn get_bool(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_bool.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type int. + // + pub fn get_int(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_int.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type double. + // + pub fn get_double(&self, index: libc::c_int) -> libc::c_double { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_double.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_string(&self, index: libc::c_int) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_string.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type binary. + // + pub fn get_binary(&self, index: libc::c_int) -> interfaces::CefBinaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_binary.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type dictionary. + // + pub fn get_dictionary(&self, + index: libc::c_int) -> interfaces::CefDictionaryValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_dictionary.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value at the specified index as type list. + // + pub fn get_list(&self, index: libc::c_int) -> interfaces::CefListValue { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_list.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Sets the value at the specified index as type null. Returns true (1) if the + // value was set successfully. + // + pub fn set_null(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_null.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Sets the value at the specified index as type bool. Returns true (1) if the + // value was set successfully. + // + pub fn set_bool(&self, index: libc::c_int, + value: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_bool.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type int. Returns true (1) if the + // value was set successfully. + // + pub fn set_int(&self, index: libc::c_int, value: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_int.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type double. Returns true (1) if + // the value was set successfully. + // + pub fn set_double(&self, index: libc::c_int, + value: libc::c_double) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_double.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type string. Returns true (1) if + // the value was set successfully. + // + pub fn set_string(&self, index: libc::c_int, value: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_string.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type binary. Returns true (1) if + // the value was set successfully. After calling this function the |value| + // object will no longer be valid. If |value| is currently owned by another + // object then the value will be copied and the |value| reference will not + // change. Otherwise, ownership will be transferred to this object and the + // |value| reference will be invalidated. + // + pub fn set_binary(&self, index: libc::c_int, + value: interfaces::CefBinaryValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_binary.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type dict. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub fn set_dictionary(&self, index: libc::c_int, + value: interfaces::CefDictionaryValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_dictionary.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Sets the value at the specified index as type list. Returns true (1) if the + // value was set successfully. After calling this function the |value| object + // will no longer be valid. If |value| is currently owned by another object + // then the value will be copied and the |value| reference will not change. + // Otherwise, ownership will be transferred to this object and the |value| + // reference will be invalidated. + // + pub fn set_list(&self, index: libc::c_int, + value: interfaces::CefListValue) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).set_list.unwrap())( + self.c_object, + CefWrap::to_c(index), + CefWrap::to_c(value))) + } + } + + // + // Creates a new object that is not owned by any other object. + // + pub fn create() -> interfaces::CefListValue { + unsafe { + CefWrap::to_rust( + ::values::cef_list_value_create( +)) + } + } +} + +impl CefWrap<*mut cef_list_value_t> for CefListValue { + fn to_c(rust_object: CefListValue) -> *mut cef_list_value_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_list_value_t) -> CefListValue { + CefListValue::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_list_value_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_list_value_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_list_value_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefListValue::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_web_plugin.rs b/ports/cef/interfaces/cef_web_plugin.rs new file mode 100644 index 00000000000..99dcbb97093 --- /dev/null +++ b/ports/cef/interfaces/cef_web_plugin.rs @@ -0,0 +1,544 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Information about a specific web plugin. +// +#[repr(C)] +pub struct _cef_web_plugin_info_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Returns the plugin name (i.e. Flash). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_name: Option types::cef_string_userfree_t>, + + // + // Returns the plugin file path (DLL/bundle/library). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_path: Option types::cef_string_userfree_t>, + + // + // Returns the version of the plugin (may be OS-specific). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_version: Option types::cef_string_userfree_t>, + + // + // Returns a description of the plugin from the version information. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_description: Option types::cef_string_userfree_t>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_web_plugin_info_t = _cef_web_plugin_info_t; + + +// +// Information about a specific web plugin. +// +pub struct CefWebPluginInfo { + c_object: *mut cef_web_plugin_info_t, +} + +impl Clone for CefWebPluginInfo { + fn clone(&self) -> CefWebPluginInfo{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefWebPluginInfo { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefWebPluginInfo { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefWebPluginInfo { + pub unsafe fn from_c_object(c_object: *mut cef_web_plugin_info_t) -> CefWebPluginInfo { + CefWebPluginInfo { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_web_plugin_info_t) -> CefWebPluginInfo { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefWebPluginInfo { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_web_plugin_info_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_web_plugin_info_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Returns the plugin name (i.e. Flash). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the plugin file path (DLL/bundle/library). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_path(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_path.unwrap())( + self.c_object)) + } + } + + // + // Returns the version of the plugin (may be OS-specific). + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_version(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_version.unwrap())( + self.c_object)) + } + } + + // + // Returns a description of the plugin from the version information. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_description(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_description.unwrap())( + self.c_object)) + } + } +} + +impl CefWrap<*mut cef_web_plugin_info_t> for CefWebPluginInfo { + fn to_c(rust_object: CefWebPluginInfo) -> *mut cef_web_plugin_info_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_info_t) -> CefWebPluginInfo { + CefWebPluginInfo::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_web_plugin_info_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_web_plugin_info_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_info_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefWebPluginInfo::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure to implement for visiting web plugin information. The functions of +// this structure will be called on the browser process UI thread. +// +#[repr(C)] +pub struct _cef_web_plugin_info_visitor_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be called once for each plugin. |count| is the 0-based + // index for the current plugin. |total| is the total number of plugins. + // Return false (0) to stop visiting plugins. This function may never be + // called if no plugins are found. + // + pub visit: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_web_plugin_info_visitor_t = _cef_web_plugin_info_visitor_t; + + +// +// Structure to implement for visiting web plugin information. The functions of +// this structure will be called on the browser process UI thread. +// +pub struct CefWebPluginInfoVisitor { + c_object: *mut cef_web_plugin_info_visitor_t, +} + +impl Clone for CefWebPluginInfoVisitor { + fn clone(&self) -> CefWebPluginInfoVisitor{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefWebPluginInfoVisitor { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefWebPluginInfoVisitor { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefWebPluginInfoVisitor { + pub unsafe fn from_c_object(c_object: *mut cef_web_plugin_info_visitor_t) -> CefWebPluginInfoVisitor { + CefWebPluginInfoVisitor { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_web_plugin_info_visitor_t) -> CefWebPluginInfoVisitor { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefWebPluginInfoVisitor { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_web_plugin_info_visitor_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_web_plugin_info_visitor_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be called once for each plugin. |count| is the 0-based + // index for the current plugin. |total| is the total number of plugins. + // Return false (0) to stop visiting plugins. This function may never be + // called if no plugins are found. + // + pub fn visit(&self, info: interfaces::CefWebPluginInfo, count: libc::c_int, + total: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).visit.unwrap())( + self.c_object, + CefWrap::to_c(info), + CefWrap::to_c(count), + CefWrap::to_c(total))) + } + } +} + +impl CefWrap<*mut cef_web_plugin_info_visitor_t> for CefWebPluginInfoVisitor { + fn to_c(rust_object: CefWebPluginInfoVisitor) -> *mut cef_web_plugin_info_visitor_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_info_visitor_t) -> CefWebPluginInfoVisitor { + CefWebPluginInfoVisitor::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_web_plugin_info_visitor_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_web_plugin_info_visitor_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_info_visitor_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefWebPluginInfoVisitor::from_c_object_addref(c_object)) + } + } +} + + +// +// Structure to implement for receiving unstable plugin information. The +// functions of this structure will be called on the browser process IO thread. +// +#[repr(C)] +pub struct _cef_web_plugin_unstable_callback_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Method that will be called for the requested plugin. |unstable| will be + // true (1) if the plugin has reached the crash count threshold of 3 times in + // 120 seconds. + // + pub is_unstable: Option ()>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_web_plugin_unstable_callback_t = _cef_web_plugin_unstable_callback_t; + + +// +// Structure to implement for receiving unstable plugin information. The +// functions of this structure will be called on the browser process IO thread. +// +pub struct CefWebPluginUnstableCallback { + c_object: *mut cef_web_plugin_unstable_callback_t, +} + +impl Clone for CefWebPluginUnstableCallback { + fn clone(&self) -> CefWebPluginUnstableCallback{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefWebPluginUnstableCallback { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefWebPluginUnstableCallback { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefWebPluginUnstableCallback { + pub unsafe fn from_c_object(c_object: *mut cef_web_plugin_unstable_callback_t) -> CefWebPluginUnstableCallback { + CefWebPluginUnstableCallback { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_web_plugin_unstable_callback_t) -> CefWebPluginUnstableCallback { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefWebPluginUnstableCallback { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_web_plugin_unstable_callback_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_web_plugin_unstable_callback_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Method that will be called for the requested plugin. |unstable| will be + // true (1) if the plugin has reached the crash count threshold of 3 times in + // 120 seconds. + // + pub fn is_unstable(&self, path: &str, unstable: libc::c_int) -> () { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_unstable.unwrap())( + self.c_object, + CefWrap::to_c(path), + CefWrap::to_c(unstable))) + } + } +} + +impl CefWrap<*mut cef_web_plugin_unstable_callback_t> for CefWebPluginUnstableCallback { + fn to_c(rust_object: CefWebPluginUnstableCallback) -> *mut cef_web_plugin_unstable_callback_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_unstable_callback_t) -> CefWebPluginUnstableCallback { + CefWebPluginUnstableCallback::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_web_plugin_unstable_callback_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_web_plugin_unstable_callback_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_web_plugin_unstable_callback_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefWebPluginUnstableCallback::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_xml_reader.rs b/ports/cef/interfaces/cef_xml_reader.rs new file mode 100644 index 00000000000..8109c2100ca --- /dev/null +++ b/ports/cef/interfaces/cef_xml_reader.rs @@ -0,0 +1,856 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure that supports the reading of XML data via the libxml streaming API. +// The functions of this structure should only be called on the thread that +// creates the object. +// +#[repr(C)] +pub struct _cef_xml_reader_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Moves the cursor to the next node in the document. This function must be + // called at least once to set the current cursor position. Returns true (1) + // if the cursor position was set successfully. + // + pub move_to_next_node: Option libc::c_int>, + + // + // Close the document. This should be called directly to ensure that cleanup + // occurs on the correct thread. + // + pub close: Option libc::c_int>, + + // + // Returns true (1) if an error has been reported by the XML parser. + // + pub has_error: Option libc::c_int>, + + // + // Returns the error string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_error: Option types::cef_string_userfree_t>, + + + // The below functions retrieve data for the node at the current cursor + // position. + + // + // Returns the node type. + // + pub get_type: Option types::cef_xml_node_type_t>, + + // + // Returns the node depth. Depth starts at 0 for the root node. + // + pub get_depth: Option libc::c_int>, + + // + // Returns the local name. See http://www.w3.org/TR/REC-xml-names/#NT- + // LocalPart for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_local_name: Option types::cef_string_userfree_t>, + + // + // Returns the namespace prefix. See http://www.w3.org/TR/REC-xml-names/ for + // additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_prefix: Option types::cef_string_userfree_t>, + + // + // Returns the qualified name, equal to (Prefix:)LocalName. See + // http://www.w3.org/TR/REC-xml-names/#ns-qualnames for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_qualified_name: Option types::cef_string_userfree_t>, + + // + // Returns the URI defining the namespace associated with the node. See + // http://www.w3.org/TR/REC-xml-names/ for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_namespace_uri: Option types::cef_string_userfree_t>, + + // + // Returns the base URI of the node. See http://www.w3.org/TR/xmlbase/ for + // additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_base_uri: Option types::cef_string_userfree_t>, + + // + // Returns the xml:lang scope within which the node resides. See + // http://www.w3.org/TR/REC-xml/#sec-lang-tag for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_xml_lang: Option types::cef_string_userfree_t>, + + // + // Returns true (1) if the node represents an NULL element. is considered + // NULL but is not. + // + pub is_empty_element: Option libc::c_int>, + + // + // Returns true (1) if the node has a text value. + // + pub has_value: Option libc::c_int>, + + // + // Returns the text value. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_value: Option types::cef_string_userfree_t>, + + // + // Returns true (1) if the node has attributes. + // + pub has_attributes: Option libc::c_int>, + + // + // Returns the number of attributes. + // + pub get_attribute_count: Option libc::size_t>, + + // + // Returns the value of the attribute at the specified 0-based index. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_attribute_byindex: Option types::cef_string_userfree_t>, + + // + // Returns the value of the attribute with the specified qualified name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_attribute_byqname: Option types::cef_string_userfree_t>, + + // + // Returns the value of the attribute with the specified local name and + // namespace URI. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_attribute_bylname: Option types::cef_string_userfree_t>, + + // + // Returns an XML representation of the current node's children. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_inner_xml: Option types::cef_string_userfree_t>, + + // + // Returns an XML representation of the current node including its children. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_outer_xml: Option types::cef_string_userfree_t>, + + // + // Returns the line number for the current node. + // + pub get_line_number: Option libc::c_int>, + + + // Attribute nodes are not traversed by default. The below functions can be + // used to move the cursor to an attribute node. move_to_carrying_element() + // can be called afterwards to return the cursor to the carrying element. The + // depth of an attribute node will be 1 + the depth of the carrying element. + + // + // Moves the cursor to the attribute at the specified 0-based index. Returns + // true (1) if the cursor position was set successfully. + // + pub move_to_attribute_byindex: Option libc::c_int>, + + // + // Moves the cursor to the attribute with the specified qualified name. + // Returns true (1) if the cursor position was set successfully. + // + pub move_to_attribute_byqname: Option libc::c_int>, + + // + // Moves the cursor to the attribute with the specified local name and + // namespace URI. Returns true (1) if the cursor position was set + // successfully. + // + pub move_to_attribute_bylname: Option libc::c_int>, + + // + // Moves the cursor to the first attribute in the current element. Returns + // true (1) if the cursor position was set successfully. + // + pub move_to_first_attribute: Option libc::c_int>, + + // + // Moves the cursor to the next attribute in the current element. Returns true + // (1) if the cursor position was set successfully. + // + pub move_to_next_attribute: Option libc::c_int>, + + // + // Moves the cursor back to the carrying element. Returns true (1) if the + // cursor position was set successfully. + // + pub move_to_carrying_element: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_xml_reader_t = _cef_xml_reader_t; + + +// +// Structure that supports the reading of XML data via the libxml streaming API. +// The functions of this structure should only be called on the thread that +// creates the object. +// +pub struct CefXmlReader { + c_object: *mut cef_xml_reader_t, +} + +impl Clone for CefXmlReader { + fn clone(&self) -> CefXmlReader{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefXmlReader { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefXmlReader { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefXmlReader { + pub unsafe fn from_c_object(c_object: *mut cef_xml_reader_t) -> CefXmlReader { + CefXmlReader { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_xml_reader_t) -> CefXmlReader { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefXmlReader { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_xml_reader_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_xml_reader_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Moves the cursor to the next node in the document. This function must be + // called at least once to set the current cursor position. Returns true (1) + // if the cursor position was set successfully. + // + pub fn move_to_next_node(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_next_node.unwrap())( + self.c_object)) + } + } + + // + // Close the document. This should be called directly to ensure that cleanup + // occurs on the correct thread. + // + pub fn close(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).close.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if an error has been reported by the XML parser. + // + pub fn has_error(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_error.unwrap())( + self.c_object)) + } + } + + // + // Returns the error string. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_error(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_error.unwrap())( + self.c_object)) + } + } + + + // The below functions retrieve data for the node at the current cursor + // position. + + // + // Returns the node type. + // + pub fn get_type(&self) -> types::cef_xml_node_type_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_type.unwrap())( + self.c_object)) + } + } + + // + // Returns the node depth. Depth starts at 0 for the root node. + // + pub fn get_depth(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_depth.unwrap())( + self.c_object)) + } + } + + // + // Returns the local name. See http://www.w3.org/TR/REC-xml-names/#NT- + // LocalPart for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_local_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_local_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the namespace prefix. See http://www.w3.org/TR/REC-xml-names/ for + // additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_prefix(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_prefix.unwrap())( + self.c_object)) + } + } + + // + // Returns the qualified name, equal to (Prefix:)LocalName. See + // http://www.w3.org/TR/REC-xml-names/#ns-qualnames for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_qualified_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_qualified_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the URI defining the namespace associated with the node. See + // http://www.w3.org/TR/REC-xml-names/ for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_namespace_uri(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_namespace_uri.unwrap())( + self.c_object)) + } + } + + // + // Returns the base URI of the node. See http://www.w3.org/TR/xmlbase/ for + // additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_base_uri(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_base_uri.unwrap())( + self.c_object)) + } + } + + // + // Returns the xml:lang scope within which the node resides. See + // http://www.w3.org/TR/REC-xml/#sec-lang-tag for additional details. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_xml_lang(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_xml_lang.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the node represents an NULL element. is considered + // NULL but is not. + // + pub fn is_empty_element(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).is_empty_element.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the node has a text value. + // + pub fn has_value(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_value.unwrap())( + self.c_object)) + } + } + + // + // Returns the text value. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_value(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_value.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if the node has attributes. + // + pub fn has_attributes(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).has_attributes.unwrap())( + self.c_object)) + } + } + + // + // Returns the number of attributes. + // + pub fn get_attribute_count(&self) -> libc::size_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_attribute_count.unwrap())( + self.c_object)) + } + } + + // + // Returns the value of the attribute at the specified 0-based index. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_attribute_byindex(&self, index: libc::c_int) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_attribute_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Returns the value of the attribute with the specified qualified name. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_attribute_byqname(&self, qualifiedName: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_attribute_byqname.unwrap())( + self.c_object, + CefWrap::to_c(qualifiedName))) + } + } + + // + // Returns the value of the attribute with the specified local name and + // namespace URI. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_attribute_bylname(&self, localName: &str, + namespaceURI: &str) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_attribute_bylname.unwrap())( + self.c_object, + CefWrap::to_c(localName), + CefWrap::to_c(namespaceURI))) + } + } + + // + // Returns an XML representation of the current node's children. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_inner_xml(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_inner_xml.unwrap())( + self.c_object)) + } + } + + // + // Returns an XML representation of the current node including its children. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_outer_xml(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_outer_xml.unwrap())( + self.c_object)) + } + } + + // + // Returns the line number for the current node. + // + pub fn get_line_number(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_line_number.unwrap())( + self.c_object)) + } + } + + + // Attribute nodes are not traversed by default. The below functions can be + // used to move the cursor to an attribute node. move_to_carrying_element() + // can be called afterwards to return the cursor to the carrying element. The + // depth of an attribute node will be 1 + the depth of the carrying element. + + // + // Moves the cursor to the attribute at the specified 0-based index. Returns + // true (1) if the cursor position was set successfully. + // + pub fn move_to_attribute_byindex(&self, index: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_attribute_byindex.unwrap())( + self.c_object, + CefWrap::to_c(index))) + } + } + + // + // Moves the cursor to the attribute with the specified qualified name. + // Returns true (1) if the cursor position was set successfully. + // + pub fn move_to_attribute_byqname(&self, qualifiedName: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_attribute_byqname.unwrap())( + self.c_object, + CefWrap::to_c(qualifiedName))) + } + } + + // + // Moves the cursor to the attribute with the specified local name and + // namespace URI. Returns true (1) if the cursor position was set + // successfully. + // + pub fn move_to_attribute_bylname(&self, localName: &str, + namespaceURI: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_attribute_bylname.unwrap())( + self.c_object, + CefWrap::to_c(localName), + CefWrap::to_c(namespaceURI))) + } + } + + // + // Moves the cursor to the first attribute in the current element. Returns + // true (1) if the cursor position was set successfully. + // + pub fn move_to_first_attribute(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_first_attribute.unwrap())( + self.c_object)) + } + } + + // + // Moves the cursor to the next attribute in the current element. Returns true + // (1) if the cursor position was set successfully. + // + pub fn move_to_next_attribute(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_next_attribute.unwrap())( + self.c_object)) + } + } + + // + // Moves the cursor back to the carrying element. Returns true (1) if the + // cursor position was set successfully. + // + pub fn move_to_carrying_element(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_carrying_element.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_xml_reader_t object. The returned object's functions can + // only be called from the thread that created the object. + // + pub fn create(stream: interfaces::CefStreamReader, + encodingType: types::cef_xml_encoding_type_t, + URI: &str) -> interfaces::CefXmlReader { + unsafe { + CefWrap::to_rust( + ::xml_reader::cef_xml_reader_create( + CefWrap::to_c(stream), + CefWrap::to_c(encodingType), + CefWrap::to_c(URI))) + } + } +} + +impl CefWrap<*mut cef_xml_reader_t> for CefXmlReader { + fn to_c(rust_object: CefXmlReader) -> *mut cef_xml_reader_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_xml_reader_t) -> CefXmlReader { + CefXmlReader::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_xml_reader_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_xml_reader_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_xml_reader_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefXmlReader::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/cef_zip_reader.rs b/ports/cef/interfaces/cef_zip_reader.rs new file mode 100644 index 00000000000..2623bb9b4ca --- /dev/null +++ b/ports/cef/interfaces/cef_zip_reader.rs @@ -0,0 +1,445 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not be edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#![allow(non_snake_case, unused_imports)] + +use eutil; +use interfaces; +use types; +use wrappers::CefWrap; + +use libc; +use std::collections::HashMap; +use std::ptr; + +// +// Structure that supports the reading of zip archives via the zlib unzip API. +// The functions of this structure should only be called on the thread that +// creates the object. +// +#[repr(C)] +pub struct _cef_zip_reader_t { + // + // Base structure. + // + pub base: types::cef_base_t, + + // + // Moves the cursor to the first file in the archive. Returns true (1) if the + // cursor position was set successfully. + // + pub move_to_first_file: Option libc::c_int>, + + // + // Moves the cursor to the next file in the archive. Returns true (1) if the + // cursor position was set successfully. + // + pub move_to_next_file: Option libc::c_int>, + + // + // Moves the cursor to the specified file in the archive. If |caseSensitive| + // is true (1) then the search will be case sensitive. Returns true (1) if the + // cursor position was set successfully. + // + pub move_to_file: Option libc::c_int>, + + // + // Closes the archive. This should be called directly to ensure that cleanup + // occurs on the correct thread. + // + pub close: Option libc::c_int>, + + + // The below functions act on the file at the current cursor position. + + // + // Returns the name of the file. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub get_file_name: Option types::cef_string_userfree_t>, + + // + // Returns the uncompressed size of the file. + // + pub get_file_size: Option i64>, + + // + // Returns the last modified timestamp for the file. + // + pub get_file_last_modified: Option libc::time_t>, + + // + // Opens the file for reading of uncompressed data. A read password may + // optionally be specified. + // + pub open_file: Option libc::c_int>, + + // + // Closes the file. + // + pub close_file: Option libc::c_int>, + + // + // Read uncompressed file contents into the specified buffer. Returns < 0 if + // an error occurred, 0 if at the end of file, or the number of bytes read. + // + pub read_file: Option libc::c_int>, + + // + // Returns the current offset in the uncompressed file contents. + // + pub tell: Option i64>, + + // + // Returns true (1) if at end of the file contents. + // + pub eof: Option libc::c_int>, + + // + // The reference count. This will only be present for Rust instances! + // + ref_count: uint, + + // + // Extra data. This will only be present for Rust instances! + // + pub extra: u8, +} + +pub type cef_zip_reader_t = _cef_zip_reader_t; + + +// +// Structure that supports the reading of zip archives via the zlib unzip API. +// The functions of this structure should only be called on the thread that +// creates the object. +// +pub struct CefZipReader { + c_object: *mut cef_zip_reader_t, +} + +impl Clone for CefZipReader { + fn clone(&self) -> CefZipReader{ + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.add_ref.unwrap())(&mut (*self.c_object).base); + } + CefZipReader { + c_object: self.c_object, + } + } + } +} + +impl Drop for CefZipReader { + fn drop(&mut self) { + unsafe { + if !self.c_object.is_null() { + ((*self.c_object).base.release.unwrap())(&mut (*self.c_object).base); + } + } + } +} + +impl CefZipReader { + pub unsafe fn from_c_object(c_object: *mut cef_zip_reader_t) -> CefZipReader { + CefZipReader { + c_object: c_object, + } + } + + pub unsafe fn from_c_object_addref(c_object: *mut cef_zip_reader_t) -> CefZipReader { + if !c_object.is_null() { + ((*c_object).base.add_ref.unwrap())(&mut (*c_object).base); + } + CefZipReader { + c_object: c_object, + } + } + + pub fn c_object(&self) -> *mut cef_zip_reader_t { + self.c_object + } + + pub fn c_object_addrefed(&self) -> *mut cef_zip_reader_t { + unsafe { + if !self.c_object.is_null() { + eutil::add_ref(self.c_object as *mut types::cef_base_t); + } + self.c_object + } + } + + pub fn is_null_cef_object(&self) -> bool { + self.c_object.is_null() + } + pub fn is_not_null_cef_object(&self) -> bool { + !self.c_object.is_null() + } + + // + // Moves the cursor to the first file in the archive. Returns true (1) if the + // cursor position was set successfully. + // + pub fn move_to_first_file(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_first_file.unwrap())( + self.c_object)) + } + } + + // + // Moves the cursor to the next file in the archive. Returns true (1) if the + // cursor position was set successfully. + // + pub fn move_to_next_file(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_next_file.unwrap())( + self.c_object)) + } + } + + // + // Moves the cursor to the specified file in the archive. If |caseSensitive| + // is true (1) then the search will be case sensitive. Returns true (1) if the + // cursor position was set successfully. + // + pub fn move_to_file(&self, fileName: &str, + caseSensitive: libc::c_int) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).move_to_file.unwrap())( + self.c_object, + CefWrap::to_c(fileName), + CefWrap::to_c(caseSensitive))) + } + } + + // + // Closes the archive. This should be called directly to ensure that cleanup + // occurs on the correct thread. + // + pub fn close(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).close.unwrap())( + self.c_object)) + } + } + + + // The below functions act on the file at the current cursor position. + + // + // Returns the name of the file. + // + // The resulting string must be freed by calling cef_string_userfree_free(). + pub fn get_file_name(&self) -> String { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_name.unwrap())( + self.c_object)) + } + } + + // + // Returns the uncompressed size of the file. + // + pub fn get_file_size(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_size.unwrap())( + self.c_object)) + } + } + + // + // Returns the last modified timestamp for the file. + // + pub fn get_file_last_modified(&self) -> libc::time_t { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).get_file_last_modified.unwrap())( + self.c_object)) + } + } + + // + // Opens the file for reading of uncompressed data. A read password may + // optionally be specified. + // + pub fn open_file(&self, password: &str) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).open_file.unwrap())( + self.c_object, + CefWrap::to_c(password))) + } + } + + // + // Closes the file. + // + pub fn close_file(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).close_file.unwrap())( + self.c_object)) + } + } + + // + // Read uncompressed file contents into the specified buffer. Returns < 0 if + // an error occurred, 0 if at the end of file, or the number of bytes read. + // + pub fn read_file(&self, buffer: &mut (), + bufferSize: libc::size_t) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).read_file.unwrap())( + self.c_object, + CefWrap::to_c(buffer), + CefWrap::to_c(bufferSize))) + } + } + + // + // Returns the current offset in the uncompressed file contents. + // + pub fn tell(&self) -> i64 { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).tell.unwrap())( + self.c_object)) + } + } + + // + // Returns true (1) if at end of the file contents. + // + pub fn eof(&self) -> libc::c_int { + if self.c_object.is_null() { + panic!("called a CEF method on a null object") + } + unsafe { + CefWrap::to_rust( + ((*self.c_object).eof.unwrap())( + self.c_object)) + } + } + + // + // Create a new cef_zip_reader_t object. The returned object's functions can + // only be called from the thread that created the object. + // + pub fn create( + stream: interfaces::CefStreamReader) -> interfaces::CefZipReader { + unsafe { + CefWrap::to_rust( + ::zip_reader::cef_zip_reader_create( + CefWrap::to_c(stream))) + } + } +} + +impl CefWrap<*mut cef_zip_reader_t> for CefZipReader { + fn to_c(rust_object: CefZipReader) -> *mut cef_zip_reader_t { + rust_object.c_object_addrefed() + } + unsafe fn to_rust(c_object: *mut cef_zip_reader_t) -> CefZipReader { + CefZipReader::from_c_object_addref(c_object) + } +} +impl CefWrap<*mut cef_zip_reader_t> for Option { + fn to_c(rust_object: Option) -> *mut cef_zip_reader_t { + match rust_object { + None => ptr::null_mut(), + Some(rust_object) => rust_object.c_object_addrefed(), + } + } + unsafe fn to_rust(c_object: *mut cef_zip_reader_t) -> Option { + if c_object.is_null() { + None + } else { + Some(CefZipReader::from_c_object_addref(c_object)) + } + } +} + diff --git a/ports/cef/interfaces/mod.rs b/ports/cef/interfaces/mod.rs new file mode 100644 index 00000000000..7080eed9fdd --- /dev/null +++ b/ports/cef/interfaces/mod.rs @@ -0,0 +1,148 @@ +/* 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/. */ + +//! This file is currently *not* autogenerated, but maybe it should be. (It's a little complicated +//! because we need to reexport a bunch of types in `types.rs`.) + +pub use interfaces::cef_app::{CefApp, cef_app_t}; +pub use interfaces::cef_auth_callback::{CefAuthCallback, cef_auth_callback_t}; +pub use interfaces::cef_browser::{CefBrowser, CefBrowserHost, CefRunFileDialogCallback}; +pub use interfaces::cef_browser::{cef_browser_host_t, cef_browser_t}; +pub use interfaces::cef_browser::{cef_run_file_dialog_callback_t}; +pub use interfaces::cef_browser_process_handler::{CefBrowserProcessHandler}; +pub use interfaces::cef_browser_process_handler::{cef_browser_process_handler_t}; +pub use interfaces::cef_callback::{CefCallback, CefCompletionCallback, cef_callback_t}; +pub use interfaces::cef_callback::{cef_completion_callback_t}; +pub use interfaces::cef_client::{CefClient, cef_client_t}; +pub use interfaces::cef_command_line::{CefCommandLine, cef_command_line_t}; +pub use interfaces::cef_context_menu_handler::{CefContextMenuHandler, CefContextMenuParams}; +pub use interfaces::cef_context_menu_handler::{cef_context_menu_handler_t}; +pub use interfaces::cef_context_menu_handler::{cef_context_menu_params_t}; +pub use interfaces::cef_cookie::{CefCookieManager, CefCookieVisitor, cef_cookie_manager_t}; +pub use interfaces::cef_cookie::{cef_cookie_visitor_t}; +pub use interfaces::cef_dialog_handler::{CefDialogHandler, CefFileDialogCallback}; +pub use interfaces::cef_dialog_handler::{cef_dialog_handler_t, cef_file_dialog_callback_t}; +pub use interfaces::cef_display_handler::{CefDisplayHandler, cef_display_handler_t}; +pub use interfaces::cef_dom::{CefDOMDocument, CefDOMNode, CefDOMVisitor, cef_domdocument_t}; +pub use interfaces::cef_dom::{cef_domnode_t, cef_domvisitor_t}; +pub use interfaces::cef_download_handler::{CefBeforeDownloadCallback, CefDownloadHandler}; +pub use interfaces::cef_download_handler::{CefDownloadItemCallback}; +pub use interfaces::cef_download_handler::{cef_before_download_callback_t}; +pub use interfaces::cef_download_handler::{cef_download_handler_t, cef_download_item_callback_t}; +pub use interfaces::cef_download_item::{CefDownloadItem, cef_download_item_t}; +pub use interfaces::cef_drag_data::{CefDragData, cef_drag_data_t}; +pub use interfaces::cef_drag_handler::{CefDragHandler, cef_drag_handler_t}; +pub use interfaces::cef_focus_handler::{CefFocusHandler, cef_focus_handler_t}; +pub use interfaces::cef_frame::{CefFrame, cef_frame_t}; +pub use interfaces::cef_geolocation::{CefGetGeolocationCallback, cef_get_geolocation_callback_t}; +pub use interfaces::cef_geolocation_handler::{CefGeolocationCallback, CefGeolocationHandler}; +pub use interfaces::cef_geolocation_handler::{cef_geolocation_callback_t}; +pub use interfaces::cef_geolocation_handler::{cef_geolocation_handler_t}; +pub use interfaces::cef_jsdialog_handler::{CefJSDialogCallback, CefJSDialogHandler}; +pub use interfaces::cef_jsdialog_handler::{cef_jsdialog_callback_t, cef_jsdialog_handler_t}; +pub use interfaces::cef_keyboard_handler::{CefKeyboardHandler, cef_keyboard_handler_t}; +pub use interfaces::cef_life_span_handler::{CefLifeSpanHandler, cef_life_span_handler_t}; +pub use interfaces::cef_load_handler::{CefLoadHandler, cef_load_handler_t}; +pub use interfaces::cef_menu_model::{CefMenuModel, cef_menu_model_t}; +pub use interfaces::cef_print_handler::{CefPrintDialogCallback, CefPrintHandler}; +pub use interfaces::cef_print_handler::{CefPrintJobCallback, cef_print_dialog_callback_t}; +pub use interfaces::cef_print_handler::{cef_print_handler_t, cef_print_job_callback_t}; +pub use interfaces::cef_print_settings::{CefPrintSettings, cef_print_settings_t}; +pub use interfaces::cef_process_message::{CefProcessMessage, cef_process_message_t}; +pub use interfaces::cef_render_handler::{CefRenderHandler, cef_render_handler_t}; +pub use interfaces::cef_render_process_handler::{CefRenderProcessHandler}; +pub use interfaces::cef_render_process_handler::{cef_render_process_handler_t}; +pub use interfaces::cef_request::{CefPostData, CefPostDataElement, CefRequest}; +pub use interfaces::cef_request::{cef_post_data_element_t, cef_post_data_t, cef_request_t}; +pub use interfaces::cef_request_context::{CefRequestContext, cef_request_context_t}; +pub use interfaces::cef_request_context_handler::{CefRequestContextHandler}; +pub use interfaces::cef_request_context_handler::{cef_request_context_handler_t}; +pub use interfaces::cef_request_handler::{CefAllowCertificateErrorCallback, CefQuotaCallback}; +pub use interfaces::cef_request_handler::{CefRequestHandler}; +pub use interfaces::cef_request_handler::{cef_allow_certificate_error_callback_t}; +pub use interfaces::cef_request_handler::{cef_quota_callback_t, cef_request_handler_t}; +pub use interfaces::cef_resource_bundle_handler::{CefResourceBundleHandler}; +pub use interfaces::cef_resource_bundle_handler::{cef_resource_bundle_handler_t}; +pub use interfaces::cef_resource_handler::{CefResourceHandler, cef_resource_handler_t}; +pub use interfaces::cef_response::{CefResponse, cef_response_t}; +pub use interfaces::cef_scheme::{CefSchemeHandlerFactory, CefSchemeRegistrar}; +pub use interfaces::cef_scheme::{cef_scheme_handler_factory_t, cef_scheme_registrar_t}; +pub use interfaces::cef_stream::{CefReadHandler, CefStreamReader, CefStreamWriter}; +pub use interfaces::cef_stream::{CefWriteHandler, cef_read_handler_t, cef_stream_reader_t}; +pub use interfaces::cef_stream::{cef_stream_writer_t, cef_write_handler_t}; +pub use interfaces::cef_string_visitor::{CefStringVisitor, cef_string_visitor_t}; +pub use interfaces::cef_task::{CefTask, CefTaskRunner, cef_task_runner_t, cef_task_t}; +pub use interfaces::cef_trace::{CefEndTracingCallback, cef_end_tracing_callback_t}; +pub use interfaces::cef_urlrequest::{CefURLRequest, CefURLRequestClient, cef_urlrequest_client_t}; +pub use interfaces::cef_urlrequest::{cef_urlrequest_t}; +pub use interfaces::cef_v8::{CefV8Accessor, CefV8Context, CefV8Exception, CefV8Handler}; +pub use interfaces::cef_v8::{CefV8StackFrame, CefV8StackTrace, CefV8Value, cef_v8accessor_t}; +pub use interfaces::cef_v8::{cef_v8context_t, cef_v8exception_t, cef_v8handler_t}; +pub use interfaces::cef_v8::{cef_v8stack_frame_t, cef_v8stack_trace_t, cef_v8value_t}; +pub use interfaces::cef_values::{CefBinaryValue, CefDictionaryValue, CefListValue}; +pub use interfaces::cef_values::{cef_binary_value_t, cef_dictionary_value_t, cef_list_value_t}; +pub use interfaces::cef_web_plugin::{CefWebPluginInfo, CefWebPluginInfoVisitor}; +pub use interfaces::cef_web_plugin::{CefWebPluginUnstableCallback, cef_web_plugin_info_t}; +pub use interfaces::cef_web_plugin::{cef_web_plugin_info_visitor_t}; +pub use interfaces::cef_web_plugin::{cef_web_plugin_unstable_callback_t}; +pub use interfaces::cef_xml_reader::{CefXmlReader, cef_xml_reader_t}; +pub use interfaces::cef_zip_reader::{CefZipReader, cef_zip_reader_t}; +pub use types::{CefBase, CefBrowserSettings, CefCookie, CefGeoposition, CefKeyEvent}; +pub use types::{CefMouseEvent, CefPopupFeatures, CefProcessId, CefScreenInfo}; +pub use types::{CefValueType, CefWindowInfo, cef_base_t}; +pub use types::{cef_browser_settings_t, cef_cookie_t, cef_geoposition_t, cef_key_event_t}; +pub use types::{cef_mouse_event_t, cef_point_t, cef_popup_features_t}; +pub use types::{cef_process_id_t, cef_screen_info_t, cef_string_map_t}; +pub use types::{cef_time_t, cef_value_type_t, cef_window_info_t}; + +pub mod cef_app; +pub mod cef_auth_callback; +pub mod cef_browser; +pub mod cef_browser_process_handler; +pub mod cef_callback; +pub mod cef_client; +pub mod cef_command_line; +pub mod cef_context_menu_handler; +pub mod cef_cookie; +pub mod cef_dialog_handler; +pub mod cef_display_handler; +pub mod cef_dom; +pub mod cef_download_handler; +pub mod cef_download_item; +pub mod cef_drag_data; +pub mod cef_drag_handler; +pub mod cef_focus_handler; +pub mod cef_frame; +pub mod cef_geolocation; +pub mod cef_geolocation_handler; +pub mod cef_jsdialog_handler; +pub mod cef_keyboard_handler; +pub mod cef_life_span_handler; +pub mod cef_load_handler; +pub mod cef_menu_model; +pub mod cef_print_handler; +pub mod cef_print_settings; +pub mod cef_process_message; +pub mod cef_render_handler; +pub mod cef_render_process_handler; +pub mod cef_request; +pub mod cef_request_context; +pub mod cef_request_context_handler; +pub mod cef_request_handler; +pub mod cef_resource_bundle_handler; +pub mod cef_resource_handler; +pub mod cef_response; +pub mod cef_scheme; +pub mod cef_stream; +pub mod cef_string_visitor; +pub mod cef_task; +pub mod cef_trace; +pub mod cef_urlrequest; +pub mod cef_v8; +pub mod cef_values; +pub mod cef_web_plugin; +pub mod cef_xml_reader; +pub mod cef_zip_reader; + + diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index fb61e3ef196..54f5df95bf0 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -44,19 +44,34 @@ extern crate core_graphics; #[cfg(target_os="macos")] extern crate core_text; +// Must come first. +pub mod macros; + pub mod browser; pub mod command_line; +pub mod cookie; pub mod core; +pub mod drag_data; pub mod eutil; -#[cfg(any(target_os="linux",target_os="macos"))] -pub mod mem; +pub mod interfaces; +pub mod print_settings; +pub mod process_message; pub mod request; +pub mod request_context; +pub mod response; +pub mod stream; pub mod string; pub mod string_list; pub mod string_map; pub mod string_multimap; +pub mod stubs; pub mod switches; pub mod task; pub mod types; pub mod urlrequest; +pub mod values; +pub mod v8; +pub mod wrappers; +pub mod xml_reader; +pub mod zip_reader; diff --git a/ports/cef/macros.rs b/ports/cef/macros.rs new file mode 100644 index 00000000000..fa72b72f48a --- /dev/null +++ b/ports/cef/macros.rs @@ -0,0 +1,122 @@ +/* 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/. */ + +#![macro_escape] + +// Provides the implementation of a CEF class. An example follows: +// +// struct ServoCefThing { +// ... +// } +// +// cef_class_impl! { +// ServoCefThing : CefThing, cef_thing_t { +// // Declare method implementations using the *C* API. (This may change later, once we +// // have associated types in Rust.) +// // +// // Note that if the method returns unit, you must write `-> ()` explicitly. This is +// // due to limitations of Rust's macro system. +// fn foo(&this, a: int, b: *mut cef_other_thing_t) -> () { +// // Inside here, `a` will have type `int`, and `b` will have the type +// // `CefOtherThing` -- i.e. the Rust-wrapped version of `cef_other_thing_t`. +// ... +// } +// +// fn bar(&this, a: int) -> *mut cef_other_thing_t { +// // Return types are automatically unwrapped from the Rust types (e.g. +// // `CefOtherThing`) into the corresponding C types (e.g. `*mut +// // cef_other_thing_t`). +// let x: CefOtherThing = ...; +// x +// } +// } +// } +macro_rules! cef_class_impl( + ($class_name:ident : $interface_name:ident, $c_interface_name:ident { + $( + fn $method_name:ident ( & $method_this:ident + $( , $method_arg_name:ident : $method_arg_type:ty )* ) + -> $method_return_type:ty $method_body:block + )* + }) => ( + impl $class_name { + pub fn as_cef_interface(self) -> $interface_name { + let cef_object = unsafe { + $interface_name::from_c_object_addref( + ::eutil::create_cef_object::<$c_interface_name,$class_name>()) + }; + unsafe { + $((*cef_object.c_object()).$method_name = Some($method_name);)* + let extra_slot = + ::std::mem::transmute::<&mut u8, + &mut $class_name>(&mut (*cef_object.c_object()) + .extra); + ::std::ptr::write(extra_slot, self); + } + cef_object + } + } + + $( + extern "C" fn $method_name(raw_this: *mut $c_interface_name, + $($method_arg_name: $method_arg_type),*) + -> $method_return_type { + let $method_this = unsafe { + $interface_name::from_c_object_addref(raw_this) + }; + $( + let $method_arg_name = unsafe { + ::wrappers::CefWrap::to_rust($method_arg_name) + }; + )* + ::wrappers::CefWrap::to_c($method_body) + } + )* + + impl ::eutil::Downcast<$class_name> for $interface_name { + fn downcast(&self) -> &$class_name { + unsafe { + ::std::mem::transmute::<&u8,&$class_name>(&(*self.c_object()).extra) + } + } + } + ) +) + +macro_rules! cef_static_method_impls( + ( + $( + fn $method_name:ident ( $($method_arg_name:ident : $method_arg_type:ty ),* ) + -> $method_return_type:ty $method_body:block + )* + ) => ( + $( + pub extern "C" fn $method_name($($method_arg_name: $method_arg_type),*) + -> $method_return_type { + $( + let $method_arg_name = unsafe { + ::wrappers::CefWrap::to_rust($method_arg_name) + }; + )* + ::wrappers::CefWrap::to_c($method_body) + } + )* + ) +) + +macro_rules! cef_stub_static_method_impls( + ( + $( + fn $method_name:ident ( $($method_arg_name:ident : $method_arg_type:ty ),* ) + -> $method_return_type:ty ; + )* + ) => ( + $( + pub extern "C" fn $method_name($(_: $method_arg_type),*) + -> $method_return_type { + panic!("unimplemented static method: {}", stringify!($method_name)) + } + )* + ) +) diff --git a/ports/cef/mem.rs b/ports/cef/mem.rs deleted file mode 100644 index 76a0cde499f..00000000000 --- a/ports/cef/mem.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* 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 libc::{c_void, size_t}; -use std::mem; -use std::ptr::set_memory; - -// -U _tc_* needed on OS X, but won't work on other platforms -#[cfg(target_os="macos")] -#[link_args="-Wl,-U,_tc_new -Wl,-U,_tc_newarray -Wl,-U,_tc_delete -Wl,-U,_tc_deletearray"] -extern {} - -extern "C" { - fn tc_new(size: size_t) -> *mut c_void; - fn tc_delete(mem: *mut c_void); - fn tc_newarray(size: size_t) -> *mut c_void; - fn tc_deletearray(mem: *mut c_void); -} - -#[allow(experimental)] -pub fn newarray0(nmem: size_t) -> *mut T { - let mem = newarray::(nmem) as *mut T; - unsafe { - set_memory(mem, 0 as u8, nmem as uint); - } - mem -} - -pub fn newarray(nmem: size_t) -> *mut T { - unsafe { - tc_newarray(nmem * mem::size_of::() as size_t) as *mut T - } -} - -#[allow(experimental)] -pub fn new0(nmem: size_t) -> *mut T { - let mem = new(nmem * mem::size_of::() as size_t) as *mut T; - unsafe { - set_memory(mem, 0 as u8, nmem as uint); - } - mem -} - -pub fn new(size: size_t) -> *mut c_void { - unsafe { - tc_new(size) - } -} - -pub fn delete(mem: *mut c_void) { - unsafe { - tc_delete(mem) - } -} - -pub fn deletearray(mem: *mut c_void) { - unsafe { - tc_deletearray(mem) - } -} diff --git a/ports/cef/print_settings.rs b/ports/cef/print_settings.rs new file mode 100644 index 00000000000..31c6d08347b --- /dev/null +++ b/ports/cef/print_settings.rs @@ -0,0 +1,9 @@ +/* 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 interfaces::cef_print_settings_t; + +cef_stub_static_method_impls! { + fn cef_print_settings_create() -> *mut cef_print_settings_t; +} diff --git a/ports/cef/process_message.rs b/ports/cef/process_message.rs new file mode 100644 index 00000000000..c3f42fe63c0 --- /dev/null +++ b/ports/cef/process_message.rs @@ -0,0 +1,11 @@ +/* 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 interfaces::cef_process_message_t; +use types::cef_string_t; + +cef_stub_static_method_impls! { + fn cef_process_message_create(name: *const cef_string_t) -> *mut cef_process_message_t; +} + diff --git a/ports/cef/request.rs b/ports/cef/request.rs index 546047e7df0..d25d0e98d56 100644 --- a/ports/cef/request.rs +++ b/ports/cef/request.rs @@ -2,20 +2,11 @@ * 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 interfaces::{cef_post_data_element_t, cef_post_data_t, cef_request_t}; -use types::{cef_post_data_element_t, cef_post_data_t, cef_request_t}; - -#[no_mangle] -pub extern "C" fn cef_request_create() -> *mut cef_request_t { - 0 as *mut cef_request_t +cef_stub_static_method_impls! { + fn cef_request_create() -> *mut cef_request_t; + fn cef_post_data_create() -> *mut cef_post_data_t; + fn cef_post_data_element_create() -> *mut cef_post_data_element_t; } -#[no_mangle] -pub extern "C" fn cef_post_data_create() -> *mut cef_post_data_t { - 0 as *mut cef_post_data_t -} - -#[no_mangle] -pub extern "C" fn cef_post_data_element_create() -> *mut cef_post_data_element_t { - 0 as *mut cef_post_data_element_t -} diff --git a/ports/cef/request_context.rs b/ports/cef/request_context.rs new file mode 100644 index 00000000000..4c256e1d62a --- /dev/null +++ b/ports/cef/request_context.rs @@ -0,0 +1,12 @@ +/* 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 interfaces::{cef_request_context_handler_t, cef_request_context_t}; + +cef_stub_static_method_impls! { + fn cef_request_context_get_global_context() -> *mut cef_request_context_t; + fn cef_request_context_create_context(_handler: *mut cef_request_context_handler_t) + -> *mut cef_request_context_t; +} + diff --git a/ports/cef/response.rs b/ports/cef/response.rs new file mode 100644 index 00000000000..c6ed25a81a3 --- /dev/null +++ b/ports/cef/response.rs @@ -0,0 +1,10 @@ +/* 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 interfaces::cef_response_t; + +cef_stub_static_method_impls! { + fn cef_response_create() -> *mut cef_response_t; +} + diff --git a/ports/cef/stream.rs b/ports/cef/stream.rs new file mode 100644 index 00000000000..753fe228501 --- /dev/null +++ b/ports/cef/stream.rs @@ -0,0 +1,23 @@ +/* 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 interfaces::{cef_read_handler_t, cef_stream_reader_t, cef_stream_writer_t}; +use interfaces::{cef_write_handler_t}; +use types::cef_string_t; + +use libc; + +cef_stub_static_method_impls! { + fn cef_stream_reader_create_for_file(_file_name: *const cef_string_t) + -> *mut cef_stream_reader_t; + fn cef_stream_reader_create_for_data(_data: *mut (), _size: libc::size_t) + -> *mut cef_stream_reader_t; + fn cef_stream_reader_create_for_handler(_handler: *mut cef_read_handler_t) + -> *mut cef_stream_reader_t; + fn cef_stream_writer_create_for_file(_file_name: *const cef_string_t) + -> *mut cef_stream_writer_t; + fn cef_stream_writer_create_for_handler(_handler: *mut cef_write_handler_t) + -> *mut cef_stream_writer_t; +} + diff --git a/ports/cef/string.rs b/ports/cef/string.rs index ce31c4330eb..19fd8754081 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -4,9 +4,8 @@ use eutil::slice_to_str; -use libc::{size_t, c_int, c_ushort,c_void}; +use libc::{mod, 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; @@ -19,35 +18,47 @@ use types::{cef_string_userfree_utf16_t, cef_string_userfree_utf8_t, cef_string_ #[no_mangle] extern "C" fn string_wide_dtor(str: *mut wchar_t) { - deletearray(str as *mut c_void) + unsafe { + libc::free(str as *mut c_void) + } } #[no_mangle] extern "C" fn string_utf8_dtor(str: *mut u8) { - deletearray(str as *mut c_void) + unsafe { + libc::free(str as *mut c_void) + } } #[no_mangle] extern "C" fn string_utf16_dtor(str: *mut c_ushort) { - deletearray(str as *mut c_void) + unsafe { + libc::free(str as *mut c_void) + } } #[no_mangle] pub extern "C" fn cef_string_userfree_wide_free(cs: *mut cef_string_userfree_wide_t) { - cef_string_wide_clear(cs); - delete(cs as *mut c_void) + cef_string_wide_clear(cs); + unsafe { + libc::free(cs as *mut c_void) + } } #[no_mangle] pub extern "C" fn cef_string_userfree_utf8_free(cs: *mut cef_string_userfree_utf8_t) { - cef_string_utf8_clear(cs); - delete(cs as *mut c_void) + unsafe { + cef_string_utf8_clear(cs); + libc::free(cs as *mut c_void) + } } #[no_mangle] pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_utf16_t) { - cef_string_utf16_clear(cs); - delete(cs as *mut c_void) + unsafe { + cef_string_utf16_clear(cs); + libc::free(cs as *mut c_void) + } } #[no_mangle] @@ -60,10 +71,12 @@ pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { } } +#[inline(never)] #[no_mangle] pub extern "C" fn cef_string_userfree_utf8_alloc() -> *mut cef_string_utf8_t { - #![inline(never)] - new0::(1) + unsafe { + libc::malloc(mem::size_of::() as u64) as *mut cef_string_utf8_t + } } #[no_mangle] @@ -72,7 +85,7 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = newarray0::(src_len + 1); + (*output).str = libc::malloc(src_len + 1) as *mut u8; if (*output).str.is_null() { return 0; } @@ -139,10 +152,12 @@ pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { } } +#[inline(never)] #[no_mangle] pub extern "C" fn cef_string_userfree_utf16_alloc() -> *mut cef_string_utf16_t { - #![inline(never)] - new0::(1) + unsafe { + libc::malloc(mem::size_of::() as u64) as *mut cef_string_utf16_t + } } #[no_mangle] @@ -151,7 +166,8 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = newarray0::(src_len + 1); + (*output).str = libc::malloc((src_len + 1) * mem::size_of::() as u64) as + *mut u16; if (*output).str.is_null() { return 0; } @@ -194,10 +210,12 @@ pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { } } +#[inline(never)] #[no_mangle] pub extern "C" fn cef_string_userfree_wide_alloc() -> *mut cef_string_wide_t { - #![inline(never)] - new0::(1) + unsafe { + libc::malloc(mem::size_of::() as u64) as *mut cef_string_wide_t + } } #[no_mangle] @@ -206,7 +224,8 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = newarray0::(src_len + 1); + (*output).str = libc::malloc((src_len + 1) * mem::size_of::() as u64) as + *mut wchar_t; if (*output).str.is_null() { return 0; } @@ -250,6 +269,19 @@ pub extern "C" fn cef_string_utf8_to_wide(src: *const u8, src_len: size_t, outpu }) } +/// Wraps a borrowed reference to a UTF-16 CEF string. +pub struct CefStringRef<'a> { + pub c_object: &'a *const cef_string_utf16_t, +} + +impl<'a> CefStringRef<'a> { + pub unsafe fn from_c_object(c_object: &'a *const cef_string_utf16_t) -> CefStringRef<'a> { + CefStringRef { + c_object: c_object, + } + } +} + #[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::() == mem::size_of::() { @@ -280,3 +312,12 @@ pub extern "C" fn cef_string_ascii_to_wide(src: *const u8, src_len: size_t, outp }) } } + +pub fn empty_utf16_string() -> cef_string_utf16_t { + cef_string_utf16_t { + str: ptr::null_mut(), + length: 0, + dtor: None, + } +} + diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index fde447ed94d..0e2912511bf 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -4,7 +4,7 @@ use libc::{c_int}; use std::mem; -use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; +use string::{cef_string_userfree_utf16_alloc,cef_string_userfree_utf16_free,cef_string_utf16_set}; use types::{cef_string_list_t,cef_string_t}; @@ -36,8 +36,8 @@ pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *con unsafe { if lt.is_null() { return; } let v = string_list_to_vec(lt); - let cs = cef_string_userfree_utf8_alloc(); - cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); + let cs = cef_string_userfree_utf16_alloc(); + cef_string_utf16_set(mem::transmute((*value).str), (*value).length, cs, 1); (*v).push(cs); } } @@ -49,7 +49,7 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int let v = string_list_to_vec(lt); if index as uint > (*v).len() - 1 { return 0; } let cs = (*v)[index as uint]; - cef_string_utf8_set(mem::transmute((*cs).str), (*cs).length, value, 1) + cef_string_utf16_set(mem::transmute((*cs).str), (*cs).length, value, 1) } } @@ -62,7 +62,7 @@ pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { let mut cs; while (*v).len() != 0 { cs = (*v).pop(); - cef_string_userfree_utf8_free(cs.unwrap()); + cef_string_userfree_utf16_free(cs.unwrap()); } } } diff --git a/ports/cef/string_map.rs b/ports/cef/string_map.rs index 91434c556f3..8321244fdc6 100644 --- a/ports/cef/string_map.rs +++ b/ports/cef/string_map.rs @@ -7,7 +7,8 @@ use libc::{c_int}; use std::collections::TreeMap; use std::mem; use std::string::String; -use string::{cef_string_userfree_utf8_alloc, cef_string_userfree_utf8_free, cef_string_utf8_set}; +use string::{cef_string_userfree_utf16_alloc, cef_string_userfree_utf16_free}; +use string::{cef_string_utf16_set}; use types::{cef_string_map_t, cef_string_t}; fn string_map_to_treemap(sm: *mut cef_string_map_t) -> *mut TreeMap { @@ -40,8 +41,8 @@ pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const c let v = string_map_to_treemap(sm); slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { let s = String::from_str(result); - let csv = cef_string_userfree_utf8_alloc(); - cef_string_utf8_set((*value).str as *const u8, (*value).length, csv, 1); + let csv = cef_string_userfree_utf16_alloc(); + cef_string_utf16_set((*value).str as *const u16, (*value).length, csv, 1); (*v).insert(s, csv); 1 }) @@ -56,7 +57,7 @@ pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { match (*v).get(&String::from_str(result)) { Some(s) => { - cef_string_utf8_set((**s).str as *const u8, (**s).length, value, 1); + cef_string_utf16_set((**s).str as *const u16, (**s).length, value, 1); 1 } None => 0 @@ -74,7 +75,10 @@ pub extern "C" fn cef_string_map_key(sm: *mut cef_string_map_t, index: c_int, va for (i, k) in (*v).keys().enumerate() { if i == index as uint { - cef_string_utf8_set(k.as_bytes().as_ptr(), k.len() as u64, value, 1); + cef_string_utf16_set(k.as_bytes().as_ptr() as *const u16, + k.len() as u64, + value, + 1); return 1; } } @@ -91,7 +95,7 @@ pub extern "C" fn cef_string_map_value(sm: *mut cef_string_map_t, index: c_int, for (i, val) in (*v).values().enumerate() { if i == index as uint { - cef_string_utf8_set((**val).str as *const u8, (**val).length, value, 1); + cef_string_utf16_set((**val).str as *const u16, (**val).length, value, 1); return 1; } } @@ -105,7 +109,7 @@ pub extern "C" fn cef_string_map_clear(sm: *mut cef_string_map_t) { if sm.is_null() { return; } let v = string_map_to_treemap(sm); for val in (*v).values() { - cef_string_userfree_utf8_free(*val); + cef_string_userfree_utf16_free(*val); } (*v).clear(); } diff --git a/ports/cef/string_multimap.rs b/ports/cef/string_multimap.rs index b8edfa041a7..88d83db9618 100644 --- a/ports/cef/string_multimap.rs +++ b/ports/cef/string_multimap.rs @@ -8,7 +8,7 @@ use std::collections::TreeMap; use std::iter::AdditiveIterator; use std::mem; use std::string::String; -use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; +use string::{cef_string_userfree_utf16_alloc,cef_string_userfree_utf16_free,cef_string_utf16_set}; use types::{cef_string_multimap_t,cef_string_t}; fn string_multimap_to_treemap(smm: *mut cef_string_multimap_t) -> *mut TreeMap> { @@ -55,8 +55,8 @@ pub extern "C" fn cef_string_multimap_append(smm: *mut cef_string_multimap_t, ke let v = string_multimap_to_treemap(smm); slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { let s = String::from_str(result); - let csv = cef_string_userfree_utf8_alloc(); - cef_string_utf8_set((*value).str as *const u8, (*value).length, csv, 1); + let csv = cef_string_userfree_utf16_alloc(); + cef_string_utf16_set((*value).str as *const u16, (*value).length, csv, 1); match (*v).get_mut(&s) { Some(vc) => (*vc).push(csv), None => { (*v).insert(s, vec!(csv)); } @@ -78,7 +78,7 @@ pub extern "C" fn cef_string_multimap_enumerate(smm: *mut cef_string_multimap_t, return 0; } let cs = (*s)[index as uint]; - cef_string_utf8_set((*cs).str as *const u8, (*cs).length, value, 1) + cef_string_utf16_set((*cs).str as *const u16, (*cs).length, value, 1) } None => 0 } @@ -95,7 +95,10 @@ pub extern "C" fn cef_string_multimap_key(smm: *mut cef_string_multimap_t, index for (key, val) in (*v).iter() { if rem < (*val).len() { - return cef_string_utf8_set((*key).as_bytes().as_ptr(), (*key).len() as u64, value, 1); + return cef_string_utf16_set((*key).as_bytes().as_ptr() as *const u16, + (*key).len() as u64, + value, + 1); } else { rem -= (*val).len(); } @@ -114,7 +117,7 @@ pub extern "C" fn cef_string_multimap_value(smm: *mut cef_string_multimap_t, ind for val in (*v).values() { if rem < (*val).len() { let cs = (*val)[rem as uint]; - return cef_string_utf8_set((*cs).str as *const u8, (*cs).length, value, 1); + return cef_string_utf16_set((*cs).str as *const u16, (*cs).length, value, 1); } else { rem -= (*val).len(); } @@ -132,7 +135,7 @@ pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) { for (_, val) in (*v).iter_mut() { while (*val).len() != 0 { let cs = (*val).pop(); - cef_string_userfree_utf8_free(cs.unwrap()); + cef_string_userfree_utf16_free(cs.unwrap()); } } (*v).clear(); diff --git a/ports/cef/stubs.rs b/ports/cef/stubs.rs new file mode 100644 index 00000000000..2264bc693c0 --- /dev/null +++ b/ports/cef/stubs.rs @@ -0,0 +1,53 @@ +/* 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/. */ + +//! Just some stubs so that you can link against this library in place of the +//! Chromium version of CEF. If you call these functions you will assuredly +//! crash. + +macro_rules! stub( + ($name:ident) => ( + #[no_mangle] + pub extern "C" fn $name() { + println!("CEF stub function called: {}", stringify!($name)); + unsafe { + ::std::intrinsics::abort() + } + } + ) +) + +stub!(cef_add_cross_origin_whitelist_entry) +stub!(cef_add_web_plugin_directory) +stub!(cef_add_web_plugin_path) +stub!(cef_begin_tracing) +stub!(cef_clear_cross_origin_whitelist) +stub!(cef_clear_scheme_handler_factories) +stub!(cef_create_url) +stub!(cef_end_tracing) +stub!(cef_force_web_plugin_shutdown) +stub!(cef_get_current_platform_thread_handle) +stub!(cef_get_current_platform_thread_id) +stub!(cef_get_extensions_for_mime_type) +stub!(cef_get_geolocation) +stub!(cef_get_mime_type) +stub!(cef_get_path) +stub!(cef_is_web_plugin_unstable) +stub!(cef_launch_process) +stub!(cef_now_from_system_trace_time) +stub!(cef_parse_url) +stub!(cef_post_delayed_task) +stub!(cef_post_task) +stub!(cef_refresh_web_plugins) +stub!(cef_register_extension) +stub!(cef_register_scheme_handler_factory) +stub!(cef_register_web_plugin_crash) +stub!(cef_remove_cross_origin_whitelist_entry) +stub!(cef_remove_web_plugin_path) +stub!(cef_set_osmodal_loop) +stub!(cef_string_utf16_to_wide) +stub!(cef_string_wide_to_utf16) +stub!(cef_unregister_internal_web_plugin) +stub!(cef_visit_web_plugin_info) + diff --git a/ports/cef/task.rs b/ports/cef/task.rs index 6992149d1b9..b6a43ca7481 100644 --- a/ports/cef/task.rs +++ b/ports/cef/task.rs @@ -2,11 +2,19 @@ * 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 libc::c_int; +use interfaces::cef_task_runner_t; use types::cef_thread_id_t; +use libc::c_int; + //FIXME: this should check the current servo task I guess? #[no_mangle] pub extern "C" fn cef_currently_on(_tid: cef_thread_id_t) -> c_int { 1 } + +cef_stub_static_method_impls! { + fn cef_task_runner_get_for_current_thread() -> *mut cef_task_runner_t; + fn cef_task_runner_get_for_thread(thread_id: cef_thread_id_t) -> *mut cef_task_runner_t; +} + diff --git a/ports/cef/types.rs b/ports/cef/types.rs index a8caa46f406..c29be3bac9a 100644 --- a/ports/cef/types.rs +++ b/ports/cef/types.rs @@ -2,9 +2,11 @@ * 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 libc::{c_uint, c_ushort, c_int, c_double, size_t, c_void, c_longlong}; +use libc::{c_uint, c_ushort, c_int, c_double, size_t, c_void}; use libc::types::os::arch::c95::wchar_t; +pub use self::cef_rect as cef_rect_t; + pub enum cef_string_map_t {} pub enum cef_string_multimap_t {} pub enum cef_string_list_t {} @@ -17,7 +19,6 @@ pub enum cef_dictionary_value_t {} pub enum cef_request_t {} pub enum cef_response_t {} pub enum cef_urlrequest_client_t {} -pub enum cef_frame_t {} pub enum cef_domnode_t {} pub enum cef_load_handler_t {} pub enum cef_request_context_t {} @@ -25,7 +26,6 @@ pub enum cef_browser_settings_t {} pub enum cef_v8context_t {} pub enum cef_v8exception_t {} pub enum cef_v8stack_trace_t {} -pub enum cef_popup_features_t {} pub enum cef_context_menu_handler_t {} pub enum cef_dialog_handler_t {} pub enum cef_download_handler_t {} @@ -39,20 +39,40 @@ pub enum cef_request_handler_t {} #[cfg(target_os="linux")] pub type cef_window_handle_t = c_uint; #[cfg(target_os="macos")] -pub enum cef_window_handle_t {} //NSView* +pub type cef_window_handle_t = *mut c_void; //NSView* //#[cfg(target_os="win")] //pub enum cef_window_handle_t {} //HWND +#[cfg(target_os="linux")] +pub type cef_cursor_handle_t = c_ulong; +#[cfg(target_os="macos")] +pub type cef_cursor_handle_t = *mut c_void; //NSCursor* +//#[cfg(target_os="win")] +//pub enum cef_cursor_handle_t {} //HCURSOR -pub type cef_string_t = cef_string_utf8; //FIXME: this is #defined... +pub enum cef_request_val {} +pub type cef_request = *mut cef_request_val; +pub enum cef_navigation_type_val {} +pub type cef_navigation_type = *mut cef_navigation_type_val; +pub enum cef_screen_info_t {} +pub type cef_v8context = *mut cef_v8context_t; +pub enum cef_v8exception_val {} +pub type cef_v8exception = *mut cef_v8exception_val; +pub enum cef_v8stack_trace_val {} +pub type cef_v8stack_trace = *mut cef_v8stack_trace_val; + +pub type CefBrowserSettings = cef_browser_settings_t; +pub type CefScreenInfo = cef_screen_info_t; + +pub type cef_string_t = cef_string_utf16; //FIXME: this is #defined... pub type cef_string_userfree_t = cef_string_t; //FIXME: this is #defined... -pub type cef_string_utf8_t = cef_string_utf8; -pub type cef_string_userfree_utf8_t = cef_string_utf8; pub struct cef_string_utf8 { pub str: *mut u8, pub length: size_t, pub dtor: Option, } +pub type cef_string_utf8_t = cef_string_utf8; +pub type cef_string_userfree_utf8_t = cef_string_utf8; pub type cef_string_utf16_t = cef_string_utf16; pub type cef_string_userfree_utf16_t = cef_string_utf16; @@ -155,6 +175,7 @@ pub enum cef_mouse_button_type_t { // Structure representing mouse event information. /// pub type cef_mouse_event_t = cef_mouse_event; +pub type CefMouseEvent = cef_mouse_event_t; pub struct cef_mouse_event { /// // X coordinate relative to the left side of the view. @@ -390,10 +411,20 @@ pub struct cef_key_event { pub focus_on_editable_field: c_int, } +pub type CefKeyEvent = cef_key_event_t; + +/// +// Structure representing a point. +/// +pub type cef_point_t = cef_point; +pub struct cef_point { + pub x: c_int, + pub y: c_int, +} + /// // Structure representing a rectangle. /// -pub type cef_rect_t = cef_rect; pub struct cef_rect { pub x: c_int, pub y: c_int, @@ -401,6 +432,17 @@ pub struct cef_rect { pub height: c_int, } +impl cef_rect { + pub fn zero() -> cef_rect { + cef_rect { + x: 0, + y: 0, + width: 0, + height: 0, + } + } +} + /// // Paint element types. /// @@ -409,6 +451,16 @@ pub enum cef_paint_element_type_t { PET_POPUP, } +/// +// DOM document types. +/// +pub enum cef_dom_document_type_t { + DOM_DOCUMENT_TYPE_UNKNOWN = 0, + DOM_DOCUMENT_TYPE_HTML, + DOM_DOCUMENT_TYPE_XHTML, + DOM_DOCUMENT_TYPE_PLUGIN, +} + /// // Supported file dialog modes. /// @@ -445,6 +497,8 @@ pub enum cef_value_type_t { VTYPE_LIST, } +pub type CefValueType = cef_value_type_t; + /// // Existing process IDs. /// @@ -458,6 +512,7 @@ pub enum cef_process_id_t { /// PID_RENDERER, } +pub type CefProcessId = cef_process_id_t; /// // Log severity levels. @@ -500,45 +555,6 @@ pub enum cef_log_severity_t { } -/// -// Structure representing a message. Can be used on any process and thread. -/// -pub type cef_process_message_t = cef_process_message; -pub struct cef_process_message { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns true (1) if this object is valid. Do not call any other functions - // if this function returns false (0). - /// - pub is_valid: Option c_int>, - - /// - // Returns true (1) if the values of this object are read-only. Some APIs may - // expose read-only objects. - /// - pub is_read_only: Option c_int>, - - /// - // Returns a writable copy of this object. - /// - pub copy: Option *mut cef_process_message>, - - /// - // Returns the message name. - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_name: Option *mut cef_string_userfree_t>, - - /// - // Returns the list of arguments. - /// - pub get_argument_list: Option *mut cef_list_value_t>, -} - /// // Initialization settings. Specify NULL or 0 to get the recommended default // values. Many of these and other settings can also configured using command- @@ -773,1398 +789,7 @@ pub struct cef_base { pub get_refct: Option c_int>, } -/// -// Structure used to create and/or parse command line arguments. Arguments with -// '--', '-' and, on Windows, '/' prefixes are considered switches. Switches -// will always precede any arguments without switch prefixes. Switches can -// optionally have a value specified using the '=' delimiter (e.g. -// "-switch=value"). An argument of "--" will terminate switch parsing with all -// subsequent tokens, regardless of prefix, being interpreted as non-switch -// arguments. Switch names are considered case-insensitive. This structure can -// be used before cef_initialize() is called. -/// -pub type cef_command_line_t = cef_command_line; -pub struct cef_command_line { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns true (1) if this object is valid. Do not call any other functions - // if this function returns false (0). - /// - pub is_valid: Option, - - /// - // Returns true (1) if the values of this object are read-only. Some APIs may - // expose read-only objects. - /// - pub is_read_only: Option, - - /// - // Returns a writable copy of this object. - /// - pub copy: Option *mut cef_command_line>, - - /// - // Initialize the command line with the specified |argc| and |argv| values. - // The first argument must be the name of the program. This function is only - // supported on non-Windows platforms. - /// - pub init_from_argv: Option, - - /// - // Initialize the command line with the string returned by calling - // GetCommandLineW(). This function is only supported on Windows. - /// - pub init_from_string: Option, - - /// - // Reset the command-line switches and arguments but leave the program - // component unchanged. - /// - pub reset: Option, - - /// - // Retrieve the original command line string as a vector of strings. The argv - // array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* } - /// - pub get_argv: Option, - - /// - // Constructs and returns the represented command line string. Use this - // function cautiously because quoting behavior is unclear. - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_command_line_string: Option *mut cef_string_userfree_t>, - - /// - // Get the program part of the command line string (the first item). - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_program: Option *mut cef_string_userfree_t>, - - /// - // Set the program part of the command line string (the first item). - /// - pub set_program: Option, - - /// - // Returns true (1) if the command line has switches. - /// - pub has_switches: Option c_int>, - - /// - // Returns true (1) if the command line contains the given switch. - /// - pub has_switch: Option c_int>, - - /// - // Returns the value associated with the given switch. If the switch has no - // value or isn't present this function returns the NULL string. - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_switch_value: Option *mut cef_string_userfree_t>, - - /// - // Returns the map of switch names and values. If a switch has no value an - // NULL string is returned. - /// - pub get_switches: Option, - - /// - // Add a switch to the end of the command line. If the switch has no value - // pass an NULL value string. - /// - pub append_switch: Option, - - /// - // Add a switch with the specified value to the end of the command line. - /// - pub append_switch_with_value: Option, - - /// - // True if there are remaining command line arguments. - /// - pub has_arguments: Option c_int>, - - /// - // Get the remaining command line arguments. - /// - pub get_arguments: Option, - - /// - // Add an argument to the end of the command line. - /// - pub append_argument: Option, - - /// - // Insert a command before the current command. Common for debuggers, like - // "valgrind" or "gdb --args". - /// - pub prepend_wrapper: Option, -} - - -/// -// Structure that manages custom scheme registrations. -/// -pub type cef_scheme_registrar_t = cef_scheme_registrar; -pub struct cef_scheme_registrar { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Register a custom scheme. This function should not be called for the built- - // in HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes. - // - // If |is_standard| is true (1) the scheme will be treated as a standard - // scheme. Standard schemes are subject to URL canonicalization and parsing - // rules as defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 - // available at http://www.ietf.org/rfc/rfc1738.txt - // - // In particular, the syntax for standard scheme URLs must be of the form: - //
-  //  [scheme]://[username]:[password]@[host]:[port]/[url-path]
-  // 
, -} - -/// -// Structure used to implement a custom resource bundle structure. The functions -// of this structure may be called on multiple threads. -/// -pub type cef_resource_bundle_handler_t = cef_resource_bundle_handler; -pub struct cef_resource_bundle_handler { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Called to retrieve a localized translation for the string specified by - // |message_id|. To provide the translation set |string| to the translation - // string and return true (1). To use the default translation return false - // (0). Supported message IDs are listed in cef_pack_strings.h. - /// - pub get_localized_string: Option c_int>, - - /// - // Called to retrieve data for the resource specified by |resource_id|. To - // provide the resource data set |data| and |data_size| to the data pointer - // and size respectively and return true (1). To use the default resource data - // return false (0). The resource data will not be copied and must remain - // resident in memory. Supported resource IDs are listed in - // cef_pack_resources.h. - /// - pub get_data_resource: Option c_int>, -} - - - -/// -// Structure representing a list value. Can be used on any process and thread. -/// -pub type cef_list_value_t = cef_list_value; -pub struct cef_list_value { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns true (1) if this object is valid. Do not call any other functions - // if this function returns false (0). - /// - pub is_valid: Option c_int>, - - /// - // Returns true (1) if this object is currently owned by another object. - /// - pub is_owned: Option c_int>, - - /// - // Returns true (1) if the values of this object are read-only. Some APIs may - // expose read-only objects. - /// - pub is_read_only: Option c_int>, - - /// - // Returns a writable copy of this object. - /// - pub copy: Option *mut cef_list_value_t>, - - /// - // Sets the number of values. If the number of values is expanded all new - // value slots will default to type null. Returns true (1) on success. - /// - pub set_size: Option c_int>, - - /// - // Returns the number of values. - /// - pub get_size: Option size_t>, - - /// - // Removes all values. Returns true (1) on success. - /// - pub clear: Option c_int>, - - /// - // Removes the value at the specified index. - /// - pub remove: Option c_int>, - - /// - // Returns the value type at the specified index. - /// - pub get_type: Option cef_value_type_t>, - - /// - // Returns the value at the specified index as type bool. - /// - pub get_bool: Option c_int>, - - /// - // Returns the value at the specified index as type int. - /// - pub get_int: Option c_int>, - - /// - // Returns the value at the specified index as type double. - /// - pub get_double: Option c_double>, - - /// - // Returns the value at the specified index as type string. - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_string: Option *mut cef_string_userfree_t>, - - /// - // Returns the value at the specified index as type binary. - /// - pub get_binary: Option *mut cef_binary_value_t>, - - /// - // Returns the value at the specified index as type dictionary. - /// - pub get_dictionary: Option *mut cef_dictionary_value_t>, - - /// - // Returns the value at the specified index as type list. - /// - pub get_list: Option *mut cef_list_value_t>, - - /// - // Sets the value at the specified index as type null. Returns true (1) if the - // value was set successfully. - /// - pub set_null: Option c_int>, - - /// - // Sets the value at the specified index as type bool. Returns true (1) if the - // value was set successfully. - /// - pub set_bool: Option c_int>, - - /// - // Sets the value at the specified index as type int. Returns true (1) if the - // value was set successfully. - /// - pub set_int: Option c_int>, - - /// - // Sets the value at the specified index as type double. Returns true (1) if - // the value was set successfully. - /// - pub set_double: Option c_int>, - - /// - // Sets the value at the specified index as type string. Returns true (1) if - // the value was set successfully. - /// - pub set_string: Option c_int>, - - /// - // Sets the value at the specified index as type binary. Returns true (1) if - // the value was set successfully. After calling this function the |value| - // object will no longer be valid. If |value| is currently owned by another - // object then the value will be copied and the |value| reference will not - // change. Otherwise, ownership will be transferred to this object and the - // |value| reference will be invalidated. - /// - pub set_binary: Option c_int>, - - /// - // Sets the value at the specified index as type dict. Returns true (1) if the - // value was set successfully. After calling this function the |value| object - // will no longer be valid. If |value| is currently owned by another object - // then the value will be copied and the |value| reference will not change. - // Otherwise, ownership will be transferred to this object and the |value| - // reference will be invalidated. - /// - pub set_dictionary: Option c_int>, - - /// - // Sets the value at the specified index as type list. Returns true (1) if the - // value was set successfully. After calling this function the |value| object - // will no longer be valid. If |value| is currently owned by another object - // then the value will be copied and the |value| reference will not change. - // Otherwise, ownership will be transferred to this object and the |value| - // reference will be invalidated. - /// - pub set_list: Option c_int>, -} - -/// -// Structure used to implement browser process callbacks. The functions of this -// structure will be called on the browser process main thread unless otherwise -// indicated. -/// -pub type cef_browser_process_handler_t = cef_browser_process_handler; -pub struct cef_browser_process_handler { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Called on the browser process UI thread immediately after the CEF context - // has been initialized. - /// - pub on_context_initialized: Option, - - /// - // Called before a child process is launched. Will be called on the browser - // process UI thread when launching a render process and on the browser - // process IO thread when launching a GPU or plugin process. Provides an - // opportunity to modify the child process command line. Do not keep a - // reference to |command_line| outside of this function. - /// - pub on_before_child_process_launch: Option, - - /// - // Called on the browser process IO thread after the main thread has been - // created for a new render process. Provides an opportunity to specify extra - // information that will be passed to - // cef_render_process_handler_t::on_render_thread_created() in the render - // process. Do not keep a reference to |extra_info| outside of this function. - /// - pub on_render_process_thread_created: Option, -} - - -/// -// Callback structure for cef_browser_host_t::RunFileDialog. The functions of -// this structure will be called on the browser process UI thread. -/// -pub type cef_run_file_dialog_callback_t = cef_run_file_dialog_callback; -pub struct cef_run_file_dialog_callback { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Called asynchronously after the file dialog is dismissed. If the selection - // was successful |file_paths| will be a single value or a list of values - // depending on the dialog mode. If the selection was cancelled |file_paths| - // will be NULL. - /// - pub cont: Option, -} - -/// -// Structure used to represent the browser process aspects of a browser window. -// The functions of this structure can only be called in the browser process. -// They may be called on any thread in that process unless otherwise indicated -// in the comments. -/// -pub type cef_browser_host_t = cef_browser_host; -pub struct cef_browser_host { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns the hosted browser object. - /// - pub get_browser: Option *mut cef_browser_t>, - - /// - // Call this function before destroying a contained browser window. This - // function performs any internal cleanup that may be needed before the - // browser window is destroyed. See cef_life_span_handler_t::do_close() - // documentation for additional usage information. - /// - pub parent_window_will_close: Option, - - /// - // Request that the browser close. The JavaScript 'onbeforeunload' event will - // be fired. If |force_close| is false (0) the event handler, if any, will be - // allowed to prompt the user and the user can optionally cancel the close. If - // |force_close| is true (1) the prompt will not be displayed and the close - // will proceed. Results in a call to cef_life_span_handler_t::do_close() if - // the event handler allows the close or if |force_close| is true (1). See - // cef_life_span_handler_t::do_close() documentation for additional usage - // information. - /// - pub close_browser: Option, - - /// - // Set focus for the browser window. If |enable| is true (1) focus will be set - // to the window. Otherwise, focus will be removed. - /// - pub set_focus: Option, - - /// - // Retrieve the window handle for this browser. - /// - pub get_window_handle: Option *mut cef_window_handle_t>, - - /// - // Retrieve the window handle of the browser that opened this browser. Will - // return NULL for non-popup windows. This function can be used in combination - // with custom handling of modal windows. - /// - pub get_opener_window_handle: Option *mut cef_window_handle_t>, - - /// - // Returns the client for this browser. - /// - pub get_client: Option *mut cef_client_t>, - - /// - // Returns the request context for this browser. - /// - pub get_request_context: Option *mut cef_request_context_t>, - - /// - // Get the current zoom level. The default zoom level is 0.0. This function - // can only be called on the UI thread. - /// - pub get_zoom_level: Option c_double>, - - /// - // Change the zoom level to the specified value. Specify 0.0 to reset the zoom - // level. If called on the UI thread the change will be applied immediately. - // Otherwise, the change will be applied asynchronously on the UI thread. - /// - pub set_zoom_level: Option, - - /// - // Call to run a file chooser dialog. Only a single file chooser dialog may be - // pending at any given time. |mode| represents the type of dialog to display. - // |title| to the title to be used for the dialog and may be NULL to show the - // default title ("Open" or "Save" depending on the mode). |default_file_name| - // is the default file name to select in the dialog. |accept_types| is a list - // of valid lower-cased MIME types or file extensions specified in an input - // element and is used to restrict selectable files to such types. |callback| - // will be executed after the dialog is dismissed or immediately if another - // dialog is already pending. The dialog will be initiated asynchronously on - // the UI thread. - /// - pub run_file_dialog: Option, - - /// - // Download the file at |url| using cef_download_handler_t. - /// - pub start_download: Option, - - /// - // Print the current browser contents. - /// - pub print: Option, - - /// - // Search for |searchText|. |identifier| can be used to have multiple searches - // running simultaniously. |forward| indicates whether to search forward or - // backward within the page. |matchCase| indicates whether the search should - // be case-sensitive. |findNext| indicates whether this is the first request - // or a follow-up. - /// - pub find: Option, - - /// - // Cancel all searches that are currently going on. - /// - pub stop_finding: Option, - - /// - // Open developer tools in its own window. - /// - pub show_dev_tools: Option, - - /// - // Explicitly close the developer tools window if one exists for this browser - // instance. - /// - pub close_dev_tools: Option, - - /// - // Set whether mouse cursor change is disabled. - /// - pub set_mouse_cursor_change_disabled: Option, - - /// - // Returns true (1) if mouse cursor change is disabled. - /// - pub is_mouse_cursor_change_disabled: Option c_int>, - - /// - // Returns true (1) if window rendering is disabled. - /// - pub is_window_rendering_disabled: Option c_int>, - - /// - // Notify the browser that the widget has been resized. The browser will first - // call cef_render_handler_t::GetViewRect to get the new size and then call - // cef_render_handler_t::OnPaint asynchronously with the updated regions. This - // function is only used when window rendering is disabled. - /// - pub was_resized: Option, - - /// - // Notify the browser that it has been hidden or shown. Layouting and - // cef_render_handler_t::OnPaint notification will stop when the browser is - // hidden. This function is only used when window rendering is disabled. - /// - pub was_hidden: Option, - - /// - // Send a notification to the browser that the screen info has changed. The - // browser will then call cef_render_handler_t::GetScreenInfo to update the - // screen information with the new values. This simulates moving the webview - // window from one display to another, or changing the properties of the - // current display. This function is only used when window rendering is - // disabled. - /// - pub notify_screen_info_changed: Option, - - /// - // Invalidate the |dirtyRect| region of the view. The browser will call - // cef_render_handler_t::OnPaint asynchronously with the updated regions. This - // function is only used when window rendering is disabled. - /// - pub invalidate: Option, - - /// - // Send a key event to the browser. - /// - pub send_key_event: Option, - - /// - // Send a mouse click event to the browser. The |x| and |y| coordinates are - // relative to the upper-left corner of the view. - /// - pub send_mouse_click_event: Option, - - /// - // Send a mouse move event to the browser. The |x| and |y| coordinates are - // relative to the upper-left corner of the view. - /// - pub send_mouse_move_event: Option, - - /// - // Send a mouse wheel event to the browser. The |x| and |y| coordinates are - // relative to the upper-left corner of the view. The |deltaX| and |deltaY| - // values represent the movement delta in the X and Y directions respectively. - // In order to scroll inside select popups with window rendering disabled - // cef_render_handler_t::GetScreenPoint should be implemented properly. - /// - pub send_mouse_wheel_event: Option, - - /// - // Send a focus event to the browser. - /// - pub send_focus_event: Option, - - /// - // Send a capture lost event to the browser. - /// - pub send_capture_lost_event: Option, - - /// - // Get the NSTextInputContext implementation for enabling IME on Mac when - // window rendering is disabled. - /// - pub get_nstext_input_context: Option cef_text_input_context_t>, - - /// - // Handles a keyDown event prior to passing it through the NSTextInputClient - // machinery. - /// - pub handle_key_event_before_text_input_client: Option, - - /// - // Performs any additional actions after NSTextInputClient handles the event. - /// - pub handle_key_event_after_text_input_client: Option, -} - - -/// -// Structure used to represent a browser window. When used in the browser -// process the functions of this structure may be called on any thread unless -// otherwise indicated in the comments. When used in the render process the -// functions of this structure may only be called on the main thread. -/// -pub type cef_browser_t = cef_browser; -pub struct cef_browser { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns the browser host object. This function can only be called in the - // browser process. - /// - pub get_host: Option *mut cef_browser_host>, - - /// - // Returns true (1) if the browser can navigate backwards. - /// - pub can_go_back: Option c_int>, - - /// - // Navigate backwards. - /// - pub go_back: Option, - - /// - // Returns true (1) if the browser can navigate forwards. - /// - pub can_go_forward: Option c_int>, - - /// - // Navigate forwards. - /// - pub go_forward: Option, - - /// - // Returns true (1) if the browser is currently loading. - /// - pub is_loading: Option c_int>, - - /// - // Reload the current page. - /// - pub reload: Option, - - /// - // Reload the current page ignoring any cached data. - /// - pub reload_ignore_cache: Option, - - /// - // Stop loading the page. - /// - pub stop_load: Option, - - /// - // Returns the globally unique identifier for this browser. - /// - pub get_identifier: Option c_int>, - - /// - // Returns true (1) if this object is pointing to the same handle as |that| - // object. - /// - pub is_same: Option c_int>, - - /// - // Returns true (1) if the window is a popup window. - /// - pub is_popup: Option c_int>, - - /// - // Returns true (1) if a document has been loaded in the browser. - /// - pub has_document: Option c_int>, - - /// - // Returns the main (top-level) frame for the browser window. - /// - pub get_main_frame: Option *mut cef_frame_t>, - - /// - // Returns the focused frame for the browser window. - /// - pub get_focused_frame: Option *mut cef_frame_t>, - - /// - // Returns the frame with the specified identifier, or NULL if not found. - /// - pub get_frame_byident: Option *mut cef_frame_t>, - - /// - // Returns the frame with the specified name, or NULL if not found. - /// - pub get_frame: Option *mut cef_frame_t>, - - /// - // Returns the number of frames that currently exist. - /// - pub get_frame_count: Option size_t>, - - /// - // Returns the identifiers of all existing frames. - /// - pub get_frame_identifiers: Option, - - /// - // Returns the names of all existing frames. - /// - pub get_frame_names: Option, - - // - // Send a message to the specified |target_process|. Returns true (1) if the - // message was sent successfully. - /// - pub send_process_message: Option c_int>, -} - -/// -// Structure used to implement render process callbacks. The functions of this -// structure will be called on the render process main thread (TID_RENDERER) -// unless otherwise indicated. -/// -pub type cef_render_process_handler_t = cef_render_process_handler; -pub struct cef_render_process_handler { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Called after the render process main thread has been created. |extra_info| - // is a read-only value originating from - // cef_browser_process_handler_t::on_render_process_thread_created(). Do not - // keep a reference to |extra_info| outside of this function. - /// - pub on_render_thread_created: Option, - - /// - // Called after WebKit has been initialized. - /// - pub on_web_kit_initialized: Option, - - /// - // Called after a browser has been created. When browsing cross-origin a new - // browser will be created before the old browser with the same identifier is - // destroyed. - /// - pub on_browser_created: Option, - - /// - // Called before a browser is destroyed. - /// - pub on_browser_destroyed: Option, - - /// - // Return the handler for browser load status events. - /// - pub get_load_handler: Option *mut cef_load_handler_t>, - - /// - // Called before browser navigation. Return true (1) to cancel the navigation - // or false (0) to allow the navigation to proceed. The |request| object - // cannot be modified in this callback. - /// - pub on_before_navigation: Option c_int>, - - /// - // Called immediately after the V8 context for a frame has been created. To - // retrieve the JavaScript 'window' object use the - // cef_v8context_t::get_global() function. V8 handles can only be accessed - // from the thread on which they are created. A task runner for posting tasks - // on the associated thread can be retrieved via the - // cef_v8context_t::get_task_runner() function. - /// - pub on_context_created: Option, - - /// - // Called immediately before the V8 context for a frame is released. No - // references to the context should be kept after this function is called. - /// - pub on_context_released: Option, - - /// - // Called for global uncaught exceptions in a frame. Execution of this - // callback is disabled by default. To enable set - // CefSettings.uncaught_exception_stack_size 0. - /// - pub on_uncaught_exception: Option, - - /// - // Called when a new node in the the browser gets focus. The |node| value may - // be NULL if no specific node has gained focus. The node object passed to - // this function represents a snapshot of the DOM at the time this function is - // executed. DOM objects are only valid for the scope of this function. Do not - // keep references to or attempt to access any DOM objects outside the scope - // of this function. - /// - pub on_focused_node_changed: Option, - - /// - // Called when a new message is received from a different process. Return true - // (1) if the message was handled or false (0) otherwise. Do not keep a - // reference to or attempt to access the message outside of this callback. - /// - pub on_process_message_received: Optionc_int>, -} - -/// -// Implement this structure to provide handler implementations. Methods will be -// called by the process and/or thread indicated. -/// -pub type cef_app_t = cef_app; -pub struct cef_app { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Provides an opportunity to view and/or modify command-line arguments before - // processing by CEF and Chromium. The |process_type| value will be NULL for - // the browser process. Do not keep a reference to the cef_command_line_t - // object passed to this function. The CefSettings.command_line_args_disabled - // value can be used to start with an NULL command-line object. Any values - // specified in CefSettings that equate to command-line arguments will be set - // before this function is called. Be cautious when using this function to - // modify command-line arguments for non-browser processes as this may result - // in undefined behavior including crashes. - /// - pub on_before_command_line_processing: Option, - - /// - // Provides an opportunity to register custom schemes. Do not keep a reference - // to the |registrar| object. This function is called on the main thread for - // each process and the registered schemes should be the same across all - // processes. - /// - pub on_register_custom_schemes: Option, - - /// - // Return the handler for resource bundle events. If - // CefSettings.pack_loading_disabled is true (1) a handler must be returned. - // If no handler is returned resources will be loaded from pack files. This - // function is called by the browser and render processes on multiple threads. - /// - pub get_resource_bundle_handler: Option *mut cef_resource_bundle_handler_t>, - - /// - // Return the handler for functionality specific to the browser process. This - // function is called on multiple threads in the browser process. - /// - pub get_browser_process_handler: Option *mut cef_browser_process_handler>, - - /// - // Return the handler for functionality specific to the render process. This - // function is called on the render process main thread. - /// - pub get_render_process_handler: Option *mut cef_render_process_handler_t>, -} - - -/// -// Structure used to make a URL request. URL requests are not associated with a -// browser instance so no cef_client_t callbacks will be executed. URL requests -// can be created on any valid CEF thread in either the browser or render -// process. Once created the functions of the URL request object must be -// accessed on the same thread that created it. -/// -pub type cef_urlrequest_t = cef_urlrequest; -pub struct cef_urlrequest { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns the request object used to create this URL request. The returned - // object is read-only and should not be modified. - /// - pub get_request: Option *mut cef_request_t>, - - /// - // Returns the client. - /// - pub get_client: Option *mut cef_urlrequest_client_t>, - - /// - // Returns the request status. - /// - pub get_request_status: Option cef_urlrequest_status_t>, - - /// - // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0 - // otherwise. - /// - pub get_request_error: Option cef_errorcode_t>, - - /// - // Returns the response, or NULL if no response information is available. - // Response information will only be available after the upload has completed. - // The returned object is read-only and should not be modified. - /// - pub get_response: Option *mut cef_response_t>, - - /// - // Cancel the request. - /// - pub cancel: Option, -} - - - -/// -// Structure used to represent a single element in the request post data. The -// functions of this structure may be called on any thread. -/// -pub type cef_post_data_element_t = cef_post_data_element; -pub struct cef_post_data_element { - /// - // Base structure. - /// - pub base: cef_base, - - /// - // Returns true (1) if this object is read-only. - /// - pub is_read_only: Option c_int>, - - /// - // Remove all contents from the post data element. - /// - pub set_to_empty: Option, - - /// - // The post data element will represent a file. - /// - pub set_to_file: Option, - - /// - // The post data element will represent bytes. The bytes passed in will be - // copied. - /// - pub set_to_bytes: Option, - - /// - // Return the type of this post data element. - /// - pub get_type: Option cef_postdataelement_type_t>, - - /// - // Return the file name. - /// - // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_file: Option *mut cef_string_userfree_t>, - - /// - // Return the number of bytes. - /// - pub get_bytes_count: Option size_t>, - - /// - // Read up to |size| bytes into |bytes| and return the number of bytes - // actually read. - /// - pub get_bytes: Option size_t>, -} - - -/// -// Structure used to represent post data for a web request. The functions of -// this structure may be called on any thread. -/// -pub type cef_post_data_t = cef_post_data; -pub struct cef_post_data { - /// - // Base structure. - /// - pub base: cef_base_t, - - /// - // Returns true (1) if this object is read-only. - /// - pub is_read_only: Option c_int>, - - /// - // Returns the number of existing post data elements. - /// - pub get_element_count: Option size_t>, - - /// - // Retrieve the post data elements. - /// - pub get_elements: Option, - - /// - // Remove the specified post data element. Returns true (1) if the removal - // succeeds. - /// - pub remove_element: Option c_int>, - - /// - // Add the specified post data element. Returns true (1) if the add succeeds. - /// - pub add_element: Option c_int>, - - /// - // Remove all existing post data elements. - /// - pub remove_elements: Option, -} - - - -/// -// Implement this structure to handle events related to browser display state. -// The functions of this structure will be called on the UI thread. -/// -pub type cef_display_handler_t = cef_display_handler; -pub struct cef_display_handler { - /// - // Base structure. - /// - pub base: cef_base_t, - - /// - // Called when a frame's address has changed. - /// - pub on_address_change: Option, - - /// - // Called when the page title changes. - /// - pub on_title_change: Option, - - /// - // Called when the browser is about to display a tooltip. |text| contains the - // text that will be displayed in the tooltip. To handle the display of the - // tooltip yourself return true (1). Otherwise, you can optionally modify - // |text| and then return false (0) to allow the browser to display the - // tooltip. When window rendering is disabled the application is responsible - // for drawing tooltips and the return value is ignored. - /// - pub on_tooltip: Option c_int>, - - /// - // Called when the browser receives a status message. |value| contains the - // text that will be displayed in the status message. - /// - pub on_status_message: Option, - - /// - // Called to display a console message. Return true (1) to stop the message - // from being output to the console. - /// - pub on_console_message: Option c_int> -} - -/// -// Implement this structure to handle events related to browser life span. The -// functions of this structure will be called on the UI thread unless otherwise -// indicated. -/// -pub type cef_life_span_handler_t = cef_life_span_handler; -pub struct cef_life_span_handler { - /// - // Base structure. - /// - pub base: cef_base_t, - - /// - // Called on the IO thread before a new popup window is created. The |browser| - // and |frame| parameters represent the source of the popup request. The - // |target_url| and |target_frame_name| values may be NULL if none were - // specified with the request. The |popupFeatures| structure contains - // information about the requested popup window. To allow creation of the - // popup window optionally modify |windowInfo|, |client|, |settings| and - // |no_javascript_access| and return false (0). To cancel creation of the - // popup window return true (1). The |client| and |settings| values will - // default to the source browser's values. The |no_javascript_access| value - // indicates whether the new browser window should be scriptable and in the - // same process as the source browser. - pub on_before_popup: Option c_int>, - - /// - // Called after a new browser is created. - /// - pub on_after_created: Option, - - /// - // Called when a modal window is about to display and the modal loop should - // begin running. Return false (0) to use the default modal loop - // implementation or true (1) to use a custom implementation. - /// - pub run_modal: Option c_int>, - - /// - // Called when a browser has recieved a request to close. This may result - // directly from a call to cef_browser_host_t::close_browser() or indirectly - // if the browser is a top-level OS window created by CEF and the user - // attempts to close the window. This function will be called after the - // JavaScript 'onunload' event has been fired. It will not be called for - // browsers after the associated OS window has been destroyed (for those - // browsers it is no longer possible to cancel the close). - // - // If CEF created an OS window for the browser returning false (0) will send - // an OS close notification to the browser window's top-level owner (e.g. - // WM_CLOSE on Windows, performClose: on OS-X and "delete_event" on Linux). If - // no OS window exists (window rendering disabled) returning false (0) will - // cause the browser object to be destroyed immediately. Return true (1) if - // the browser is parented to another window and that other window needs to - // receive close notification via some non-standard technique. - // - // If an application provides its own top-level window it should handle OS - // close notifications by calling cef_browser_host_t::CloseBrowser(false (0)) - // instead of immediately closing (see the example below). This gives CEF an - // opportunity to process the 'onbeforeunload' event and optionally cancel the - // close before do_close() is called. - // - // The cef_life_span_handler_t::on_before_close() function will be called - // immediately before the browser object is destroyed. The application should - // only exit after on_before_close() has been called for all existing - // browsers. - // - // If the browser represents a modal window and a custom modal loop - // implementation was provided in cef_life_span_handler_t::run_modal() this - // callback should be used to restore the opener window to a usable state. - // - // By way of example consider what should happen during window close when the - // browser is parented to an application-provided top-level OS window. 1. - // User clicks the window close button which sends an OS close - // notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and - // "delete_event" on Linux). - // 2. Application's top-level window receives the close notification and: - // A. Calls CefBrowserHost::CloseBrowser(false). - // B. Cancels the window close. - // 3. JavaScript 'onbeforeunload' handler executes and shows the close - // confirmation dialog (which can be overridden via - // CefJSDialogHandler::OnBeforeUnloadDialog()). - // 4. User approves the close. 5. JavaScript 'onunload' handler executes. 6. - // Application's do_close() handler is called. Application will: - // A. Set a flag to indicate that the next close attempt will be allowed. - // B. Return false. - // 7. CEF sends an OS close notification. 8. Application's top-level window - // receives the OS close notification and - // allows the window to close based on the flag from #6B. - // 9. Browser OS window is destroyed. 10. Application's - // cef_life_span_handler_t::on_before_close() handler is called and - // the browser object is destroyed. - // 11. Application exits by calling cef_quit_message_loop() if no other - // browsers - // exist. - /// - pub do_close: Option c_int>, - - /// - // Called just before a browser is destroyed. Release all references to the - // browser object and do not attempt to execute any functions on the browser - // object after this callback returns. If this is a modal window and a custom - // modal loop implementation was provided in run_modal() this callback should - // be used to exit the custom modal loop. See do_close() documentation for - // additional usage information. - /// - pub on_before_close: Option, -} - -/// -// Implement this structure to provide handler implementations. -/// -pub type cef_client_t = cef_client; -pub struct cef_client { - /// - // Base structure. - /// - pub base: cef_base_t, - - /// - // Return the handler for context menus. If no handler is provided the default - // implementation will be used. - /// - pub get_context_menu_handler: Option *mut cef_context_menu_handler_t>, - - /// - // Return the handler for dialogs. If no handler is provided the default - // implementation will be used. - /// - pub get_dialog_handler: Option *mut cef_dialog_handler_t>, - - /// - // Return the handler for browser display state events. - /// - pub get_display_handler: Option *mut cef_display_handler_t>, - - /// - // Return the handler for download events. If no handler is returned downloads - // will not be allowed. - /// - pub get_download_handler: Option *mut cef_download_handler_t>, - - /// - // Return the handler for drag events. - /// - pub get_drag_handler: Option *mut cef_drag_handler_t>, - - /// - // Return the handler for focus events. - /// - pub get_focus_handler: Option *mut cef_focus_handler_t>, - - /// - // Return the handler for geolocation permissions requests. If no handler is - // provided geolocation access will be denied by default. - /// - pub get_geolocation_handler: Option *mut cef_geolocation_handler_t>, - - /// - // Return the handler for JavaScript dialogs. If no handler is provided the - // default implementation will be used. - /// - pub get_jsdialog_handler: Option *mut cef_jsdialog_handler_t>, - - /// - // Return the handler for keyboard events. - /// - pub get_keyboard_handler: Option *mut cef_keyboard_handler_t>, - - /// - // Return the handler for browser life span events. - /// - pub get_life_span_handler: Option *mut cef_life_span_handler_t>, - - /// - // Return the handler for browser load status events. - /// - pub get_load_handler: Option *mut cef_load_handler_t>, - - /// - // Return the handler for off-screen rendering events. - /// - pub get_render_handler: Option *mut cef_render_handler_t>, - - /// - // Return the handler for browser request events. - /// - pub get_request_handler: Option *mut cef_request_handler_t>, - - /// - // Called when a new message is received from a different process. Return true - // (1) if the message was handled or false (0) otherwise. Do not keep a - // reference to or attempt to access the message outside of this callback. - /// - pub on_process_message_received: Option c_int>, -} +pub type CefBase = *mut cef_base_t; /// // Class representing window information. @@ -2206,3 +831,684 @@ pub struct cef_window_info { /// pub window: cef_window_handle_t } + +pub type CefWindowInfo = cef_window_info_t; + +/// +// Supported menu item types. +/// +pub enum cef_menu_item_type_t { + MENUITEMTYPE_NONE, + MENUITEMTYPE_COMMAND, + MENUITEMTYPE_CHECK, + MENUITEMTYPE_RADIO, + MENUITEMTYPE_SEPARATOR, + MENUITEMTYPE_SUBMENU, +} + +/// +// Supported context menu type flags. +/// +pub enum cef_context_menu_type_flags_t { + /// + // No node is selected. + /// + CM_TYPEFLAG_NONE = 0, + /// + // The top page is selected. + /// + CM_TYPEFLAG_PAGE = 1 << 0, + /// + // A subframe page is selected. + /// + CM_TYPEFLAG_FRAME = 1 << 1, + /// + // A link is selected. + /// + CM_TYPEFLAG_LINK = 1 << 2, + /// + // A media node is selected. + /// + CM_TYPEFLAG_MEDIA = 1 << 3, + /// + // There is a textual or mixed selection that is selected. + /// + CM_TYPEFLAG_SELECTION = 1 << 4, + /// + // An editable element is selected. + /// + CM_TYPEFLAG_EDITABLE = 1 << 5, +} + +/// +// Supported context menu media types. +/// +pub enum cef_context_menu_media_type_t { + /// + // No special node is in context. + /// + CM_MEDIATYPE_NONE, + /// + // An image node is selected. + /// + CM_MEDIATYPE_IMAGE, + /// + // A video node is selected. + /// + CM_MEDIATYPE_VIDEO, + /// + // An audio node is selected. + /// + CM_MEDIATYPE_AUDIO, + /// + // A file node is selected. + /// + CM_MEDIATYPE_FILE, + /// + // A plugin node is selected. + /// + CM_MEDIATYPE_PLUGIN, +} + +/// +// Supported context menu media state bit flags. +/// +pub enum cef_context_menu_media_state_flags_t { + CM_MEDIAFLAG_NONE = 0, + CM_MEDIAFLAG_ERROR = 1 << 0, + CM_MEDIAFLAG_PAUSED = 1 << 1, + CM_MEDIAFLAG_MUTED = 1 << 2, + CM_MEDIAFLAG_LOOP = 1 << 3, + CM_MEDIAFLAG_CAN_SAVE = 1 << 4, + CM_MEDIAFLAG_HAS_AUDIO = 1 << 5, + CM_MEDIAFLAG_HAS_VIDEO = 1 << 6, + CM_MEDIAFLAG_CONTROL_ROOT_ELEMENT = 1 << 7, + CM_MEDIAFLAG_CAN_PRINT = 1 << 8, + CM_MEDIAFLAG_CAN_ROTATE = 1 << 9, +} + +/// +// Supported context menu edit state bit flags. +/// +pub enum cef_context_menu_edit_state_flags_t { + CM_EDITFLAG_NONE = 0, + CM_EDITFLAG_CAN_UNDO = 1 << 0, + CM_EDITFLAG_CAN_REDO = 1 << 1, + CM_EDITFLAG_CAN_CUT = 1 << 2, + CM_EDITFLAG_CAN_COPY = 1 << 3, + CM_EDITFLAG_CAN_PASTE = 1 << 4, + CM_EDITFLAG_CAN_DELETE = 1 << 5, + CM_EDITFLAG_CAN_SELECT_ALL = 1 << 6, + CM_EDITFLAG_CAN_TRANSLATE = 1 << 7, +} + +/// +// Supported event bit flags. +/// +pub enum cef_event_flags_t { + EVENTFLAG_NONE = 0, + EVENTFLAG_CAPS_LOCK_ON = 1 << 0, + EVENTFLAG_SHIFT_DOWN = 1 << 1, + EVENTFLAG_CONTROL_DOWN = 1 << 2, + EVENTFLAG_ALT_DOWN = 1 << 3, + EVENTFLAG_LEFT_MOUSE_BUTTON = 1 << 4, + EVENTFLAG_MIDDLE_MOUSE_BUTTON = 1 << 5, + EVENTFLAG_RIGHT_MOUSE_BUTTON = 1 << 6, + // Mac OS-X command key. + EVENTFLAG_COMMAND_DOWN = 1 << 7, + EVENTFLAG_NUM_LOCK_ON = 1 << 8, + EVENTFLAG_IS_KEY_PAD = 1 << 9, + EVENTFLAG_IS_LEFT = 1 << 10, + EVENTFLAG_IS_RIGHT = 1 << 11, +} + +/// +// Time information. Values should always be in UTC. +/// +#[repr(C)] +pub struct _cef_time_t { + year: c_int, // Four digit year "2007" + month: c_int, // 1-based month (values 1 = January, etc.) + day_of_week: c_int, // 0-based day of week (0 = Sunday, etc.) + day_of_month: c_int, // 1-based day of month (1-31) + hour: c_int, // Hour within the current day (0-23) + minute: c_int, // Minute within the current hour (0-59) + second: c_int, // Second within the current minute (0-59 plus leap + // seconds which may take it up to 60). + millisecond: c_int, // Milliseconds within the current second (0-999) +} + +pub type cef_time_t = _cef_time_t; + +/// +// DOM event processing phases. +/// +pub enum cef_dom_event_phase_t { + DOM_EVENT_PHASE_UNKNOWN = 0, + DOM_EVENT_PHASE_CAPTURING, + DOM_EVENT_PHASE_AT_TARGET, + DOM_EVENT_PHASE_BUBBLING, +} + +/// +// DOM node types. +/// +pub enum cef_dom_node_type_t { + DOM_NODE_TYPE_UNSUPPORTED = 0, + DOM_NODE_TYPE_ELEMENT, + DOM_NODE_TYPE_ATTRIBUTE, + DOM_NODE_TYPE_TEXT, + DOM_NODE_TYPE_CDATA_SECTION, + DOM_NODE_TYPE_PROCESSING_INSTRUCTIONS, + DOM_NODE_TYPE_COMMENT, + DOM_NODE_TYPE_DOCUMENT, + DOM_NODE_TYPE_DOCUMENT_TYPE, + DOM_NODE_TYPE_DOCUMENT_FRAGMENT, +} + +/// +// Focus sources. +/// +pub enum cef_focus_source_t { + /// + // The source is explicit navigation via the API (LoadURL(), etc). + /// + FOCUS_SOURCE_NAVIGATION = 0, + /// + // The source is a system-generated focus event. + /// + FOCUS_SOURCE_SYSTEM, +} + +/// +// Supported JavaScript dialog types. +/// +pub enum cef_jsdialog_type_t { + JSDIALOGTYPE_ALERT = 0, + JSDIALOGTYPE_CONFIRM, + JSDIALOGTYPE_PROMPT, +} + +/// +// Structure representing a size. +/// +pub struct _cef_size_t { + pub width: c_int, + pub height: c_int, +} + +pub type cef_size_t = _cef_size_t; + +/// +// Structure representing a print job page range. +/// +pub struct _cef_page_range_t { + pub from: c_int, + pub to: c_int, +} + +pub type cef_page_range_t = _cef_page_range_t; + +/// +// Print job duplex mode values. +/// +pub enum cef_duplex_mode_t { + DUPLEX_MODE_UNKNOWN = -1, + DUPLEX_MODE_SIMPLEX, + DUPLEX_MODE_LONG_EDGE, + DUPLEX_MODE_SHORT_EDGE, +} + +/// +// Print job color mode values. +/// +pub enum cef_color_model_t { + COLOR_MODEL_UNKNOWN, + COLOR_MODEL_GRAY, + COLOR_MODEL_COLOR, + COLOR_MODEL_CMYK, + COLOR_MODEL_CMY, + COLOR_MODEL_KCMY, + COLOR_MODEL_CMY_K, // CMY_K represents CMY+K. + COLOR_MODEL_BLACK, + COLOR_MODEL_GRAYSCALE, + COLOR_MODEL_RGB, + COLOR_MODEL_RGB16, + COLOR_MODEL_RGBA, + COLOR_MODEL_COLORMODE_COLOR, // Used in samsung printer ppds. + COLOR_MODEL_COLORMODE_MONOCHROME, // Used in samsung printer ppds. + COLOR_MODEL_HP_COLOR_COLOR, // Used in HP color printer ppds. + COLOR_MODEL_HP_COLOR_BLACK, // Used in HP color printer ppds. + COLOR_MODEL_PRINTOUTMODE_NORMAL, // Used in foomatic ppds. + COLOR_MODEL_PRINTOUTMODE_NORMAL_GRAY, // Used in foomatic ppds. + COLOR_MODEL_PROCESSCOLORMODEL_CMYK, // Used in canon printer ppds. + COLOR_MODEL_PROCESSCOLORMODEL_GREYSCALE, // Used in canon printer ppds. + COLOR_MODEL_PROCESSCOLORMODEL_RGB, // Used in canon printer ppds +} + +/// +// Resource type for a request. +/// +pub enum cef_resource_type_t { + /// + // Top level page. + /// + RT_MAIN_FRAME = 0, + + /// + // Frame or iframe. + /// + RT_SUB_FRAME, + + /// + // CSS stylesheet. + /// + RT_STYLESHEET, + + /// + // External script. + /// + RT_SCRIPT, + + /// + // Image (jpg/gif/png/etc). + /// + RT_IMAGE, + + /// + // Font. + /// + RT_FONT_RESOURCE, + + /// + // Some other subresource. This is the default type if the actual type is + // unknown. + /// + RT_SUB_RESOURCE, + + /// + // Object (or embed) tag for a plugin, or a resource that a plugin requested. + /// + RT_OBJECT, + + /// + // Media resource. + /// + RT_MEDIA, + + /// + // Main resource of a dedicated worker. + /// + RT_WORKER, + + /// + // Main resource of a shared worker. + /// + RT_SHARED_WORKER, + + /// + // Explicitly requested prefetch. + /// + RT_PREFETCH, + + /// + // Favicon. + /// + RT_FAVICON, + + /// + // XMLHttpRequest. + /// + RT_XHR, + + /// + // A request for a + /// + RT_PING, + + /// + // Main resource of a service worker. + /// + RT_SERVICE_WORKER, +} + +/// +// Transition type for a request. Made up of one source value and 0 or more +// qualifiers. +/// +pub enum cef_transition_type_t { + /// + // Source is a link click or the JavaScript window.open function. This is + // also the default value for requests like sub-resource loads that are not + // navigations. + /// + TT_LINK = 0, + + /// + // Source is some other "explicit" navigation action such as creating a new + // browser or using the LoadURL function. This is also the default value + // for navigations where the actual type is unknown. + /// + TT_EXPLICIT = 1, + + /// + // Source is a subframe navigation. This is any content that is automatically + // loaded in a non-toplevel frame. For example, if a page consists of several + // frames containing ads, those ad URLs will have this transition type. + // The user may not even realize the content in these pages is a separate + // frame, so may not care about the URL. + /// + TT_AUTO_SUBFRAME = 3, + + /// + // Source is a subframe navigation explicitly requested by the user that will + // generate new navigation entries in the back/forward list. These are + // probably more important than frames that were automatically loaded in + // the background because the user probably cares about the fact that this + // link was loaded. + /// + TT_MANUAL_SUBFRAME = 4, + + /// + // Source is a form submission by the user. NOTE: In some situations + // submitting a form does not result in this transition type. This can happen + // if the form uses a script to submit the contents. + /// + TT_FORM_SUBMIT = 7, + + /// + // Source is a "reload" of the page via the Reload function or by re-visiting + // the same URL. NOTE: This is distinct from the concept of whether a + // particular load uses "reload semantics" (i.e. bypasses cached data). + /// + TT_RELOAD = 8, + + /// + // General mask defining the bits used for the source values. + /// + TT_SOURCE_MASK = 0xFF, + + // Qualifiers. + // Any of the core values above can be augmented by one or more qualifiers. + // These qualifiers further define the transition. + + /// + // Attempted to visit a URL but was blocked. + /// + TT_BLOCKED_FLAG = 0x00800000, + + /// + // Used the Forward or Back function to navigate among browsing history. + /// + TT_FORWARD_BACK_FLAG = 0x01000000, + + /// + // The beginning of a navigation chain. + /// + TT_CHAIN_START_FLAG = 0x10000000, + + /// + // The last transition in a redirect chain. + /// + TT_CHAIN_END_FLAG = 0x20000000, + + /// + // Redirects caused by JavaScript or a meta refresh tag on the page. + /// + TT_CLIENT_REDIRECT_FLAG = 0x40000000, + + /// + // Redirects sent from the server by HTTP headers. + /// + TT_SERVER_REDIRECT_FLAG = 0x80000000, + + /// + // Used to test whether a transition involves a redirect. + /// + TT_IS_REDIRECT_MASK = 0xC0000000, + + /// + // General mask defining the bits used for the qualifiers. + /// + TT_QUALIFIER_MASK = 0xFFFFFF00, +} + +/// +// Process termination status values. +/// +pub enum cef_termination_status_t { + /// + // Non-zero exit status. + /// + TS_ABNORMAL_TERMINATION, + + /// + // SIGKILL or task manager kill. + /// + TS_PROCESS_WAS_KILLED, + + /// + // Segmentation fault. + /// + TS_PROCESS_CRASHED, +} + +/// +// V8 access control values. +/// +pub enum cef_v8_accesscontrol_t { + V8_ACCESS_CONTROL_DEFAULT = 0, + V8_ACCESS_CONTROL_ALL_CAN_READ = 1, + V8_ACCESS_CONTROL_ALL_CAN_WRITE = 1 << 1, + V8_ACCESS_CONTROL_PROHIBITS_OVERWRITING = 1 << 2 +} + +/// +// V8 property attribute values. +/// +pub enum cef_v8_propertyattribute_t { + V8_PROPERTY_ATTRIBUTE_NONE = 0, // Writeable, Enumerable, + // Configurable + V8_PROPERTY_ATTRIBUTE_READONLY = 1 << 0, // Not writeable + V8_PROPERTY_ATTRIBUTE_DONTENUM = 1 << 1, // Not enumerable + V8_PROPERTY_ATTRIBUTE_DONTDELETE = 1 << 2 // Not configurable +} + +/// +// XML node types. +/// +pub enum cef_xml_node_type_t { + XML_NODE_UNSUPPORTED = 0, + XML_NODE_PROCESSING_INSTRUCTION, + XML_NODE_DOCUMENT_TYPE, + XML_NODE_ELEMENT_START, + XML_NODE_ELEMENT_END, + XML_NODE_ATTRIBUTE, + XML_NODE_TEXT, + XML_NODE_CDATA, + XML_NODE_ENTITY_REFERENCE, + XML_NODE_WHITESPACE, + XML_NODE_COMMENT, +} + +/// +// Geoposition error codes. +/// +pub enum cef_geoposition_error_code_t { + GEOPOSITON_ERROR_NONE = 0, + GEOPOSITON_ERROR_PERMISSION_DENIED, + GEOPOSITON_ERROR_POSITION_UNAVAILABLE, + GEOPOSITON_ERROR_TIMEOUT, +} + +/// +// Structure representing geoposition information. The properties of this +// structure correspond to those of the JavaScript Position object although +// their types may differ. +/// +pub struct _cef_geoposition_t { + /// + // Latitude in decimal degrees north (WGS84 coordinate frame). + /// + pub latitude: c_double, + + /// + // Longitude in decimal degrees west (WGS84 coordinate frame). + /// + pub longitude: c_double, + + /// + // Altitude in meters (above WGS84 datum). + /// + pub altitude: c_double, + + /// + // Accuracy of horizontal position in meters. + /// + pub accuracy: c_double, + + /// + // Accuracy of altitude in meters. + /// + pub altitude_accuracy: c_double, + + /// + // Heading in decimal degrees clockwise from true north. + /// + pub heading: c_double, + + /// + // Horizontal component of device velocity in meters per second. + /// + pub speed: c_double, + + /// + // Time of position measurement in miliseconds since Epoch in UTC time. This + // is taken from the host computer's system clock. + /// + pub timestamp: cef_time_t, + + /// + // Error code, see enum above. + /// + pub error_code: cef_geoposition_error_code_t, + + /// + // Human-readable error message. + /// + pub error_message: cef_string_t, +} + +pub type cef_geoposition_t = _cef_geoposition_t; + +pub type CefGeoposition = cef_geoposition_t; + +/// +// Cookie information. +/// +pub struct _cef_cookie_t { + /// + // The cookie name. + /// + pub name: cef_string_t, + + /// + // The cookie value. + /// + pub value: cef_string_t, + + /// + // If |domain| is empty a host cookie will be created instead of a domain + // cookie. Domain cookies are stored with a leading "." and are visible to + // sub-domains whereas host cookies are not. + /// + pub domain: cef_string_t, + + /// + // If |path| is non-empty only URLs at or below the path will get the cookie + // value. + /// + pub path: cef_string_t, + + /// + // If |secure| is true the cookie will only be sent for HTTPS requests. + /// + pub secure: c_int, + + /// + // If |httponly| is true the cookie will only be sent for HTTP requests. + /// + pub httponly: c_int, + + /// + // The cookie creation date. This is automatically populated by the system on + // cookie creation. + /// + pub creation: cef_time_t, + + /// + // The cookie last access date. This is automatically populated by the system + // on access. + /// + pub last_access: cef_time_t, + + /// + // The cookie expiration date is only valid if |has_expires| is true. + /// + pub has_expires: c_int, + pub expires: cef_time_t, +} + +pub type cef_cookie_t = _cef_cookie_t; + +pub type CefCookie = cef_cookie_t; + +/// +// Popup window features. +/// +pub struct _cef_popup_features_t { + pub x: c_int, + pub x_set: c_int, + pub y: c_int, + pub y_set: c_int, + pub width: c_int, + pub width_set: c_int, + pub height: c_int, + pub height_set: c_int, + + pub menu_bar_visible: c_int, + pub status_bar_visible: c_int, + pub tool_bar_visible: c_int, + pub location_bar_visible: c_int, + pub scrollbars_visible: c_int, + pub resizable: c_int, + + pub fullscreen: c_int, + pub dialog: c_int, + pub additional_features: cef_string_list_t, +} + +pub type cef_popup_features_t = _cef_popup_features_t; + +pub type CefPopupFeatures = cef_popup_features_t; + +// FIXME(pcwalton): Really should be a set of bitflags. +pub enum cef_drag_operations_mask_t { + DRAG_OPERATION_NONE = 0, + DRAG_OPERATION_COPY = 1, + DRAG_OPERATION_LINK = 2, + DRAG_OPERATION_GENERIC = 4, + DRAG_OPERATION_PRIVATE = 8, + DRAG_OPERATION_MOVE = 16, + DRAG_OPERATION_DELETE = 32, + DRAG_OPERATION_EVERY = 0xffffffff, +} + +pub enum cef_xml_encoding_type_t { + XML_ENCODING_NONE = 0, + XML_ENCODING_UTF8, + XML_ENCODING_UTF16LE, + XML_ENCODING_UTF16BE, + XML_ENCODING_ASCII, +} + diff --git a/ports/cef/urlrequest.rs b/ports/cef/urlrequest.rs index e55546325d0..77938e858b6 100644 --- a/ports/cef/urlrequest.rs +++ b/ports/cef/urlrequest.rs @@ -2,9 +2,7 @@ * 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 types::{cef_request_t, cef_urlrequest_client_t, cef_urlrequest_t}; - +use interfaces::{cef_request_t, cef_urlrequest_client_t, cef_urlrequest_t}; #[no_mangle] pub extern "C" fn cef_urlrequest_create(_request: *mut cef_request_t, diff --git a/ports/cef/v8.rs b/ports/cef/v8.rs new file mode 100644 index 00000000000..e8e5996a100 --- /dev/null +++ b/ports/cef/v8.rs @@ -0,0 +1,29 @@ +/* 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 interfaces::{cef_v8accessor_t, cef_v8context_t, cef_v8handler_t, cef_v8stack_trace_t}; +use interfaces::{cef_v8value_t}; +use types::{cef_string_t, cef_time_t}; + +use libc::{mod, c_double, c_int}; + +cef_stub_static_method_impls! { + fn cef_v8context_get_current_context() -> *mut cef_v8context_t; + fn cef_v8context_get_entered_context() -> *mut cef_v8context_t; + fn cef_v8context_in_context() -> libc::c_int; + fn cef_v8value_create_undefined() -> *mut cef_v8value_t; + fn cef_v8value_create_null() -> *mut cef_v8value_t; + fn cef_v8value_create_bool(_value: c_int) -> *mut cef_v8value_t; + fn cef_v8value_create_int(_value: i32) -> *mut cef_v8value_t; + fn cef_v8value_create_uint(_value: u32) -> *mut cef_v8value_t; + fn cef_v8value_create_double(_value: c_double) -> *mut cef_v8value_t; + fn cef_v8value_create_date(_date: *const cef_time_t) -> *mut cef_v8value_t; + fn cef_v8value_create_string(_value: *const cef_string_t) -> *mut cef_v8value_t; + fn cef_v8value_create_object(_accessor: *mut cef_v8accessor_t) -> *mut cef_v8value_t; + fn cef_v8value_create_array(_length: libc::c_int) -> *mut cef_v8value_t; + fn cef_v8value_create_function(_name: *const cef_string_t, _handler: *mut cef_v8handler_t) + -> *mut cef_v8value_t; + fn cef_v8stack_trace_get_current(_frame_limit: libc::c_int) -> *mut cef_v8stack_trace_t; +} + diff --git a/ports/cef/values.rs b/ports/cef/values.rs new file mode 100644 index 00000000000..81a0e60a3d0 --- /dev/null +++ b/ports/cef/values.rs @@ -0,0 +1,14 @@ +/* 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 interfaces::{cef_binary_value_t, cef_dictionary_value_t, cef_list_value_t}; + +use libc; + +cef_stub_static_method_impls! { + fn cef_binary_value_create(_data: *const (), _size: libc::size_t) -> *mut cef_binary_value_t; + fn cef_dictionary_value_create() -> *mut cef_dictionary_value_t; + fn cef_list_value_create() -> *mut cef_list_value_t; +} + diff --git a/ports/cef/wrappers.rs b/ports/cef/wrappers.rs new file mode 100644 index 00000000000..4030681ebbb --- /dev/null +++ b/ports/cef/wrappers.rs @@ -0,0 +1,227 @@ +/* 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 interfaces::{cef_drag_data_t, cef_post_data_element_t, cef_v8value_t, CefPostDataElement}; +use interfaces::{CefV8Value}; +use types::{cef_base_t, cef_browser_settings_t, cef_color_model_t}; +use types::{cef_context_menu_edit_state_flags_t, cef_context_menu_handler_t}; +use types::{cef_context_menu_media_state_flags_t}; +use types::{cef_context_menu_media_type_t, cef_context_menu_type_flags_t, cef_cookie_t}; +use types::{cef_dialog_handler_t}; +use types::{cef_dom_document_type_t, cef_dom_node_type_t}; +use types::{cef_download_handler_t, cef_drag_handler_t}; +use types::{cef_drag_operations_mask_t, cef_duplex_mode_t}; +use types::{cef_errorcode_t, cef_event_flags_t, cef_event_handle_t}; +use types::{cef_file_dialog_mode_t, cef_focus_handler_t, cef_focus_source_t}; +use types::{cef_geolocation_handler_t, cef_geoposition_t}; +use types::{cef_jsdialog_handler_t, cef_jsdialog_type_t}; +use types::{cef_key_event, cef_keyboard_handler_t}; +use types::{cef_load_handler_t, cef_menu_item_type_t, cef_mouse_button_type_t}; +use types::{cef_mouse_event, cef_navigation_type_t}; +use types::{cef_page_range_t, cef_paint_element_type_t, cef_point_t, cef_postdataelement_type_t}; +use types::{cef_popup_features_t, cef_process_id_t}; +use types::{cef_rect_t, cef_request_context_t, cef_request_handler_t}; +use types::{cef_resource_type_t}; +use types::{cef_screen_info_t, cef_size_t, cef_string_t}; +use types::{cef_string_list_t, cef_string_map_t, cef_string_multimap_t, cef_string_utf16}; +use types::{cef_termination_status_t, cef_text_input_context_t, cef_thread_id_t}; +use types::{cef_time_t, cef_transition_type_t, cef_urlrequest_status_t}; +use types::{cef_v8_accesscontrol_t, cef_v8_propertyattribute_t, cef_value_type_t}; +use types::{cef_window_info_t, cef_xml_encoding_type_t, cef_xml_node_type_t}; + +use libc::{c_char, c_int, c_void}; +use std::collections::HashMap; +use std::mem; + +pub trait CefWrap { + fn to_c(rust_object: Self) -> CObject; + unsafe fn to_rust(c_object: CObject) -> Self; +} + +macro_rules! cef_noop_wrapper( + ($ty:ty) => ( + impl CefWrap<$ty> for $ty { + fn to_c(rust_object: $ty) -> $ty { + rust_object + } + unsafe fn to_rust(c_object: $ty) -> $ty { + c_object + } + } + ) +) + +macro_rules! cef_pointer_wrapper( + ($ty:ty) => ( + impl<'a> CefWrap<*const $ty> for &'a $ty { + fn to_c(rust_object: &'a $ty) -> *const $ty { + rust_object + } + unsafe fn to_rust(c_object: *const $ty) -> &'a $ty { + mem::transmute::<*const $ty,&'a $ty>(c_object) + } + } + impl<'a> CefWrap<*mut $ty> for &'a mut $ty { + fn to_c(rust_object: &'a mut $ty) -> *mut $ty { + rust_object + } + unsafe fn to_rust(c_object: *mut $ty) -> &'a mut $ty { + mem::transmute::<*mut $ty,&'a mut $ty>(c_object) + } + } + cef_noop_wrapper!(*const $ty) + cef_noop_wrapper!(*mut $ty) + ) +) + +macro_rules! cef_unimplemented_wrapper( + ($c_type:ty, $rust_type:ty) => ( + impl CefWrap<$c_type> for $rust_type { + fn to_c(_: $rust_type) -> $c_type { + panic!("unimplemented CEF type conversion: {}", stringify!($c_type)) + } + unsafe fn to_rust(_: $c_type) -> $rust_type { + panic!("unimplemented CEF type conversion: {}", stringify!($c_type)) + } + } + ) +) + +cef_pointer_wrapper!(()) +cef_pointer_wrapper!(*mut ()) +cef_pointer_wrapper!(*mut c_void) +cef_pointer_wrapper!(c_void) +cef_pointer_wrapper!(cef_base_t) +cef_pointer_wrapper!(cef_browser_settings_t) +cef_pointer_wrapper!(cef_cookie_t) +cef_pointer_wrapper!(cef_geoposition_t) +cef_pointer_wrapper!(cef_key_event) +cef_pointer_wrapper!(cef_mouse_event) +cef_pointer_wrapper!(cef_page_range_t) +cef_pointer_wrapper!(cef_point_t) +cef_pointer_wrapper!(cef_popup_features_t) +cef_pointer_wrapper!(cef_rect_t) +cef_pointer_wrapper!(cef_screen_info_t) +cef_pointer_wrapper!(cef_size_t) +cef_pointer_wrapper!(cef_time_t) +cef_pointer_wrapper!(cef_window_info_t) +cef_pointer_wrapper!(i32) +cef_pointer_wrapper!(i64) +cef_pointer_wrapper!(u32) +cef_pointer_wrapper!(u64) + +cef_noop_wrapper!(()) +cef_noop_wrapper!(*const cef_geolocation_handler_t) +cef_noop_wrapper!(*const cef_string_utf16) +cef_noop_wrapper!(*mut cef_context_menu_handler_t) +cef_noop_wrapper!(*mut cef_dialog_handler_t) +cef_noop_wrapper!(*mut cef_download_handler_t) +cef_noop_wrapper!(*mut cef_drag_data_t) +cef_noop_wrapper!(*mut cef_drag_handler_t) +cef_noop_wrapper!(*mut cef_event_handle_t) +cef_noop_wrapper!(*mut cef_focus_handler_t) +cef_noop_wrapper!(*mut cef_geolocation_handler_t) +cef_noop_wrapper!(*mut cef_jsdialog_handler_t) +cef_noop_wrapper!(*mut cef_keyboard_handler_t) +cef_noop_wrapper!(*mut cef_load_handler_t) +cef_noop_wrapper!(*mut cef_request_context_t) +cef_noop_wrapper!(*mut cef_request_handler_t) +cef_noop_wrapper!(*mut cef_string_list_t) +cef_noop_wrapper!(*mut cef_string_utf16) +cef_noop_wrapper!(c_int) +cef_noop_wrapper!(cef_color_model_t) +cef_noop_wrapper!(cef_context_menu_edit_state_flags_t) +cef_noop_wrapper!(cef_context_menu_media_state_flags_t) +cef_noop_wrapper!(cef_context_menu_media_type_t) +cef_noop_wrapper!(cef_context_menu_type_flags_t) +cef_noop_wrapper!(cef_dom_document_type_t) +cef_noop_wrapper!(cef_dom_node_type_t) +cef_noop_wrapper!(cef_drag_operations_mask_t) +cef_noop_wrapper!(cef_duplex_mode_t) +cef_noop_wrapper!(cef_errorcode_t) +cef_noop_wrapper!(cef_event_flags_t) +cef_noop_wrapper!(cef_event_handle_t) +cef_noop_wrapper!(cef_file_dialog_mode_t) +cef_noop_wrapper!(cef_focus_source_t) +cef_noop_wrapper!(cef_jsdialog_handler_t) +cef_noop_wrapper!(cef_jsdialog_type_t) +cef_noop_wrapper!(cef_key_event) +cef_noop_wrapper!(cef_menu_item_type_t) +cef_noop_wrapper!(cef_mouse_button_type_t) +cef_noop_wrapper!(cef_navigation_type_t) +cef_noop_wrapper!(cef_paint_element_type_t) +cef_noop_wrapper!(cef_postdataelement_type_t) +cef_noop_wrapper!(cef_process_id_t) +cef_noop_wrapper!(cef_resource_type_t) +cef_noop_wrapper!(cef_termination_status_t) +cef_noop_wrapper!(cef_text_input_context_t) +cef_noop_wrapper!(cef_thread_id_t) +cef_noop_wrapper!(cef_time_t) +cef_noop_wrapper!(cef_transition_type_t) +cef_noop_wrapper!(cef_urlrequest_status_t) +cef_noop_wrapper!(cef_v8_accesscontrol_t) +cef_noop_wrapper!(cef_v8_propertyattribute_t) +cef_noop_wrapper!(cef_value_type_t) +cef_noop_wrapper!(cef_xml_encoding_type_t) +cef_noop_wrapper!(cef_xml_node_type_t) +cef_noop_wrapper!(f64) +cef_noop_wrapper!(i64) +cef_noop_wrapper!(u32) +cef_noop_wrapper!(u64) + +cef_unimplemented_wrapper!(*const *mut cef_v8value_t, *const CefV8Value) +cef_unimplemented_wrapper!(*mut *mut cef_post_data_element_t, *mut CefPostDataElement) +cef_unimplemented_wrapper!(cef_string_list_t, Vec) +cef_unimplemented_wrapper!(cef_string_map_t, HashMap) +cef_unimplemented_wrapper!(cef_string_multimap_t, HashMap>) +cef_unimplemented_wrapper!(cef_string_t, String) + +impl<'a> CefWrap<*const cef_string_t> for &'a str { + fn to_c(_: &'a str) -> *const cef_string_t { + panic!("unimplemented CEF type conversion: &'a str") + } + unsafe fn to_rust(_: *const cef_string_t) -> &'a str { + panic!("unimplemented CEF type conversion: *const cef_string_t") + } +} + +impl<'a> CefWrap<*mut cef_string_t> for &'a mut str { + fn to_c(_: &'a mut str) -> *mut cef_string_t { + panic!("unimplemented CEF type conversion: &'a str") + } + unsafe fn to_rust(_: *mut cef_string_t) -> &'a mut str { + mem::transmute::<(int,int),_>(panic!("unimplemented CEF type conversion: *mut \ + cef_string_t")) + } +} + +// FIXME(pcwalton): This is pretty bogus, but it's only used for `init_from_argv`, which should +// never be called by Rust programs anyway. We should fix the wrapper generation though. +impl<'a,'b> CefWrap<*const *const c_char> for &'a &'b str { + fn to_c(_: &'a &'b str) -> *const *const c_char { + panic!("unimplemented CEF type conversion: &'a &'b str") + } + unsafe fn to_rust(_: *const *const c_char) -> &'a &'b str { + panic!("unimplemented CEF type conversion: *const *const cef_string_t") + } +} + +impl<'a,'b> CefWrap<*mut *const c_char> for &'a mut &'b str { + fn to_c(_: &'a mut &'b str) -> *mut *const c_char { + panic!("unimplemented CEF type conversion: &'a mut &'b str") + } + unsafe fn to_rust(_: *mut *const c_char) -> &'a mut &'b str { + panic!("unimplemented CEF type conversion: *mut *const c_char") + } +} + +impl<'a> CefWrap for &'a mut String { + fn to_c(_: &'a mut String) -> cef_string_t { + panic!("unimplemented CEF type conversion: &'a mut String") + } + unsafe fn to_rust(_: cef_string_t) -> &'a mut String { + panic!("unimplemented CEF type conversion: cef_string_t") + } +} + diff --git a/ports/cef/xml_reader.rs b/ports/cef/xml_reader.rs new file mode 100644 index 00000000000..e80698db8ef --- /dev/null +++ b/ports/cef/xml_reader.rs @@ -0,0 +1,14 @@ +/* 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 interfaces::{cef_stream_reader_t, cef_xml_reader_t}; +use types::{cef_string_t, cef_xml_encoding_type_t}; + +cef_stub_static_method_impls! { + fn cef_xml_reader_create(stream: *mut cef_stream_reader_t, + encoding_type: cef_xml_encoding_type_t, + uri: *const cef_string_t) + -> *mut cef_xml_reader_t; +} + diff --git a/ports/cef/zip_reader.rs b/ports/cef/zip_reader.rs new file mode 100644 index 00000000000..2603f6b2383 --- /dev/null +++ b/ports/cef/zip_reader.rs @@ -0,0 +1,10 @@ +/* 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 interfaces::{cef_stream_reader_t, cef_zip_reader_t}; + +cef_stub_static_method_impls! { + fn cef_zip_reader_create(stream: *mut cef_stream_reader_t) -> *mut cef_zip_reader_t; +} + From e4362dad737beeba8b962a603d25adf2652b8cb3 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 25 Nov 2014 17:30:46 -0700 Subject: [PATCH 2/5] Fixes for Linux. --- ports/cef/browser.rs | 1 + ports/cef/macros.rs | 1 + ports/cef/types.rs | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/cef/browser.rs b/ports/cef/browser.rs index fa018079e2b..ee7652ded98 100644 --- a/ports/cef/browser.rs +++ b/ports/cef/browser.rs @@ -87,6 +87,7 @@ cef_static_method_impls! { browser_host_create(client, false); 1i32 } + fn cef_browser_host_create_browser_sync(_window_info: *const cef_window_info_t, client: *mut cef_client_t, _url: *const cef_string_t, diff --git a/ports/cef/macros.rs b/ports/cef/macros.rs index fa72b72f48a..4debc353555 100644 --- a/ports/cef/macros.rs +++ b/ports/cef/macros.rs @@ -92,6 +92,7 @@ macro_rules! cef_static_method_impls( )* ) => ( $( + #[no_mangle] pub extern "C" fn $method_name($($method_arg_name: $method_arg_type),*) -> $method_return_type { $( diff --git a/ports/cef/types.rs b/ports/cef/types.rs index c29be3bac9a..66809dc0223 100644 --- a/ports/cef/types.rs +++ b/ports/cef/types.rs @@ -2,7 +2,11 @@ * 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 libc::{c_uint, c_ushort, c_int, c_double, size_t, c_void}; +use libc::{c_uint, c_ushort, c_int, c_double, size_t}; +#[cfg(target_os="linux")] +use libc::c_ulong; +#[cfg(target_os="macos")] +use libc::c_void; use libc::types::os::arch::c95::wchar_t; pub use self::cef_rect as cef_rect_t; From 14ef53cf57addf85242e63e24433aeddf60a9793 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 25 Nov 2014 17:07:59 -0800 Subject: [PATCH 3/5] Add back API hashes --- ports/cef/core.rs | 20 +++++++++++++++++++- ports/cef/interfaces/cef_browser.rs | 23 ----------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index bb0a92c071a..c5bbe52f3c8 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -11,11 +11,19 @@ use types::{cef_main_args_t, cef_settings_t}; use glfw_app; use libc::funcs::c95::string::strlen; -use libc::{c_int, c_void}; +use libc::{c_char, c_int, c_void}; use native; use servo::Browser; use std::slice; +static CEF_API_HASH_UNIVERSAL: &'static [u8] = b"8efd129f4afc344bd04b2feb7f73a149b6c4e27f\0"; +#[cfg(target_os="windows")] +static CEF_API_HASH_PLATFORM: &'static [u8] = b"5c7f3e50ff5265985d11dc1a466513e25748bedd\0"; +#[cfg(target_os="macos")] +static CEF_API_HASH_PLATFORM: &'static [u8] = b"6813214accbf2ebfb6bdcf8d00654650b251bf3d\0"; +#[cfg(target_os="linux")] +static CEF_API_HASH_PLATFORM: &'static [u8] = b"2bc564c3871965ef3a2531b528bda3e17fa17a6d\0"; + #[no_mangle] pub extern "C" fn cef_initialize(args: *const cef_main_args_t, _settings: *mut cef_settings_t, @@ -115,3 +123,13 @@ pub extern "C" fn cef_execute_process(args: *const cef_main_args_t, //process type not specified, must be browser process (NOOP) -1 } + +#[no_mangle] +pub extern "C" fn cef_api_hash(entry: c_int) -> *const c_char { + if entry == 0 { + &CEF_API_HASH_PLATFORM[0] as *const u8 as *const c_char + } else { + &CEF_API_HASH_UNIVERSAL[0] as *const u8 as *const c_char + } +} + diff --git a/ports/cef/interfaces/cef_browser.rs b/ports/cef/interfaces/cef_browser.rs index e2f18a76d73..3383033c3a6 100644 --- a/ports/cef/interfaces/cef_browser.rs +++ b/ports/cef/interfaces/cef_browser.rs @@ -1107,13 +1107,6 @@ pub struct _cef_browser_host_t { pub drag_source_system_drag_ended: Option ()>, - // - // Instructs the browser to perform an accelerated composite. The appropriate - // Direct3D or OpenGL state must have been set up before calling this - // function. - // - pub composite: Option ()>, - // // Instructs the browser to initialize accelerated compositing. The // appropriate Direct3D or OpenGL state must have been set up before calling @@ -1932,22 +1925,6 @@ impl CefBrowserHost { } } - // - // Instructs the browser to perform an accelerated composite. The appropriate - // Direct3D or OpenGL state must have been set up before calling this - // function. - // - pub fn composite(&self) -> () { - if self.c_object.is_null() { - panic!("called a CEF method on a null object") - } - unsafe { - CefWrap::to_rust( - ((*self.c_object).composite.unwrap())( - self.c_object)) - } - } - // // Instructs the browser to initialize accelerated compositing. The // appropriate Direct3D or OpenGL state must have been set up before calling From 1ac5bfe830254ea4870ab254c5d348bae11094b7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 25 Nov 2014 17:45:04 -0800 Subject: [PATCH 4/5] Add mostly-correct (albeit leaky) string marshaling --- ports/cef/browser.rs | 4 +- ports/cef/interfaces/cef_app.rs | 2 +- ports/cef/interfaces/cef_auth_callback.rs | 2 +- ports/cef/interfaces/cef_browser.rs | 16 ++++---- ports/cef/interfaces/cef_command_line.rs | 16 ++++---- ports/cef/interfaces/cef_cookie.rs | 11 ++--- ports/cef/interfaces/cef_dialog_handler.rs | 4 +- ports/cef/interfaces/cef_display_handler.rs | 8 ++-- ports/cef/interfaces/cef_dom.rs | 14 +++---- ports/cef/interfaces/cef_download_handler.rs | 4 +- ports/cef/interfaces/cef_drag_data.rs | 14 +++---- ports/cef/interfaces/cef_frame.rs | 6 +-- .../cef/interfaces/cef_geolocation_handler.rs | 4 +- ports/cef/interfaces/cef_jsdialog_handler.rs | 10 ++--- ports/cef/interfaces/cef_life_span_handler.rs | 4 +- ports/cef/interfaces/cef_load_handler.rs | 2 +- ports/cef/interfaces/cef_menu_model.rs | 22 +++++----- ports/cef/interfaces/cef_print_handler.rs | 2 +- ports/cef/interfaces/cef_print_settings.rs | 2 +- ports/cef/interfaces/cef_process_message.rs | 2 +- ports/cef/interfaces/cef_request.rs | 13 +++--- ports/cef/interfaces/cef_request_handler.rs | 16 ++++---- ports/cef/interfaces/cef_response.rs | 6 +-- ports/cef/interfaces/cef_scheme.rs | 4 +- ports/cef/interfaces/cef_stream.rs | 4 +- ports/cef/interfaces/cef_string_visitor.rs | 2 +- ports/cef/interfaces/cef_trace.rs | 2 +- ports/cef/interfaces/cef_urlrequest.rs | 4 +- ports/cef/interfaces/cef_v8.rs | 22 +++++----- ports/cef/interfaces/cef_values.rs | 38 ++++++++--------- ports/cef/interfaces/cef_web_plugin.rs | 2 +- ports/cef/interfaces/cef_xml_reader.rs | 15 +++---- ports/cef/interfaces/cef_zip_reader.rs | 4 +- ports/cef/wrappers.rs | 41 +++++++++++++++---- 34 files changed, 175 insertions(+), 147 deletions(-) diff --git a/ports/cef/browser.rs b/ports/cef/browser.rs index ee7652ded98..6bdfba87772 100644 --- a/ports/cef/browser.rs +++ b/ports/cef/browser.rs @@ -81,7 +81,7 @@ cef_static_method_impls! { -> c_int { let _window_info: &cef_window_info_t = _window_info; let client: CefClient = client; - let _url: &str = _url; + let _url: &[u16] = _url; let _browser_settings: &cef_browser_settings_t = _browser_settings; let _request_context: CefRequestContext = _request_context; browser_host_create(client, false); @@ -96,7 +96,7 @@ cef_static_method_impls! { -> *mut cef_browser_t { let _window_info: &cef_window_info_t = _window_info; let client: CefClient = client; - let _url: &str = _url; + let _url: &[u16] = _url; let _browser_settings: &cef_browser_settings_t = _browser_settings; let _request_context: CefRequestContext = _request_context; browser_host_create(client, true) diff --git a/ports/cef/interfaces/cef_app.rs b/ports/cef/interfaces/cef_app.rs index d54e42ae605..d3ddfa1673d 100644 --- a/ports/cef/interfaces/cef_app.rs +++ b/ports/cef/interfaces/cef_app.rs @@ -195,7 +195,7 @@ impl CefApp { // modify command-line arguments for non-browser processes as this may result // in undefined behavior including crashes. // - pub fn on_before_command_line_processing(&self, process_type: &str, + pub fn on_before_command_line_processing(&self, process_type: &[u16], command_line: interfaces::CefCommandLine) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_auth_callback.rs b/ports/cef/interfaces/cef_auth_callback.rs index 3abd16d3abd..8f24912c477 100644 --- a/ports/cef/interfaces/cef_auth_callback.rs +++ b/ports/cef/interfaces/cef_auth_callback.rs @@ -152,7 +152,7 @@ impl CefAuthCallback { // // Continue the authentication request. // - pub fn cont(&self, username: &str, password: &str) -> () { + pub fn cont(&self, username: &[u16], password: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_browser.rs b/ports/cef/interfaces/cef_browser.rs index 3383033c3a6..c8e42570375 100644 --- a/ports/cef/interfaces/cef_browser.rs +++ b/ports/cef/interfaces/cef_browser.rs @@ -497,7 +497,7 @@ impl CefBrowser { // // Returns the frame with the specified name, or NULL if not found. // - pub fn get_frame(&self, name: &str) -> interfaces::CefFrame { + pub fn get_frame(&self, name: &[u16]) -> interfaces::CefFrame { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1368,7 +1368,7 @@ impl CefBrowserHost { // the UI thread. // pub fn run_file_dialog(&self, mode: types::cef_file_dialog_mode_t, - title: &str, default_file_name: &str, accept_types: Vec, + title: &[u16], default_file_name: &[u16], accept_types: Vec, callback: interfaces::CefRunFileDialogCallback) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -1388,7 +1388,7 @@ impl CefBrowserHost { // // Download the file at |url| using cef_download_handler_t. // - pub fn start_download(&self, url: &str) -> () { + pub fn start_download(&self, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1421,7 +1421,7 @@ impl CefBrowserHost { // be case-sensitive. |findNext| indicates whether this is the first request // or a follow-up. // - pub fn find(&self, identifier: libc::c_int, searchText: &str, + pub fn find(&self, identifier: libc::c_int, searchText: &[u16], forward: libc::c_int, matchCase: libc::c_int, findNext: libc::c_int) -> ( ) { if self.c_object.is_null() { @@ -1523,7 +1523,7 @@ impl CefBrowserHost { // If a misspelled word is currently selected in an editable node calling this // function will replace it with the specified |word|. // - pub fn replace_misspelling(&self, word: &str) -> () { + pub fn replace_misspelling(&self, word: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1538,7 +1538,7 @@ impl CefBrowserHost { // // Add the specified |word| to the spelling dictionary. // - pub fn add_word_to_dictionary(&self, word: &str) -> () { + pub fn add_word_to_dictionary(&self, word: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1949,7 +1949,7 @@ impl CefBrowserHost { // process thread and will not block. // pub fn create_browser(windowInfo: &interfaces::CefWindowInfo, - client: interfaces::CefClient, url: &str, + client: interfaces::CefClient, url: &[u16], settings: &interfaces::CefBrowserSettings, request_context: interfaces::CefRequestContext) -> libc::c_int { unsafe { @@ -1969,7 +1969,7 @@ impl CefBrowserHost { // be used. This function can only be called on the browser process UI thread. // pub fn create_browser_sync(windowInfo: &interfaces::CefWindowInfo, - client: interfaces::CefClient, url: &str, + client: interfaces::CefClient, url: &[u16], settings: &interfaces::CefBrowserSettings, request_context: interfaces::CefRequestContext) -> interfaces::CefBrowser { unsafe { diff --git a/ports/cef/interfaces/cef_command_line.rs b/ports/cef/interfaces/cef_command_line.rs index 7cdc0b15379..ad23eb599b5 100644 --- a/ports/cef/interfaces/cef_command_line.rs +++ b/ports/cef/interfaces/cef_command_line.rs @@ -350,7 +350,7 @@ impl CefCommandLine { // Initialize the command line with the string returned by calling // GetCommandLineW(). This function is only supported on Windows. // - pub fn init_from_string(&self, command_line: &str) -> () { + pub fn init_from_string(&self, command_line: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -427,7 +427,7 @@ impl CefCommandLine { // // Set the program part of the command line string (the first item). // - pub fn set_program(&self, program: &str) -> () { + pub fn set_program(&self, program: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -456,7 +456,7 @@ impl CefCommandLine { // // Returns true (1) if the command line contains the given switch. // - pub fn has_switch(&self, name: &str) -> libc::c_int { + pub fn has_switch(&self, name: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -473,7 +473,7 @@ impl CefCommandLine { // value or isn't present this function returns the NULL string. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_switch_value(&self, name: &str) -> String { + pub fn get_switch_value(&self, name: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -505,7 +505,7 @@ impl CefCommandLine { // Add a switch to the end of the command line. If the switch has no value // pass an NULL value string. // - pub fn append_switch(&self, name: &str) -> () { + pub fn append_switch(&self, name: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -520,7 +520,7 @@ impl CefCommandLine { // // Add a switch with the specified value to the end of the command line. // - pub fn append_switch_with_value(&self, name: &str, value: &str) -> () { + pub fn append_switch_with_value(&self, name: &[u16], value: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -565,7 +565,7 @@ impl CefCommandLine { // // Add an argument to the end of the command line. // - pub fn append_argument(&self, argument: &str) -> () { + pub fn append_argument(&self, argument: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -581,7 +581,7 @@ impl CefCommandLine { // Insert a command before the current command. Common for debuggers, like // "valgrind" or "gdb --args". // - pub fn prepend_wrapper(&self, wrapper: &str) -> () { + pub fn prepend_wrapper(&self, wrapper: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_cookie.rs b/ports/cef/interfaces/cef_cookie.rs index 62a970482c0..a6bb4995c27 100644 --- a/ports/cef/interfaces/cef_cookie.rs +++ b/ports/cef/interfaces/cef_cookie.rs @@ -251,7 +251,7 @@ impl CefCookieManager { // ordered by longest path, then by earliest creation date. Returns false (0) // if cookies cannot be accessed. // - pub fn visit_url_cookies(&self, url: &str, includeHttpOnly: libc::c_int, + pub fn visit_url_cookies(&self, url: &[u16], includeHttpOnly: libc::c_int, visitor: interfaces::CefCookieVisitor) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -274,7 +274,7 @@ impl CefCookieManager { // setting the cookie if such characters are found. This function must be // called on the IO thread. // - pub fn set_cookie(&self, url: &str, + pub fn set_cookie(&self, url: &[u16], cookie: &interfaces::CefCookie) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -297,7 +297,8 @@ impl CefCookieManager { // non- NULL invalid URL is specified or if cookies cannot be accessed. This // function must be called on the IO thread. // - pub fn delete_cookies(&self, url: &str, cookie_name: &str) -> libc::c_int { + pub fn delete_cookies(&self, url: &[u16], + cookie_name: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -319,7 +320,7 @@ impl CefCookieManager { // browsers do not persist them. Returns false (0) if cookies cannot be // accessed. // - pub fn set_storage_path(&self, path: &str, + pub fn set_storage_path(&self, path: &[u16], persist_session_cookies: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -371,7 +372,7 @@ impl CefCookieManager { // generally intended to be transient and most Web browsers do not persist // them. Returns NULL if creation fails. // - pub fn create_manager(path: &str, + pub fn create_manager(path: &[u16], persist_session_cookies: libc::c_int) -> interfaces::CefCookieManager { unsafe { CefWrap::to_rust( diff --git a/ports/cef/interfaces/cef_dialog_handler.rs b/ports/cef/interfaces/cef_dialog_handler.rs index 04660cbf16b..88d0ec94210 100644 --- a/ports/cef/interfaces/cef_dialog_handler.rs +++ b/ports/cef/interfaces/cef_dialog_handler.rs @@ -328,8 +328,8 @@ impl CefDialogHandler { // return false (0). // pub fn on_file_dialog(&self, browser: interfaces::CefBrowser, - mode: types::cef_file_dialog_mode_t, title: &str, - default_file_name: &str, accept_types: Vec, + mode: types::cef_file_dialog_mode_t, title: &[u16], + default_file_name: &[u16], accept_types: Vec, callback: interfaces::CefFileDialogCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_display_handler.rs b/ports/cef/interfaces/cef_display_handler.rs index bb26a50b4b5..9fbadebaba8 100644 --- a/ports/cef/interfaces/cef_display_handler.rs +++ b/ports/cef/interfaces/cef_display_handler.rs @@ -185,7 +185,7 @@ impl CefDisplayHandler { // Called when a frame's address has changed. // pub fn on_address_change(&self, browser: interfaces::CefBrowser, - frame: interfaces::CefFrame, url: &str) -> () { + frame: interfaces::CefFrame, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -203,7 +203,7 @@ impl CefDisplayHandler { // Called when the page title changes. // pub fn on_title_change(&self, browser: interfaces::CefBrowser, - title: &str) -> () { + title: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -243,7 +243,7 @@ impl CefDisplayHandler { // text that will be displayed in the status message. // pub fn on_status_message(&self, browser: interfaces::CefBrowser, - value: &str) -> () { + value: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -261,7 +261,7 @@ impl CefDisplayHandler { // from being output to the console. // pub fn on_console_message(&self, browser: interfaces::CefBrowser, - message: &str, source: &str, line: libc::c_int) -> libc::c_int { + message: &[u16], source: &[u16], line: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_dom.rs b/ports/cef/interfaces/cef_dom.rs index ef12b54d21d..185c166fabc 100644 --- a/ports/cef/interfaces/cef_dom.rs +++ b/ports/cef/interfaces/cef_dom.rs @@ -460,7 +460,7 @@ impl CefDOMDocument { // // Returns the document element with the specified ID value. // - pub fn get_element_by_id(&self, id: &str) -> interfaces::CefDOMNode { + pub fn get_element_by_id(&self, id: &[u16]) -> interfaces::CefDOMNode { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -606,7 +606,7 @@ impl CefDOMDocument { // partial URL. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_complete_url(&self, partialURL: &str) -> String { + pub fn get_complete_url(&self, partialURL: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1032,7 +1032,7 @@ impl CefDOMNode { // // Set the value of this node. Returns true (1) on success. // - pub fn set_value(&self, value: &str) -> libc::c_int { + pub fn set_value(&self, value: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1192,7 +1192,7 @@ impl CefDOMNode { // // Returns true (1) if this element has an attribute named |attrName|. // - pub fn has_element_attribute(&self, attrName: &str) -> libc::c_int { + pub fn has_element_attribute(&self, attrName: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1208,7 +1208,7 @@ impl CefDOMNode { // Returns the element attribute named |attrName|. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_element_attribute(&self, attrName: &str) -> String { + pub fn get_element_attribute(&self, attrName: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1239,8 +1239,8 @@ impl CefDOMNode { // Set the value for the element attribute named |attrName|. Returns true (1) // on success. // - pub fn set_element_attribute(&self, attrName: &str, - value: &str) -> libc::c_int { + pub fn set_element_attribute(&self, attrName: &[u16], + value: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_download_handler.rs b/ports/cef/interfaces/cef_download_handler.rs index 78cdcf83d66..1648129aa7a 100644 --- a/ports/cef/interfaces/cef_download_handler.rs +++ b/ports/cef/interfaces/cef_download_handler.rs @@ -151,7 +151,7 @@ impl CefBeforeDownloadCallback { // suggested name and the default temp directory. Set |show_dialog| to true // (1) if you do wish to show the default "Save As" dialog. // - pub fn cont(&self, download_path: &str, show_dialog: libc::c_int) -> () { + pub fn cont(&self, download_path: &[u16], show_dialog: libc::c_int) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -453,7 +453,7 @@ impl CefDownloadHandler { // this function. // pub fn on_before_download(&self, browser: interfaces::CefBrowser, - download_item: interfaces::CefDownloadItem, suggested_name: &str, + download_item: interfaces::CefDownloadItem, suggested_name: &[u16], callback: interfaces::CefBeforeDownloadCallback) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_drag_data.rs b/ports/cef/interfaces/cef_drag_data.rs index 2fd56c027d6..02c11f12431 100644 --- a/ports/cef/interfaces/cef_drag_data.rs +++ b/ports/cef/interfaces/cef_drag_data.rs @@ -496,7 +496,7 @@ impl CefDragData { // // Set the link URL that is being dragged. // - pub fn set_link_url(&self, url: &str) -> () { + pub fn set_link_url(&self, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -511,7 +511,7 @@ impl CefDragData { // // Set the title associated with the link being dragged. // - pub fn set_link_title(&self, title: &str) -> () { + pub fn set_link_title(&self, title: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -526,7 +526,7 @@ impl CefDragData { // // Set the metadata associated with the link being dragged. // - pub fn set_link_metadata(&self, data: &str) -> () { + pub fn set_link_metadata(&self, data: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -541,7 +541,7 @@ impl CefDragData { // // Set the plain text fragment that is being dragged. // - pub fn set_fragment_text(&self, text: &str) -> () { + pub fn set_fragment_text(&self, text: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -556,7 +556,7 @@ impl CefDragData { // // Set the text/html fragment that is being dragged. // - pub fn set_fragment_html(&self, html: &str) -> () { + pub fn set_fragment_html(&self, html: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -571,7 +571,7 @@ impl CefDragData { // // Set the base URL that the fragment came from. // - pub fn set_fragment_base_url(&self, base_url: &str) -> () { + pub fn set_fragment_base_url(&self, base_url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -602,7 +602,7 @@ impl CefDragData { // // Add a file that is being dragged into the webview. // - pub fn add_file(&self, path: &str, display_name: &str) -> () { + pub fn add_file(&self, path: &[u16], display_name: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_frame.rs b/ports/cef/interfaces/cef_frame.rs index 0c237d98dff..2611cd62dee 100644 --- a/ports/cef/interfaces/cef_frame.rs +++ b/ports/cef/interfaces/cef_frame.rs @@ -472,7 +472,7 @@ impl CefFrame { // // Load the specified |url|. // - pub fn load_url(&self, url: &str) -> () { + pub fn load_url(&self, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -489,7 +489,7 @@ impl CefFrame { // should have a standard scheme (for example, http scheme) or behaviors like // link clicks and web security restrictions may not behave as expected. // - pub fn load_string(&self, string_val: &str, url: &str) -> () { + pub fn load_string(&self, string_val: &[u16], url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -509,7 +509,7 @@ impl CefFrame { // error. The |start_line| parameter is the base line number to use for error // reporting. // - pub fn execute_java_script(&self, code: &str, script_url: &str, + pub fn execute_java_script(&self, code: &[u16], script_url: &[u16], start_line: libc::c_int) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_geolocation_handler.rs b/ports/cef/interfaces/cef_geolocation_handler.rs index 73fe9d842fa..d626419062b 100644 --- a/ports/cef/interfaces/cef_geolocation_handler.rs +++ b/ports/cef/interfaces/cef_geolocation_handler.rs @@ -312,7 +312,7 @@ impl CefGeolocationHandler { // request immediately. // pub fn on_request_geolocation_permission(&self, - browser: interfaces::CefBrowser, requesting_url: &str, + browser: interfaces::CefBrowser, requesting_url: &[u16], request_id: libc::c_int, callback: interfaces::CefGeolocationCallback) -> libc::c_int { if self.c_object.is_null() { @@ -335,7 +335,7 @@ impl CefGeolocationHandler { // ID for the permission request. // pub fn on_cancel_geolocation_permission(&self, - browser: interfaces::CefBrowser, requesting_url: &str, + browser: interfaces::CefBrowser, requesting_url: &[u16], request_id: libc::c_int) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_jsdialog_handler.rs b/ports/cef/interfaces/cef_jsdialog_handler.rs index ca0353e57a8..8e399a1e1b5 100644 --- a/ports/cef/interfaces/cef_jsdialog_handler.rs +++ b/ports/cef/interfaces/cef_jsdialog_handler.rs @@ -148,7 +148,7 @@ impl CefJSDialogCallback { // Continue the JS dialog request. Set |success| to true (1) if the OK button // was pressed. The |user_input| value should be specified for prompt dialogs. // - pub fn cont(&self, success: libc::c_int, user_input: &str) -> () { + pub fn cont(&self, success: libc::c_int, user_input: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -348,9 +348,9 @@ impl CefJSDialogHandler { // the application must execute |callback| once the custom dialog is // dismissed. // - pub fn on_jsdialog(&self, browser: interfaces::CefBrowser, origin_url: &str, - accept_lang: &str, dialog_type: types::cef_jsdialog_type_t, - message_text: &str, default_prompt_text: &str, + pub fn on_jsdialog(&self, browser: interfaces::CefBrowser, origin_url: &[u16], + accept_lang: &[u16], dialog_type: types::cef_jsdialog_type_t, + message_text: &[u16], default_prompt_text: &[u16], callback: interfaces::CefJSDialogCallback, suppress_message: &mut libc::c_int) -> libc::c_int { if self.c_object.is_null() { @@ -380,7 +380,7 @@ impl CefJSDialogHandler { // dialog is dismissed. // pub fn on_before_unload_dialog(&self, browser: interfaces::CefBrowser, - message_text: &str, is_reload: libc::c_int, + message_text: &[u16], is_reload: libc::c_int, callback: interfaces::CefJSDialogCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_life_span_handler.rs b/ports/cef/interfaces/cef_life_span_handler.rs index 453bacf111e..b296bfe42fd 100644 --- a/ports/cef/interfaces/cef_life_span_handler.rs +++ b/ports/cef/interfaces/cef_life_span_handler.rs @@ -260,8 +260,8 @@ impl CefLifeSpanHandler { // indicates whether the new browser window should be scriptable and in the // same process as the source browser. pub fn on_before_popup(&self, browser: interfaces::CefBrowser, - frame: interfaces::CefFrame, target_url: &str, target_frame_name: &str, - popupFeatures: &interfaces::CefPopupFeatures, + frame: interfaces::CefFrame, target_url: &[u16], + target_frame_name: &[u16], popupFeatures: &interfaces::CefPopupFeatures, windowInfo: &mut interfaces::CefWindowInfo, client: interfaces::CefClient, settings: &mut interfaces::CefBrowserSettings, diff --git a/ports/cef/interfaces/cef_load_handler.rs b/ports/cef/interfaces/cef_load_handler.rs index 989302d3691..831f617f533 100644 --- a/ports/cef/interfaces/cef_load_handler.rs +++ b/ports/cef/interfaces/cef_load_handler.rs @@ -264,7 +264,7 @@ impl CefLoadHandler { // pub fn on_load_error(&self, browser: interfaces::CefBrowser, frame: interfaces::CefFrame, errorCode: types::cef_errorcode_t, - errorText: &str, failedUrl: &str) -> () { + errorText: &[u16], failedUrl: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_menu_model.rs b/ports/cef/interfaces/cef_menu_model.rs index 2d45ad335c6..c1972ddc8cc 100644 --- a/ports/cef/interfaces/cef_menu_model.rs +++ b/ports/cef/interfaces/cef_menu_model.rs @@ -526,7 +526,8 @@ impl CefMenuModel { // // Add an item to the menu. Returns true (1) on success. // - pub fn add_item(&self, command_id: libc::c_int, label: &str) -> libc::c_int { + pub fn add_item(&self, command_id: libc::c_int, + label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -543,7 +544,7 @@ impl CefMenuModel { // Add a check item to the menu. Returns true (1) on success. // pub fn add_check_item(&self, command_id: libc::c_int, - label: &str) -> libc::c_int { + label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -560,7 +561,7 @@ impl CefMenuModel { // Add a radio item to the menu. Only a single item with the specified // |group_id| can be checked at a time. Returns true (1) on success. // - pub fn add_radio_item(&self, command_id: libc::c_int, label: &str, + pub fn add_radio_item(&self, command_id: libc::c_int, label: &[u16], group_id: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -579,7 +580,7 @@ impl CefMenuModel { // Add a sub-menu to the menu. The new sub-menu is returned. // pub fn add_sub_menu(&self, command_id: libc::c_int, - label: &str) -> interfaces::CefMenuModel { + label: &[u16]) -> interfaces::CefMenuModel { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -613,7 +614,7 @@ impl CefMenuModel { // success. // pub fn insert_item_at(&self, index: libc::c_int, command_id: libc::c_int, - label: &str) -> libc::c_int { + label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -632,7 +633,7 @@ impl CefMenuModel { // on success. // pub fn insert_check_item_at(&self, index: libc::c_int, - command_id: libc::c_int, label: &str) -> libc::c_int { + command_id: libc::c_int, label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -652,7 +653,7 @@ impl CefMenuModel { // (1) on success. // pub fn insert_radio_item_at(&self, index: libc::c_int, - command_id: libc::c_int, label: &str, + command_id: libc::c_int, label: &[u16], group_id: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -673,7 +674,7 @@ impl CefMenuModel { // returned. // pub fn insert_sub_menu_at(&self, index: libc::c_int, command_id: libc::c_int, - label: &str) -> interfaces::CefMenuModel { + label: &[u16]) -> interfaces::CefMenuModel { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -803,7 +804,8 @@ impl CefMenuModel { // // Sets the label for the specified |command_id|. Returns true (1) on success. // - pub fn set_label(&self, command_id: libc::c_int, label: &str) -> libc::c_int { + pub fn set_label(&self, command_id: libc::c_int, + label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -819,7 +821,7 @@ impl CefMenuModel { // // Set the label at the specified |index|. Returns true (1) on success. // - pub fn set_label_at(&self, index: libc::c_int, label: &str) -> libc::c_int { + pub fn set_label_at(&self, index: libc::c_int, label: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_print_handler.rs b/ports/cef/interfaces/cef_print_handler.rs index ec794b50f2f..7d4ceb16025 100644 --- a/ports/cef/interfaces/cef_print_handler.rs +++ b/ports/cef/interfaces/cef_print_handler.rs @@ -506,7 +506,7 @@ impl CefPrintHandler { // completed. Return true (1) if the job will proceed or false (0) to cancel // the job immediately. // - pub fn on_print_job(&self, document_name: &str, pdf_file_path: &str, + pub fn on_print_job(&self, document_name: &[u16], pdf_file_path: &[u16], callback: interfaces::CefPrintJobCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_print_settings.rs b/ports/cef/interfaces/cef_print_settings.rs index ef81ec47fdb..86528c88b76 100644 --- a/ports/cef/interfaces/cef_print_settings.rs +++ b/ports/cef/interfaces/cef_print_settings.rs @@ -381,7 +381,7 @@ impl CefPrintSettings { // // Set the device name. // - pub fn set_device_name(&self, name: &str) -> () { + pub fn set_device_name(&self, name: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_process_message.rs b/ports/cef/interfaces/cef_process_message.rs index 5d5ab1ce3f7..b2fcf4c784b 100644 --- a/ports/cef/interfaces/cef_process_message.rs +++ b/ports/cef/interfaces/cef_process_message.rs @@ -244,7 +244,7 @@ impl CefProcessMessage { // // Create a new cef_process_message_t object with the specified name. // - pub fn create(name: &str) -> interfaces::CefProcessMessage { + pub fn create(name: &[u16]) -> interfaces::CefProcessMessage { unsafe { CefWrap::to_rust( ::process_message::cef_process_message_create( diff --git a/ports/cef/interfaces/cef_request.rs b/ports/cef/interfaces/cef_request.rs index 8f490ac26bf..5d6fa8fc3d4 100644 --- a/ports/cef/interfaces/cef_request.rs +++ b/ports/cef/interfaces/cef_request.rs @@ -277,7 +277,7 @@ impl CefRequest { // // Set the fully qualified URL. // - pub fn set_url(&self, url: &str) -> () { + pub fn set_url(&self, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -308,7 +308,7 @@ impl CefRequest { // // Set the request function type. // - pub fn set_method(&self, method: &str) -> () { + pub fn set_method(&self, method: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -382,8 +382,9 @@ impl CefRequest { // // Set all values at one time. // - pub fn set(&self, url: &str, method: &str, postData: interfaces::CefPostData, - headerMap: HashMap>) -> () { + pub fn set(&self, url: &[u16], method: &[u16], + postData: interfaces::CefPostData, headerMap: HashMap>) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -449,7 +450,7 @@ impl CefRequest { // Get the URL to the first party for cookies used in combination with // cef_urlrequest_t. // - pub fn set_first_party_for_cookies(&self, url: &str) -> () { + pub fn set_first_party_for_cookies(&self, url: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -961,7 +962,7 @@ impl CefPostDataElement { // // The post data element will represent a file. // - pub fn set_to_file(&self, fileName: &str) -> () { + pub fn set_to_file(&self, fileName: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_request_handler.rs b/ports/cef/interfaces/cef_request_handler.rs index 68c60a6eb60..e519cad7399 100644 --- a/ports/cef/interfaces/cef_request_handler.rs +++ b/ports/cef/interfaces/cef_request_handler.rs @@ -639,7 +639,7 @@ impl CefRequestHandler { // the new URL and can be changed if desired. // pub fn on_resource_redirect(&self, browser: interfaces::CefBrowser, - frame: interfaces::CefFrame, old_url: &str, + frame: interfaces::CefFrame, old_url: &[u16], new_url: *mut types::cef_string_t) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -663,8 +663,8 @@ impl CefRequestHandler { // information is available. Return false (0) to cancel the request. // pub fn get_auth_credentials(&self, browser: interfaces::CefBrowser, - frame: interfaces::CefFrame, isProxy: libc::c_int, host: &str, - port: libc::c_int, realm: &str, scheme: &str, + frame: interfaces::CefFrame, isProxy: libc::c_int, host: &[u16], + port: libc::c_int, realm: &[u16], scheme: &[u16], callback: interfaces::CefAuthCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -693,7 +693,7 @@ impl CefRequestHandler { // false (0) to cancel the request. // pub fn on_quota_request(&self, browser: interfaces::CefBrowser, - origin_url: &str, new_size: i64, + origin_url: &[u16], new_size: i64, callback: interfaces::CefQuotaCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -717,7 +717,7 @@ impl CefRequestHandler { // OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION. // pub fn on_protocol_execution(&self, browser: interfaces::CefBrowser, - url: &str, allow_os_execution: &mut libc::c_int) -> () { + url: &[u16], allow_os_execution: &mut libc::c_int) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -742,7 +742,7 @@ impl CefRequestHandler { // be accepted without calling this function. // pub fn on_certificate_error(&self, cert_error: types::cef_errorcode_t, - request_url: &str, + request_url: &[u16], callback: interfaces::CefAllowCertificateErrorCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -762,7 +762,7 @@ impl CefRequestHandler { // true (1) to block loading of the plugin. // pub fn on_before_plugin_load(&self, browser: interfaces::CefBrowser, - url: &str, policy_url: &str, + url: &[u16], policy_url: &[u16], info: interfaces::CefWebPluginInfo) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -783,7 +783,7 @@ impl CefRequestHandler { // |plugin_path| is the path of the plugin that crashed. // pub fn on_plugin_crashed(&self, browser: interfaces::CefBrowser, - plugin_path: &str) -> () { + plugin_path: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_response.rs b/ports/cef/interfaces/cef_response.rs index d2599c4f8c0..412472a44c3 100644 --- a/ports/cef/interfaces/cef_response.rs +++ b/ports/cef/interfaces/cef_response.rs @@ -261,7 +261,7 @@ impl CefResponse { // // Set the response status text. // - pub fn set_status_text(&self, statusText: &str) -> () { + pub fn set_status_text(&self, statusText: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -291,7 +291,7 @@ impl CefResponse { // // Set the response mime type. // - pub fn set_mime_type(&self, mimeType: &str) -> () { + pub fn set_mime_type(&self, mimeType: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -307,7 +307,7 @@ impl CefResponse { // Get the value for the specified response header field. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_header(&self, name: &str) -> String { + pub fn get_header(&self, name: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_scheme.rs b/ports/cef/interfaces/cef_scheme.rs index 3391b9fd119..729ac8d53ee 100644 --- a/ports/cef/interfaces/cef_scheme.rs +++ b/ports/cef/interfaces/cef_scheme.rs @@ -231,7 +231,7 @@ impl CefSchemeRegistrar { // per unique |scheme_name| value. If |scheme_name| is already registered or // if an error occurs this function will return false (0). // - pub fn add_custom_scheme(&self, scheme_name: &str, is_standard: libc::c_int, + pub fn add_custom_scheme(&self, scheme_name: &[u16], is_standard: libc::c_int, is_local: libc::c_int, is_display_isolated: libc::c_int) -> libc::c_int { if self.c_object.is_null() { @@ -391,7 +391,7 @@ impl CefSchemeHandlerFactory { // passed to this function will not contain cookie data. // pub fn create(&self, browser: interfaces::CefBrowser, - frame: interfaces::CefFrame, scheme_name: &str, + frame: interfaces::CefFrame, scheme_name: &[u16], request: interfaces::CefRequest) -> interfaces::CefResourceHandler { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_stream.rs b/ports/cef/interfaces/cef_stream.rs index ecae891aa17..a4163db6c14 100644 --- a/ports/cef/interfaces/cef_stream.rs +++ b/ports/cef/interfaces/cef_stream.rs @@ -478,7 +478,7 @@ impl CefStreamReader { // // Create a new cef_stream_reader_t object from a file. // - pub fn create_for_file(fileName: &str) -> interfaces::CefStreamReader { + pub fn create_for_file(fileName: &[u16]) -> interfaces::CefStreamReader { unsafe { CefWrap::to_rust( ::stream::cef_stream_reader_create_for_file( @@ -972,7 +972,7 @@ impl CefStreamWriter { // // Create a new cef_stream_writer_t object for a file. // - pub fn create_for_file(fileName: &str) -> interfaces::CefStreamWriter { + pub fn create_for_file(fileName: &[u16]) -> interfaces::CefStreamWriter { unsafe { CefWrap::to_rust( ::stream::cef_stream_writer_create_for_file( diff --git a/ports/cef/interfaces/cef_string_visitor.rs b/ports/cef/interfaces/cef_string_visitor.rs index 26fc75997e0..9c8492e84e2 100644 --- a/ports/cef/interfaces/cef_string_visitor.rs +++ b/ports/cef/interfaces/cef_string_visitor.rs @@ -144,7 +144,7 @@ impl CefStringVisitor { // // Method that will be executed. // - pub fn visit(&self, string: &str) -> () { + pub fn visit(&self, string: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_trace.rs b/ports/cef/interfaces/cef_trace.rs index 7cccbb1135d..34644003f33 100644 --- a/ports/cef/interfaces/cef_trace.rs +++ b/ports/cef/interfaces/cef_trace.rs @@ -153,7 +153,7 @@ impl CefEndTracingCallback { // the path at which tracing data was written. The client is responsible for // deleting |tracing_file|. // - pub fn on_end_tracing_complete(&self, tracing_file: &str) -> () { + pub fn on_end_tracing_complete(&self, tracing_file: &[u16]) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_urlrequest.rs b/ports/cef/interfaces/cef_urlrequest.rs index 73189180f4d..123224e47c6 100644 --- a/ports/cef/interfaces/cef_urlrequest.rs +++ b/ports/cef/interfaces/cef_urlrequest.rs @@ -553,8 +553,8 @@ impl CefURLRequestClient { // function will only be called for requests initiated from the browser // process. // - pub fn get_auth_credentials(&self, isProxy: libc::c_int, host: &str, - port: libc::c_int, realm: &str, scheme: &str, + pub fn get_auth_credentials(&self, isProxy: libc::c_int, host: &[u16], + port: libc::c_int, realm: &[u16], scheme: &[u16], callback: interfaces::CefAuthCallback) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") diff --git a/ports/cef/interfaces/cef_v8.rs b/ports/cef/interfaces/cef_v8.rs index fd69ec4fa42..1418c48dba4 100644 --- a/ports/cef/interfaces/cef_v8.rs +++ b/ports/cef/interfaces/cef_v8.rs @@ -344,7 +344,7 @@ impl CefV8Context { // function will return true (1). On failure |exception| will be set to the // exception, if any, and the function will return false (0). // - pub fn eval(&self, code: &str, retval: interfaces::CefV8Value, + pub fn eval(&self, code: &[u16], retval: interfaces::CefV8Value, exception: interfaces::CefV8Exception) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -533,7 +533,7 @@ impl CefV8Handler { // function return value. If execution fails set |exception| to the exception // that will be thrown. Return true (1) if execution was handled. // - pub fn execute(&self, name: &str, object: interfaces::CefV8Value, + pub fn execute(&self, name: &[u16], object: interfaces::CefV8Value, arguments_count: libc::size_t, arguments: *const interfaces::CefV8Value, retval: interfaces::CefV8Value, exception: *mut types::cef_string_t) -> libc::c_int { @@ -706,7 +706,7 @@ impl CefV8Accessor { // exception that will be thrown. Return true (1) if accessor retrieval was // handled. // - pub fn get(&self, name: &str, object: interfaces::CefV8Value, + pub fn get(&self, name: &[u16], object: interfaces::CefV8Value, retval: interfaces::CefV8Value, exception: *mut types::cef_string_t) -> libc::c_int { if self.c_object.is_null() { @@ -730,7 +730,7 @@ impl CefV8Accessor { // exception that will be thrown. Return true (1) if accessor assignment was // handled. // - pub fn set(&self, name: &str, object: interfaces::CefV8Value, + pub fn set(&self, name: &[u16], object: interfaces::CefV8Value, value: interfaces::CefV8Value, exception: *mut types::cef_string_t) -> libc::c_int { if self.c_object.is_null() { @@ -1874,7 +1874,7 @@ impl CefV8Value { // // Returns true (1) if the object has a value with the specified identifier. // - pub fn has_value_bykey(&self, key: &str) -> libc::c_int { + pub fn has_value_bykey(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1907,7 +1907,7 @@ impl CefV8Value { // exception is thrown. For read-only and don't-delete values this function // will return true (1) even though deletion failed. // - pub fn delete_value_bykey(&self, key: &str) -> libc::c_int { + pub fn delete_value_bykey(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1941,7 +1941,7 @@ impl CefV8Value { // Returns the value with the specified identifier on success. Returns NULL if // this function is called incorrectly or an exception is thrown. // - pub fn get_value_bykey(&self, key: &str) -> interfaces::CefV8Value { + pub fn get_value_bykey(&self, key: &[u16]) -> interfaces::CefV8Value { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -1976,7 +1976,7 @@ impl CefV8Value { // exception is thrown. For read-only values this function will return true // (1) even though assignment failed. // - pub fn set_value_bykey(&self, key: &str, value: interfaces::CefV8Value, + pub fn set_value_bykey(&self, key: &[u16], value: interfaces::CefV8Value, attribute: types::cef_v8_propertyattribute_t) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -2018,7 +2018,7 @@ impl CefV8Value { // function is called incorrectly or an exception is thrown. For read-only // values this function will return true (1) even though assignment failed. // - pub fn set_value_byaccessor(&self, key: &str, + pub fn set_value_byaccessor(&self, key: &[u16], settings: types::cef_v8_accesscontrol_t, attribute: types::cef_v8_propertyattribute_t) -> libc::c_int { if self.c_object.is_null() { @@ -2304,7 +2304,7 @@ impl CefV8Value { // // Create a new cef_v8value_t object of type string. // - pub fn create_string(value: &str) -> interfaces::CefV8Value { + pub fn create_string(value: &[u16]) -> interfaces::CefV8Value { unsafe { CefWrap::to_rust( ::v8::cef_v8value_create_string( @@ -2350,7 +2350,7 @@ impl CefV8Value { // cef_v8handler_t or cef_v8accessor_t callback, or in combination with // calling enter() and exit() on a stored cef_v8context_t reference. // - pub fn create_function(name: &str, + pub fn create_function(name: &[u16], handler: interfaces::CefV8Handler) -> interfaces::CefV8Value { unsafe { CefWrap::to_rust( diff --git a/ports/cef/interfaces/cef_values.rs b/ports/cef/interfaces/cef_values.rs index e4b2a95736b..abea93e2e04 100644 --- a/ports/cef/interfaces/cef_values.rs +++ b/ports/cef/interfaces/cef_values.rs @@ -646,7 +646,7 @@ impl CefDictionaryValue { // // Returns true (1) if the current dictionary has a value for the given key. // - pub fn has_key(&self, key: &str) -> libc::c_int { + pub fn has_key(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -677,7 +677,7 @@ impl CefDictionaryValue { // Removes the value at the specified key. Returns true (1) is the value was // removed successfully. // - pub fn remove(&self, key: &str) -> libc::c_int { + pub fn remove(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -692,7 +692,7 @@ impl CefDictionaryValue { // // Returns the value type for the specified key. // - pub fn get_type(&self, key: &str) -> interfaces::CefValueType { + pub fn get_type(&self, key: &[u16]) -> interfaces::CefValueType { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -707,7 +707,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type bool. // - pub fn get_bool(&self, key: &str) -> libc::c_int { + pub fn get_bool(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -722,7 +722,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type int. // - pub fn get_int(&self, key: &str) -> libc::c_int { + pub fn get_int(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -737,7 +737,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type double. // - pub fn get_double(&self, key: &str) -> libc::c_double { + pub fn get_double(&self, key: &[u16]) -> libc::c_double { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -753,7 +753,7 @@ impl CefDictionaryValue { // Returns the value at the specified key as type string. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_string(&self, key: &str) -> String { + pub fn get_string(&self, key: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -768,7 +768,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type binary. // - pub fn get_binary(&self, key: &str) -> interfaces::CefBinaryValue { + pub fn get_binary(&self, key: &[u16]) -> interfaces::CefBinaryValue { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -783,7 +783,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type dictionary. // - pub fn get_dictionary(&self, key: &str) -> interfaces::CefDictionaryValue { + pub fn get_dictionary(&self, key: &[u16]) -> interfaces::CefDictionaryValue { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -798,7 +798,7 @@ impl CefDictionaryValue { // // Returns the value at the specified key as type list. // - pub fn get_list(&self, key: &str) -> interfaces::CefListValue { + pub fn get_list(&self, key: &[u16]) -> interfaces::CefListValue { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -814,7 +814,7 @@ impl CefDictionaryValue { // Sets the value at the specified key as type null. Returns true (1) if the // value was set successfully. // - pub fn set_null(&self, key: &str) -> libc::c_int { + pub fn set_null(&self, key: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -830,7 +830,7 @@ impl CefDictionaryValue { // Sets the value at the specified key as type bool. Returns true (1) if the // value was set successfully. // - pub fn set_bool(&self, key: &str, value: libc::c_int) -> libc::c_int { + pub fn set_bool(&self, key: &[u16], value: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -847,7 +847,7 @@ impl CefDictionaryValue { // Sets the value at the specified key as type int. Returns true (1) if the // value was set successfully. // - pub fn set_int(&self, key: &str, value: libc::c_int) -> libc::c_int { + pub fn set_int(&self, key: &[u16], value: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -864,7 +864,7 @@ impl CefDictionaryValue { // Sets the value at the specified key as type double. Returns true (1) if the // value was set successfully. // - pub fn set_double(&self, key: &str, value: libc::c_double) -> libc::c_int { + pub fn set_double(&self, key: &[u16], value: libc::c_double) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -881,7 +881,7 @@ impl CefDictionaryValue { // Sets the value at the specified key as type string. Returns true (1) if the // value was set successfully. // - pub fn set_string(&self, key: &str, value: &str) -> libc::c_int { + pub fn set_string(&self, key: &[u16], value: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -901,7 +901,7 @@ impl CefDictionaryValue { // Otherwise, ownership will be transferred to this object and the |value| // reference will be invalidated. // - pub fn set_binary(&self, key: &str, + pub fn set_binary(&self, key: &[u16], value: interfaces::CefBinaryValue) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -923,7 +923,7 @@ impl CefDictionaryValue { // Otherwise, ownership will be transferred to this object and the |value| // reference will be invalidated. // - pub fn set_dictionary(&self, key: &str, + pub fn set_dictionary(&self, key: &[u16], value: interfaces::CefDictionaryValue) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -945,7 +945,7 @@ impl CefDictionaryValue { // Otherwise, ownership will be transferred to this object and the |value| // reference will be invalidated. // - pub fn set_list(&self, key: &str, + pub fn set_list(&self, key: &[u16], value: interfaces::CefListValue) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -1568,7 +1568,7 @@ impl CefListValue { // Sets the value at the specified index as type string. Returns true (1) if // the value was set successfully. // - pub fn set_string(&self, index: libc::c_int, value: &str) -> libc::c_int { + pub fn set_string(&self, index: libc::c_int, value: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_web_plugin.rs b/ports/cef/interfaces/cef_web_plugin.rs index 99dcbb97093..725c749560a 100644 --- a/ports/cef/interfaces/cef_web_plugin.rs +++ b/ports/cef/interfaces/cef_web_plugin.rs @@ -504,7 +504,7 @@ impl CefWebPluginUnstableCallback { // true (1) if the plugin has reached the crash count threshold of 3 times in // 120 seconds. // - pub fn is_unstable(&self, path: &str, unstable: libc::c_int) -> () { + pub fn is_unstable(&self, path: &[u16], unstable: libc::c_int) -> () { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/interfaces/cef_xml_reader.rs b/ports/cef/interfaces/cef_xml_reader.rs index 8109c2100ca..361339cd85e 100644 --- a/ports/cef/interfaces/cef_xml_reader.rs +++ b/ports/cef/interfaces/cef_xml_reader.rs @@ -636,7 +636,7 @@ impl CefXmlReader { // Returns the value of the attribute with the specified qualified name. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_attribute_byqname(&self, qualifiedName: &str) -> String { + pub fn get_attribute_byqname(&self, qualifiedName: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -653,8 +653,8 @@ impl CefXmlReader { // namespace URI. // // The resulting string must be freed by calling cef_string_userfree_free(). - pub fn get_attribute_bylname(&self, localName: &str, - namespaceURI: &str) -> String { + pub fn get_attribute_bylname(&self, localName: &[u16], + namespaceURI: &[u16]) -> String { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -737,7 +737,8 @@ impl CefXmlReader { // Moves the cursor to the attribute with the specified qualified name. // Returns true (1) if the cursor position was set successfully. // - pub fn move_to_attribute_byqname(&self, qualifiedName: &str) -> libc::c_int { + pub fn move_to_attribute_byqname(&self, + qualifiedName: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -754,8 +755,8 @@ impl CefXmlReader { // namespace URI. Returns true (1) if the cursor position was set // successfully. // - pub fn move_to_attribute_bylname(&self, localName: &str, - namespaceURI: &str) -> libc::c_int { + pub fn move_to_attribute_bylname(&self, localName: &[u16], + namespaceURI: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } @@ -819,7 +820,7 @@ impl CefXmlReader { // pub fn create(stream: interfaces::CefStreamReader, encodingType: types::cef_xml_encoding_type_t, - URI: &str) -> interfaces::CefXmlReader { + URI: &[u16]) -> interfaces::CefXmlReader { unsafe { CefWrap::to_rust( ::xml_reader::cef_xml_reader_create( diff --git a/ports/cef/interfaces/cef_zip_reader.rs b/ports/cef/interfaces/cef_zip_reader.rs index 2623bb9b4ca..efac8229cca 100644 --- a/ports/cef/interfaces/cef_zip_reader.rs +++ b/ports/cef/interfaces/cef_zip_reader.rs @@ -254,7 +254,7 @@ impl CefZipReader { // is true (1) then the search will be case sensitive. Returns true (1) if the // cursor position was set successfully. // - pub fn move_to_file(&self, fileName: &str, + pub fn move_to_file(&self, fileName: &[u16], caseSensitive: libc::c_int) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") @@ -333,7 +333,7 @@ impl CefZipReader { // Opens the file for reading of uncompressed data. A read password may // optionally be specified. // - pub fn open_file(&self, password: &str) -> libc::c_int { + pub fn open_file(&self, password: &[u16]) -> libc::c_int { if self.c_object.is_null() { panic!("called a CEF method on a null object") } diff --git a/ports/cef/wrappers.rs b/ports/cef/wrappers.rs index 4030681ebbb..d9c2ecee5bc 100644 --- a/ports/cef/wrappers.rs +++ b/ports/cef/wrappers.rs @@ -30,9 +30,10 @@ use types::{cef_time_t, cef_transition_type_t, cef_urlrequest_status_t}; use types::{cef_v8_accesscontrol_t, cef_v8_propertyattribute_t, cef_value_type_t}; use types::{cef_window_info_t, cef_xml_encoding_type_t, cef_xml_node_type_t}; -use libc::{c_char, c_int, c_void}; +use libc::{mod, c_char, c_int, c_ushort, c_void}; use std::collections::HashMap; use std::mem; +use std::ptr; pub trait CefWrap { fn to_c(rust_object: Self) -> CObject; @@ -177,20 +178,42 @@ cef_unimplemented_wrapper!(cef_string_map_t, HashMap) cef_unimplemented_wrapper!(cef_string_multimap_t, HashMap>) cef_unimplemented_wrapper!(cef_string_t, String) -impl<'a> CefWrap<*const cef_string_t> for &'a str { - fn to_c(_: &'a str) -> *const cef_string_t { - panic!("unimplemented CEF type conversion: &'a str") +impl<'a> CefWrap<*const cef_string_t> for &'a [u16] { + fn to_c(buffer: &'a [u16]) -> *const cef_string_t { + unsafe { + let ptr: *mut c_ushort = mem::transmute(libc::malloc(((buffer.len() * 2) + 1) as u64)); + ptr::copy_memory(ptr, mem::transmute(buffer.as_ptr()), (buffer.len() * 2) as uint); + *ptr.offset(buffer.len() as int) = 0; + + // FIXME(pcwalton): This leaks!! We should instead have the caller pass some scratch + // stack space to create the object in. What a botch. + let boxed_string = box cef_string_utf16 { + str: ptr, + length: buffer.len() as u64, + dtor: Some(free_boxed_utf16_string), + }; + let result: *const cef_string_utf16 = &*boxed_string; + mem::forget(boxed_string); + result + } } - unsafe fn to_rust(_: *const cef_string_t) -> &'a str { - panic!("unimplemented CEF type conversion: *const cef_string_t") + unsafe fn to_rust(cef_string: *const cef_string_t) -> &'a [u16] { + let (ptr, len): (*mut c_ushort, uint) = ((*cef_string).str, (*cef_string).length as uint); + mem::transmute((ptr, len)) } } -impl<'a> CefWrap<*mut cef_string_t> for &'a mut str { - fn to_c(_: &'a mut str) -> *mut cef_string_t { +extern "C" fn free_boxed_utf16_string(string: *mut c_ushort) { + unsafe { + libc::free(string as *mut c_void) + } +} + +impl<'a> CefWrap<*mut cef_string_t> for &'a mut [u16] { + fn to_c(_: &'a mut [u16]) -> *mut cef_string_t { panic!("unimplemented CEF type conversion: &'a str") } - unsafe fn to_rust(_: *mut cef_string_t) -> &'a mut str { + unsafe fn to_rust(_: *mut cef_string_t) -> &'a mut [u16] { mem::transmute::<(int,int),_>(panic!("unimplemented CEF type conversion: *mut \ cef_string_t")) } From c52f550367977aff32180ce632fd0ad6e8db8248 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 25 Nov 2014 18:28:59 -0800 Subject: [PATCH 5/5] Update to get the reference counting correct --- ports/cef/core.rs | 5 +++++ ports/cef/eutil.rs | 10 ++++------ ports/cef/interfaces/cef_app.rs | 2 +- ports/cef/interfaces/cef_auth_callback.rs | 2 +- ports/cef/interfaces/cef_browser.rs | 6 +++--- .../cef/interfaces/cef_browser_process_handler.rs | 2 +- ports/cef/interfaces/cef_callback.rs | 4 ++-- ports/cef/interfaces/cef_client.rs | 2 +- ports/cef/interfaces/cef_command_line.rs | 2 +- ports/cef/interfaces/cef_context_menu_handler.rs | 4 ++-- ports/cef/interfaces/cef_cookie.rs | 4 ++-- ports/cef/interfaces/cef_dialog_handler.rs | 4 ++-- ports/cef/interfaces/cef_display_handler.rs | 2 +- ports/cef/interfaces/cef_dom.rs | 6 +++--- ports/cef/interfaces/cef_download_handler.rs | 6 +++--- ports/cef/interfaces/cef_download_item.rs | 2 +- ports/cef/interfaces/cef_drag_data.rs | 2 +- ports/cef/interfaces/cef_drag_handler.rs | 2 +- ports/cef/interfaces/cef_focus_handler.rs | 2 +- ports/cef/interfaces/cef_frame.rs | 2 +- ports/cef/interfaces/cef_geolocation.rs | 2 +- ports/cef/interfaces/cef_geolocation_handler.rs | 4 ++-- ports/cef/interfaces/cef_jsdialog_handler.rs | 4 ++-- ports/cef/interfaces/cef_keyboard_handler.rs | 2 +- ports/cef/interfaces/cef_life_span_handler.rs | 2 +- ports/cef/interfaces/cef_load_handler.rs | 2 +- ports/cef/interfaces/cef_menu_model.rs | 2 +- ports/cef/interfaces/cef_print_handler.rs | 6 +++--- ports/cef/interfaces/cef_print_settings.rs | 2 +- ports/cef/interfaces/cef_process_message.rs | 2 +- ports/cef/interfaces/cef_render_handler.rs | 2 +- ports/cef/interfaces/cef_render_process_handler.rs | 2 +- ports/cef/interfaces/cef_request.rs | 6 +++--- ports/cef/interfaces/cef_request_context.rs | 2 +- .../cef/interfaces/cef_request_context_handler.rs | 2 +- ports/cef/interfaces/cef_request_handler.rs | 6 +++--- .../cef/interfaces/cef_resource_bundle_handler.rs | 2 +- ports/cef/interfaces/cef_resource_handler.rs | 2 +- ports/cef/interfaces/cef_response.rs | 2 +- ports/cef/interfaces/cef_scheme.rs | 4 ++-- ports/cef/interfaces/cef_stream.rs | 8 ++++---- ports/cef/interfaces/cef_string_visitor.rs | 2 +- ports/cef/interfaces/cef_task.rs | 4 ++-- ports/cef/interfaces/cef_trace.rs | 2 +- ports/cef/interfaces/cef_urlrequest.rs | 4 ++-- ports/cef/interfaces/cef_v8.rs | 14 +++++++------- ports/cef/interfaces/cef_values.rs | 6 +++--- ports/cef/interfaces/cef_web_plugin.rs | 6 +++--- ports/cef/interfaces/cef_xml_reader.rs | 2 +- ports/cef/interfaces/cef_zip_reader.rs | 2 +- ports/cef/macros.rs | 7 ++++++- 51 files changed, 97 insertions(+), 89 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index c5bbe52f3c8..a3e6b90dd9a 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -133,3 +133,8 @@ pub extern "C" fn cef_api_hash(entry: c_int) -> *const c_char { } } +#[no_mangle] +pub extern "C" fn cef_get_min_log_level() -> c_int { + 0 +} + diff --git a/ports/cef/eutil.rs b/ports/cef/eutil.rs index bde30231fcd..0821bb9d6c6 100644 --- a/ports/cef/eutil.rs +++ b/ports/cef/eutil.rs @@ -30,11 +30,10 @@ pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int { /// Creates a new raw CEF object of the given type and sets up its reference counting machinery. /// All fields are initialized to zero. It is the caller's responsibility to ensure that the given /// type is a CEF type with `cef_base_t` as its first member. -pub unsafe fn create_cef_object() -> *mut Base { - let size = (mem::size_of::() as size_t) + (mem::size_of::() as size_t) - 1; - println!("allocating CEF object with size {}", size); - let object = libc::calloc(1, size) as *mut cef_base_t; - (*object).size = size - mem::size_of::() as u64; // Subtract out the refcount. +pub unsafe fn create_cef_object(size: size_t) -> *mut Base { + let object = libc::calloc(1, (mem::size_of::() + mem::size_of::()) as u64) as + *mut cef_base_t; + (*object).size = size; (*object).add_ref = Some(servo_add_ref); (*object).release = Some(servo_release); *ref_count(object) = 1; @@ -72,7 +71,6 @@ extern "C" fn servo_release(object: *mut cef_base_t) -> c_int { } unsafe fn servo_free(object: *mut cef_base_t) { - println!("freeing Servo-created CEF object!"); libc::free(object as *mut c_void); } diff --git a/ports/cef/interfaces/cef_app.rs b/ports/cef/interfaces/cef_app.rs index d3ddfa1673d..b47864fa63c 100644 --- a/ports/cef/interfaces/cef_app.rs +++ b/ports/cef/interfaces/cef_app.rs @@ -106,7 +106,7 @@ pub struct _cef_app_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_auth_callback.rs b/ports/cef/interfaces/cef_auth_callback.rs index 8f24912c477..04a85d76442 100644 --- a/ports/cef/interfaces/cef_auth_callback.rs +++ b/ports/cef/interfaces/cef_auth_callback.rs @@ -71,7 +71,7 @@ pub struct _cef_auth_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_browser.rs b/ports/cef/interfaces/cef_browser.rs index c8e42570375..47c49466e2a 100644 --- a/ports/cef/interfaces/cef_browser.rs +++ b/ports/cef/interfaces/cef_browser.rs @@ -186,7 +186,7 @@ pub struct _cef_browser_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -623,7 +623,7 @@ pub struct _cef_run_file_dialog_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -1118,7 +1118,7 @@ pub struct _cef_browser_host_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_browser_process_handler.rs b/ports/cef/interfaces/cef_browser_process_handler.rs index 71acc80ae8b..5a03a2ac882 100644 --- a/ports/cef/interfaces/cef_browser_process_handler.rs +++ b/ports/cef/interfaces/cef_browser_process_handler.rs @@ -96,7 +96,7 @@ pub struct _cef_browser_process_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_callback.rs b/ports/cef/interfaces/cef_callback.rs index d90d58095e9..58e6e8d1ee3 100644 --- a/ports/cef/interfaces/cef_callback.rs +++ b/ports/cef/interfaces/cef_callback.rs @@ -68,7 +68,7 @@ pub struct _cef_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -218,7 +218,7 @@ pub struct _cef_completion_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_client.rs b/ports/cef/interfaces/cef_client.rs index 66a5e1ee34b..11d534133ee 100644 --- a/ports/cef/interfaces/cef_client.rs +++ b/ports/cef/interfaces/cef_client.rs @@ -151,7 +151,7 @@ pub struct _cef_client_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_command_line.rs b/ports/cef/interfaces/cef_command_line.rs index ad23eb599b5..0f5acc73061 100644 --- a/ports/cef/interfaces/cef_command_line.rs +++ b/ports/cef/interfaces/cef_command_line.rs @@ -200,7 +200,7 @@ pub struct _cef_command_line_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_context_menu_handler.rs b/ports/cef/interfaces/cef_context_menu_handler.rs index 3017851eb1c..8dac9e5ebf8 100644 --- a/ports/cef/interfaces/cef_context_menu_handler.rs +++ b/ports/cef/interfaces/cef_context_menu_handler.rs @@ -99,7 +99,7 @@ pub struct _cef_context_menu_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -426,7 +426,7 @@ pub struct _cef_context_menu_params_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_cookie.rs b/ports/cef/interfaces/cef_cookie.rs index a6bb4995c27..de4770490d1 100644 --- a/ports/cef/interfaces/cef_cookie.rs +++ b/ports/cef/interfaces/cef_cookie.rs @@ -132,7 +132,7 @@ pub struct _cef_cookie_manager_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -433,7 +433,7 @@ pub struct _cef_cookie_visitor_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_dialog_handler.rs b/ports/cef/interfaces/cef_dialog_handler.rs index 88d0ec94210..98e1f6e9d6e 100644 --- a/ports/cef/interfaces/cef_dialog_handler.rs +++ b/ports/cef/interfaces/cef_dialog_handler.rs @@ -72,7 +72,7 @@ pub struct _cef_file_dialog_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -238,7 +238,7 @@ pub struct _cef_dialog_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_display_handler.rs b/ports/cef/interfaces/cef_display_handler.rs index 9fbadebaba8..664c2bf8891 100644 --- a/ports/cef/interfaces/cef_display_handler.rs +++ b/ports/cef/interfaces/cef_display_handler.rs @@ -103,7 +103,7 @@ pub struct _cef_display_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_dom.rs b/ports/cef/interfaces/cef_dom.rs index 185c166fabc..bd226731ce9 100644 --- a/ports/cef/interfaces/cef_dom.rs +++ b/ports/cef/interfaces/cef_dom.rs @@ -69,7 +69,7 @@ pub struct _cef_domvisitor_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -308,7 +308,7 @@ pub struct _cef_domdocument_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -820,7 +820,7 @@ pub struct _cef_domnode_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_download_handler.rs b/ports/cef/interfaces/cef_download_handler.rs index 1648129aa7a..c6538434063 100644 --- a/ports/cef/interfaces/cef_download_handler.rs +++ b/ports/cef/interfaces/cef_download_handler.rs @@ -68,7 +68,7 @@ pub struct _cef_before_download_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -209,7 +209,7 @@ pub struct _cef_download_item_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -367,7 +367,7 @@ pub struct _cef_download_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_download_item.rs b/ports/cef/interfaces/cef_download_item.rs index c8e893cf73e..2acda63dcd4 100644 --- a/ports/cef/interfaces/cef_download_item.rs +++ b/ports/cef/interfaces/cef_download_item.rs @@ -160,7 +160,7 @@ pub struct _cef_download_item_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_drag_data.rs b/ports/cef/interfaces/cef_drag_data.rs index 02c11f12431..385210f5d53 100644 --- a/ports/cef/interfaces/cef_drag_data.rs +++ b/ports/cef/interfaces/cef_drag_data.rs @@ -204,7 +204,7 @@ pub struct _cef_drag_data_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_drag_handler.rs b/ports/cef/interfaces/cef_drag_handler.rs index cd50c65b119..fbcd50089ad 100644 --- a/ports/cef/interfaces/cef_drag_handler.rs +++ b/ports/cef/interfaces/cef_drag_handler.rs @@ -70,7 +70,7 @@ pub struct _cef_drag_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_focus_handler.rs b/ports/cef/interfaces/cef_focus_handler.rs index 37f63af58e3..f5114646b14 100644 --- a/ports/cef/interfaces/cef_focus_handler.rs +++ b/ports/cef/interfaces/cef_focus_handler.rs @@ -83,7 +83,7 @@ pub struct _cef_focus_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_frame.rs b/ports/cef/interfaces/cef_frame.rs index 2611cd62dee..2de1a1af466 100644 --- a/ports/cef/interfaces/cef_frame.rs +++ b/ports/cef/interfaces/cef_frame.rs @@ -214,7 +214,7 @@ pub struct _cef_frame_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_geolocation.rs b/ports/cef/interfaces/cef_geolocation.rs index 0872cf91b35..8c044f5e04d 100644 --- a/ports/cef/interfaces/cef_geolocation.rs +++ b/ports/cef/interfaces/cef_geolocation.rs @@ -67,7 +67,7 @@ pub struct _cef_get_geolocation_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_geolocation_handler.rs b/ports/cef/interfaces/cef_geolocation_handler.rs index d626419062b..18c93ed895a 100644 --- a/ports/cef/interfaces/cef_geolocation_handler.rs +++ b/ports/cef/interfaces/cef_geolocation_handler.rs @@ -65,7 +65,7 @@ pub struct _cef_geolocation_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -224,7 +224,7 @@ pub struct _cef_geolocation_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_jsdialog_handler.rs b/ports/cef/interfaces/cef_jsdialog_handler.rs index 8e399a1e1b5..be9d47fa1ba 100644 --- a/ports/cef/interfaces/cef_jsdialog_handler.rs +++ b/ports/cef/interfaces/cef_jsdialog_handler.rs @@ -66,7 +66,7 @@ pub struct _cef_jsdialog_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -255,7 +255,7 @@ pub struct _cef_jsdialog_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_keyboard_handler.rs b/ports/cef/interfaces/cef_keyboard_handler.rs index 78be704e22b..0061984ced1 100644 --- a/ports/cef/interfaces/cef_keyboard_handler.rs +++ b/ports/cef/interfaces/cef_keyboard_handler.rs @@ -81,7 +81,7 @@ pub struct _cef_keyboard_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_life_span_handler.rs b/ports/cef/interfaces/cef_life_span_handler.rs index b296bfe42fd..d218c4bbf15 100644 --- a/ports/cef/interfaces/cef_life_span_handler.rs +++ b/ports/cef/interfaces/cef_life_span_handler.rs @@ -168,7 +168,7 @@ pub struct _cef_life_span_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_load_handler.rs b/ports/cef/interfaces/cef_load_handler.rs index 831f617f533..d46e515c3ef 100644 --- a/ports/cef/interfaces/cef_load_handler.rs +++ b/ports/cef/interfaces/cef_load_handler.rs @@ -108,7 +108,7 @@ pub struct _cef_load_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_menu_model.rs b/ports/cef/interfaces/cef_menu_model.rs index c1972ddc8cc..b1757917f47 100644 --- a/ports/cef/interfaces/cef_menu_model.rs +++ b/ports/cef/interfaces/cef_menu_model.rs @@ -401,7 +401,7 @@ pub struct _cef_menu_model_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_print_handler.rs b/ports/cef/interfaces/cef_print_handler.rs index 7d4ceb16025..b8f36809dc0 100644 --- a/ports/cef/interfaces/cef_print_handler.rs +++ b/ports/cef/interfaces/cef_print_handler.rs @@ -70,7 +70,7 @@ pub struct _cef_print_dialog_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -220,7 +220,7 @@ pub struct _cef_print_job_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -385,7 +385,7 @@ pub struct _cef_print_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_print_settings.rs b/ports/cef/interfaces/cef_print_settings.rs index 86528c88b76..cd28e8d7784 100644 --- a/ports/cef/interfaces/cef_print_settings.rs +++ b/ports/cef/interfaces/cef_print_settings.rs @@ -206,7 +206,7 @@ pub struct _cef_print_settings_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_process_message.rs b/ports/cef/interfaces/cef_process_message.rs index b2fcf4c784b..da56b1f3bba 100644 --- a/ports/cef/interfaces/cef_process_message.rs +++ b/ports/cef/interfaces/cef_process_message.rs @@ -91,7 +91,7 @@ pub struct _cef_process_message_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_render_handler.rs b/ports/cef/interfaces/cef_render_handler.rs index 0ab5bf7e6e5..bae32a055b3 100644 --- a/ports/cef/interfaces/cef_render_handler.rs +++ b/ports/cef/interfaces/cef_render_handler.rs @@ -184,7 +184,7 @@ pub struct _cef_render_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_render_process_handler.rs b/ports/cef/interfaces/cef_render_process_handler.rs index a9a8f92352a..869082f8db4 100644 --- a/ports/cef/interfaces/cef_render_process_handler.rs +++ b/ports/cef/interfaces/cef_render_process_handler.rs @@ -173,7 +173,7 @@ pub struct _cef_render_process_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_request.rs b/ports/cef/interfaces/cef_request.rs index 5d6fa8fc3d4..07a534e5e4c 100644 --- a/ports/cef/interfaces/cef_request.rs +++ b/ports/cef/interfaces/cef_request.rs @@ -167,7 +167,7 @@ pub struct _cef_request_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -581,7 +581,7 @@ pub struct _cef_post_data_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -853,7 +853,7 @@ pub struct _cef_post_data_element_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_request_context.rs b/ports/cef/interfaces/cef_request_context.rs index 84a10d44c3f..0c55410507c 100644 --- a/ports/cef/interfaces/cef_request_context.rs +++ b/ports/cef/interfaces/cef_request_context.rs @@ -89,7 +89,7 @@ pub struct _cef_request_context_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_request_context_handler.rs b/ports/cef/interfaces/cef_request_context_handler.rs index 7a0425302c7..fc068697e0b 100644 --- a/ports/cef/interfaces/cef_request_context_handler.rs +++ b/ports/cef/interfaces/cef_request_context_handler.rs @@ -65,7 +65,7 @@ pub struct _cef_request_context_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_request_handler.rs b/ports/cef/interfaces/cef_request_handler.rs index e519cad7399..169f8c4a670 100644 --- a/ports/cef/interfaces/cef_request_handler.rs +++ b/ports/cef/interfaces/cef_request_handler.rs @@ -70,7 +70,7 @@ pub struct _cef_quota_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -225,7 +225,7 @@ pub struct _cef_allow_certificate_error_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -485,7 +485,7 @@ pub struct _cef_request_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_resource_bundle_handler.rs b/ports/cef/interfaces/cef_resource_bundle_handler.rs index 3551a0d06e1..4730a16981b 100644 --- a/ports/cef/interfaces/cef_resource_bundle_handler.rs +++ b/ports/cef/interfaces/cef_resource_bundle_handler.rs @@ -82,7 +82,7 @@ pub struct _cef_resource_bundle_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_resource_handler.rs b/ports/cef/interfaces/cef_resource_handler.rs index 63cc82fb070..715271adac6 100644 --- a/ports/cef/interfaces/cef_resource_handler.rs +++ b/ports/cef/interfaces/cef_resource_handler.rs @@ -117,7 +117,7 @@ pub struct _cef_resource_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_response.rs b/ports/cef/interfaces/cef_response.rs index 412472a44c3..791572bb1c6 100644 --- a/ports/cef/interfaces/cef_response.rs +++ b/ports/cef/interfaces/cef_response.rs @@ -122,7 +122,7 @@ pub struct _cef_response_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_scheme.rs b/ports/cef/interfaces/cef_scheme.rs index 729ac8d53ee..62f71533ebc 100644 --- a/ports/cef/interfaces/cef_scheme.rs +++ b/ports/cef/interfaces/cef_scheme.rs @@ -108,7 +108,7 @@ pub struct _cef_scheme_registrar_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -303,7 +303,7 @@ pub struct _cef_scheme_handler_factory_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_stream.rs b/ports/cef/interfaces/cef_stream.rs index a4163db6c14..a1e748793d8 100644 --- a/ports/cef/interfaces/cef_stream.rs +++ b/ports/cef/interfaces/cef_stream.rs @@ -90,7 +90,7 @@ pub struct _cef_read_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -318,7 +318,7 @@ pub struct _cef_stream_reader_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -583,7 +583,7 @@ pub struct _cef_write_handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -812,7 +812,7 @@ pub struct _cef_stream_writer_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_string_visitor.rs b/ports/cef/interfaces/cef_string_visitor.rs index 9c8492e84e2..cb589e7850a 100644 --- a/ports/cef/interfaces/cef_string_visitor.rs +++ b/ports/cef/interfaces/cef_string_visitor.rs @@ -64,7 +64,7 @@ pub struct _cef_string_visitor_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_task.rs b/ports/cef/interfaces/cef_task.rs index 5f8aa5cb19e..19cf20a8633 100644 --- a/ports/cef/interfaces/cef_task.rs +++ b/ports/cef/interfaces/cef_task.rs @@ -68,7 +68,7 @@ pub struct _cef_task_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -244,7 +244,7 @@ pub struct _cef_task_runner_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_trace.rs b/ports/cef/interfaces/cef_trace.rs index 34644003f33..76000fc060a 100644 --- a/ports/cef/interfaces/cef_trace.rs +++ b/ports/cef/interfaces/cef_trace.rs @@ -69,7 +69,7 @@ pub struct _cef_end_tracing_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_urlrequest.rs b/ports/cef/interfaces/cef_urlrequest.rs index 123224e47c6..876bea28942 100644 --- a/ports/cef/interfaces/cef_urlrequest.rs +++ b/ports/cef/interfaces/cef_urlrequest.rs @@ -101,7 +101,7 @@ pub struct _cef_urlrequest_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -387,7 +387,7 @@ pub struct _cef_urlrequest_client_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_v8.rs b/ports/cef/interfaces/cef_v8.rs index 1418c48dba4..4a42ef8d36c 100644 --- a/ports/cef/interfaces/cef_v8.rs +++ b/ports/cef/interfaces/cef_v8.rs @@ -131,7 +131,7 @@ pub struct _cef_v8context_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -447,7 +447,7 @@ pub struct _cef_v8handler_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -619,7 +619,7 @@ pub struct _cef_v8accessor_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -844,7 +844,7 @@ pub struct _cef_v8exception_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -1416,7 +1416,7 @@ pub struct _cef_v8value_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -2423,7 +2423,7 @@ pub struct _cef_v8stack_trace_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -2660,7 +2660,7 @@ pub struct _cef_v8stack_frame_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_values.rs b/ports/cef/interfaces/cef_values.rs index abea93e2e04..9eed34a61e2 100644 --- a/ports/cef/interfaces/cef_values.rs +++ b/ports/cef/interfaces/cef_values.rs @@ -91,7 +91,7 @@ pub struct _cef_binary_value_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -476,7 +476,7 @@ pub struct _cef_dictionary_value_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -1179,7 +1179,7 @@ pub struct _cef_list_value_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_web_plugin.rs b/ports/cef/interfaces/cef_web_plugin.rs index 725c749560a..5f4943d6077 100644 --- a/ports/cef/interfaces/cef_web_plugin.rs +++ b/ports/cef/interfaces/cef_web_plugin.rs @@ -86,7 +86,7 @@ pub struct _cef_web_plugin_info_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -273,7 +273,7 @@ pub struct _cef_web_plugin_info_visitor_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! @@ -421,7 +421,7 @@ pub struct _cef_web_plugin_unstable_callback_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_xml_reader.rs b/ports/cef/interfaces/cef_xml_reader.rs index 361339cd85e..eb453ce6ebe 100644 --- a/ports/cef/interfaces/cef_xml_reader.rs +++ b/ports/cef/interfaces/cef_xml_reader.rs @@ -277,7 +277,7 @@ pub struct _cef_xml_reader_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/interfaces/cef_zip_reader.rs b/ports/cef/interfaces/cef_zip_reader.rs index efac8229cca..7f1c08e335f 100644 --- a/ports/cef/interfaces/cef_zip_reader.rs +++ b/ports/cef/interfaces/cef_zip_reader.rs @@ -140,7 +140,7 @@ pub struct _cef_zip_reader_t { // // The reference count. This will only be present for Rust instances! // - ref_count: uint, + pub ref_count: uint, // // Extra data. This will only be present for Rust instances! diff --git a/ports/cef/macros.rs b/ports/cef/macros.rs index 4debc353555..c02f936c2ee 100644 --- a/ports/cef/macros.rs +++ b/ports/cef/macros.rs @@ -43,8 +43,13 @@ macro_rules! cef_class_impl( impl $class_name { pub fn as_cef_interface(self) -> $interface_name { let cef_object = unsafe { + // Calculate the offset of the reference count. This is the size of the + // structure. + let null: *const $c_interface_name = ::std::ptr::null(); + let offset: *const uint = &(*null).ref_count; + let size = (offset as ::libc::size_t) - (null as ::libc::size_t); $interface_name::from_c_object_addref( - ::eutil::create_cef_object::<$c_interface_name,$class_name>()) + ::eutil::create_cef_object::<$c_interface_name,$class_name>(size)) }; unsafe { $((*cef_object.c_object()).$method_name = Some($method_name);)*