mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 798764 - Global console: add support for a global ConsoleProgressListener; r=past
This commit is contained in:
parent
101c6d3fe1
commit
44f1fefdae
@ -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;
|
||||
},
|
||||
|
@ -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;
|
||||
},
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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 \
|
||||
|
97
toolkit/devtools/webconsole/test/test_file_uri.html
Normal file
97
toolkit/devtools/webconsole/test/test_file_uri.html
Normal file
@ -0,0 +1,97 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Test for file activity tracking</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript;version=1.8" src="common.js"></script>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
</head>
|
||||
<body>
|
||||
<p>Test for file activity tracking</p>
|
||||
|
||||
<script class="testbody" type="text/javascript;version=1.8">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
|
||||
let gState;
|
||||
let gTmpFile;
|
||||
|
||||
function doFileActivity()
|
||||
{
|
||||
info("doFileActivity");
|
||||
let fileContent = "<p>hello world from bug 798764";
|
||||
|
||||
gTmpFile = FileUtils.getFile("TmpD", ["bug798764.html"]);
|
||||
gTmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
|
||||
|
||||
let fout = FileUtils.openSafeFileOutputStream(gTmpFile,
|
||||
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE);
|
||||
|
||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
let fileContentStream = converter.convertToInputStream(fileContent);
|
||||
|
||||
NetUtil.asyncCopy(fileContentStream, fout, addIframe);
|
||||
}
|
||||
|
||||
function addIframe(aStatus)
|
||||
{
|
||||
ok(Components.isSuccessCode(aStatus),
|
||||
"the temporary file was saved successfully");
|
||||
|
||||
let iframe = document.createElement("iframe");
|
||||
iframe.src = NetUtil.newURI(gTmpFile).spec;
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
function startTest()
|
||||
{
|
||||
removeEventListener("load", startTest);
|
||||
|
||||
attachConsole(["FileActivity"], onAttach);
|
||||
}
|
||||
|
||||
function onAttach(aState, aResponse)
|
||||
{
|
||||
gState = aState;
|
||||
gState.dbgClient.addListener("fileActivity", onFileActivity);
|
||||
doFileActivity();
|
||||
}
|
||||
|
||||
function onFileActivity(aType, aPacket)
|
||||
{
|
||||
is(aPacket.from, gState.actor, "fileActivity actor");
|
||||
|
||||
gState.dbgClient.removeListener("fileActivity", onFileActivity);
|
||||
|
||||
ok(/bug798764\.html$/.test(aPacket.uri), "file URI match");
|
||||
|
||||
testEnd();
|
||||
}
|
||||
|
||||
function testEnd()
|
||||
{
|
||||
if (gTmpFile) {
|
||||
gTmpFile.remove(false);
|
||||
gTmpFile = null;
|
||||
}
|
||||
|
||||
if (gState) {
|
||||
closeDebugger(gState, function() {
|
||||
gState = null;
|
||||
SimpleTest.finish();
|
||||
});
|
||||
} else {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener("load", startTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user