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 | const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1"; |
michael@0 | 7 | const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream; |
michael@0 | 8 | |
michael@0 | 9 | var cmdFileController = |
michael@0 | 10 | { |
michael@0 | 11 | supportsCommand: function(aCommand) |
michael@0 | 12 | { |
michael@0 | 13 | switch(aCommand) { |
michael@0 | 14 | case 'cmd_fl_save': |
michael@0 | 15 | case 'cmd_fl_import': |
michael@0 | 16 | return true; |
michael@0 | 17 | default: |
michael@0 | 18 | } |
michael@0 | 19 | return false; |
michael@0 | 20 | }, |
michael@0 | 21 | isCommandEnabled: function(aCommand) |
michael@0 | 22 | { |
michael@0 | 23 | return this.supportsCommand(aCommand); |
michael@0 | 24 | }, |
michael@0 | 25 | doCommand: function(aCommand) |
michael@0 | 26 | { |
michael@0 | 27 | switch(aCommand) { |
michael@0 | 28 | case 'cmd_fl_save': |
michael@0 | 29 | var sink = new Object; |
michael@0 | 30 | sink.write = function(aContent, aCount) |
michael@0 | 31 | { |
michael@0 | 32 | // replace NC:succ with NC:orig_succ, |
michael@0 | 33 | // so the rdf stuff differs |
michael@0 | 34 | var content = aContent.replace(/NC:succ/g,"NC:orig_succ"); |
michael@0 | 35 | content = content.replace(/NC:failCount/g,"NC:orig_failCount"); |
michael@0 | 36 | this.mSink.write(content, content.length); |
michael@0 | 37 | return aCount; |
michael@0 | 38 | }; |
michael@0 | 39 | var fp = doCreateRDFFP('Xalan results', |
michael@0 | 40 | nsIFilePicker.modeSave); |
michael@0 | 41 | var res = fp.show(); |
michael@0 | 42 | |
michael@0 | 43 | if (res == nsIFilePicker.returnOK || |
michael@0 | 44 | res == nsIFilePicker.returnReplace) { |
michael@0 | 45 | var serial = doCreate(kRDFXMLSerializerID, |
michael@0 | 46 | nsIRDFXMLSerializer); |
michael@0 | 47 | serial.init(view.mResultDS); |
michael@0 | 48 | serial.QueryInterface(nsIRDFXMLSource); |
michael@0 | 49 | var fl = fp.file; |
michael@0 | 50 | var fstream = doCreate(kFileOutStreamCID, |
michael@0 | 51 | nsIFileOutputStream); |
michael@0 | 52 | fstream.init(fl, 26, 420, 0); |
michael@0 | 53 | sink.mSink = fstream; |
michael@0 | 54 | serial.Serialize(sink); |
michael@0 | 55 | } |
michael@0 | 56 | break; |
michael@0 | 57 | case 'cmd_fl_import': |
michael@0 | 58 | var fp = doCreateRDFFP('Previous Xalan results', |
michael@0 | 59 | nsIFilePicker.modeLoad); |
michael@0 | 60 | var res = fp.show(); |
michael@0 | 61 | |
michael@0 | 62 | if (res == nsIFilePicker.returnOK) { |
michael@0 | 63 | var fl = fp.file; |
michael@0 | 64 | if (view.mPreviousResultDS) { |
michael@0 | 65 | view.database.RemoveDataSource(view.mPreviousResultDS); |
michael@0 | 66 | view.mPreviousResultDS = null; |
michael@0 | 67 | } |
michael@0 | 68 | view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec); |
michael@0 | 69 | view.database.AddDataSource(view.mPreviousResultDS); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | document.getElementById('obs_orig_success') |
michael@0 | 73 | .setAttribute('hidden','false'); |
michael@0 | 74 | break; |
michael@0 | 75 | default: |
michael@0 | 76 | alert('Unknown Command'+aCommand); |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | registerController(cmdFileController); |