diff --git a/toolkit/devtools/webconsole/NetworkHelper.jsm b/toolkit/devtools/webconsole/NetworkHelper.jsm index a2dd3bb077c..853d4448325 100644 --- a/toolkit/devtools/webconsole/NetworkHelper.jsm +++ b/toolkit/devtools/webconsole/NetworkHelper.jsm @@ -212,10 +212,9 @@ var NetworkHelper = */ getWindowForRequest: function NH_getWindowForRequest(aRequest) { - let loadContext = this.getRequestLoadContext(aRequest); - if (loadContext) { - return loadContext.associatedWindow; - } + try { + return this.getRequestLoadContext(aRequest).associatedWindow; + } catch (ex) { } return null; }, @@ -227,18 +226,13 @@ var NetworkHelper = */ getRequestLoadContext: function NH_getRequestLoadContext(aRequest) { - if (aRequest && aRequest.notificationCallbacks) { - try { - return aRequest.notificationCallbacks.getInterface(Ci.nsILoadContext); - } catch (ex) { } - } + try { + return aRequest.notificationCallbacks.getInterface(Ci.nsILoadContext); + } catch (ex) { } - if (aRequest && aRequest.loadGroup - && aRequest.loadGroup.notificationCallbacks) { - try { - return aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext); - } catch (ex) { } - } + try { + return aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext); + } catch (ex) { } return null; }, diff --git a/toolkit/devtools/webconsole/WebConsoleUtils.jsm b/toolkit/devtools/webconsole/WebConsoleUtils.jsm index d057190c6b0..e936c3acb4b 100644 --- a/toolkit/devtools/webconsole/WebConsoleUtils.jsm +++ b/toolkit/devtools/webconsole/WebConsoleUtils.jsm @@ -2590,16 +2590,16 @@ _global.NetworkResponseListener = NetworkResponseListener; * location changes. * * @constructor - * @param object aBrowser - * The xul:browser for which we need to track location changes. + * @param object aWindow + * The window for which we need to track location changes. * @param object aOwner * The listener owner which needs to implement two methods: * - onFileActivity(aFileURI) * - onLocationChange(aState, aTabURI, aPageTitle) */ -function ConsoleProgressListener(aBrowser, aOwner) +function ConsoleProgressListener(aWindow, aOwner) { - this.browser = aBrowser; + this.window = aWindow; this.owner = aOwner; } @@ -2637,6 +2637,8 @@ ConsoleProgressListener.prototype = { */ _initialized: false, + _webProgress: null, + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), @@ -2650,8 +2652,13 @@ ConsoleProgressListener.prototype = { return; } + this._webProgress = this.window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIWebProgress); + this._webProgress.addProgressListener(this, + Ci.nsIWebProgress.NOTIFY_STATE_ALL); + this._initialized = true; - this.browser.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_ALL); }, /** @@ -2768,8 +2775,7 @@ ConsoleProgressListener.prototype = { let isWindow = aState & Ci.nsIWebProgressListener.STATE_IS_WINDOW; // Skip non-interesting states. - if (!isNetwork || !isWindow || - aProgress.DOMWindow != this.browser.contentWindow) { + if (!isNetwork || !isWindow || aProgress.DOMWindow != this.window) { return; } @@ -2777,9 +2783,8 @@ ConsoleProgressListener.prototype = { this.owner.onLocationChange("start", aRequest.URI.spec, ""); } else if (isStop) { - let window = this.browser.contentWindow; - this.owner.onLocationChange("stop", window.location.href, - window.document.title); + this.owner.onLocationChange("stop", this.window.location.href, + this.window.document.title); } }, @@ -2801,11 +2806,15 @@ ConsoleProgressListener.prototype = { this._fileActivity = false; this._locationChange = false; - if (this.browser.removeProgressListener) { - this.browser.removeProgressListener(this); + try { + this._webProgress.removeProgressListener(this); + } + catch (ex) { + // This can throw during browser shutdown. } - this.browser = null; + this._webProgress = null; + this.window = null; this.owner = null; }, }; diff --git a/toolkit/devtools/webconsole/dbg-webconsole-actors.js b/toolkit/devtools/webconsole/dbg-webconsole-actors.js index 19529438ccf..59885f65861 100644 --- a/toolkit/devtools/webconsole/dbg-webconsole-actors.js +++ b/toolkit/devtools/webconsole/dbg-webconsole-actors.js @@ -47,15 +47,20 @@ XPCOMUtils.defineLazyModuleGetter(this, "ConsoleAPIStorage", * @constructor * @param object aConnection * The connection to the client, DebuggerServerConnection. - * @param object [aTabActor] - * Optional, the parent tab actor. This must be an instance of - * BrowserTabActor. + * @param object [aParentActor] + * Optional, the parent actor. */ -function WebConsoleActor(aConnection, aTabActor) +function WebConsoleActor(aConnection, aParentActor) { this.conn = aConnection; - if (aTabActor instanceof BrowserTabActor) { - this._browser = aTabActor.browser; + + if (aParentActor instanceof BrowserTabActor && + aParentActor.browser instanceof Ci.nsIDOMWindow) { + this._window = aParentActor.browser; + } + else if (aParentActor instanceof BrowserTabActor && + aParentActor.browser instanceof Ci.nsIDOMElement) { + this._window = aParentActor.browser.contentWindow; } else { this._window = Services.wm.getMostRecentWindow("navigator:browser"); @@ -73,14 +78,6 @@ function WebConsoleActor(aConnection, aTabActor) WebConsoleActor.prototype = { - /** - * The xul:browser we work with. This is only available when the Web Console - * actor is a tab actor. - * @private - * @type nsIDOMElement - */ - _browser: null, - /** * Tells if this Web Console actor is a global actor or not. * @private @@ -137,7 +134,7 @@ WebConsoleActor.prototype = * The content window we work with. * @type nsIDOMWindow */ - get window() this._browser ? this._browser.contentWindow : this._window, + get window() this._window, _window: null, @@ -220,7 +217,7 @@ WebConsoleActor.prototype = this._objectActorsPool = null; this._networkEventActorsPool = null; this._sandboxLocation = this.sandbox = null; - this.conn = this._browser = this._window = null; + this.conn = this._window = null; }, /** @@ -332,26 +329,18 @@ WebConsoleActor.prototype = startedListeners.push(listener); break; case "FileActivity": - if (this._isGlobalActor) { - // The ConsoleProgressListener cannot listen for global events. - // See bug 798764. - break; - } if (!this.consoleProgressListener) { this.consoleProgressListener = - new ConsoleProgressListener(this._browser, this); + new ConsoleProgressListener(this.window, this); } this.consoleProgressListener.startMonitor(this.consoleProgressListener. MONITOR_FILE_ACTIVITY); startedListeners.push(listener); break; case "LocationChange": - if (this._isGlobalActor) { - break; - } if (!this.consoleProgressListener) { this.consoleProgressListener = - new ConsoleProgressListener(this._browser, this); + new ConsoleProgressListener(this.window, this); } this.consoleProgressListener.startMonitor(this.consoleProgressListener. MONITOR_LOCATION_CHANGE); diff --git a/toolkit/devtools/webconsole/test/Makefile.in b/toolkit/devtools/webconsole/test/Makefile.in index 8eab0267d87..75bba21a650 100644 --- a/toolkit/devtools/webconsole/test/Makefile.in +++ b/toolkit/devtools/webconsole/test/Makefile.in @@ -19,6 +19,7 @@ MOCHITEST_CHROME_FILES = \ test_object_actor.html \ test_network_get.html \ test_network_post.html \ + test_file_uri.html \ network_requests_iframe.html \ data.json \ common.js \ diff --git a/toolkit/devtools/webconsole/test/test_file_uri.html b/toolkit/devtools/webconsole/test/test_file_uri.html new file mode 100644 index 00000000000..0a8ae55a53a --- /dev/null +++ b/toolkit/devtools/webconsole/test/test_file_uri.html @@ -0,0 +1,97 @@ + + +
+ +Test for file activity tracking
+ + + +