Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /*** |
michael@0 | 2 | |
michael@0 | 3 | MochiKit.MockDOM 1.4 |
michael@0 | 4 | |
michael@0 | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
michael@0 | 6 | |
michael@0 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
michael@0 | 8 | |
michael@0 | 9 | ***/ |
michael@0 | 10 | |
michael@0 | 11 | if (typeof(MochiKit) == "undefined") { |
michael@0 | 12 | MochiKit = {}; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | if (typeof(MochiKit.MockDOM) == "undefined") { |
michael@0 | 16 | MochiKit.MockDOM = {}; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | MochiKit.MockDOM.NAME = "MochiKit.MockDOM"; |
michael@0 | 20 | MochiKit.MockDOM.VERSION = "1.4"; |
michael@0 | 21 | |
michael@0 | 22 | MochiKit.MockDOM.__repr__ = function () { |
michael@0 | 23 | return "[" + this.NAME + " " + this.VERSION + "]"; |
michael@0 | 24 | }; |
michael@0 | 25 | |
michael@0 | 26 | /** @id MochiKit.MockDOM.toString */ |
michael@0 | 27 | MochiKit.MockDOM.toString = function () { |
michael@0 | 28 | return this.__repr__(); |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | /** @id MochiKit.MockDOM.createDocument */ |
michael@0 | 32 | MochiKit.MockDOM.createDocument = function () { |
michael@0 | 33 | var doc = new MochiKit.MockDOM.MockElement("DOCUMENT"); |
michael@0 | 34 | doc.body = doc.createElement("BODY"); |
michael@0 | 35 | doc.appendChild(doc.body); |
michael@0 | 36 | return doc; |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | /** @id MochiKit.MockDOM.MockElement */ |
michael@0 | 40 | MochiKit.MockDOM.MockElement = function (name, data, ownerDocument) { |
michael@0 | 41 | this.tagName = this.nodeName = name.toUpperCase(); |
michael@0 | 42 | this.ownerDocument = ownerDocument || null; |
michael@0 | 43 | if (name == "DOCUMENT") { |
michael@0 | 44 | this.nodeType = 9; |
michael@0 | 45 | this.childNodes = []; |
michael@0 | 46 | } else if (typeof(data) == "string") { |
michael@0 | 47 | this.nodeValue = data; |
michael@0 | 48 | this.nodeType = 3; |
michael@0 | 49 | } else { |
michael@0 | 50 | this.nodeType = 1; |
michael@0 | 51 | this.childNodes = []; |
michael@0 | 52 | } |
michael@0 | 53 | if (name.substring(0, 1) == "<") { |
michael@0 | 54 | var nameattr = name.substring( |
michael@0 | 55 | name.indexOf('"') + 1, name.lastIndexOf('"')); |
michael@0 | 56 | name = name.substring(1, name.indexOf(" ")); |
michael@0 | 57 | this.tagName = this.nodeName = name.toUpperCase(); |
michael@0 | 58 | this.setAttribute("name", nameattr); |
michael@0 | 59 | } |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | MochiKit.MockDOM.MockElement.prototype = { |
michael@0 | 63 | /** @id MochiKit.MockDOM.MockElement.prototype.createElement */ |
michael@0 | 64 | createElement: function (tagName) { |
michael@0 | 65 | return new MochiKit.MockDOM.MockElement(tagName, null, this.nodeType == 9 ? this : this.ownerDocument); |
michael@0 | 66 | }, |
michael@0 | 67 | /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */ |
michael@0 | 68 | createTextNode: function (text) { |
michael@0 | 69 | return new MochiKit.MockDOM.MockElement("text", text, this.nodeType == 9 ? this : this.ownerDocument); |
michael@0 | 70 | }, |
michael@0 | 71 | /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */ |
michael@0 | 72 | setAttribute: function (name, value) { |
michael@0 | 73 | this[name] = value; |
michael@0 | 74 | }, |
michael@0 | 75 | /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */ |
michael@0 | 76 | getAttribute: function (name) { |
michael@0 | 77 | return this[name]; |
michael@0 | 78 | }, |
michael@0 | 79 | /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */ |
michael@0 | 80 | appendChild: function (child) { |
michael@0 | 81 | this.childNodes.push(child); |
michael@0 | 82 | }, |
michael@0 | 83 | /** @id MochiKit.MockDOM.MockElement.prototype.toString */ |
michael@0 | 84 | toString: function () { |
michael@0 | 85 | return "MockElement(" + this.tagName + ")"; |
michael@0 | 86 | }, |
michael@0 | 87 | /** @id MochiKit.MockDOM.MockElement.prototype.getElementsByTagName */ |
michael@0 | 88 | getElementsByTagName: function (tagName) { |
michael@0 | 89 | var foundElements = []; |
michael@0 | 90 | MochiKit.Base.nodeWalk(this, function(node){ |
michael@0 | 91 | if (tagName == '*' || tagName == node.tagName) { |
michael@0 | 92 | foundElements.push(node); |
michael@0 | 93 | return node.childNodes; |
michael@0 | 94 | } |
michael@0 | 95 | }); |
michael@0 | 96 | return foundElements; |
michael@0 | 97 | } |
michael@0 | 98 | }; |
michael@0 | 99 | |
michael@0 | 100 | /** @id MochiKit.MockDOM.EXPORT_OK */ |
michael@0 | 101 | MochiKit.MockDOM.EXPORT_OK = [ |
michael@0 | 102 | "mockElement", |
michael@0 | 103 | "createDocument" |
michael@0 | 104 | ]; |
michael@0 | 105 | |
michael@0 | 106 | /** @id MochiKit.MockDOM.EXPORT */ |
michael@0 | 107 | MochiKit.MockDOM.EXPORT = [ |
michael@0 | 108 | "document" |
michael@0 | 109 | ]; |
michael@0 | 110 | |
michael@0 | 111 | MochiKit.MockDOM.__new__ = function () { |
michael@0 | 112 | this.document = this.createDocument(); |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | MochiKit.MockDOM.__new__(); |