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 // 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 // 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 // docShell, that has been created way before) doesn't know that that
// happened. // happened.
// This is the reason why now we must retrieve the correct value from the // 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 // 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 // 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 // docShell, that has been created way before) doesn't know that that
// happened. // happened.
// This is the reason why now we must retrieve the correct value from the // This is the reason why now we must retrieve the correct value from the
@ -2183,7 +2183,7 @@ nsFrameLoader::MaybeCreateDocShell()
} }
ApplySandboxFlags(sandboxFlags); ApplySandboxFlags(sandboxFlags);
// Grab the userContextId from owner if XUL // Grab the userContextId from owner
nsresult rv = PopulateUserContextIdFromAttribute(attrs); nsresult rv = PopulateUserContextIdFromAttribute(attrs);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
@ -3372,10 +3372,10 @@ nsFrameLoader::PopulateUserContextIdFromAttribute(OriginAttributes& aAttr)
{ {
if (aAttr.mUserContextId == if (aAttr.mUserContextId ==
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) { nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
// Grab the userContextId from owner if XUL // Grab the userContextId from owner if XUL or mozbrowser frame
nsAutoString userContextIdStr; nsAutoString userContextIdStr;
int32_t namespaceID = mOwnerContent->GetNameSpaceID(); int32_t namespaceID = mOwnerContent->GetNameSpaceID();
if ((namespaceID == kNameSpaceID_XUL) && if ((namespaceID == kNameSpaceID_XUL || OwnerIsMozBrowserFrame()) &&
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid, mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid,
userContextIdStr) && userContextIdStr) &&
!userContextIdStr.IsEmpty()) { !userContextIdStr.IsEmpty()) {

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

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