# HG changeset patch # User Atul Varma # Date 1211351049 25200 # Node ID 5c35e18a9d1a446b1202e88d72739196ddf00533 # Parent 9c96d374aaae2f5fad3c7afb81b550d28c22d738 Added a modified version of beret.js from gnusto (originally at src/xpcom/beret/beret.js in the gnusto source tree), because this file contains code to load quetzal save files (gnusto-engine.js contains code to save quetzal files). Implemented basic save/restore functionality; right now we're just using DOM storage in Firefox 2/3. diff -r 9c96d374aaae -r 5c35e18a9d1a base64.js --- a/base64.js Sun May 18 23:47:15 2008 -0700 +++ b/base64.js Tue May 20 23:24:09 2008 -0700 @@ -7,6 +7,28 @@ var base64_tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +function encode_base64(data) { + var out = "", c1, c2, c3, e1, e2, e3, e4; + for (var i = 0; i < data.length; ) { + c1 = data[i++]; + c2 = data[i++]; + c3 = data[i++]; + e1 = c1 >> 2; + e2 = ((c1 & 3) << 4) + (c2 >> 4); + e3 = ((c2 & 15) << 2) + (c3 >> 6); + e4 = c3 & 63; + if (isNaN(c2)) + e3 = e4 = 64; + else if (isNaN(c3)) + e4 = 64; + out += (base64_tab.charAt(e1) + + base64_tab.charAt(e2) + + base64_tab.charAt(e3) + + base64_tab.charAt(e4)); + } + return out; +} + function decode_base64(data) { var out = [], c1, c2, c3, e1, e2, e3, e4; for (var i = 0; i < data.length; ) { diff -r 9c96d374aaae -r 5c35e18a9d1a beret.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beret.js Tue May 20 23:24:09 2008 -0700 @@ -0,0 +1,207 @@ +// -*- Mode: Java; tab-width: 2; -*- +// $Id: beret.js,v 1.22 2006/10/24 16:11:09 naltrexone42 Exp $ +// +// Copyright (c) 2003 Thomas Thurman +// thomas@thurman.org.uk +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of version 2 of the GNU General Public License +// as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have be able to view the GNU General Public License at +// http://www.gnu.org/copyleft/gpl.html ; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +//////////////////////////////////////////////////////////////// +// +// iff_parse +// +// Parses an IFF file entirely contained in the array |s|. +// The return value is a list. The first element is the form type +// of the file; subsequent elements represent chunks. Each chunk is +// represented by a list whose first element is the chunk type, +// whose second element is the starting offset of the data within +// the array, and whose third element is the length. +// +function iff_parse(s) { + + function num_from(offset) { + return s[offset]<<24 | s[offset+1]<<16 | s[offset+2]<<8 | s[offset+3]; + } + + function string_from(offset) { + return String.fromCharCode(s[offset]) + + String.fromCharCode(s[offset+1]) + + String.fromCharCode(s[offset+2]) + + String.fromCharCode(s[offset+3]); + } + + var result = [string_from(8)]; + + var cursor = 12; + + while (cursor < s.length) { + var chunk = [string_from(cursor)]; + var chunk_length = num_from(cursor+4); + + if (chunk_length<0 || (chunk_length+cursor)>s.length) { + // fixme: do something sensible here + throw new Error('WEEBLE, panic\n'); + return []; + } + + chunk.push(cursor+8); + chunk.push(chunk_length); + + result.push(chunk); + + cursor += 8 + chunk_length; + if (chunk_length % 2) cursor++; + } + + return result; +} + +function Beret(engine) { + this.m_engine = engine; +} + +Beret.prototype = { + + //////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////// + // // + // PUBLIC METHODS // + // // + // Documentation for these methods is in the IDL. // + // // + //////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////// + + load: function b_load(content) { + + function magic_number_is_string(str) { + for (var ij=0; ij + diff -r 9c96d374aaae -r 5c35e18a9d1a web-zui.js --- a/web-zui.js Sun May 18 23:47:15 2008 -0700 +++ b/web-zui.js Tue May 20 23:24:09 2008 -0700 @@ -187,6 +187,26 @@ self._currentCallback = callback; }, + onSave: function(data) { + // TODO: Attempt to use other forms of local storage + // (e.g. Google Gears, HTML 5 database storage, etc) if + // available; if none are available, we should return false. + + globalStorage[location.hostname]['saveData'] = encode_base64(data); + return true; + }, + + onRestore: function() { + // TODO: Attempt to use other forms of local storage if + // available; if none are available, we should return null. + + var saveData = globalStorage[location.hostname]['saveData']; + if (saveData) + return decode_base64(saveData.value); + else + return null; + }, + onQuit: function() { self._finalize(); },