Rewild Your Web
at main 73 lines 2.7 kB view raw
1--- original 2+++ modified 3@@ -122,6 +122,7 @@ 4 webview_id: WebViewId, 5 parent_info: Option<PipelineId>, 6 opener: Option<BrowsingContextId>, 7+ is_embedded_webview: bool, 8 ) -> DomRoot<WindowProxy> { 9 if let Some(window_proxy) = self.get(browsing_context_id) { 10 // Note: we do not set the window to be the currently-active one, 11@@ -133,17 +134,30 @@ 12 .borrow() 13 .find_iframe(parent_id, browsing_context_id) 14 }); 15- let parent_browsing_context = match (parent_info, iframe.as_ref()) { 16- (_, Some(iframe)) => Some(iframe.owner_window().window_proxy()), 17- (Some(parent_id), _) => self.remote_window_proxy( 18- cx, 19- senders, 20- window.upcast(), 21- webview_id, 22- parent_id, 23- opener, 24- ), 25- _ => None, 26+ 27+ // For embedded webview iframes, treat them as having no parent so that 28+ // window.parent === window.self returns true. 29+ // We check both the passed-in flag AND the iframe (if found in same thread). 30+ let is_embedded_webview = is_embedded_webview || 31+ iframe 32+ .as_ref() 33+ .is_some_and(|iframe| iframe.is_embedded_webview()); 34+ 35+ let parent_browsing_context = if is_embedded_webview { 36+ None 37+ } else { 38+ match (parent_info, iframe.as_ref()) { 39+ (_, Some(iframe)) => Some(iframe.owner_window().window_proxy()), 40+ (Some(parent_id), _) => self.remote_window_proxy( 41+ cx, 42+ senders, 43+ window.upcast(), 44+ webview_id, 45+ parent_id, 46+ opener, 47+ ), 48+ _ => None, 49+ } 50 }; 51 52 let opener_browsing_context = opener.and_then(|id| self.find_window_proxy(id)); 53@@ -153,11 +167,19 @@ 54 opener_browsing_context.as_deref(), 55 ); 56 57+ // For embedded webviews, don't pass the iframe as frame_element since 58+ // they are top-level browsing contexts. 59+ let frame_element = if is_embedded_webview { 60+ None 61+ } else { 62+ iframe.as_deref().map(Castable::upcast) 63+ }; 64+ 65 let window_proxy = WindowProxy::new( 66 window, 67 browsing_context_id, 68 webview_id, 69- iframe.as_deref().map(Castable::upcast), 70+ frame_element, 71 parent_browsing_context.as_deref(), 72 opener, 73 creator,