Bug 853972 - Clicking on a notification should select the originating tab. r=felipe,wchen

--HG--
extra : rebase_source : e8f794ff0e474d669489eff7e82b3b0eccf4db0e
This commit is contained in:
Jared Wein 2014-01-13 13:56:28 +01:00
Родитель 1c71633710
Коммит a87d862c84
6 изменённых файлов: 108 добавлений и 2 удалений

Просмотреть файл

@ -277,3 +277,7 @@ let ClickEventHandler = {
}
};
ClickEventHandler.init();
addEventListener("DOMWebNotificationClicked", function(event) {
sendAsyncMessage("DOMWebNotificationClicked", {});
}, false);

Просмотреть файл

@ -2946,7 +2946,7 @@
let browser = aMessage.target;
switch (aMessage.name) {
case "DOMTitleChanged":
case "DOMTitleChanged": {
let tab = this._getTabForBrowser(browser);
if (!tab)
return;
@ -2954,7 +2954,8 @@
if (titleChanged && !tab.selected && !tab.hasAttribute("busy"))
tab.setAttribute("titlechanged", "true");
break;
case "contextmenu":
}
case "contextmenu": {
gContextMenuContentData = { event: aMessage.objects.event,
browser: browser };
let popup = browser.ownerDocument.getElementById("contentAreaContextMenu");
@ -2963,6 +2964,16 @@
gContextMenuContentData.event.clientY,
true, false, null);
break;
}
case "DOMWebNotificationClicked": {
let tab = this._getTabForBrowser(browser);
if (!tab)
return;
this.selectedTab = tab;
let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
focusManager.activeWindow = window;
break;
}
}
]]></body>
</method>
@ -3020,6 +3031,7 @@
messageManager.addMessageListener("DOMTitleChanged", this);
messageManager.addMessageListener("contextmenu", this);
}
messageManager.addMessageListener("DOMWebNotificationClicked", this);
]]>
</constructor>

Просмотреть файл

@ -51,6 +51,7 @@ support-files =
file_bug906190_redirected.html
file_bug906190.js
file_bug906190.sjs
file_dom_notifications.html
file_fullscreen-window-open.html
head.js
healthreport_testRemoteCommands.html
@ -268,6 +269,7 @@ skip-if = os == "linux" # Intermittent failures, bug 917535
[browser_middleMouse_inherit.js]
[browser_minimize.js]
[browser_mixedcontent_securityflags.js]
[browser_notification_tab_switching.js]
[browser_offlineQuotaNotification.js]
[browser_overflowScroll.js]
[browser_pageInfo.js]

Просмотреть файл

@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
let tab;
let notification;
let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html";
function test () {
waitForExplicitFinish();
let pm = Services.perms;
registerCleanupFunction(function() {
pm.remove(notificationURL, "desktop-notification");
gBrowser.removeTab(tab);
window.restore();
});
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
tab = gBrowser.addTab(notificationURL);
tab.linkedBrowser.addEventListener("load", onLoad, true);
}
function onLoad() {
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
tab.linkedBrowser.removeEventListener("load", onLoad, true);
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
notification = win.showNotification();
notification.addEventListener("show", onAlertShowing);
}
function onAlertShowing() {
info("Notification alert showing");
notification.removeEventListener("show", onAlertShowing);
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 onTabSelect() {
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL,
"Notification tab should be selected.");
finish();
}

Просмотреть файл

@ -0,0 +1,23 @@
<html>
<head>
<script>
"use strict";
function showNotification() {
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>

Просмотреть файл

@ -391,6 +391,13 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
if (!strcmp("alertclickcallback", aTopic)) {
nsCOMPtr<nsPIDOMWindow> window = mNotification->GetOwner();
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
if (doc) {
nsContentUtils::DispatchChromeEvent(doc, window,
NS_LITERAL_STRING("DOMWebNotificationClicked"),
true, true);
}
mNotification->DispatchTrustedEvent(NS_LITERAL_STRING("click"));
} else if (!strcmp("alertfinished", aTopic)) {
mNotification->mIsClosed = true;