Rewild Your Web
18
fork

Configure Feed

Select the types of activity you want to include in your feed.

servo: fix event loop creation for embedded webviews

Signed-off-by: webbeef <me@webbeef.org>

webbeef c4ccd7b2 171636f4

+69 -36
+69 -36
patches/components/constellation/constellation.rs.patch
··· 363 363 }, 364 364 #[cfg(feature = "webgpu")] 365 365 ScriptToConstellationMessage::RequestAdapter(response_sender, options, ids) => self 366 - @@ -2045,9 +2189,414 @@ 366 + @@ -2045,7 +2189,412 @@ 367 367 let _ = event_loop.send(ScriptThreadMessage::TriggerGarbageCollection); 368 368 } 369 369 }, ··· 598 598 + ScriptToConstellationMessage::AtProto(request, response) => { 599 599 + self.at_proto.process_request(request, response); 600 600 + }, 601 - } 602 - } 603 - 601 + + } 602 + + } 603 + + 604 604 + fn handle_pairing_event(&mut self, event: constellation_traits::PairingEvent) { 605 605 + if let constellation_traits::PairingEvent::MessageReceived { ref from, ref data } = event { 606 606 + debug!("P2P message received from {from}, {} bytes", data.len()); ··· 742 742 + } 743 743 + } 744 744 + return; 745 - + } 745 + } 746 746 + 747 747 + // Handle peer disconnect: clean up remote channel state. 748 748 + if let constellation_traits::PairingEvent::PeerExpired { ref id } = event { ··· 773 773 + let _ = event_loop.send(ScriptThreadMessage::DispatchPairingEvent(event.clone())); 774 774 + } 775 775 + } 776 - + } 777 - + 776 + } 777 + 778 778 /// Check the origin of a message against that of the pipeline it came from. 779 - /// Note: this is still limited as a security check, 780 - /// see <https://github.com/servo/servo/issues/11722> 781 779 @@ -2364,6 +2913,29 @@ 782 780 TransferState::TransferInProgress(queue) => queue.push_back(task), 783 781 TransferState::CompletionFailed(queue) => queue.push_back(task), ··· 850 848 let Some((webview_id_sender, webview_id_receiver)) = generic_channel::channel() else { 851 849 warn!("Failed to create channel"); 852 850 let _ = response_sender.send(None); 853 - @@ -3619,6 +4217,361 @@ 851 + @@ -3619,6 +4217,396 @@ 854 852 }); 855 853 } 856 854 ··· 893 891 + }; 894 892 + let new_browsing_context_id = BrowsingContextId::from(new_webview_id); 895 893 + 896 - + let (script_sender, parent_browsing_context_id) = 897 - + match self.pipelines.get(&parent_pipeline_id) { 898 - + Some(pipeline) => (pipeline.event_loop.clone(), pipeline.browsing_context_id), 899 - + None => { 900 - + warn!( 901 - + "{}: Embedded webview created in closed parent pipeline", 902 - + parent_pipeline_id 903 - + ); 904 - + let _ = response_sender.send(None); 905 - + return; 906 - + }, 907 - + }; 894 + + let parent_browsing_context_id = match self.pipelines.get(&parent_pipeline_id) { 895 + + Some(pipeline) => pipeline.browsing_context_id, 896 + + None => { 897 + + warn!( 898 + + "{}: Embedded webview created in closed parent pipeline", 899 + + parent_pipeline_id 900 + + ); 901 + + let _ = response_sender.send(None); 902 + + return; 903 + + }, 904 + + }; 908 905 + let (is_parent_private, is_parent_throttled, is_parent_secure) = 909 906 + match self.browsing_contexts.get(&parent_browsing_context_id) { 910 907 + Some(ctx) => (ctx.is_private, ctx.throttled, ctx.inherited_secure_context), ··· 919 916 + }; 920 917 + 921 918 + let new_pipeline_id = PipelineId::new(); 922 - + let pipeline = Pipeline::new_already_spawned( 923 - + new_pipeline_id, 924 - + new_browsing_context_id, 919 + + 920 + + // Give embedded webviews their own event loop. 921 + + let event_loop = match self.get_or_create_event_loop_for_new_pipeline( 925 922 + new_webview_id, 926 - + None, // No opener for embedded webviews - they are isolated 927 - + script_sender, 928 - + self.paint_proxy.clone(), 929 - + is_parent_throttled, 930 - + load_data, 931 - + ); 923 + + None, // no opener 924 + + Some(parent_pipeline_id), 925 + + &load_data, 926 + + is_parent_private, 927 + + ) { 928 + + Ok(event_loop) => event_loop, 929 + + Err(error) => { 930 + + warn!("Failed to create event loop for embedded webview: {error:?}"); 931 + + let _ = response_sender.send(None); 932 + + return; 933 + + }, 934 + + }; 935 + + 936 + + let theme = self 937 + + .webviews 938 + + .get(&parent_webview_id) 939 + + .map(ConstellationWebView::theme) 940 + + .unwrap_or(Theme::Light); 932 941 + 933 942 + // Send the response before adding to constellation state 934 943 + let _ = response_sender.send(Some(EmbeddedWebViewCreationResponse { ··· 938 947 + user_content_manager_id, 939 948 + })); 940 949 + 941 - + // Track this as an embedded webview 950 + + // Track this as an embedded webview. 942 951 + self.embedded_webview_to_iframe.insert( 943 952 + new_webview_id, 944 953 + (new_browsing_context_id, parent_pipeline_id), 945 954 + ); 946 955 + 947 - + assert!(!self.pipelines.contains_key(&new_pipeline_id)); 948 - + self.pipelines.insert(new_pipeline_id, pipeline); 949 956 + self.webviews.insert( 950 957 + new_webview_id, 951 958 + ConstellationWebView::new_with_hide_focus( ··· 956 963 + hide_focus, 957 964 + ), 958 965 + ); 966 + + 967 + + let new_pipeline_info = NewPipelineInfo { 968 + + parent_info: Some(parent_pipeline_id), 969 + + new_pipeline_id, 970 + + browsing_context_id: new_browsing_context_id, 971 + + webview_id: new_webview_id, 972 + + opener: None, 973 + + load_data, 974 + + viewport_details: viewport_details, 975 + + user_content_manager_id, 976 + + theme, 977 + + is_embedded_webview: true, 978 + + hide_focus, 979 + + }; 980 + + 981 + + let pipeline = 982 + + match Pipeline::spawn(new_pipeline_info, event_loop, self, is_parent_throttled) { 983 + + Ok(pipeline) => pipeline, 984 + + Err(error) => { 985 + + warn!("Failed to spawn pipeline for embedded webview: {error:?}"); 986 + + return; 987 + + }, 988 + + }; 989 + + 990 + + assert!(!self.pipelines.contains_key(&new_pipeline_id)); 991 + + self.pipelines.insert(new_pipeline_id, pipeline); 959 992 + 960 993 + // Create a new browsing context group for embedded webviews (they are fully isolated) 961 994 + let bc_group_id = BrowsingContextGroupId(self.browsing_context_group_next_id); ··· 1212 1245 #[servo_tracing::instrument(skip_all)] 1213 1246 fn handle_refresh_cursor(&self, pipeline_id: PipelineId) { 1214 1247 let Some(pipeline) = self.pipelines.get(&pipeline_id) else { 1215 - @@ -4744,7 +5697,7 @@ 1248 + @@ -4744,7 +5732,7 @@ 1216 1249 } 1217 1250 1218 1251 #[servo_tracing::instrument(skip_all)] ··· 1221 1254 // Send a flat projection of the history to embedder. 1222 1255 // The final vector is a concatenation of the URLs of the past 1223 1256 // entries, the current entry and the future entries. 1224 - @@ -4847,9 +5800,23 @@ 1257 + @@ -4847,9 +5835,23 @@ 1225 1258 ); 1226 1259 self.embedder_proxy.send(EmbedderMsg::HistoryChanged( 1227 1260 webview_id,