mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1101825 - Create UITour event framework. r=MattN
This commit is contained in:
parent
1e8cb75575
commit
13136e7c82
@ -12,6 +12,7 @@ let UITourListener = {
|
||||
return;
|
||||
}
|
||||
addMessageListener("UITour:SendPageCallback", this);
|
||||
addMessageListener("UITour:SendPageNotification", this);
|
||||
sendAsyncMessage("UITour:onPageEvent", {detail: event.detail, type: event.type});
|
||||
},
|
||||
|
||||
@ -68,14 +69,18 @@ let UITourListener = {
|
||||
receiveMessage: function(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "UITour:SendPageCallback":
|
||||
this.sendPageCallback(aMessage.data);
|
||||
this.sendPageEvent("Response", aMessage.data);
|
||||
break;
|
||||
}
|
||||
case "UITour:SendPageNotification":
|
||||
this.sendPageEvent("Notification", aMessage.data);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
sendPageCallback: function (detail) {
|
||||
sendPageEvent: function (type, detail) {
|
||||
let doc = content.document;
|
||||
let event = new doc.defaultView.CustomEvent("mozUITourResponse", {
|
||||
let eventName = "mozUITour" + type;
|
||||
let event = new doc.defaultView.CustomEvent(eventName, {
|
||||
bubbles: true,
|
||||
detail: Cu.cloneInto(detail, doc.defaultView)
|
||||
});
|
||||
|
@ -608,6 +608,12 @@ this.UITour = {
|
||||
}).then(null, Cu.reportError);
|
||||
break;
|
||||
}
|
||||
|
||||
case "ping": {
|
||||
if (typeof data.callbackID == "string")
|
||||
this.sendPageCallback(messageManager, data.callbackID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!window.gMultiProcessBrowser) { // Non-e10s. See bug 1089000.
|
||||
@ -1622,7 +1628,29 @@ this.UITour = {
|
||||
reject("Search engine not available");
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
notify(eventName, params) {
|
||||
let winEnum = Services.wm.getEnumerator("navigator:browser");
|
||||
while (winEnum.hasMoreElements()) {
|
||||
let window = winEnum.getNext();
|
||||
if (window.closed)
|
||||
continue;
|
||||
debugger;
|
||||
let originTabs = this.originTabs.get(window);
|
||||
if (!originTabs)
|
||||
continue;
|
||||
|
||||
for (let tab of originTabs) {
|
||||
let messageManager = tab.linkedBrowser.messageManager;
|
||||
let detail = {
|
||||
event: eventName,
|
||||
params: params,
|
||||
};
|
||||
messageManager.sendAsyncMessage("UITour:SendPageNotification", detail);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.UITour.init();
|
||||
|
@ -33,6 +33,8 @@ skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_modalDialog.js]
|
||||
run-if = os == "mac" # modal dialog disabling only working on OS X
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_observe.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_panel_close_annotation.js]
|
||||
skip-if = true # Disabled due to frequent failures, bugs 1026310 and 1032137
|
||||
[browser_UITour_registerPageID.js]
|
||||
|
51
browser/modules/test/browser_UITour_observe.js
Normal file
51
browser/modules/test/browser_UITour_observe.js
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
|
||||
let gTestTab;
|
||||
let gContentAPI;
|
||||
let gContentWindow;
|
||||
|
||||
Components.utils.import("resource:///modules/UITour.jsm");
|
||||
|
||||
function test() {
|
||||
requestLongerTimeout(2);
|
||||
UITourTest();
|
||||
}
|
||||
|
||||
let tests = [
|
||||
function test_no_params(done) {
|
||||
function listener(event, params) {
|
||||
is(event, "test-event-1", "Correct event name");
|
||||
is(params, null, "No param object");
|
||||
gContentAPI.observe(null);
|
||||
done();
|
||||
}
|
||||
|
||||
gContentAPI.observe(listener, () => {
|
||||
UITour.notify("test-event-1");
|
||||
});
|
||||
},
|
||||
function test_param_string(done) {
|
||||
function listener(event, params) {
|
||||
is(event, "test-event-2", "Correct event name");
|
||||
is(params, "a param", "Correct param string");
|
||||
gContentAPI.observe(null);
|
||||
done();
|
||||
}
|
||||
|
||||
gContentAPI.observe(listener, () => {
|
||||
UITour.notify("test-event-2", "a param");
|
||||
});
|
||||
},
|
||||
function test_param_object(done) {
|
||||
function listener(event, params) {
|
||||
is(event, "test-event-3", "Correct event name");
|
||||
is(JSON.stringify(params), JSON.stringify({key: "something"}), "Correct param object");
|
||||
gContentAPI.observe(null);
|
||||
done();
|
||||
}
|
||||
|
||||
gContentAPI.observe(listener, () => {
|
||||
UITour.notify("test-event-3", {key: "something"});
|
||||
});
|
||||
},
|
||||
];
|
@ -43,23 +43,54 @@ if (typeof Mozilla == 'undefined') {
|
||||
var id = _generateCallbackID();
|
||||
|
||||
function listener(event) {
|
||||
if (typeof event.detail != "object")
|
||||
if (typeof event.detail != 'object')
|
||||
return;
|
||||
if (event.detail.callbackID != id)
|
||||
return;
|
||||
|
||||
document.removeEventListener("mozUITourResponse", listener);
|
||||
document.removeEventListener('mozUITourResponse', listener);
|
||||
callback(event.detail.data);
|
||||
}
|
||||
document.addEventListener("mozUITourResponse", listener);
|
||||
document.addEventListener('mozUITourResponse', listener);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
var notificationListener = null;
|
||||
function _notificationListener(event) {
|
||||
if (typeof event.detail != 'object')
|
||||
return;
|
||||
if (typeof notificationListener != 'function')
|
||||
return;
|
||||
|
||||
notificationListener(event.detail.event, event.detail.params);
|
||||
}
|
||||
|
||||
Mozilla.UITour.DEFAULT_THEME_CYCLE_DELAY = 10 * 1000;
|
||||
|
||||
Mozilla.UITour.CONFIGNAME_SYNC = "sync";
|
||||
Mozilla.UITour.CONFIGNAME_AVAILABLETARGETS = "availableTargets";
|
||||
Mozilla.UITour.CONFIGNAME_SYNC = 'sync';
|
||||
Mozilla.UITour.CONFIGNAME_AVAILABLETARGETS = 'availableTargets';
|
||||
|
||||
Mozilla.UITour.ping = function(callback) {
|
||||
var data = {};
|
||||
if (callback) {
|
||||
data.callbackID = _waitForCallback(callback);
|
||||
}
|
||||
_sendEvent('ping', data);
|
||||
};
|
||||
|
||||
Mozilla.UITour.observe = function(listener, callback) {
|
||||
notificationListener = listener;
|
||||
|
||||
if (listener) {
|
||||
document.addEventListener('mozUITourNotification',
|
||||
_notificationListener);
|
||||
Mozilla.UITour.ping(callback);
|
||||
} else {
|
||||
document.removeEventListener('mozUITourNotification',
|
||||
_notificationListener);
|
||||
}
|
||||
};
|
||||
|
||||
Mozilla.UITour.registerPageID = function(pageID) {
|
||||
_sendEvent('registerPageID', {
|
||||
|
Loading…
Reference in New Issue
Block a user