Changeset 628

Show
Ignore:
Timestamp:
01/19/08 15:44:21 (11 months ago)
Author:
boo..@youngpup.net
Message:

Per anthony's suggestion, don't throw in GM_apiLeakCheck to help out scripts
which might hit this accidentally. Instead we log an error to the console but
execution continues without the API.

Also, added more descriptive error messages.

Files:

Legend:

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

    r612 r628  
    88 
    99GM_ScriptStorage.prototype.setValue = function(name, val) { 
    10   GM_apiLeakCheck(); 
     10  if (!GM_apiLeakCheck("GM_setValue")) { 
     11    return; 
     12  } 
    1113 
    1214  this.prefMan.setValue(name, val); 
     
    1416 
    1517GM_ScriptStorage.prototype.getValue = function(name, defVal) { 
    16   GM_apiLeakCheck(); 
     18  if (!GM_apiLeakCheck("GM_getValue")) { 
     19    return; 
     20  } 
    1721 
    1822  return this.prefMan.getValue(name, defVal); 
     
    2428 
    2529GM_Resources.prototype.getResourceURL = function(name) { 
    26   GM_apiLeakCheck(); 
     30  if (!GM_apiLeakCheck("GM_getResourceURL")) { 
     31    return; 
     32  } 
    2733 
    2834  var dep = this.getDep_(name); 
     
    4652 
    4753GM_Resources.prototype.getResourceText = function(name) { 
    48   GM_apiLeakCheck(); 
     54  if (!GM_apiLeakCheck("GM_getResourceText")) { 
     55    return; 
     56  } 
    4957 
    5058  var dep = this.getDep_(name); 
     
    7381 
    7482GM_ScriptLogger.prototype.log = function(message) { 
    75   GM_apiLeakCheck(); 
     83  if (!GM_apiLeakCheck("GM_log")) { 
     84    return; 
     85  } 
    7686 
    7787  GM_log(this.prefix + message, true); 
  • trunk/src/chrome/chromeFiles/content/xmlhttprequester.js

    r605 r628  
    1313// text/xml and we can't support that 
    1414GM_xmlhttpRequester.prototype.contentStartRequest = function(details) { 
    15   GM_apiLeakCheck(); 
     15  if (!GM_apiLeakCheck("GM_xmlhttpRequest")) { 
     16    return; 
     17  } 
    1618 
    1719  // don't actually need the timer functionality, but this pops it 
  • trunk/src/components/greasemonkey.js

    r627 r628  
    88const appSvc = Cc["@mozilla.org/appshell/appShellService;1"] 
    99                 .getService(Ci.nsIAppShellService); 
     10 
     11const gmSvcFilename = Components.stack.filename; 
    1012 
    1113function alert(msg) { 
     
    1618 
    1719// Examines the stack to determine if an API should be callable. 
    18 // NOTE: This function's mechanism relies on the fact that it is implemented 
    19 // in this file. 
    20 function GM_apiLeakCheck() { 
     20function GM_apiLeakCheck(apiName) { 
    2121  var stack = Components.stack; 
    22   var gmSvcFilename = stack.filename; 
    2322 
    2423  do { 
     
    2827      if ('chrome' != stack.filename.substr(0, 6) && 
    2928          gmSvcFilename != stack.filename) { 
    30         throw new Error("Greasemonkey access violation"); 
     29        GM_logError(new Error("Greasemonkey access violation: unsafeWindow " + 
     30                    "cannot call " + apiName + ".")); 
     31        return false; 
    3132      } 
    3233    } 
     
    3435    stack = stack.caller; 
    3536  } while (stack); 
     37 
     38  return true; 
    3639}; 
    3740 
     
    335338  registerMenuCommand: function(unsafeContentWin, commandName, commandFunc, 
    336339                                accelKey, accelModifiers, accessKey) { 
    337     GM_apiLeakCheck(); 
     340    if (!GM_apiLeakCheck("GM_registerMenuCommand")) { 
     341      return; 
     342    } 
    338343 
    339344    var command = {name: commandName, 
     
    350355 
    351356  openInTab: function(unsafeContentWin, url) { 
    352     GM_apiLeakCheck(); 
     357    if (!GM_apiLeakCheck("GM_openInTab")) { 
     358      return; 
     359    } 
    353360 
    354361    var unsafeTop = new XPCNativeWrapper(unsafeContentWin, "top").top;