Bug 1195735, r=zer0

This commit is contained in:
Gijs Kruitbosch
2015-10-01 12:04:12 -04:00
parent 3f7082f106
commit 0edb4230be
2 changed files with 45 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ const { platform } = require("../system");
const { getMostRecentBrowserWindow, getOwnerBrowserWindow,
getHiddenWindow, getScreenPixelsPerCSSPixel } = require("../window/utils");
const { create: createFrame, swapFrameLoaders } = require("../frame/utils");
const { create: createFrame, swapFrameLoaders, getDocShell } = require("../frame/utils");
const { window: addonWindow } = require("../addon/window");
const { isNil } = require("../lang/type");
const { data } = require('../self');
@@ -247,10 +247,11 @@ function setupPanelFrame(frame) {
}
}
function make(document) {
function make(document, options) {
document = document || getMostRecentBrowserWindow().document;
let panel = document.createElementNS(XUL_NS, "panel");
panel.setAttribute("type", "arrow");
panel.setAttribute("sdkscriptenabled", "" + options.allowJavascript);
// Note that panel is a parent of `viewFrame` who's `docShell` will be
// configured at creation time. If `panel` and there for `viewFrame` won't
@@ -259,7 +260,7 @@ function make(document) {
attach(panel, document);
let frameOptions = {
allowJavascript: true,
allowJavascript: options.allowJavascript,
allowPlugins: true,
allowAuth: true,
allowWindowControl: false,
@@ -284,8 +285,16 @@ function make(document) {
// See Bug 886329
if (target !== this) return;
try { swapFrameLoaders(backgroundFrame, viewFrame); }
catch(error) { console.exception(error); }
try {
swapFrameLoaders(backgroundFrame, viewFrame);
// We need to re-set this because... swapFrameLoaders. Or something.
let shouldEnableScript = panel.getAttribute("sdkscriptenabled") == "true";
getDocShell(backgroundFrame).allowJavascript = shouldEnableScript;
getDocShell(viewFrame).allowJavascript = shouldEnableScript;
}
catch(error) {
console.exception(error);
}
events.emit(type, { subject: panel });
}
@@ -331,6 +340,7 @@ function make(document) {
panel.backgroundFrame = backgroundFrame;
panel.viewFrame = viewFrame;
// Store event listener on the panel instance so that it won't be GC-ed
// while panel is alive.
@@ -356,8 +366,10 @@ function detach(panel) {
exports.detach = detach;
function dispose(panel) {
panel.backgroundFrame.parentNode.removeChild(panel.backgroundFrame);
panel.backgroundFrame.remove();
panel.viewFrame.remove();
panel.backgroundFrame = null;
panel.viewFrame = null;
events.off("document-element-inserted", panel.onContentChange);
panel.onContentChange = null;
detach(panel);