aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlanchorelement.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-06-02 09:45:26 -0500
committerbors-servo <lbergstrom+bors@mozilla.com>2016-06-02 09:45:26 -0500
commitbdecfa13d2114281472d5df4548a8faaf8a5bd87 (patch)
treeeb0b7fb1c83ee298e17b6bcc0cec0e39ddb39391 /components/script/dom/htmlanchorelement.rs
parente7241c8215d070860e1830ba4b690f1243725000 (diff)
parent835b6a90177a6ea1eafdaa5eb1093ca3ce4e799f (diff)
downloadservo-bdecfa13d2114281472d5df4548a8faaf8a5bd87.tar.gz
servo-bdecfa13d2114281472d5df4548a8faaf8a5bd87.zip
Auto merge of #11542 - asajeffrey:mozbrowser-send-opentab-event, r=paulrouget
Fire a mozbrowseropenwindow event when an html anchor has a non-self target <!-- Please describe your changes on the following line: --> When an html anchor has a non-self target, fire a `mozbrowseropenwindow` event. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11539. - [X] These changes do not require tests because we don't have the infrastructure for mozbrowser testing yet. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11542) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmlanchorelement.rs')
-rw-r--r--components/script/dom/htmlanchorelement.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs
index 95d03872ac5..c69e61cae80 100644
--- a/components/script/dom/htmlanchorelement.rs
+++ b/components/script/dom/htmlanchorelement.rs
@@ -26,9 +26,11 @@ use dom::node::{Node, document_from_node, window_from_node};
use dom::urlhelper::UrlHelper;
use dom::virtualmethods::VirtualMethods;
use num_traits::ToPrimitive;
+use script_traits::MozBrowserEvent;
use std::default::Default;
use string_cache::Atom;
use url::Url;
+use util::prefs::mozbrowser_enabled;
#[dom_struct]
pub struct HTMLAnchorElement {
@@ -542,30 +544,48 @@ impl Activatable for HTMLAnchorElement {
}
}
+/// https://html.spec.whatwg.org/multipage/#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
+fn is_current_browsing_context(target: DOMString) -> bool {
+ target.is_empty() || target == "_self"
+}
+
/// https://html.spec.whatwg.org/multipage/#following-hyperlinks-2
fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>) {
// Step 1: replace.
// Step 2: source browsing context.
// Step 3: target browsing context.
+ let target = subject.get_attribute(&ns!(), &atom!("target"));
- // Step 4.
+ // Step 4: disown target's opener if needed.
let attribute = subject.get_attribute(&ns!(), &atom!("href")).unwrap();
let mut href = attribute.Value();
- // Step 6.
+ // Step 7: append a hyperlink suffix.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=28925
if let Some(suffix) = hyperlink_suffix {
href.push_str(&suffix);
}
- // Step 4-5.
+ // Step 5: parse the URL.
+ // Step 6: navigate to an error document if parsing failed.
let document = document_from_node(subject);
let url = match document.url().join(&href) {
Ok(url) => url,
Err(_) => return,
};
- // Step 7.
+ // Step 8: navigate to the URL.
+ if let Some(target) = target {
+ if mozbrowser_enabled() && !is_current_browsing_context(target.Value()) {
+ // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowseropenwindow
+ // TODO: referrer and opener
+ // TODO: should we send the normalized url or the non-normalized href?
+ let event = MozBrowserEvent::OpenWindow(url.into_string(), Some(String::from(target.Value())), None);
+ document.trigger_mozbrowser_event(event);
+ return
+ }
+ }
+
debug!("following hyperlink to {}", url);
let window = document.window();
window.load_url(url);