home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 November / PCWNOV08.iso / Software / Freeware / NoScript 1.7.7 / noscript-1.7.7-fx+mz+sm.xpi / chrome / noscript.jar / content / noscript / noscriptBM.js < prev    next >
Encoding:
JavaScript  |  2008-07-14  |  4.1 KB  |  122 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2.  
  3. NoScript - a Firefox extension for whitelist driven safe JavaScript execution
  4. Copyright (C) 2004-2008 Giorgio Maone - g.maone@informaction.com
  5.  
  6. Contributors: 
  7.   Hwasung Kim
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. ***** END LICENSE BLOCK *****/
  24.  
  25. var noscriptBM = {
  26.   openOneBookmarkOriginal: null,
  27.   openOneBookmark: function (aURI, aTargetBrowser, aDS) {
  28.     var ncNS = typeof(gNC_NS) == "undefined" ? ( typeof(NC_NS) == "undefined" ?
  29.       "http://home.netscape.com/NC-rdf#" : NC_NS ) : gNC_NS;
  30.     const url = BookmarksUtils.getProperty(aURI, ncNS+"URL", aDS);
  31.     
  32.     var openCallback = function(url) {
  33.       noscriptBM.openOneBookmarkOriginal.apply(BookmarksCommand, [aURI, aTargetBrowser, aDS]);
  34.     };
  35.   
  36.     if(!noscriptBM.handleBookmark(url, openCallback)) {
  37.       openCallback();
  38.     }
  39.   },
  40.   
  41.   handleURLBarCommandOriginal: null,
  42.   handleURLBarCommand: function() {
  43.     if(!(window.gURLBar && gURLBar.value))
  44.       return;
  45.    
  46.     var originalArguments = arguments;
  47.     callback = function() { noscriptBM.handleURLBarCommandOriginal.apply(window, originalArguments); };
  48.     
  49.     var shortcut = gURLBar.value;
  50.     var jsrx = /^\s*(?:data|javascript):/i;
  51.     var isJS = jsrx.test(shortcut);
  52.     var allowJS = noscriptUtil.service.getPref("allowURLBarJS", true);
  53.     
  54.     if (isJS && allowJS) {
  55.       if(noscriptUtil.service.executeJSURL(shortcut, callback)) return;
  56.     } else if (window.getShortcutOrURI && (shortcut.indexOf(" ") > 0  && !isJS || shortcut.indexOf(":") < 0)) {
  57.       var url = getShortcutOrURI(shortcut, {});
  58.       if(jsrx.test(url) && noscriptBM.handleBookmark(url, callback))
  59.         return;
  60.     }
  61.     
  62.     callback();
  63.   },
  64.  
  65.   handleBookmark: function(url, openCallback) {
  66.     return noscriptUtil.service.handleBookmark(url, openCallback);
  67.   },
  68.   
  69.   patchPlacesMethod: function(k, m) {
  70.     if(m in k) {
  71.       // Dirty eval hack due to Tab Mix Plus conflict: http://tmp.garyr.net/forum/viewtopic.php?t=8052
  72.       k[m] = eval(k[m].toSource()
  73.         .replace(/\b\w+\.checkURLSecurity\(/, 'noscriptBM.checkURLSecurity('))
  74.     }
  75.   },
  76.   
  77.   checkURLSecurity: function(node) {
  78.     var patch = arguments.callee;
  79.     if(!noscriptBM.placesUtils.checkURLSecurity(node)) return false;
  80.     if(patch._reentrant) return true;
  81.     try {
  82.       patch._reentrant = true;
  83.       const url = node.uri;
  84.       node = null;
  85.       var self = this;
  86.       return !noscriptBM.handleBookmark(url, function(url) {
  87.         patch.caller.apply(self, patch.caller.arguments);
  88.         self = null;
  89.       });
  90.     } finally {
  91.       patch._reentrant = false;
  92.     }
  93.   },
  94.   
  95.   onLoad: function(ev) {
  96.     ev.currentTarget.removeEventListener("load", arguments.callee, false);
  97.     if(!noscriptUtil.service) return;
  98.  
  99.     if(window.BookmarksCommand) { // patch bookmark clicks
  100.       noscriptBM.openOneBookmarkOriginal = BookmarksCommand.openOneBookmark;
  101.       BookmarksCommand.openOneBookmark = noscriptBM.openOneBookmark;
  102.     }
  103.     
  104.     if(window.handleURLBarCommand) { // patch URLBar for keyword-triggered bookmarklets
  105.       noscriptBM.handleURLBarCommandOriginal = window.handleURLBarCommand;
  106.       window.handleURLBarCommand = noscriptBM.handleURLBarCommand;
  107.     }
  108.     var pu = window.PlacesUIUtils || window.PlacesUtils || false;
  109.     if (typeof(pu) == "object") {
  110.       noscriptBM.placesUtils = pu;
  111.       window.setTimeout(function() {
  112.         var methods = ["openNodeIn", "openSelectedNodeWithEvent"];
  113.         for each (method in methods)
  114.           noscriptBM.patchPlacesMethod(pu, method);
  115.       }, 0);
  116.     }
  117.   }
  118. };
  119.  
  120. window.addEventListener("load", noscriptBM.onLoad, false);
  121.  
  122.