Bug 1097479 - Allow nested content process to embed apps and add a nested pref check function. r=kanru

--HG--
extra : rebase_source : cffe31cb84bfd635458465774e77c4ff182839f0
This commit is contained in:
Kevin Chen 2015-04-29 03:48:00 +02:00
parent 07344315f6
commit 41669c8fe2
6 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 1097479 - Allow embed remote apps or widgets in content
// process if nested-oop is enabled
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
SpecialPowers.setAllAppsLaunchable(true);
function runTest() {
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
is(e.detail.message == 'app', true, e.detail.message);
SimpleTest.finish();
});
document.body.appendChild(iframe);
var context = { 'url': 'http://example.org',
'appId': SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
'isInBrowserElement': true };
SpecialPowers.pushPermissions([
{'type': 'browser', 'allow': 1, 'context': context},
{'type': 'embed-apps', 'allow': 1, 'context': context}
], function() {
iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AllowEmbedAppsInNestedOOIframe.html';
});
}
addEventListener('testready', () => {
SpecialPowers.pushPrefEnv({"set": [["dom.ipc.tabs.nested.enabled", true]]}, runTest);
});

View File

@ -0,0 +1,19 @@
<html>
<head>
<script type="text/javascript">
addEventListener('load', function(e) {
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('remote', 'true');
iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
alert(e.detail.message);
});
document.body.appendChild(iframe);
iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AppFramePermission.html';
});
</script>
</head>
<body>
</body>
</html>

View File

@ -16,6 +16,8 @@ skip-if = toolkit=='gonk'
skip-if = toolkit=='gonk' || (toolkit == 'gonk' && !debug)
[test_browserElement_oop_Alert.html]
[test_browserElement_oop_AlertInFrame.html]
[test_browserElement_oop_AllowEmbedAppsInNestedOOIframe.html]
skip-if = toolkit=='gonk'
[test_browserElement_oop_AppFramePermission.html]
skip-if = (toolkit == 'gonk' && !debug)
[test_browserElement_oop_AppWindowNamespace.html]

View File

@ -6,6 +6,7 @@ support-files =
browserElementTestHelpers.js
browserElement_Alert.js
browserElement_AlertInFrame.js
browserElement_AllowEmbedAppsInNestedOOIframe.js
browserElement_AppFramePermission.js
browserElement_AppWindowNamespace.js
browserElement_Auth.js
@ -73,6 +74,7 @@ support-files =
browserElement_GetContentDimensions.js
file_browserElement_AlertInFrame.html
file_browserElement_AlertInFrame_Inner.html
file_browserElement_AllowEmbedAppsInNestedOOIframe.html
file_browserElement_AppFramePermission.html
file_browserElement_AppWindowNamespace.html
file_browserElement_ThemeColor.html

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 1097479</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_AllowEmbedAppsInNestedOOIframe.js">
</script>
</body>
</html>

View File

@ -479,6 +479,20 @@ bool WidgetsEnabled()
return sMozWidgetsEnabled;
}
bool NestedEnabled()
{
static bool sMozNestedEnabled = false;
static bool sBoolVarCacheInitialized = false;
if (!sBoolVarCacheInitialized) {
sBoolVarCacheInitialized = true;
Preferences::AddBoolVarCache(&sMozNestedEnabled,
"dom.ipc.tabs.nested.enabled");
}
return sMozNestedEnabled;
}
} // anonymous namespace
/* [infallible] */ NS_IMETHODIMP
@ -581,8 +595,12 @@ nsGenericHTMLFrameElement::GetAppManifestURL(nsAString& aOut)
return NS_OK;
}
if (XRE_GetProcessType() != GeckoProcessType_Default) {
NS_WARNING("Can't embed-apps. Embed-apps is restricted to in-proc apps, see bug 1059662");
// Only allow content process to embed an app when nested content
// process is enabled.
if (XRE_GetProcessType() != GeckoProcessType_Default &&
!(GetBoolAttr(nsGkAtoms::Remote) && NestedEnabled())){
NS_WARNING("Can't embed-apps. Embed-apps is restricted to in-proc apps "
"or content processes with nested pref enabled, see bug 1097479");
return NS_OK;
}