File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ impl<H: CefEventHandler> ImplClient for BrowserProcessClientImpl<H> {
2828 _source_process : cef:: ProcessId ,
2929 message : Option < & mut cef:: ProcessMessage > ,
3030 ) -> :: std:: os:: raw:: c_int {
31- match message. unpack ( ) {
31+ let unpacked_message = unsafe { message. and_then ( |m| m. unpack ( ) ) } ;
32+ match unpacked_message {
3233 Some ( UnpackedMessage {
3334 message_type : MessageType :: SendToNative ,
3435 data,
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ impl ImplRenderProcessHandler for RenderProcessHandlerImpl {
2626 _source_process : cef:: ProcessId ,
2727 message : Option < & mut cef:: ProcessMessage > ,
2828 ) -> :: std:: os:: raw:: c_int {
29- match message. unpack ( ) {
29+ let unpacked_message = unsafe { message. and_then ( |m| m. unpack ( ) ) } ;
30+ match unpacked_message {
3031 Some ( UnpackedMessage {
3132 message_type : MessageType :: SendToJS ,
3233 data,
Original file line number Diff line number Diff line change @@ -94,17 +94,19 @@ pub(crate) struct UnpackedMessage<'a> {
9494 pub ( crate ) message_type : MessageType ,
9595 pub ( crate ) data : & ' a [ u8 ] ,
9696}
97- pub ( crate ) trait UnpackMessage {
98- fn unpack ( & ' _ self ) -> Option < UnpackedMessage < ' _ > > ;
99- }
100- impl UnpackMessage for Option < & mut cef:: ProcessMessage > {
101- fn unpack ( & ' _ self ) -> Option < UnpackedMessage < ' _ > > {
102- let Some ( message) = self else { return None } ;
103- message. unpack ( )
104- }
97+
98+ trait Sealed { }
99+ impl Sealed for cef:: ProcessMessage { }
100+ #[ allow( private_bounds) ]
101+ pub ( crate ) trait UnpackMessage : Sealed {
102+ /// # Safety
103+ ///
104+ /// The caller must ensure that the message is valid.
105+ /// Message should come from cef.
106+ unsafe fn unpack ( & self ) -> Option < UnpackedMessage < ' _ > > ;
105107}
106108impl UnpackMessage for cef:: ProcessMessage {
107- fn unpack ( & ' _ self ) -> Option < UnpackedMessage < ' _ > > {
109+ unsafe fn unpack ( & self ) -> Option < UnpackedMessage < ' _ > > {
108110 let pointer: * mut cef:: sys:: _cef_string_utf16_t = self . name ( ) . into ( ) ;
109111 let message = unsafe { super :: utility:: pointer_to_string ( pointer) } ;
110112 let Ok ( message_type) = message. try_into ( ) else {
You can’t perform that action at this time.
0 commit comments