diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 19:59:38 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 19:59:38 +0000 |
commit | d843cd31b00d652198d49b099074db6db940833d (patch) | |
tree | 50ecb9d11882ff7f48ac50cc8d94826d8b0fa98f /ceee | |
parent | 5e073c78e35b9553e0c85b5634a902915b04b756 (diff) | |
download | chromium_src-d843cd31b00d652198d49b099074db6db940833d.zip chromium_src-d843cd31b00d652198d49b099074db6db940833d.tar.gz chromium_src-d843cd31b00d652198d49b099074db6db940833d.tar.bz2 |
The FF CEEE does not inject content scripts into the content window
at initial start up if the page loaded contains iframes.
The problem is that a hash map was being used to track the scripts to run,
and the window object was used as a key. The window of iframes was mapping
to the same entry in the map as the top level window, causing some scripts
to be lost and not run.
The code now puts all scripts to run in an array. As it runs each one, it
sees if the scripts have already been run in the given window. If so, they
are not run again.
BUG=0
TEST=make sure that content scripts are run for the first page loaded into
chrome frame.
Review URL: http://codereview.chromium.org/5188007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/firefox/content/overlay.js | 42 | ||||
-rw-r--r-- | ceee/firefox/content/userscript_api.js | 9 |
2 files changed, 24 insertions, 27 deletions
diff --git a/ceee/firefox/content/overlay.js b/ceee/firefox/content/overlay.js index 23dbd8e..bba7a47f 100644 --- a/ceee/firefox/content/overlay.js +++ b/ceee/firefox/content/overlay.js @@ -113,12 +113,13 @@ function CEEE_Class() { this.userscriptsModule_ = null; /** - * Collection of functions to run once the extensions have been fully - * initialized. Maps a content window to a map of description-to-function. - * @type {Object} + * Array of functions to run once the extensions have been fully + * initialized. Each element of the array is itself an array with three + * elements: a content window, a string description, and the function to call. + * @type {Array.<{win: Object, desc: string, func: function()}>} * @private */ - this.runWhenExtensionsInited_ = {}; + this.runWhenExtensionsInited_ = []; }; /** @@ -248,12 +249,7 @@ CEEE_Class.prototype.onLoad_ = function() { */ CEEE_Class.prototype.runWhenExtensionsInited = function(w, desc, f) { this.logInfo('Deferring "' + desc + '" for window=' + w.location.href); - var map = this.runWhenExtensionsInited_[w]; - if (!map) { - map = {}; - this.runWhenExtensionsInited_[w] = map; - } - map[desc] = f; + this.runWhenExtensionsInited_.push({win: w, desc: desc, func: f}); }; /** @@ -262,6 +258,7 @@ CEEE_Class.prototype.runWhenExtensionsInited = function(w, desc, f) { * File objects) of extensions loaded. */ CEEE_Class.prototype.initExtensions = function(extensions) { + this.logInfo('initExtensions starting'); // Initialize only once. if (!this.toolstripUrl_ && extensions.length > 0) { var baseDir = Components.classes['@mozilla.org/file/local;1'] @@ -276,25 +273,18 @@ CEEE_Class.prototype.initExtensions = function(extensions) { } else { this.toolstripDir_ = baseDir; - // Inject user scripts for pages loaded before we knew which - // extensions were installed. Make sure to delete all array elements - // and clear the array so that we don't leak references that may be - // held by the closures in the array. - for (var w in this.runWhenExtensionsInited_) { - var map = this.runWhenExtensionsInited_[w]; - for (var desc in map) { - var windowName = (w && w.location && w.location.href) || '?'; - this.logInfo('Running "' + desc + '" in window=' + windowName); - map[desc](); - delete map[desc]; - } - delete this.runWhenExtensionsInited_[w]; + for (var i = 0; i < this.runWhenExtensionsInited_.length; ++i) { + var obj = this.runWhenExtensionsInited_[i]; + var w = obj.win; + var windowName = (w && w.location && w.location.href) || '?'; + this.logInfo('Running "' + obj.desc + '" in window=' + windowName); + obj.func(); } - - this.runWhenExtensionsInited_ = {}; + this.runWhenExtensionsInited_ = []; } } -} + this.logInfo('initExtensions done'); +}; /** * Create the ChromeFrame element that goes into the toolstrip. diff --git a/ceee/firefox/content/userscript_api.js b/ceee/firefox/content/userscript_api.js index 87522d9..e5a760a 100644 --- a/ceee/firefox/content/userscript_api.js +++ b/ceee/firefox/content/userscript_api.js @@ -678,7 +678,14 @@ UserScriptManager.prototype.runUserScripts = function(w) { // these scripts in memory, then we will need a Chrome extension autoupdate // automation notification. - ceee.logInfo('runUserScripts: starting'); + // If there is already a sandbox for this window, then it means the user + // scripts have already been run. Don't need to run them again. + if (w.ceeeSandbox) { + ceee.logInfo('runUserScripts: already ran url=' + w.location.toString()); + return; + } + + ceee.logInfo('runUserScripts: starting for url=' + w.location.toString()); var s = prepareSandbox(w); // Run each user script whose pattern matches the URL of content window. |