зеркало из https://github.com/mozilla/gecko-dev.git
Bug 719461: Added iconchange event to mozbrowser contained frames. r=jlebar
This commit is contained in:
Родитель
90bc12cbe0
Коммит
f9fade7f61
|
@ -45,6 +45,11 @@ BrowserElementChild.prototype = {
|
|||
this._titleChangedHandler.bind(this),
|
||||
/* useCapture = */ true,
|
||||
/* wantsUntrusted = */ false);
|
||||
|
||||
addEventListener('DOMLinkAdded',
|
||||
this._iconChangedHandler.bind(this),
|
||||
/* useCapture = */ true,
|
||||
/* wantsUntrusted = */ false);
|
||||
},
|
||||
|
||||
_titleChangedHandler: function(e) {
|
||||
|
@ -61,6 +66,25 @@ BrowserElementChild.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
_iconChangedHandler: function(e) {
|
||||
debug("Got iconchanged: (" + e.target.href + ")");
|
||||
var hasIcon = e.target.rel.split(' ').some(function(x) {
|
||||
return x.toLowerCase() === 'icon';
|
||||
});
|
||||
|
||||
if (hasIcon) {
|
||||
var win = e.target.ownerDocument.defaultView;
|
||||
// Ignore iconchanges which don't come from the top-level
|
||||
// <iframe mozbrowser> window.
|
||||
if (win == content) {
|
||||
sendAsyncMsg('iconchange', e.target.href);
|
||||
}
|
||||
else {
|
||||
debug("Not top level!");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// The docShell keeps a weak reference to the progress listener, so we need
|
||||
// to keep a strong ref to it ourselves.
|
||||
_progressListener: {
|
||||
|
|
|
@ -98,6 +98,7 @@ BrowserElementParent.prototype = {
|
|||
addMessageListener("loadstart", this._fireEventFromMsg);
|
||||
addMessageListener("loadend", this._fireEventFromMsg);
|
||||
addMessageListener("titlechange", this._fireEventFromMsg);
|
||||
addMessageListener("iconchange", this._fireEventFromMsg);
|
||||
|
||||
mm.loadFrameScript("chrome://global/content/BrowserElementChild.js",
|
||||
/* allowDelayedLoad = */ true);
|
||||
|
|
|
@ -54,6 +54,7 @@ _TEST_FILES = \
|
|||
test_browserFrame5.html \
|
||||
test_browserFrame6.html \
|
||||
test_browserFrame7.html \
|
||||
test_browserFrame8.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=719461
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 719461</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="browserFrameHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719461">Mozilla Bug 719461</a>
|
||||
|
||||
<!--
|
||||
Test that the onmozbrowsericonchange event works.
|
||||
-->
|
||||
|
||||
<script type="application/javascript;version=1.7">
|
||||
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function createHtml(link) {
|
||||
return 'data:text/html,<html><head>' + link + '<body></body></html>';
|
||||
}
|
||||
|
||||
function createLink(name) {
|
||||
return '<link rel="icon" type="image/png" href="http://example.com/' + name + '.png">';
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
browserFrameHelpers.setEnabledPref(true);
|
||||
browserFrameHelpers.addToWhitelist();
|
||||
|
||||
var iframe1 = document.createElement('iframe');
|
||||
iframe1.mozbrowser = true;
|
||||
document.body.appendChild(iframe1);
|
||||
|
||||
// iframe2 is a red herring; we modify its favicon but don't listen for
|
||||
// iconchanges; we want to make sure that its iconchange events aren't
|
||||
// picked up by the listener on iframe1.
|
||||
var iframe2 = document.createElement('iframe');
|
||||
iframe2.mozbrowser = true;
|
||||
document.body.appendChild(iframe2);
|
||||
|
||||
// iframe3 is another red herring. It's not a mozbrowser, so we shouldn't
|
||||
// get any iconchange events on it.
|
||||
var iframe3 = document.createElement('iframe');
|
||||
document.body.appendChild(iframe3);
|
||||
|
||||
var numIconChanges = 0;
|
||||
|
||||
iframe1.addEventListener('mozbrowsericonchange', function(e) {
|
||||
|
||||
numIconChanges++;
|
||||
|
||||
if (numIconChanges == 1) {
|
||||
is(e.detail, 'http://example.com/myicon.png');
|
||||
|
||||
// We should recieve iconchange events when the user creates new links
|
||||
// to a favicon, but only when we listen for them
|
||||
SpecialPowers.getBrowserFrameMessageManager(iframe1)
|
||||
.loadFrameScript("data:,content.document.title='New title';",
|
||||
/* allowDelayedLoad = */ false);
|
||||
|
||||
SpecialPowers.getBrowserFrameMessageManager(iframe1)
|
||||
.loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/newicon.png>')",
|
||||
/* allowDelayedLoad = */ false);
|
||||
|
||||
SpecialPowers.getBrowserFrameMessageManager(iframe2)
|
||||
.loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/newicon.png>')",
|
||||
/* allowDelayedLoad = */ false);
|
||||
}
|
||||
else if (numIconChanges == 2) {
|
||||
is(e.detail, 'http://example.com/newicon.png');
|
||||
|
||||
// Full new pages should trigger iconchange events
|
||||
iframe1.src = createHtml(createLink('3rdicon'));
|
||||
}
|
||||
else if (numIconChanges == 3) {
|
||||
is(e.detail, 'http://example.com/3rdicon.png');
|
||||
|
||||
// the rel attribute can have various space seperated values, make
|
||||
// sure we only pick up correct values for 'icon'
|
||||
SpecialPowers.getBrowserFrameMessageManager(iframe1)
|
||||
.loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=shortcuticon href=http://example.com/newicon.png>')",
|
||||
/* allowDelayedLoad = */ false);
|
||||
// Test setting a page with multiple links elements
|
||||
iframe1.src = createHtml(createLink('another') + createLink('icon'));
|
||||
}
|
||||
else if (numIconChanges == 4) {
|
||||
is(e.detail, 'http://example.com/another.png');
|
||||
// 2 events will be triggered by previous test, wait for next
|
||||
}
|
||||
else if (numIconChanges == 5) {
|
||||
is(e.detail, 'http://example.com/icon.png');
|
||||
|
||||
// Make sure icon check is case insensitive
|
||||
SpecialPowers.getBrowserFrameMessageManager(iframe1)
|
||||
.loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/ucaseicon.png>')",
|
||||
/* allowDelayedLoad = */ false);
|
||||
}
|
||||
else if (numIconChanges == 6) {
|
||||
is(e.detail, 'http://example.com/ucaseicon.png');
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
ok(false, 'Too many iconchange events.');
|
||||
}
|
||||
});
|
||||
|
||||
iframe3.addEventListener('mozbrowsericonchange', function(e) {
|
||||
ok(false, 'Should not get a iconchange event for iframe3.');
|
||||
});
|
||||
|
||||
|
||||
iframe1.src = createHtml(createLink('myicon'));
|
||||
// We should not recieve icon change events for either of the below iframes
|
||||
iframe2.src = createHtml(createLink('myicon'));
|
||||
iframe3.src = createHtml(createLink('myicon'));
|
||||
|
||||
}
|
||||
|
||||
addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче