mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Backed out changeset c3099024c40a (bug 874050) for OSX 10.8 bc1 orange
This commit is contained in:
parent
3557efcdb1
commit
4fc024771c
@ -1,92 +1,58 @@
|
|||||||
/* Any copyright is dedicated to the Public Domain.
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
let tab;
|
let tab;
|
||||||
let notification;
|
let notification;
|
||||||
let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html";
|
let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html";
|
||||||
|
|
||||||
function test () {
|
function test () {
|
||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
|
|
||||||
let pm = Services.perms;
|
let pm = Services.perms;
|
||||||
registerCleanupFunction(function() {
|
registerCleanupFunction(function() {
|
||||||
pm.remove(notificationURL, "desktop-notification");
|
pm.remove(notificationURL, "desktop-notification");
|
||||||
gBrowser.removeTab(tab);
|
gBrowser.removeTab(tab);
|
||||||
window.restore();
|
window.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||||
|
|
||||||
tab = gBrowser.addTab(notificationURL);
|
tab = gBrowser.addTab(notificationURL);
|
||||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLoad() {
|
function onLoad() {
|
||||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
||||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||||
win.newWindow = win.open("about:blank", "", "height=100,width=100");
|
notification = win.showNotification();
|
||||||
win.newWindow.addEventListener("load", function() {
|
notification.addEventListener("show", onAlertShowing);
|
||||||
info("new window loaded");
|
}
|
||||||
win.newWindow.addEventListener("blur", function b() {
|
|
||||||
info("new window got blur");
|
function onAlertShowing() {
|
||||||
win.newWindow.removeEventListener("blur", b);
|
info("Notification alert showing");
|
||||||
notification = win.showNotification1();
|
notification.removeEventListener("show", onAlertShowing);
|
||||||
win.newWindow.addEventListener("focus", onNewWindowFocused);
|
|
||||||
notification.addEventListener("show", onAlertShowing);
|
let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul");
|
||||||
});
|
if (!alertWindow) {
|
||||||
|
todo(false, "Notifications don't use XUL windows on all platforms.");
|
||||||
function waitUntilNewWindowHasFocus() {
|
notification.close();
|
||||||
if (!win.newWindow.document.hasFocus()) {
|
finish();
|
||||||
setTimeout(waitUntilNewWindowHasFocus, 50);
|
return;
|
||||||
} else {
|
}
|
||||||
// Focus another window so that new window gets blur event.
|
gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect);
|
||||||
gBrowser.selectedTab.linkedBrowser.contentWindow.focus();
|
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow);
|
||||||
}
|
info("Clicked on notification");
|
||||||
}
|
alertWindow.close();
|
||||||
win.newWindow.focus();
|
}
|
||||||
waitUntilNewWindowHasFocus();
|
|
||||||
});
|
function onTabSelect() {
|
||||||
}
|
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
|
||||||
|
is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL,
|
||||||
function onAlertShowing() {
|
"Notification tab should be selected.");
|
||||||
info("Notification alert showing");
|
|
||||||
notification.removeEventListener("show", onAlertShowing);
|
finish();
|
||||||
|
}
|
||||||
let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul");
|
|
||||||
if (!alertWindow) {
|
|
||||||
todo(false, "Notifications don't use XUL windows on all platforms.");
|
|
||||||
notification.close();
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect);
|
|
||||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow);
|
|
||||||
info("Clicked on notification");
|
|
||||||
alertWindow.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onNewWindowFocused(event) {
|
|
||||||
event.target.close();
|
|
||||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
|
||||||
// Using timeout to test that something do *not* happen!
|
|
||||||
setTimeout(openSecondNotification, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
function openSecondNotification() {
|
|
||||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
|
||||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
|
||||||
notification = win.showNotification2();
|
|
||||||
notification.addEventListener("show", onAlertShowing);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTabSelect() {
|
|
||||||
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
|
|
||||||
is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL,
|
|
||||||
"Notification tab should be selected.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
@ -1,40 +1,23 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function showNotification1() {
|
function showNotification() {
|
||||||
var options = {
|
var options = {
|
||||||
dir: undefined,
|
dir: undefined,
|
||||||
lang: undefined,
|
lang: undefined,
|
||||||
body: "Test body",
|
body: "Test body",
|
||||||
tag: "Test tag",
|
tag: "Test tag",
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
};
|
};
|
||||||
var n = new Notification("Test title", options);
|
return new Notification("Test title", options);
|
||||||
n.addEventListener("click", function(event) {
|
}
|
||||||
event.preventDefault();
|
</script>
|
||||||
dump("Should focus new window.");
|
</head>
|
||||||
newWindow.focus();
|
<body>
|
||||||
});
|
<form id="notificationForm" onsubmit="showNotification();">
|
||||||
return n;
|
<input type="submit" value="Show notification" id="submit"/>
|
||||||
}
|
</form>
|
||||||
|
</body>
|
||||||
function showNotification2() {
|
</html>
|
||||||
var options = {
|
|
||||||
dir: undefined,
|
|
||||||
lang: undefined,
|
|
||||||
body: "Test body",
|
|
||||||
tag: "Test tag",
|
|
||||||
icon: undefined,
|
|
||||||
};
|
|
||||||
return new Notification("Test title", options);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form id="notificationForm" onsubmit="showNotification();">
|
|
||||||
<input type="submit" value="Show notification" id="submit"/>
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
@ -76,7 +76,6 @@ Event::ConstructorInit(EventTarget* aOwner,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mPrivateDataDuplicated = false;
|
mPrivateDataDuplicated = false;
|
||||||
mWantsPopupControlCheck = false;
|
|
||||||
|
|
||||||
if (aEvent) {
|
if (aEvent) {
|
||||||
mEvent = aEvent;
|
mEvent = aEvent;
|
||||||
@ -656,20 +655,12 @@ PopupAllowedForEvent(const char *eventName)
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
PopupControlState
|
PopupControlState
|
||||||
Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent)
|
Event::GetEventPopupControlState(WidgetEvent* aEvent)
|
||||||
{
|
{
|
||||||
// generally if an event handler is running, new windows are disallowed.
|
// generally if an event handler is running, new windows are disallowed.
|
||||||
// check for exceptions:
|
// check for exceptions:
|
||||||
PopupControlState abuse = openAbused;
|
PopupControlState abuse = openAbused;
|
||||||
|
|
||||||
if (aDOMEvent && aDOMEvent->InternalDOMEvent()->GetWantsPopupControlCheck()) {
|
|
||||||
nsAutoString type;
|
|
||||||
aDOMEvent->GetType(type);
|
|
||||||
if (PopupAllowedForEvent(NS_ConvertUTF16toUTF8(type).get())) {
|
|
||||||
return openAllowed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(aEvent->mClass) {
|
switch(aEvent->mClass) {
|
||||||
case eBasicEventClass:
|
case eBasicEventClass:
|
||||||
// For these following events only allow popups if they're
|
// For these following events only allow popups if they're
|
||||||
|
@ -30,7 +30,6 @@ namespace dom {
|
|||||||
class EventTarget;
|
class EventTarget;
|
||||||
class ErrorEvent;
|
class ErrorEvent;
|
||||||
class ProgressEvent;
|
class ProgressEvent;
|
||||||
class WantsPopupControlCheck;
|
|
||||||
|
|
||||||
// Dummy class so we can cast through it to get from nsISupports to
|
// Dummy class so we can cast through it to get from nsISupports to
|
||||||
// Event subclasses with only two non-ambiguous static casts.
|
// Event subclasses with only two non-ambiguous static casts.
|
||||||
@ -114,8 +113,7 @@ public:
|
|||||||
// Returns true if the event should be trusted.
|
// Returns true if the event should be trusted.
|
||||||
bool Init(EventTarget* aGlobal);
|
bool Init(EventTarget* aGlobal);
|
||||||
|
|
||||||
static PopupControlState GetEventPopupControlState(WidgetEvent* aEvent,
|
static PopupControlState GetEventPopupControlState(WidgetEvent* aEvent);
|
||||||
nsIDOMEvent* aDOMEvent = nullptr);
|
|
||||||
|
|
||||||
static void PopupAllowedEventsChanged();
|
static void PopupAllowedEventsChanged();
|
||||||
|
|
||||||
@ -237,17 +235,6 @@ protected:
|
|||||||
void SetEventType(const nsAString& aEventTypeArg);
|
void SetEventType(const nsAString& aEventTypeArg);
|
||||||
already_AddRefed<nsIContent> GetTargetFromFrame();
|
already_AddRefed<nsIContent> GetTargetFromFrame();
|
||||||
|
|
||||||
friend class WantsPopupControlCheck;
|
|
||||||
void SetWantsPopupControlCheck(bool aCheck)
|
|
||||||
{
|
|
||||||
mWantsPopupControlCheck = aCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetWantsPopupControlCheck()
|
|
||||||
{
|
|
||||||
return IsTrusted() && mWantsPopupControlCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IsChrome() returns true if aCx is chrome context or the event is created
|
* IsChrome() returns true if aCx is chrome context or the event is created
|
||||||
* in chrome's thread. Otherwise, false.
|
* in chrome's thread. Otherwise, false.
|
||||||
@ -261,28 +248,6 @@ protected:
|
|||||||
bool mEventIsInternal;
|
bool mEventIsInternal;
|
||||||
bool mPrivateDataDuplicated;
|
bool mPrivateDataDuplicated;
|
||||||
bool mIsMainThreadEvent;
|
bool mIsMainThreadEvent;
|
||||||
// True when popup control check should rely on event.type, not
|
|
||||||
// WidgetEvent.message.
|
|
||||||
bool mWantsPopupControlCheck;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MOZ_STACK_CLASS WantsPopupControlCheck
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
WantsPopupControlCheck(nsIDOMEvent* aEvent) : mEvent(aEvent->InternalDOMEvent())
|
|
||||||
{
|
|
||||||
mOriginalWantsPopupControlCheck = mEvent->GetWantsPopupControlCheck();
|
|
||||||
mEvent->SetWantsPopupControlCheck(mEvent->IsTrusted());
|
|
||||||
}
|
|
||||||
|
|
||||||
~WantsPopupControlCheck()
|
|
||||||
{
|
|
||||||
mEvent->SetWantsPopupControlCheck(mOriginalWantsPopupControlCheck);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Event* mEvent;
|
|
||||||
bool mOriginalWantsPopupControlCheck;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
@ -976,7 +976,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
|
|||||||
nsAutoTObserverArray<Listener, 2>::EndLimitedIterator iter(mListeners);
|
nsAutoTObserverArray<Listener, 2>::EndLimitedIterator iter(mListeners);
|
||||||
Maybe<nsAutoPopupStatePusher> popupStatePusher;
|
Maybe<nsAutoPopupStatePusher> popupStatePusher;
|
||||||
if (mIsMainThreadELM) {
|
if (mIsMainThreadELM) {
|
||||||
popupStatePusher.emplace(Event::GetEventPopupControlState(aEvent, *aDOMEvent));
|
popupStatePusher.emplace(Event::GetEventPopupControlState(aEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasListener = false;
|
bool hasListener = false;
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "nsIScriptSecurityManager.h"
|
#include "nsIScriptSecurityManager.h"
|
||||||
#include "nsIXPConnect.h"
|
#include "nsIXPConnect.h"
|
||||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||||
#include "mozilla/dom/Event.h"
|
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "nsContentPermissionHelper.h"
|
#include "nsContentPermissionHelper.h"
|
||||||
#ifdef MOZ_B2G
|
#ifdef MOZ_B2G
|
||||||
@ -361,31 +360,19 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
|||||||
const char16_t* aData)
|
const char16_t* aData)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsPIDOMWindow> window = mNotification->GetOwner();
|
nsCOMPtr<nsPIDOMWindow> window = mNotification->GetOwner();
|
||||||
if (!window || !window->IsCurrentInnerWindow()) {
|
if (!window) {
|
||||||
// Window has been closed, this observer is not valid anymore
|
// Window has been closed, this observer is not valid anymore
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("alertclickcallback", aTopic)) {
|
if (!strcmp("alertclickcallback", aTopic)) {
|
||||||
|
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
|
||||||
nsCOMPtr<nsIDOMEvent> event;
|
if (doc) {
|
||||||
NS_NewDOMEvent(getter_AddRefs(event), mNotification, nullptr, nullptr);
|
nsContentUtils::DispatchChromeEvent(doc, window,
|
||||||
nsresult rv = event->InitEvent(NS_LITERAL_STRING("click"), false, true);
|
NS_LITERAL_STRING("DOMWebNotificationClicked"),
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
true, true);
|
||||||
event->SetTrusted(true);
|
|
||||||
WantsPopupControlCheck popupControlCheck(event);
|
|
||||||
bool doDefaultAction = true;
|
|
||||||
mNotification->DispatchEvent(event, &doDefaultAction);
|
|
||||||
if (doDefaultAction) {
|
|
||||||
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
|
|
||||||
if (doc) {
|
|
||||||
// Browser UI may use DOMWebNotificationClicked to focus the tab
|
|
||||||
// from which the event was dispatched.
|
|
||||||
nsContentUtils::DispatchChromeEvent(doc, window->GetOuterWindow(),
|
|
||||||
NS_LITERAL_STRING("DOMWebNotificationClicked"),
|
|
||||||
true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
mNotification->DispatchTrustedEvent(NS_LITERAL_STRING("click"));
|
||||||
} else if (!strcmp("alertfinished", aTopic)) {
|
} else if (!strcmp("alertfinished", aTopic)) {
|
||||||
nsCOMPtr<nsINotificationStorage> notificationStorage =
|
nsCOMPtr<nsINotificationStorage> notificationStorage =
|
||||||
do_GetService(NS_NOTIFICATION_STORAGE_CONTRACTID);
|
do_GetService(NS_NOTIFICATION_STORAGE_CONTRACTID);
|
||||||
|
Loading…
Reference in New Issue
Block a user