PK 6f, q q install.js/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is useragent toolbar. * * The Initial Developer of the Original Code is David Illsley. * Portions created by the Initial Developer are Copyright (C) 2001 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Andy Edmonds * David Illsley * Pavol Vaskovic * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ initInstall("Referer Toolbar", "/mozdev/refspoof", "0.4.0"); mgDir = getFolder("Chrome","refspoof"); setPackageFolder(mgDir); var err = addDirectory("refspoof"); if ( err == SUCCESS ) { registerChrome(CONTENT | DELAYED_CHROME, getFolder(mgDir, "content")); err = performInstall(); if ( err == SUCCESS ) { alert("The Referer Toolbar have been succesfully installed. \n" +"Please restart your browser to continue."); } else { alert("performInstall() failed. \n" +"_____________________________\nError code:" + err); cancelInstall(err); } } else { alert("Failed to create directory. \n" +"You probably don't have appropriate permissions \n" +"(write access to mozilla/chrome directory). \n" +"_____________________________\nError code:" + err); cancelInstall(err); } PK pk, refspoof/PK m,refspoof/content/PK ,eI$$refspoof/content/contents.rdf chrome://refspoof/content/refspoof_overlay.xul PK -,refspoof/content/CVS/PK -,refspoof/content/CVS/Entries/contents.rdf/1.1/Sat May 25 15:00:44 2002// /spoof.rdf/1.1/Sat May 25 14:48:54 2002// /refspoof_overlay.js/1.3/Thu Jul 4 16:15:39 2002// /refspoof_overlay.xul/1.3/Thu Jul 4 14:43:13 2002// D PK xk,^@+##refspoof/content/CVS/Repositoryrefspoof/src/xpi/refspoof/content PK xk,refspoof/content/CVS/Root:pserver:boyd@mozdev.org:/cvs PK xc,"rB33$refspoof/content/refspoof_overlay.js /* **** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is refspoof for Mozilla. * * The Initial Developer of the Original Code is Boyd Ebsworthy. * Portions created by the Initial Developer are Copyright (C) 2001 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ function RefspoofToolbar () { //bookmark this.gRDF = null; this.gRDFC = null; this.gRDFU = null; this.gsource = null; this.gspoof_rdf = null; //preferences this.gpref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService) this.gpref = this.gpref.getBranch(""); this.gPREF_STRING = 'refspoof.spooffile'; this.gDEFAULT_SPOOF_RDF = 'file:///c:/spoof.rdf'; //init stuff this.init_menu_ds = false; } RefspoofToolbar.prototype = { /* dtor */ onDestroy : function () { }, /******************************************************************************************** * menu datasource initialisation */ initListDS : function () { //only init once. if(!this.init_menu_ds) { this.initDataSource(); if(this.gsource) { var popup = document.getElementById('spoofmark_list'); if(popup) { popup.database.AddDataSource(this.gsource); popup.builder.rebuild(); this.init_menu_ds = true; } } } return this.init_menu_ds; }, /****************************************************************************************** * spoof() * called by spoof button in overlay */ spoof : function () { var URI = document.getElementById('urlbar').value; //from navigator.xul this.openURI(URI, this.getReferer()); }, /***************************************************************************************** * check the users settings for "open in tab" then calls reallyOpenURI with the * appropriate parameters. */ openURI : function (URI, refURI) { this.reallyOpenURI(URI, refURI, document.getElementById('open_in_tab').checked); }, /***************************************************************************************** * reallyOpenURI() - for lack of a better name. * URI = destination url * refURI = referer url * toTab = true : open destination in a new tab. false : use current browser. */ reallyOpenURI : function (URI , refURI, toTab){ if(!URI) return; if(!refURI) { alert("Invalid referer"); return; } /* clean up the ! */ URI = this.cleanURI(URI); refURI = this.cleanURI(refURI); var browser = getBrowser(); var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); try { var refnsiURI = ioService.newURI(refURI, null, null); } catch(e) { // it isn't a valid url alert("caught an exception while converting the uri \n\"" + e + "\""); return; } /** the loadURI* functions take a string for the destination * and an [xpconnect wrapped nsIURi] for the referer - kinda dumb :) */ if(toTab) { var tab = browser.addTab(URI, refnsiURI); if (!prefRoot.getBoolPref("browser.tabs.loadInBackground")) browser.selectedTab = tab; } else { browser.loadURI(URI, refnsiURI); } }, /***************************************************************************************** * ref=url checkbox action handler **/ refURLCheckBoxHandler : function () { this.enableRefererBar(!document.getElementById('ref_is_url').checked); }, enableRefererBar : function (bool) { if(bool) { document.getElementById('ref_is_url').checked = false; document.getElementById('referer-text').removeAttribute("disabled"); } else { document.getElementById('ref_is_url').checked = true; document.getElementById('referer-text').setAttribute("disabled", "true"); } }, /***************************************************************************************** * context menu handler function * gContextMenu info in : contentAreaContextOverlay.xul and nsContextMenu.js * see contentAreaUtils.js for usefull stuff. **/ contextMenuListener : function() { if(gContextMenu) { gContextMenu.showItem( "context-spoof", gContextMenu.isTextSelected || gContextMenu.onLink); gContextMenu.showItem( "context-spoof-sep", gContextMenu.isTextSelected || gContextMenu.onLink); } }, // get data under the cursor, selected text then link. getContextData : function () { var data = ''; if(gContextMenu.isTextSelected) { data = gContextMenu.searchSelected(); } else if(gContextMenu.onLink) { data = gContextMenu.linkURL(); } else { alert('nothing usefull here'); } return data; }, // open as ref = url the context menu target //openContextDataAsURI openContextDataAsURI : function() { var URI = this.getContextData(); if(URI != '') { this.enableRefererBar(false); this.openURI(URI, URI); } }, // set the urlbar to context menu target setContextDataToURLBar : function () { var URI = this.getContextData(); if(URI != '') { document.getElementById('urlbar').value = URI; } }, // set the referer bar to context menu target setContextDataToRefererBar : function () { var URI = this.getContextData(); if(URI != '') { this.enableRefererBar(true); document.getElementById('referer-text').value = URI; } }, /***************************************************************************************** * Preferences function **/ savePrefs : function () { this.gpref.setCharPref(this.gPREF_STRING, this.gspoof_rdf ); }, getSpoofFile : function () { if(!this.gspoof_rdf) { try { this.gspoof_rdf = this.gpref.getCharPref(this.gPREF_STRING); } catch (e) { //use default prefs this.gspoof_rdf = this.gDEFAULT_SPOOF_RDF; this.savePrefs(); } } return this.gspoof_rdf; }, /***************************************************************************************** * bookmark functions **/ getReferer : function () { var refisurl = document.getElementById('ref_is_url').checked; if(refisurl){ return document.getElementById('urlbar').value; } else { return document.getElementById('referer-text').value; } }, storeHandler : function(){ var URI = document.getElementById('urlbar').value; if(!URI) return; this.storeSpoof(URI, this.getReferer()); }, listItemHandler : function (menuItem) { var URI = menuItem.getAttribute("label"); var referer = menuItem.getAttribute("referer"); this.openURI(URI , referer); }, /* special greets to a special site removes '!' from a URL */ /* stripBang : function(URI) { URI = URI.toString(); URI = URI.replace(/!/g, ""); if(0) { var index = URI.indexOf("!"); //FIXME: regexps are better. :) while(index > 0) { fixedURI = URI.substring(0,index); URI = fixedURI + URI.substring(index+1,URI.length); index = URI.indexOf("!"); } } return URI; }, */ cleanURI : function (URI) { //strip the bang URI = URI.toString(); URI = URI.replace(/!/g, ""); return URI; }, initDataSource : function () { /* get the rdf file */ var rdf = this.getSpoofFile(); if(!rdf) { alert("Invalid RDF File, unable to store bookmark. check your preferences."); return; } if (!this.gRDF) { this.gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); } if (!this.gsource){ this.gsource = this.gRDF.GetDataSource(rdf); if (!this.gsource) { alert("Unable to get datasource.\nEnsure file is valid.\n"); return; } } }, /** add a spoofmark to the rdf file V2. stolen from sessionHistoryUI.js - WORKiNG for the first time at 25/05/2002 4:49AM w00t!! - wish i had better doc... - note to self, moz fails/refuse to write in RDF file located in the chrome directory. ==> updated */ storeSpoof : function (newURI, newReferer) { if(!newURI) return; /* clean up the ! */ newURI = this.cleanURI(newURI); newReferer = this.cleanURI(newReferer); this.initDataSource(); if (this.gsource) { if (!this.gRDFC) { this.gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils); } try { var entries = this.gRDFC.MakeSeq(this.gsource, this.gRDF.GetResource("SP:spoof")); if (!entries) { alert("!entries : unable to make a sequence for spoof.\nEnsure if file is valid"); return; } //create a new node var newnode = this.gRDF.GetAnonymousResource(); //get a random id.. //store URL var fieldprop = this.gRDF.GetResource("http://www.spoof.com/SP-rdf#URL"); var newvalue = this.gRDF.GetLiteral(newURI); this.gsource.Assert(newnode, fieldprop, newvalue, true); //store referer var fieldprop = this.gRDF.GetResource("http://www.spoof.com/SP-rdf#Referer"); var newvalue = this.gRDF.GetLiteral(newReferer); this.gsource.Assert(newnode, fieldprop, newvalue, true); // Insert it to the beginning of the list. entries.InsertElementAt(newnode, 1, true); // try to flush datasource... this.gsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); } catch(e) { alert("storeSpoof got an E : " + e); } } }, }; const refspoofToolbar = new RefspoofToolbar; /*************************************************************************************************** * "friend" function */ function refspoof_documentLoadHandler () { //get event for the contextual menu.. so i can "be contextual" too. var contextMenu = document.getElementById('contentAreaContextMenu'); if(contextMenu) { contextMenu.addEventListener ( "popupshowing" , refspoofToolbar.contextMenuListener , false ); } if(refspoofToolbar.initListDS()) { //XXX DOESN'T REMOVE THE LISTENER document.removeEventListener("load", refspoofToolbar.documentLoadHandler, true); } } function myretrieveURLFromData (aData, flavour) { switch (flavour) { //XXX : for some reason when plain text is dragged from //the content area, the flavour is set a text/x-moz-url //i don't know how to differentiate an url from a text drag. case "text/unicode": case "text/x-moz-url": var data = aData.toString(); //remove leading useless char data = data.replace(/^(\n|\r|\t|\s)+/g, ""); //remove trailing useless char data = data.replace(/(\n|\r|\t|\s)+$/g, ""); //extract url from possible valid x-moz-uri var separator = data.indexOf("\n"); if (separator != -1) data = data.substr(0, separator); return data; case "application/x-moz-file": var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); return ioService.getURLSpecFromFile(aData); } return null; } /***** DnD test *****/ var btDragObserver = { //onDragStart: function (aEvent, aXferData, aDragAction) { //}, //canHandleMultipleItems: true, onDrop: function (aEvent, aXferData, aDragSession) { var url = myretrieveURLFromData(aXferData.data, aXferData.flavour.contentType); if(url) { refspoofToolbar.enableRefererBar(false); refspoofToolbar.openURI(url, url); } }, onDragOver: function (aEvent, aFlavour, aDragSession) { var statusTextFld = document.getElementById("statusbar-display"); //statusTextFld.label = gNavigatorBundle.getString("droponhomebutton"); statusTextFld.label = "Drop text or link here to spoof it."; aDragSession.dragAction = Components.interfaces.nsIDragService.DRAGDROP_ACTION_LINK; }, onDragExit: function (aEvent, aDragSession) { var statusTextFld = document.getElementById("statusbar-display"); statusTextFld.label = ""; }, getSupportedFlavours: function () { var flavourSet = new FlavourSet(); flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); flavourSet.appendFlavour("text/x-moz-url"); flavourSet.appendFlavour("text/unicode"); return flavourSet; } }PK pc,➰zz%refspoof/content/refspoof_overlay.xul PK ,eиrefspoof/content/spoof.rdf PK xk, refspoof/CVS/PK xk,hrefspoof/CVS/EntriesD/content//// PK pk,v>refspoof/CVS/Repositoryrefspoof/src/xpi/refspoof PK pk,refspoof/CVS/Root:pserver:boyd@mozdev.org:/cvs PK 6f, q q install.jsPK pk, A refspoof/PK m,A refspoof/content/PK ,eI$$! refspoof/content/contents.rdfPK -,ANrefspoof/content/CVS/PK -, refspoof/content/CVS/EntriesPK xk,^@+## refspoof/content/CVS/RepositoryPK xk, refspoof/content/CVS/RootPK xc,"rB33$ 8refspoof/content/refspoof_overlay.jsPK pc,➰zz% CDrefspoof/content/refspoof_overlay.xulPK ,eи![refspoof/content/spoof.rdfPK xk, A\refspoof/CVS/PK xk,h ]refspoof/CVS/EntriesPK pk,v> \]refspoof/CVS/RepositoryPK pk, ]refspoof/CVS/RootPK]