Bug 1238180 - Avoid unsafe CPOWs when opening Page / Frame / Image Info from the context menu. r=florian

--HG--
extra : commitid : 5UlX2bYXMNa
extra : rebase_source : 096d891c38daccc0ffb8143a66e3007f7ea74e00
This commit is contained in:
Mike Conley 2016-01-18 11:24:47 -05:00
Родитель d36d8ac46e
Коммит 1e0155b956
4 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -2275,16 +2275,22 @@ function BrowserViewSource(browser) {
});
}
// doc - document to use for source, or null for this window's document
// documentURL - URL of the document to view, or null for this window's document
// initialTab - name of the initial tab to display, or null for the first tab
// imageElement - image to load in the Media Tab of the Page Info window; can be null/omitted
// frameOuterWindowID - the id of the frame that the context menu opened in; can be null/omitted
function BrowserPageInfo(doc, initialTab, imageElement, frameOuterWindowID) {
var args = {doc: doc, initialTab: initialTab, imageElement: imageElement,
frameOuterWindowID: frameOuterWindowID};
function BrowserPageInfo(documentURL, initialTab, imageElement, frameOuterWindowID) {
if (documentURL instanceof HTMLDocument) {
Deprecated.warning("Please pass the location URL instead of the document " +
"to BrowserPageInfo() as the first argument.",
"https://bugzilla.mozilla.org/show_bug.cgi?id=1238180");
documentURL = documentURL.location;
}
let args = { initialTab, imageElement, frameOuterWindowID };
var windows = Services.wm.getEnumerator("Browser:page-info");
var documentURL = doc ? doc.location : window.gBrowser.selectedBrowser.currentURI.spec;
documentURL = documentURL || window.gBrowser.selectedBrowser.currentURI.spec;
// Check for windows matching the url
while (windows.hasMoreElements()) {

Просмотреть файл

@ -1065,12 +1065,11 @@ nsContextMenu.prototype = {
},
viewInfo: function() {
BrowserPageInfo(this.target.ownerDocument.defaultView.top.document);
BrowserPageInfo();
},
viewImageInfo: function() {
BrowserPageInfo(this.target.ownerDocument.defaultView.top.document,
"mediaTab", this.target);
BrowserPageInfo(null, "mediaTab", this.target);
},
viewImageDesc: function(e) {
@ -1082,7 +1081,7 @@ nsContextMenu.prototype = {
},
viewFrameInfo: function() {
BrowserPageInfo(this.target.ownerDocument, null, null,
BrowserPageInfo(gContextMenuContentData.docLocation, null, null,
this.frameOuterWindowID);
},

Просмотреть файл

@ -9,7 +9,8 @@ function test() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
var doc = gBrowser.contentDocument;
var pageInfo = BrowserPageInfo(doc, "mediaTab");
var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec,
"mediaTab");
pageInfo.addEventListener("load", function () {
pageInfo.removeEventListener("load", arguments.callee, true);

Просмотреть файл

@ -10,7 +10,8 @@ function test() {
var doc = gBrowser.contentDocument;
var testImg = doc.getElementById("test-image");
var pageInfo = BrowserPageInfo(doc, "mediaTab", testImg);
var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec,
"mediaTab", testImg);
pageInfo.addEventListener("load", function () {
pageInfo.removeEventListener("load", arguments.callee, true);