Skip to content

Commit

Permalink
Issue #8352: Dispatch mozbrowsershowmodalprompt event for alert().
Browse files Browse the repository at this point in the history
  • Loading branch information
simartin committed Dec 19, 2015
1 parent 2a3a7a7 commit 0d910bb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/msg/constellation_msg.rs
Expand Up @@ -289,7 +289,7 @@ pub enum MozBrowserEvent {
/// Sent when the SSL state changes within a browser `<iframe>`.
SecurityChange,
/// Sent when alert(), confirm(), or prompt() is called within a browser `<iframe>`.
ShowModalPrompt,
ShowModalPrompt(String, String, String, String), // TODO(simartin): Handle unblock()
/// Sent when the document.title changes within a browser `<iframe>`.
TitleChange(String),
/// Sent when an HTTP authentification is requested.
Expand All @@ -311,7 +311,7 @@ impl MozBrowserEvent {
MozBrowserEvent::LocationChange(_) => "mozbrowserlocationchange",
MozBrowserEvent::OpenWindow => "mozbrowseropenwindow",
MozBrowserEvent::SecurityChange => "mozbrowsersecuritychange",
MozBrowserEvent::ShowModalPrompt => "mozbrowsershowmodalprompt",
MozBrowserEvent::ShowModalPrompt(_, _, _, _) => "mozbrowsershowmodalprompt",
MozBrowserEvent::TitleChange(_) => "mozbrowsertitlechange",
MozBrowserEvent::UsernameAndPasswordRequired => "mozbrowserusernameandpasswordrequired",
MozBrowserEvent::OpenSearch => "mozbrowseropensearch"
Expand Down
11 changes: 10 additions & 1 deletion components/script/dom/htmliframeelement.rs
Expand Up @@ -4,6 +4,7 @@

use dom::attr::{Attr, AttrValue};
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementIconChangeEventDetail;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserShowModalPromptEventDetail;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
Expand Down Expand Up @@ -272,7 +273,7 @@ impl MozBrowserEventDetailBuilder for HTMLIFrameElement {
MozBrowserEvent::AsyncScroll | MozBrowserEvent::Close | MozBrowserEvent::ContextMenu |
MozBrowserEvent::Error | MozBrowserEvent::LoadEnd | MozBrowserEvent::LoadStart |
MozBrowserEvent::OpenWindow | MozBrowserEvent::SecurityChange | MozBrowserEvent::OpenSearch |
MozBrowserEvent::ShowModalPrompt | MozBrowserEvent::UsernameAndPasswordRequired => {
MozBrowserEvent::UsernameAndPasswordRequired => {
rval.set(NullValue());
}
MozBrowserEvent::LocationChange(ref string) | MozBrowserEvent::TitleChange(ref string) => {
Expand All @@ -285,6 +286,14 @@ impl MozBrowserEventDetailBuilder for HTMLIFrameElement {
sizes: Some(DOMString::from(sizes)),
}.to_jsval(cx, rval);
}
MozBrowserEvent::ShowModalPrompt(prompt_type, title, message, return_value) => {
BrowserShowModalPromptEventDetail {
promptType: Some(DOMString::from(prompt_type)),
title: Some(DOMString::from(title)),
message: Some(DOMString::from(message)),
returnValue: Some(DOMString::from(return_value)),
}.to_jsval(cx, rval)
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions components/script/dom/webidls/BrowserElement.webidl
Expand Up @@ -30,6 +30,14 @@ dictionary BrowserElementIconChangeEventDetail {
DOMString sizes;
};

dictionary BrowserShowModalPromptEventDetail {
DOMString promptType;
DOMString title;
DOMString message;
DOMString returnValue;
// TODO(simartin) unblock() callback
};

BrowserElement implements BrowserElementCommon;
BrowserElement implements BrowserElementPrivileged;

Expand Down
9 changes: 7 additions & 2 deletions components/script/dom/window.rs
Expand Up @@ -45,7 +45,7 @@ use libc;
use msg::ParseErrorReporter;
use msg::compositor_msg::{LayerId, ScriptToCompositorMsg};
use msg::constellation_msg::{ConstellationChan, DocumentState, LoadData};
use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData};
use msg::constellation_msg::{MozBrowserEvent, PipelineId, SubpageId, WindowSizeData};
use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
use net_traits::ResourceTask;
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask};
Expand Down Expand Up @@ -394,14 +394,19 @@ impl WindowMethods for Window {
fn Alert(&self, s: DOMString) {
// Right now, just print to the console
// Ensure that stderr doesn't trample through the alert() we use to
// communicate test results.
// communicate test results (see executorservo.py in wptrunner).
let stderr = stderr();
let mut stderr = stderr.lock();
let stdout = stdout();
let mut stdout = stdout.lock();
writeln!(&mut stdout, "ALERT: {}", s).unwrap();
stdout.flush().unwrap();
stderr.flush().unwrap();

// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsershowmodalprompt
let event = MozBrowserEvent::ShowModalPrompt("alert".to_owned(), "Alert".to_owned(),
String::from(s), "".to_owned());
self.Document().trigger_mozbrowser_event(event);
}

// https://html.spec.whatwg.org/multipage/#dom-window-close
Expand Down
6 changes: 6 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -5691,6 +5691,12 @@
"url": "/_mozilla/mozilla/mozbrowser/mozbrowsericonchange_event.html"
}
],
"mozilla/mozbrowser/mozbrowsershowmodalprompt_event.html": [
{
"path": "mozilla/mozbrowser/mozbrowsershowmodalprompt_event.html",
"url": "/_mozilla/mozilla/mozbrowser/mozbrowsershowmodalprompt_event.html"
}
],
"mozilla/mozbrowser/reload.html": [
{
"path": "mozilla/mozbrowser/reload.html",
Expand Down
@@ -0,0 +1,19 @@
<!doctype html>
<meta charset="utf-8">
<title>Dispatch mozbrowsershowmodalprompt event for alert (issue #8352)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body></body>
<script>
async_test(function(t) {
var iframe = document.createElement("iframe");
iframe.mozbrowser = "true";
iframe.src = "mozbrowsershowmodalprompt_event_iframe.html";
iframe.addEventListener("mozbrowsershowmodalprompt", t.step_func(e => {
assert_equals(e.detail.promptType, "alert");
assert_equals(e.detail.message, "my alert message");
t.done();
}));
document.body.appendChild(iframe);
});
</script>
@@ -0,0 +1,6 @@
<html>
<body></body>
<script>
window.alert("my alert message");
</script>
</html>

0 comments on commit 0d910bb

Please sign in to comment.