Bug 1157433 Create gContextMenuContentData to keep the Addon-SDK happy. r=Neil

This commit is contained in:
Philip Chee 2015-04-28 21:57:24 +08:00
Родитель 23f1d8dca1
Коммит 266b55a86f
2 изменённых файлов: 58 добавлений и 4 удалений

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

@ -27,7 +27,7 @@
-->
<menupopup id="contentAreaContextMenu"
pagemenu="start"
onpopupshowing="if (event.target != this) return true; gContextMenu = new nsContextMenu(this, null, event.shiftKey); return gContextMenu.shouldDisplay;"
onpopupshowing="if (event.target != this) return true; gContextMenu = new nsContextMenu(this, event.shiftKey, event); return gContextMenu.shouldDisplay;"
onpopuphiding="if (event.target != this) return; gContextMenu.hiding(); gContextMenu = null;">
<menuseparator id="page-menu-separator"/>
<menuitem id="popupwindow-reject"

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

@ -15,20 +15,22 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var gContextMenuContentData = null;
XPCOMUtils.defineLazyGetter(this, "PageMenuParent", function() {
let tmp = {};
Components.utils.import("resource://gre/modules/PageMenu.jsm", tmp);
return new tmp.PageMenuParent();
});
function nsContextMenu(aXulMenu, aBrowser, aIsShift) {
function nsContextMenu(aXulMenu, aIsShift, aEvent) {
this.shouldDisplay = true;
this.initMenu(aBrowser, aXulMenu, aIsShift);
this.initMenu(aXulMenu, aIsShift, aEvent);
}
// Prototype for nsContextMenu "class."
nsContextMenu.prototype = {
initMenu: function(aBrowser, aXulMenu, aIsShift) {
initMenu: function(aXulMenu, aIsShift, aEvent) {
// Get contextual info.
this.setTarget(document.popupNode, document.popupRangeParent,
document.popupRangeOffset);
@ -48,9 +50,61 @@ nsContextMenu.prototype = {
// Initialize (disable/remove) menu items.
this.initItems();
// Initialize gContextMenuContentData.
if (aEvent)
this.initContentData(aEvent);
},
initContentData: function(aEvent) {
var addonInfo = {};
var subject = {
event: aEvent,
addonInfo: addonInfo,
};
subject.wrappedJSObject = subject;
// Notifies the Addon-SDK which then populates addonInfo.
Services.obs.notifyObservers(subject, "content-contextmenu", null);
var popupNode = this.target;
var doc = popupNode.ownerDocument;
var contentType = null;
var contentDisposition = null;
if (this.onImage) {
try {
let imageCache = Components.classes["@mozilla.org/image/tools;1"]
.getService(Components.interfaces.imgITools)
.getImgCacheForDocument(doc)
let props = imageCache.findEntryProperties(popupNode.currentURI);
if (props) {
let nsISupportsCString = Components.interfaces.nsISupportsCString;
contentType = props.get("type", nsISupportsCString).data;
contentDisposition = props.get("content-disposition",
nsISupportsCString).data;
}
} catch (e) {
Components.utils.reportError(e);
}
}
gContextMenuContentData = {
isRemote: false,
event: aEvent,
popupNode: popupNode,
browser: this.browser,
addonInfo: addonInfo,
documentURIObject: doc.documentURIObject,
docLocation: doc.location.href,
charSet: doc.characterSet,
referrer: doc.referrer,
referrerPolicy: doc.referrerPolicy,
contentType: contentType,
contentDisposition: contentDisposition,
};
},
hiding: function () {
gContextMenuContentData = null;
InlineSpellCheckerUI.clearSuggestionsFromMenu();
InlineSpellCheckerUI.clearDictionaryListFromMenu();
InlineSpellCheckerUI.uninit();