Changeset 748

Show
Ignore:
Timestamp:
06/30/08 20:40:32 (5 months ago)
Author:
oyasu..@gmail.com
Message:

Fixes #108 by adding the @unwrap header and changing the default back to scripts run in an anonymous function wrapper in the GM sandbox, when it was not present on installation. (Also a small cleanup of the load sequence in the greasemonkey service.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/chrome/chromeFiles/content/config.js

    r721 r748  
    8888          script._resources.push(scriptResource); 
    8989          break; 
     90        case "Unwrap": 
     91          script._unwrap = true; 
     92          break; 
    9093        } 
    9194      } 
     
    149152      } 
    150153 
     154      if (scriptObj._unwrap) { 
     155        scriptNode.appendChild(doc.createTextNode("\n\t\t")); 
     156        scriptNode.appendChild(doc.createElement("Unwrap")); 
     157      } 
     158 
    151159      scriptNode.appendChild(doc.createTextNode("\n\t")); 
    152160 
     
    202210        } 
    203211 
    204         var match = result.match(/\/\/ \@(\S+)\s+([^\n]+)/); 
    205         if (match != null) { 
    206           switch (match[1]) { 
     212        var match = result.match(/\/\/ \@(\S+)(?:\s+([^\n]+))?/); 
     213        if (match === null) continue; 
     214 
     215        var header = match[1]; 
     216        var value = match[2]; 
     217        if (value) { // @header <value> 
     218          switch (header) { 
    207219            case "name": 
    208220            case "namespace": 
    209221            case "description": 
    210               script["_" + match[1]] = match[2]
     222              script["_" + header] = value
    211223              break; 
    212224            case "include": 
    213               script._includes.push(match[2]); 
     225              script._includes.push(value); 
    214226              break; 
    215227            case "exclude": 
    216               script._excludes.push(match[2]); 
     228              script._excludes.push(value); 
    217229              break; 
    218230            case "require": 
    219               var reqUri = ioservice.newURI(match[2], null, uri); 
     231              var reqUri = ioservice.newURI(value, null, uri); 
    220232              var scriptRequire = new ScriptRequire(script); 
    221233              scriptRequire._downloadURL = reqUri.spec; 
     
    223235              break; 
    224236            case "resource": 
    225               var res = match[2].match(/(\S+)\s+(.*)/); 
     237              var res = value.match(/(\S+)\s+(.*)/); 
    226238              if (res === null) { 
    227239                // NOTE: Unlocalized strings 
    228240                throw new Error("Invalid syntax for @resource declaration '" + 
    229                                 match[2] + "'. Resources are declared like: " + 
     241                                value + "'. Resources are declared like: " + 
    230242                                "@resource <name> <url>."); 
    231243              } 
     
    245257              scriptResource._downloadURL = resUri.spec; 
    246258              script._resources.push(scriptResource); 
     259              break; 
     260          } 
     261        } else { // plain @header 
     262          switch (header) { 
     263            case "unwrap": 
     264              script._unwrap = true; 
    247265              break; 
    248266          } 
     
    416434  this._requires = []; 
    417435  this._resources = []; 
     436  this._unwrap = false; 
    418437} 
    419438 
     
    444463  get requires() { return this._requires.concat(); }, 
    445464  get resources() { return this._resources.concat(); }, 
     465  get unwrap() { return this._unwrap; }, 
    446466 
    447467  get _file() { 
  • trunk/src/components/greasemonkey.js

    r745 r748  
    126126 
    127127  startup: function() { 
    128     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    129       .getService(Ci.mozIJSSubScriptLoader) 
    130       .loadSubScript("chrome://global/content/XPCNativeWrapper.js"); 
    131  
    132     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    133       .getService(Ci.mozIJSSubScriptLoader) 
    134       .loadSubScript("chrome://greasemonkey/content/prefmanager.js"); 
    135  
    136     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    137       .getService(Ci.mozIJSSubScriptLoader) 
    138       .loadSubScript("chrome://greasemonkey/content/utils.js"); 
    139  
    140     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    141       .getService(Ci.mozIJSSubScriptLoader) 
    142       .loadSubScript("chrome://greasemonkey/content/config.js"); 
    143  
    144     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    145       .getService(Ci.mozIJSSubScriptLoader) 
    146       .loadSubScript("chrome://greasemonkey/content/convert2RegExp.js"); 
    147  
    148     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    149       .getService(Ci.mozIJSSubScriptLoader) 
    150       .loadSubScript("chrome://greasemonkey/content/miscapis.js"); 
    151  
    152     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    153       .getService(Ci.mozIJSSubScriptLoader) 
    154       .loadSubScript("chrome://greasemonkey/content/xmlhttprequester.js"); 
    155  
    156     Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    157       .getService(Ci.mozIJSSubScriptLoader) 
    158       .loadSubScript("chrome://greasemonkey/content/updater.js"); 
    159  
     128    function load(urls) { 
     129      var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] 
     130        .getService(Ci.mozIJSSubScriptLoader); 
     131      for (var i = 0; i < arguments.length; i++) 
     132        loader.loadSubScript(arguments[i]); 
     133    } 
     134   
     135    load("chrome://global/content/XPCNativeWrapper.js", 
     136         "chrome://greasemonkey/content/prefmanager.js", 
     137         "chrome://greasemonkey/content/utils.js", 
     138         "chrome://greasemonkey/content/config.js", 
     139         "chrome://greasemonkey/content/convert2RegExp.js", 
     140         "chrome://greasemonkey/content/miscapis.js", 
     141         "chrome://greasemonkey/content/xmlhttprequester.js", 
     142         "chrome://greasemonkey/content/updater.js"); 
    160143    //loggify(this, "GM_GreasemonkeyService"); 
    161144  }, 
     
    310293                         contents + 
    311294                         "\n"; 
    312       if (!this.evalInSandbox(scriptSrc, url, sandbox, script)) 
     295      if (!script.unwrap) 
     296        scriptSrc = "(function(){"+ scriptSrc +"})()"; 
     297      if (!this.evalInSandbox(scriptSrc, url, sandbox, script) && script.unwrap) 
    313298        this.evalInSandbox("(function(){"+ scriptSrc +"})()", 
    314                            url, sandbox, script); 
     299                           url, sandbox, script); // wrap anyway on early return 
    315300    } 
    316301  },