forked from
me.webbeef.org/browser.html
Rewild Your Web
1--- original
2+++ modified
3@@ -298,6 +298,7 @@
4 &self,
5 name: DOMString,
6 noopener: bool,
7+ target_url: Option<ServoUrl>,
8 ) -> Option<DomRoot<WindowProxy>> {
9 let (response_sender, response_receiver) = generic_channel::channel().unwrap();
10 let window = self
11@@ -333,6 +334,7 @@
12 opener_webview_id: window.webview_id(),
13 opener_pipeline_id: self.currently_active.get().unwrap(),
14 response_sender,
15+ target_url,
16 };
17 let constellation_msg = ScriptToConstellationMessage::CreateAuxiliaryWebView(load_info);
18 window.send_to_constellation(constellation_msg);
19@@ -351,6 +353,8 @@
20 // Use the current `WebView`'s theme initially, but the embedder may
21 // change this later.
22 theme: window.theme(),
23+ is_embedded_webview: false,
24+ hide_focus: false,
25 };
26
27 with_script_thread(|script_thread| {
28@@ -503,14 +507,32 @@
29 // (TODO) Step 11. Let referrerPolicy be the empty string.
30 // (TODO) Step 12. If noreferrer is true, then set referrerPolicy to "no-referrer".
31
32+ // Resolve the target URL early so we can pass it to choose_browsing_context.
33+ // This is needed for embedded webviews where the embedder needs to know what URL
34+ // will be navigated to before creating the new browsing context.
35+ let target_url = if !url.is_empty() {
36+ let existing_document = self
37+ .currently_active
38+ .get()
39+ .and_then(ScriptThread::find_document)
40+ .unwrap();
41+ match existing_document.url().join(&url) {
42+ Ok(resolved_url) => Some(resolved_url),
43+ Err(_) => return Err(Error::Syntax(None)),
44+ }
45+ } else {
46+ None
47+ };
48+
49 // Step 13 - 14
50 // Let targetNavigable and windowType be the result of applying the rules for
51 // choosing a navigable given target, sourceDocument's node navigable, and noopener.
52 // If targetNavigable is null, then return null.
53- let (chosen, new) = match self.choose_browsing_context(non_empty_target, noopener) {
54- (Some(chosen), new) => (chosen, new),
55- (None, _) => return Ok(None),
56- };
57+ let (chosen, new) =
58+ match self.choose_browsing_context(non_empty_target, noopener, target_url.clone()) {
59+ (Some(chosen), new) => (chosen, new),
60+ (None, _) => return Ok(None),
61+ };
62 // TODO Step 15.2, Set up browsing context features for targetNavigable's
63 // active browsing context given tokenizedFeatures.
64 let target_document = match chosen.document() {
65@@ -525,16 +547,12 @@
66 let target_window = target_document.window();
67 // Step 15.3 and 15.4 will have happened elsewhere,
68 // since we've created a new browsing context and loaded it with about:blank.
69- if !url.is_empty() {
70+ if let Some(url) = target_url {
71 let existing_document = self
72 .currently_active
73 .get()
74 .and_then(ScriptThread::find_document)
75 .unwrap();
76- let url = match existing_document.url().join(&url) {
77- Ok(url) => url,
78- Err(_) => return Err(Error::Syntax(None)),
79- };
80 let referrer = if noreferrer {
81 Referrer::NoReferrer
82 } else {
83@@ -598,6 +616,7 @@
84 &self,
85 name: DOMString,
86 noopener: bool,
87+ target_url: Option<ServoUrl>,
88 ) -> (Option<DomRoot<WindowProxy>>, bool) {
89 match name.to_lowercase().as_ref() {
90 "" | "_self" => {
91@@ -615,7 +634,10 @@
92 // Step 5
93 (Some(DomRoot::from_ref(self.top())), false)
94 },
95- "_blank" => (self.create_auxiliary_browsing_context(name, noopener), true),
96+ "_blank" => (
97+ self.create_auxiliary_browsing_context(name, noopener, target_url),
98+ true,
99+ ),
100 _ => {
101 // Step 6.
102 // TODO: expand the search to all 'familiar' bc,
103@@ -623,7 +645,10 @@
104 // See https://html.spec.whatwg.org/multipage/#familiar-with
105 match ScriptThread::find_window_proxy_by_name(&name) {
106 Some(proxy) => (Some(proxy), false),
107- None => (self.create_auxiliary_browsing_context(name, noopener), true),
108+ None => (
109+ self.create_auxiliary_browsing_context(name, noopener, target_url),
110+ true,
111+ ),
112 }
113 },
114 }