Skip to content

Commit

Permalink
Restore delayed script execution.
Browse files Browse the repository at this point in the history
  • Loading branch information
arantius committed Jul 15, 2015
1 parent baa2762 commit 106fc36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 7 additions & 6 deletions content/framescript.js
Expand Up @@ -91,15 +91,18 @@ function createScriptFromObject(aObject) {


function injectDelayedScript(aMessage) {
// TODO: Make this work again.
var windowId = aMessage.data.windowId;
var windowMediator = Components
.classes['@mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator);
var win = windowMediator.getOuterWindowWithId(windowId);

console.log('injectDelayedScript; windowId='+windowId+'; win='+win+'\n');
// injectScripts([script], win);
if (!win) {
dump('Couldn\'t find window with (outer?) ID ' + windowId + '!\n');
} else {
var script = createScriptFromObject(aMessage.data.script);
injectScripts([script], win);
}
};


Expand Down Expand Up @@ -142,13 +145,11 @@ function runScripts(aRunWhen, aContentWin) {
var url = urlForWin(aContentWin);
if (!GM_util.isGreasemonkeyable(url)) return;

var windowId = GM_util.windowId(aContentWin);

var response = sendSyncMessage(
'greasemonkey:scripts-for-url', {
'url': url,
'when': aRunWhen,
'windowId': windowId
'windowId': GM_util.windowId(aContentWin, 'outer'),
});
if (!response || !response[0]) return;

Expand Down
8 changes: 6 additions & 2 deletions modules/util/windowId.js
Expand Up @@ -2,7 +2,7 @@ Components.utils.import('chrome://greasemonkey-modules/content/util.js');

var EXPORTED_SYMBOLS = ['windowId'];

function windowId(win) {
function windowId(win, which) {
try {
// Do not operate on chrome windows.
win.QueryInterface(Components.interfaces.nsIDOMChromeWindow);
Expand All @@ -25,7 +25,11 @@ function windowId(win) {
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var windowId;
try {
windowId = domWindowUtils.currentInnerWindowID;
if ('outer' == which) {
windowId = domWindowUtils.outerWindowID;
} else if (!which || 'inner' == which) {
windowId = domWindowUtils.currentInnerWindowID;
}
} catch (e) { }
if ('undefined' == typeof windowId) {
// Firefox <4.0 does not provide this, use the document instead.
Expand Down

0 comments on commit 106fc36

Please sign in to comment.