Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | dump("Loading remote script!\n"); |
michael@0 | 6 | dump(content + "\n"); |
michael@0 | 7 | |
michael@0 | 8 | var cpm = Components.classes["@mozilla.org/childprocessmessagemanager;1"] |
michael@0 | 9 | .getService(Components.interfaces.nsISyncMessageSender); |
michael@0 | 10 | cpm.addMessageListener("cpm-async", |
michael@0 | 11 | function(m) { |
michael@0 | 12 | cpm.sendSyncMessage("ppm-sync"); |
michael@0 | 13 | dump(content.document.documentElement); |
michael@0 | 14 | cpm.sendAsyncMessage("ppm-async"); |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | var Cc = Components.classes; |
michael@0 | 18 | var Ci = Components.interfaces; |
michael@0 | 19 | var dshell = content.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 20 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 21 | .QueryInterface(Ci.nsIDocShellTreeItem) |
michael@0 | 22 | .rootTreeItem |
michael@0 | 23 | .QueryInterface(Ci.nsIDocShell); |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | addEventListener("click", |
michael@0 | 27 | function(e) { |
michael@0 | 28 | dump(e.target + "\n"); |
michael@0 | 29 | if (e.target instanceof Components.interfaces.nsIDOMHTMLAnchorElement && |
michael@0 | 30 | dshell == docShell) { |
michael@0 | 31 | var retval = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 32 | getInterface(Components.interfaces.nsIContentFrameMessageManager). |
michael@0 | 33 | sendSyncMessage("linkclick", { href: e.target.href }); |
michael@0 | 34 | dump(uneval(retval[0]) + "\n"); |
michael@0 | 35 | // Test here also that both retvals are the same |
michael@0 | 36 | sendAsyncMessage("linkclick-reply-object", uneval(retval[0]) == uneval(retval[1]) ? retval[0] : ""); |
michael@0 | 37 | } |
michael@0 | 38 | }, |
michael@0 | 39 | true); |
michael@0 | 40 | |
michael@0 | 41 | addMessageListener("chrome-message", |
michael@0 | 42 | function(m) { |
michael@0 | 43 | dump(uneval(m.json) + "\n"); |
michael@0 | 44 | sendAsyncMessage("chrome-message-reply", m.json); |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | addMessageListener("speed-test-start", |
michael@0 | 48 | function(m) { |
michael@0 | 49 | while (sendSyncMessage("speed-test")[0].message != "done"); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | addMessageListener("async-echo", function(m) { |
michael@0 | 53 | sendAsyncMessage(m.name); |
michael@0 | 54 | }); |