Changeset 626

Show
Ignore:
Timestamp:
01/19/08 14:26:38 (11 months ago)
Author:
boo..@youngpup.net
Message:

Update to simplify and tighten Anthony's unsafeWindow patch. Moving GM_apiLeak
into greasemonkey.js allows us to restrict to just one file:// URL and all
chrome:// URLs.

Files:

Legend:

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

    r605 r626  
    2020GM_MenuCommander.prototype.registerMenuCommand = 
    2121  function(commandName, commandFunc, accelKey, accelModifiers, accessKey) { 
    22     GM_apiLeakCheck(); 
    23  
    2422    GM_log("> GM_MenuCommander.registerMenuCommand"); 
    2523 
  • trunk/src/chrome/chromeFiles/content/utils.js

    r611 r626  
    66var GM_consoleService = Components.classes["@mozilla.org/consoleservice;1"] 
    77                        .getService(Components.interfaces.nsIConsoleService); 
    8  
    9 function GM_apiLeakCheck() { 
    10   var stack = Components.stack; 
    11  
    12   do { 
    13     if (2 == stack.language) { 
    14       if ('file' != stack.filename.substr(0, 4) && 
    15           'chrome' != stack.filename.substr(0, 6)) { 
    16         throw new Error("Greasemonkey access violation"); 
    17       } 
    18     } 
    19  
    20     stack = stack.caller; 
    21   } while (stack); 
    22 }; 
    238 
    249function GM_isDef(thing) { 
  • trunk/src/components/greasemonkey.js

    r624 r626  
    1313    .getService(Ci.nsIPromptService) 
    1414    .alert(null, "Greasemonkey alert", msg); 
     15}; 
     16 
     17// 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. 
     20function GM_apiLeakCheck() { 
     21  var stack = Components.stack; 
     22  var gmSvcFilename = stack.filename; 
     23 
     24  do { 
     25    // Valid stack frames for GM api calls are: native and js when coming from 
     26    // chrome:// URLs and the greasemonkey.js component's file:// URL. 
     27    if (2 == stack.language) { 
     28      if ('chrome' != stack.filename.substr(0, 6) && 
     29          gmSvcFilename != stack.filename) { 
     30        throw new Error("Greasemonkey access violation"); 
     31      } 
     32    } 
     33 
     34    stack = stack.caller; 
     35  } while (stack); 
    1536}; 
    1637 
     
    314335  registerMenuCommand: function(unsafeContentWin, commandName, commandFunc, 
    315336                                accelKey, accelModifiers, accessKey) { 
     337    GM_apiLeakCheck(); 
     338 
    316339    var command = {name: commandName, 
    317340                   accelKey: accelKey,