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 | /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | function findBody(node) |
michael@0 | 7 | { |
michael@0 | 8 | if (node.nodeType != Node.ELEMENT_NODE) { |
michael@0 | 9 | return null; |
michael@0 | 10 | } |
michael@0 | 11 | var children = node.childNodes; |
michael@0 | 12 | if (children == null) { |
michael@0 | 13 | return null; |
michael@0 | 14 | } |
michael@0 | 15 | var length = children.length; |
michael@0 | 16 | var child = null; |
michael@0 | 17 | var count = 0; |
michael@0 | 18 | while (count < length) { |
michael@0 | 19 | child = children[count]; |
michael@0 | 20 | if (child.tagName == "BODY") { |
michael@0 | 21 | dump("BODY found"); |
michael@0 | 22 | return child; |
michael@0 | 23 | } |
michael@0 | 24 | var body = findBody(child); |
michael@0 | 25 | if (null != body) { |
michael@0 | 26 | return body; |
michael@0 | 27 | } |
michael@0 | 28 | count++; |
michael@0 | 29 | } |
michael@0 | 30 | return null; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // Given the body element, find the first table element |
michael@0 | 34 | function findTable(body) |
michael@0 | 35 | { |
michael@0 | 36 | // XXX A better way to do this would be to use getElementsByTagName(), but |
michael@0 | 37 | // it isn't implemented yet... |
michael@0 | 38 | var children = body.childNodes |
michael@0 | 39 | if (children == null) { |
michael@0 | 40 | return null; |
michael@0 | 41 | } |
michael@0 | 42 | var length = children.length; |
michael@0 | 43 | var child = null; |
michael@0 | 44 | var count = 0; |
michael@0 | 45 | while (count < length) { |
michael@0 | 46 | child = children[count]; |
michael@0 | 47 | if (child.nodeType == Node.ELEMENT_NODE) { |
michael@0 | 48 | if (child.tagName == "TABLE") { |
michael@0 | 49 | dump("TABLE found"); |
michael@0 | 50 | break; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | count++; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | return child; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | // Given a table element, find the first table body |
michael@0 | 60 | function findTableBody(table) |
michael@0 | 61 | { |
michael@0 | 62 | // XXX A better way to do this would be to use getElementsByTagName(), but |
michael@0 | 63 | // it isn't implemented yet... |
michael@0 | 64 | var children = table.childNodes |
michael@0 | 65 | if (children == null) { |
michael@0 | 66 | return null; |
michael@0 | 67 | } |
michael@0 | 68 | var length = children.length; |
michael@0 | 69 | var child = null; |
michael@0 | 70 | var count = 0; |
michael@0 | 71 | while (count < length) { |
michael@0 | 72 | child = children[count]; |
michael@0 | 73 | if (child.nodeType == Node.ELEMENT_NODE) { |
michael@0 | 74 | if (child.tagName == "TBODY") { |
michael@0 | 75 | break; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | count++; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | return child; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // Change the text of the first table cell |
michael@0 | 85 | function changeCell(table) |
michael@0 | 86 | { |
michael@0 | 87 | // Get a table body |
michael@0 | 88 | var body = findTableBody(table) |
michael@0 | 89 | |
michael@0 | 90 | // The table body's first child is a table row |
michael@0 | 91 | var row = body.firstChild |
michael@0 | 92 | |
michael@0 | 93 | // The row's first child is a table cell |
michael@0 | 94 | var cell = row.firstChild |
michael@0 | 95 | |
michael@0 | 96 | // Get the cell's text |
michael@0 | 97 | var text = cell.firstChild |
michael@0 | 98 | |
michael@0 | 99 | // Append some text |
michael@0 | 100 | text.append(" NEW TEXT") |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | changeCell(findTable(findBody(document.documentElement))) |
michael@0 | 104 |