Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | let Cu = Components.utils; |
michael@0 | 8 | let Ci = Components.interfaces; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource:///modules/sessionstore/FrameTree.jsm", this); |
michael@0 | 11 | let gFrameTree = new FrameTree(this); |
michael@0 | 12 | |
michael@0 | 13 | gFrameTree.addObserver({ |
michael@0 | 14 | onFrameTreeReset: function () { |
michael@0 | 15 | sendAsyncMessage("ss-test:onFrameTreeReset"); |
michael@0 | 16 | }, |
michael@0 | 17 | |
michael@0 | 18 | onFrameTreeCollected: function () { |
michael@0 | 19 | sendAsyncMessage("ss-test:onFrameTreeCollected"); |
michael@0 | 20 | } |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * This frame script is only loaded for sessionstore mochitests. It enables us |
michael@0 | 25 | * to modify and query docShell data when running with multiple processes. |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | addEventListener("hashchange", function () { |
michael@0 | 29 | sendAsyncMessage("ss-test:hashchange"); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | addEventListener("MozStorageChanged", function () { |
michael@0 | 33 | sendSyncMessage("ss-test:MozStorageChanged"); |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | addMessageListener("ss-test:modifySessionStorage", function (msg) { |
michael@0 | 37 | for (let key of Object.keys(msg.data)) { |
michael@0 | 38 | content.sessionStorage[key] = msg.data[key]; |
michael@0 | 39 | } |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | addMessageListener("ss-test:modifySessionStorage2", function (msg) { |
michael@0 | 43 | for (let key of Object.keys(msg.data)) { |
michael@0 | 44 | content.frames[0].sessionStorage[key] = msg.data[key]; |
michael@0 | 45 | } |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | addMessageListener("ss-test:purgeDomainData", function ({data: domain}) { |
michael@0 | 49 | Services.obs.notifyObservers(null, "browser:purge-domain-data", domain); |
michael@0 | 50 | content.setTimeout(() => sendAsyncMessage("ss-test:purgeDomainData")); |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | addMessageListener("ss-test:purgeSessionHistory", function () { |
michael@0 | 54 | Services.obs.notifyObservers(null, "browser:purge-session-history", ""); |
michael@0 | 55 | content.setTimeout(() => sendAsyncMessage("ss-test:purgeSessionHistory")); |
michael@0 | 56 | }); |
michael@0 | 57 | |
michael@0 | 58 | addMessageListener("ss-test:getStyleSheets", function (msg) { |
michael@0 | 59 | let sheets = content.document.styleSheets; |
michael@0 | 60 | let titles = Array.map(sheets, ss => [ss.title, ss.disabled]); |
michael@0 | 61 | sendSyncMessage("ss-test:getStyleSheets", titles); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | addMessageListener("ss-test:enableStyleSheetsForSet", function (msg) { |
michael@0 | 65 | content.document.enableStyleSheetsForSet(msg.data); |
michael@0 | 66 | sendAsyncMessage("ss-test:enableStyleSheetsForSet"); |
michael@0 | 67 | }); |
michael@0 | 68 | |
michael@0 | 69 | addMessageListener("ss-test:enableSubDocumentStyleSheetsForSet", function (msg) { |
michael@0 | 70 | let iframe = content.document.getElementById(msg.data.id); |
michael@0 | 71 | iframe.contentDocument.enableStyleSheetsForSet(msg.data.set); |
michael@0 | 72 | sendAsyncMessage("ss-test:enableSubDocumentStyleSheetsForSet"); |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | addMessageListener("ss-test:getAuthorStyleDisabled", function (msg) { |
michael@0 | 76 | let {authorStyleDisabled} = |
michael@0 | 77 | docShell.contentViewer.QueryInterface(Ci.nsIMarkupDocumentViewer); |
michael@0 | 78 | sendSyncMessage("ss-test:getAuthorStyleDisabled", authorStyleDisabled); |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | addMessageListener("ss-test:setAuthorStyleDisabled", function (msg) { |
michael@0 | 82 | let markupDocumentViewer = |
michael@0 | 83 | docShell.contentViewer.QueryInterface(Ci.nsIMarkupDocumentViewer); |
michael@0 | 84 | markupDocumentViewer.authorStyleDisabled = msg.data; |
michael@0 | 85 | sendSyncMessage("ss-test:setAuthorStyleDisabled"); |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | addMessageListener("ss-test:setUsePrivateBrowsing", function (msg) { |
michael@0 | 89 | let loadContext = |
michael@0 | 90 | docShell.QueryInterface(Ci.nsILoadContext); |
michael@0 | 91 | loadContext.usePrivateBrowsing = msg.data; |
michael@0 | 92 | sendAsyncMessage("ss-test:setUsePrivateBrowsing"); |
michael@0 | 93 | }); |
michael@0 | 94 | |
michael@0 | 95 | addMessageListener("ss-test:getScrollPosition", function (msg) { |
michael@0 | 96 | let frame = content; |
michael@0 | 97 | if (msg.data.hasOwnProperty("frame")) { |
michael@0 | 98 | frame = content.frames[msg.data.frame]; |
michael@0 | 99 | } |
michael@0 | 100 | let {scrollX: x, scrollY: y} = frame; |
michael@0 | 101 | sendAsyncMessage("ss-test:getScrollPosition", {x: x, y: y}); |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | addMessageListener("ss-test:setScrollPosition", function (msg) { |
michael@0 | 105 | let frame = content; |
michael@0 | 106 | let {x, y} = msg.data; |
michael@0 | 107 | if (msg.data.hasOwnProperty("frame")) { |
michael@0 | 108 | frame = content.frames[msg.data.frame]; |
michael@0 | 109 | } |
michael@0 | 110 | frame.scrollTo(x, y); |
michael@0 | 111 | |
michael@0 | 112 | frame.addEventListener("scroll", function onScroll(event) { |
michael@0 | 113 | if (frame.document == event.target) { |
michael@0 | 114 | frame.removeEventListener("scroll", onScroll); |
michael@0 | 115 | sendAsyncMessage("ss-test:setScrollPosition"); |
michael@0 | 116 | } |
michael@0 | 117 | }); |
michael@0 | 118 | }); |
michael@0 | 119 | |
michael@0 | 120 | addMessageListener("ss-test:createDynamicFrames", function ({data}) { |
michael@0 | 121 | function createIFrame(rows) { |
michael@0 | 122 | let frames = content.document.getElementById(data.id); |
michael@0 | 123 | frames.setAttribute("rows", rows); |
michael@0 | 124 | |
michael@0 | 125 | let frame = content.document.createElement("frame"); |
michael@0 | 126 | frame.setAttribute("src", data.url); |
michael@0 | 127 | frames.appendChild(frame); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | addEventListener("DOMContentLoaded", function onContentLoaded(event) { |
michael@0 | 131 | if (content.document == event.target) { |
michael@0 | 132 | removeEventListener("DOMContentLoaded", onContentLoaded, true); |
michael@0 | 133 | // DOMContentLoaded is fired right after we finished parsing the document. |
michael@0 | 134 | createIFrame("33%, 33%, 33%"); |
michael@0 | 135 | } |
michael@0 | 136 | }, true); |
michael@0 | 137 | |
michael@0 | 138 | addEventListener("load", function onLoad(event) { |
michael@0 | 139 | if (content.document == event.target) { |
michael@0 | 140 | removeEventListener("load", onLoad, true); |
michael@0 | 141 | |
michael@0 | 142 | // Creating this frame on the same tick as the load event |
michael@0 | 143 | // means that it must not be included in the frame tree. |
michael@0 | 144 | createIFrame("25%, 25%, 25%, 25%"); |
michael@0 | 145 | } |
michael@0 | 146 | }, true); |
michael@0 | 147 | |
michael@0 | 148 | sendAsyncMessage("ss-test:createDynamicFrames"); |
michael@0 | 149 | }); |
michael@0 | 150 | |
michael@0 | 151 | addMessageListener("ss-test:removeLastFrame", function ({data}) { |
michael@0 | 152 | let frames = content.document.getElementById(data.id); |
michael@0 | 153 | frames.lastElementChild.remove(); |
michael@0 | 154 | sendAsyncMessage("ss-test:removeLastFrame"); |
michael@0 | 155 | }); |
michael@0 | 156 | |
michael@0 | 157 | addMessageListener("ss-test:mapFrameTree", function (msg) { |
michael@0 | 158 | let result = gFrameTree.map(frame => ({href: frame.location.href})); |
michael@0 | 159 | sendAsyncMessage("ss-test:mapFrameTree", result); |
michael@0 | 160 | }); |
michael@0 | 161 | |
michael@0 | 162 | addMessageListener("ss-test:click", function ({data}) { |
michael@0 | 163 | content.document.getElementById(data.id).click(); |
michael@0 | 164 | sendAsyncMessage("ss-test:click"); |
michael@0 | 165 | }); |
michael@0 | 166 | |
michael@0 | 167 | addMessageListener("ss-test:historyPushState", function ({data}) { |
michael@0 | 168 | content.window.history. |
michael@0 | 169 | pushState(data.stateObj || {}, data.title || "", data.url); |
michael@0 | 170 | |
michael@0 | 171 | sendAsyncMessage("ss-test:historyPushState"); |
michael@0 | 172 | }); |
michael@0 | 173 | |
michael@0 | 174 | addMessageListener("ss-test:historyReplaceState", function ({data}) { |
michael@0 | 175 | content.window.history. |
michael@0 | 176 | replaceState(data.stateObj || {}, data.title || "", data.url); |
michael@0 | 177 | |
michael@0 | 178 | sendAsyncMessage("ss-test:historyReplaceState"); |
michael@0 | 179 | }); |