Bug 1309735 - Allow usercontextid to be set on mozbrowser frames. r=baku

This allows the `usercontextid` attribute to be set on mozbrowser frames.  This
will help Responsive Design Mode support display of pages in containers, since
it uses such frames internally.

MozReview-Commit-ID: HWEJni6z1sp

--HG--
extra : rebase_source : 45ab8c2c6780782a5201aaf54b6ffb3449912bc1
This commit is contained in:
J. Ryan Stinnett 2018-02-23 17:32:18 -06:00
Родитель 20d9cf4517
Коммит e612db42ac
2 изменённых файлов: 22 добавлений и 16 удалений

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

@ -1078,7 +1078,7 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther,
// When we swap docShells, maybe we have to deal with a new page created just
// for this operation. In this case, the browser code should already have set
// the correct userContextId attribute value in the owning XULElement, but our
// the correct userContextId attribute value in the owning element, but our
// docShell, that has been created way before) doesn't know that that
// happened.
// This is the reason why now we must retrieve the correct value from the
@ -1501,7 +1501,7 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
// When we swap docShells, maybe we have to deal with a new page created just
// for this operation. In this case, the browser code should already have set
// the correct userContextId attribute value in the owning XULElement, but our
// the correct userContextId attribute value in the owning element, but our
// docShell, that has been created way before) doesn't know that that
// happened.
// This is the reason why now we must retrieve the correct value from the
@ -2183,7 +2183,7 @@ nsFrameLoader::MaybeCreateDocShell()
}
ApplySandboxFlags(sandboxFlags);
// Grab the userContextId from owner if XUL
// Grab the userContextId from owner
nsresult rv = PopulateUserContextIdFromAttribute(attrs);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -3372,10 +3372,10 @@ nsFrameLoader::PopulateUserContextIdFromAttribute(OriginAttributes& aAttr)
{
if (aAttr.mUserContextId ==
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
// Grab the userContextId from owner if XUL
// Grab the userContextId from owner if XUL or mozbrowser frame
nsAutoString userContextIdStr;
int32_t namespaceID = mOwnerContent->GetNameSpaceID();
if ((namespaceID == kNameSpaceID_XUL) &&
if ((namespaceID == kNameSpaceID_XUL || OwnerIsMozBrowserFrame()) &&
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid,
userContextIdStr) &&
!userContextIdStr.IsEmpty()) {

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

@ -29,10 +29,12 @@ Test swapFrameLoaders with different frame types and remoteness
["xul", "html"],
["html", "xul"],
["html", "html"],
["xul", "xul", "remote"],
["xul", "html", "remote"],
["html", "xul", "remote"],
["html", "html", "remote"],
["xul", "xul", { remote: true }],
["xul", "html", { remote: true }],
["html", "xul", { remote: true }],
["html", "html", { remote: true }],
["xul", "html", { userContextId: 2 }],
["xul", "html", { userContextId: 2, remote: true }],
];
const HEIGHTS = [
@ -69,12 +71,17 @@ Test swapFrameLoaders with different frame types and remoteness
});
}
async function addFrame(type, remote, height) {
async function addFrame(type, options, height) {
let remote = options && options.remote;
let userContextId = options && options.userContextId;
let frame = document.createElementNS(NS[type], TAG[type]);
frame.setAttribute("remote", remote);
if (remote && type == "xul") {
frame.setAttribute("style", "-moz-binding: none;");
}
if (userContextId) {
frame.setAttribute("usercontextid", userContextId);
}
if (type == "html") {
frame.setAttribute("mozbrowser", "true");
frame.setAttribute("noisolation", "true");
@ -99,15 +106,14 @@ Test swapFrameLoaders with different frame types and remoteness
add_task(async function() {
for (let scenario of SCENARIOS) {
let [ typeA, typeB, remote ] = scenario;
remote = !!remote;
let [ typeA, typeB, options ] = scenario;
let heightA = HEIGHTS[0];
info(`Adding frame A, type ${typeA}, remote ${remote}, height ${heightA}`);
let frameA = await addFrame(typeA, remote, heightA);
info(`Adding frame A, type ${typeA}, options ${JSON.stringify(options)}, height ${heightA}`);
let frameA = await addFrame(typeA, options, heightA);
let heightB = HEIGHTS[1];
info(`Adding frame B, type ${typeB}, remote ${remote}, height ${heightB}`);
let frameB = await addFrame(typeB, remote, heightB);
info(`Adding frame B, type ${typeB}, options ${JSON.stringify(options)}, height ${heightB}`);
let frameB = await addFrame(typeB, options, heightB);
let frameScriptFactory = function(name) {
return `function() {