|
| 1 | +use cef::rc::{Rc, RcImpl}; |
| 2 | +use cef::sys::{_cef_life_span_handler_t, cef_base_ref_counted_t}; |
| 3 | +use cef::{ImplLifeSpanHandler, WrapLifeSpanHandler}; |
| 4 | + |
| 5 | +pub(crate) struct BrowserProcessLifeSpanHandlerImpl { |
| 6 | + object: *mut RcImpl<_cef_life_span_handler_t, Self>, |
| 7 | +} |
| 8 | +impl BrowserProcessLifeSpanHandlerImpl { |
| 9 | + pub(crate) fn new() -> Self { |
| 10 | + Self { object: std::ptr::null_mut() } |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +impl ImplLifeSpanHandler for BrowserProcessLifeSpanHandlerImpl { |
| 15 | + fn on_before_popup( |
| 16 | + &self, |
| 17 | + _browser: Option<&mut cef::Browser>, |
| 18 | + _frame: Option<&mut cef::Frame>, |
| 19 | + _popup_id: ::std::os::raw::c_int, |
| 20 | + target_url: Option<&cef::CefString>, |
| 21 | + _target_frame_name: Option<&cef::CefString>, |
| 22 | + _target_disposition: cef::WindowOpenDisposition, |
| 23 | + _user_gesture: ::std::os::raw::c_int, |
| 24 | + _popup_features: Option<&cef::PopupFeatures>, |
| 25 | + _window_info: Option<&mut cef::WindowInfo>, |
| 26 | + _client: Option<&mut Option<impl cef::ImplClient>>, |
| 27 | + _settings: Option<&mut cef::BrowserSettings>, |
| 28 | + _extra_info: Option<&mut Option<cef::DictionaryValue>>, |
| 29 | + _no_javascript_access: Option<&mut ::std::os::raw::c_int>, |
| 30 | + ) -> ::std::os::raw::c_int { |
| 31 | + let target = target_url.map(|url| url.to_string()).unwrap_or("unknown".to_string()); |
| 32 | + tracing::error!("Browser tried to open a popup at URL: {}", target); |
| 33 | + |
| 34 | + // Deny any popup by returning 1 |
| 35 | + 1 |
| 36 | + } |
| 37 | + |
| 38 | + fn get_raw(&self) -> *mut _cef_life_span_handler_t { |
| 39 | + self.object.cast() |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +impl Clone for BrowserProcessLifeSpanHandlerImpl { |
| 44 | + fn clone(&self) -> Self { |
| 45 | + unsafe { |
| 46 | + let rc_impl = &mut *self.object; |
| 47 | + rc_impl.interface.add_ref(); |
| 48 | + } |
| 49 | + Self { object: self.object } |
| 50 | + } |
| 51 | +} |
| 52 | +impl Rc for BrowserProcessLifeSpanHandlerImpl { |
| 53 | + fn as_base(&self) -> &cef_base_ref_counted_t { |
| 54 | + unsafe { |
| 55 | + let base = &*self.object; |
| 56 | + std::mem::transmute(&base.cef_object) |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | +impl WrapLifeSpanHandler for BrowserProcessLifeSpanHandlerImpl { |
| 61 | + fn wrap_rc(&mut self, object: *mut RcImpl<_cef_life_span_handler_t, Self>) { |
| 62 | + self.object = object; |
| 63 | + } |
| 64 | +} |
0 commit comments