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: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | var view = |
michael@0 | 7 | { |
michael@0 | 8 | onRun : function() |
michael@0 | 9 | { |
michael@0 | 10 | runQueue.mArray = new Array(); |
michael@0 | 11 | var sels = this.boxObject.view.selection,a=new Object(),b=new Object(),k; |
michael@0 | 12 | var rowResource, name, path; |
michael@0 | 13 | for (k=0;k<sels.getRangeCount();k++){ |
michael@0 | 14 | sels.getRangeAt(k,a,b); |
michael@0 | 15 | for (var l=a.value;l<=b.value;l++) { |
michael@0 | 16 | rowResource = this.builder.getResourceAtIndex(l); |
michael@0 | 17 | itemCache.getItem(rowResource); |
michael@0 | 18 | } |
michael@0 | 19 | } |
michael@0 | 20 | runQueue.run(); |
michael@0 | 21 | }, |
michael@0 | 22 | displayTest : function() |
michael@0 | 23 | { |
michael@0 | 24 | var current = this.boxObject.view.selection.currentIndex; |
michael@0 | 25 | var rowResource = this.builder.getResourceAtIndex(current); |
michael@0 | 26 | var item = itemCache.getItem(rowResource); |
michael@0 | 27 | }, |
michael@0 | 28 | browseForRDF : function() |
michael@0 | 29 | { |
michael@0 | 30 | var fp = doCreateRDFFP('Xalan Description File', |
michael@0 | 31 | nsIFilePicker.modeOpen); |
michael@0 | 32 | var res = fp.show(); |
michael@0 | 33 | |
michael@0 | 34 | if (res == nsIFilePicker.returnOK) { |
michael@0 | 35 | var furl = fp.fileURL; |
michael@0 | 36 | this.setDataSource(fp.fileURL.spec); |
michael@0 | 37 | } |
michael@0 | 38 | }, |
michael@0 | 39 | dump_Good : function() |
michael@0 | 40 | { |
michael@0 | 41 | var enumi = this.mResultDS.GetSources(krTypeSucc, kGood, true); |
michael@0 | 42 | var k = 0; |
michael@0 | 43 | while (enumi.hasMoreElements()) { |
michael@0 | 44 | k += 1; |
michael@0 | 45 | dump(enumi.getNext().QueryInterface(nsIRDFResource).Value+"\n"); |
michael@0 | 46 | } |
michael@0 | 47 | dump("found "+k+" good tests\n"); |
michael@0 | 48 | }, |
michael@0 | 49 | prune_ds : function() |
michael@0 | 50 | { |
michael@0 | 51 | if (this.mResultDS) { |
michael@0 | 52 | this.mResultDS.QueryInterface(nsIRDFPurgeableDataSource).Sweep(); |
michael@0 | 53 | } |
michael@0 | 54 | regressionStats.init() |
michael@0 | 55 | itemCache.mArray = new Array(); |
michael@0 | 56 | }, |
michael@0 | 57 | setDataSource : function(aSpec) |
michael@0 | 58 | { |
michael@0 | 59 | var baseSpec; |
michael@0 | 60 | if (aSpec) { |
michael@0 | 61 | baseSpec = aSpec; |
michael@0 | 62 | } |
michael@0 | 63 | else { |
michael@0 | 64 | baseSpec = document.getElementById("xalan_rdf").value; |
michael@0 | 65 | } |
michael@0 | 66 | if (this.mXalanDS && this.mXalanDS.URI == baseSpec) { |
michael@0 | 67 | this.mXalanDS.QueryInterface(nsIRDFRemoteDataSource); |
michael@0 | 68 | this.mXalanDS.Refresh(true); |
michael@0 | 69 | } |
michael@0 | 70 | else { |
michael@0 | 71 | if (this.mXalanDS) { |
michael@0 | 72 | this.database.RemoveDataSource(view.mXalanDS); |
michael@0 | 73 | } |
michael@0 | 74 | this.mXalanDS = kRDFSvc.GetDataSourceBlocking(baseSpec); |
michael@0 | 75 | if (!this.mXalanDS) { |
michael@0 | 76 | alert("Unable do load DataSource: "+baseSpec); |
michael@0 | 77 | return; |
michael@0 | 78 | } |
michael@0 | 79 | this.database.AddDataSource(this.mXalanDS); |
michael@0 | 80 | } |
michael@0 | 81 | regressionStats.init(); |
michael@0 | 82 | if (!this.mResultDS) { |
michael@0 | 83 | this.mResultDS = doCreate(kRDFInMemContractID, |
michael@0 | 84 | nsIRDFDataSource); |
michael@0 | 85 | this.database.AddDataSource(view.mResultDS); |
michael@0 | 86 | if (!this.mResultDS) { |
michael@0 | 87 | alert("Unable to create result InMemDatasource"); |
michael@0 | 88 | return; |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | this.builder.rebuild(); |
michael@0 | 93 | document.getElementById("xalan_rdf").value = baseSpec; |
michael@0 | 94 | runItem.prototype.kXalan.init(runItem.prototype.kXalan.URLTYPE_STANDARD, |
michael@0 | 95 | 0, baseSpec, null, null); |
michael@0 | 96 | }, |
michael@0 | 97 | loadHtml : function(aUrl, aListener) |
michael@0 | 98 | { |
michael@0 | 99 | const nsIIRequestor = Components.interfaces.nsIInterfaceRequestor; |
michael@0 | 100 | const nsIWebProgress = Components.interfaces.nsIWebProgress; |
michael@0 | 101 | var req = this.mIframe.webNavigation.QueryInterface(nsIIRequestor); |
michael@0 | 102 | var prog = req.getInterface(nsIWebProgress); |
michael@0 | 103 | prog.addProgressListener(aListener, nsIWebProgress.NOTIFY_ALL); |
michael@0 | 104 | this.mIframe.webNavigation.loadURI(aUrl, 0,null,null,null); |
michael@0 | 105 | }, |
michael@0 | 106 | fillItemContext : function() |
michael@0 | 107 | { |
michael@0 | 108 | var index = view.boxObject.view.selection.currentIndex; |
michael@0 | 109 | var res = view.builder.getResourceAtIndex(index); |
michael@0 | 110 | var purp = view.mXalanDS.GetTarget(res, krTypePurp, true); |
michael@0 | 111 | return (purp != null); |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | regressionStats = |
michael@0 | 116 | { |
michael@0 | 117 | observe: function(aSubject, aTopic, aData) |
michael@0 | 118 | { |
michael@0 | 119 | if (aTopic != 'success') { |
michael@0 | 120 | return; |
michael@0 | 121 | } |
michael@0 | 122 | var arc = (aData == "true") ? krTypeSuccCount : krTypeFailCount; |
michael@0 | 123 | this.assertNewCount(aSubject, arc, 1); |
michael@0 | 124 | }, |
michael@0 | 125 | init: function() |
michael@0 | 126 | { |
michael@0 | 127 | if (this.mRegressionDS) { |
michael@0 | 128 | this.mRegressionDS.QueryInterface(nsIRDFPurgeableDataSource).Sweep(); |
michael@0 | 129 | } |
michael@0 | 130 | else { |
michael@0 | 131 | this.mRegressionDS = |
michael@0 | 132 | doCreate(kRDFInMemContractID, nsIRDFDataSource); |
michael@0 | 133 | view.database.AddDataSource(this.mRegressionDS); |
michael@0 | 134 | } |
michael@0 | 135 | }, |
michael@0 | 136 | getParent: function(aDS, aSource) |
michael@0 | 137 | { |
michael@0 | 138 | // parent chached? |
michael@0 | 139 | var parent = this.mRegressionDS.GetTarget(aSource, krTypeParent, true); |
michael@0 | 140 | if (!parent) { |
michael@0 | 141 | var labels = view.mXalanDS.ArcLabelsIn(aSource); |
michael@0 | 142 | while (labels.hasMoreElements()) { |
michael@0 | 143 | var arc = labels.getNext().QueryInterface(nsIRDFResource); |
michael@0 | 144 | if (arc.Value.match(this.mChildRE)) { |
michael@0 | 145 | parent = view.mXalanDS.GetSource(arc, aSource, true); |
michael@0 | 146 | // cache the parent |
michael@0 | 147 | this.mRegressionDS.Assert(aSource, krTypeParent, |
michael@0 | 148 | parent, true); |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | return parent; |
michael@0 | 153 | }, |
michael@0 | 154 | assertNewCount: function(aSource, aArc, aIncrement) |
michael@0 | 155 | { |
michael@0 | 156 | var root = kRDFSvc.GetResource('urn:root'); |
michael@0 | 157 | var count = 0; |
michael@0 | 158 | // parent chached? |
michael@0 | 159 | var parent = this.getParent(view.XalanDS, aSource); |
michael@0 | 160 | while (parent && !parent.EqualsNode(root)) { |
michael@0 | 161 | var countRes = view.mResultDS.GetTarget(parent, aArc, true); |
michael@0 | 162 | if (countRes) { |
michael@0 | 163 | count = countRes.QueryInterface(nsIRDFInt).Value; |
michael@0 | 164 | } |
michael@0 | 165 | var newCountRes = kRDFSvc.GetIntLiteral(count + aIncrement); |
michael@0 | 166 | if (!newCountRes) { |
michael@0 | 167 | return; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | if (countRes) { |
michael@0 | 171 | view.mResultDS.Change(parent, aArc, countRes, newCountRes); |
michael@0 | 172 | } |
michael@0 | 173 | else { |
michael@0 | 174 | view.mResultDS.Assert(parent, aArc, newCountRes, true); |
michael@0 | 175 | } |
michael@0 | 176 | parent = this.getParent(view.XalanDS, parent); |
michael@0 | 177 | } |
michael@0 | 178 | }, |
michael@0 | 179 | mRegressionDS: 0, |
michael@0 | 180 | mChildRE: /http:\/\/www\.w3\.org\/1999\/02\/22-rdf-syntax-ns#_/ |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | function rdfObserve(aSubject, aTopic, aData) |
michael@0 | 184 | { |
michael@0 | 185 | if (aTopic == "success") { |
michael@0 | 186 | var target = (aData == "true") ? kGood : kBad; |
michael@0 | 187 | view.mResultDS.Assert(aSubject, krTypeSucc, target, true); |
michael@0 | 188 | |
michael@0 | 189 | regressionStats.observe(aSubject, aTopic, aData); |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | runItem.prototype.kObservers.push(rdfObserve); |