Backed out changeset 7d1f7dd996f7 (bug 1310845)

This commit is contained in:
Carsten "Tomcat" Book
2016-11-16 14:50:44 +01:00
parent e8b977693f
commit 84568d0bc2
102 changed files with 2720 additions and 330 deletions

View File

@@ -12,8 +12,10 @@
#include "mozilla/Preferences.h"
#include "mozilla/ErrorResult.h"
#include "GeckoProfiler.h"
#include "mozIApplication.h"
#include "nsAttrValueInlines.h"
#include "nsContentUtils.h"
#include "nsIAppsService.h"
#include "nsIDocShell.h"
#include "nsIDOMDocument.h"
#include "nsIFrame.h"
@@ -189,6 +191,31 @@ nsGenericHTMLFrameElement::GetFrameLoader()
return loader.forget();
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::GetParentApplication(mozIApplication** aApplication)
{
if (!aApplication) {
return NS_ERROR_FAILURE;
}
*aApplication = nullptr;
nsIPrincipal *principal = NodePrincipal();
uint32_t appId = principal->GetAppId();
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
if (NS_WARN_IF(!appsService)) {
return NS_ERROR_FAILURE;
}
nsresult rv = appsService->GetAppByLocalId(appId, aApplication);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
void
nsGenericHTMLFrameElement::PresetOpenerWindow(mozIDOMWindowProxy* aWindow, ErrorResult& aRv)
{
@@ -469,12 +496,12 @@ nsGenericHTMLFrameElement::BrowserFramesEnabled()
}
/**
* Return true if this frame element really is a mozbrowser. (It
* Return true if this frame element really is a mozbrowser or mozapp. (It
* needs to have the right attributes, and its creator must have the right
* permissions.)
*/
/* [infallible] */ nsresult
nsGenericHTMLFrameElement::GetReallyIsBrowser(bool *aOut)
nsGenericHTMLFrameElement::GetReallyIsBrowserOrApp(bool *aOut)
{
*aOut = false;
@@ -501,6 +528,34 @@ nsGenericHTMLFrameElement::GetReallyIsBrowser(bool *aOut)
return NS_OK;
}
/* [infallible] */ NS_IMETHODIMP
nsGenericHTMLFrameElement::GetReallyIsApp(bool *aOut)
{
nsAutoString manifestURL;
GetAppManifestURL(manifestURL);
*aOut = !manifestURL.IsEmpty();
return NS_OK;
}
namespace {
bool NestedEnabled()
{
static bool sMozNestedEnabled = false;
static bool sBoolVarCacheInitialized = false;
if (!sBoolVarCacheInitialized) {
sBoolVarCacheInitialized = true;
Preferences::AddBoolVarCache(&sMozNestedEnabled,
"dom.ipc.tabs.nested.enabled");
}
return sMozNestedEnabled;
}
} // namespace
/* [infallible] */ NS_IMETHODIMP
nsGenericHTMLFrameElement::GetIsolated(bool *aOut)
{
@@ -515,6 +570,91 @@ nsGenericHTMLFrameElement::GetIsolated(bool *aOut)
return NS_OK;
}
/*
* Get manifest url of app.
*/
void nsGenericHTMLFrameElement::GetManifestURL(nsAString& aManifestURL)
{
aManifestURL.Truncate();
nsAutoString manifestURL;
GetAttr(kNameSpaceID_None, nsGkAtoms::mozapp, manifestURL);
if (manifestURL.IsEmpty()) {
return;
}
// Check permission.
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
NS_ENSURE_TRUE_VOID(permMgr);
nsIPrincipal *principal = NodePrincipal();
const char* aPermissionType = "embed-apps";
uint32_t permission = nsIPermissionManager::DENY_ACTION;
nsresult rv = permMgr->TestPermissionFromPrincipal(principal,
aPermissionType,
&permission);
NS_ENSURE_SUCCESS_VOID(rv);
if (permission != nsIPermissionManager::ALLOW_ACTION) {
return;
}
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(appsService);
nsCOMPtr<mozIApplication> app;
appsService->GetAppByManifestURL(manifestURL, getter_AddRefs(app));
if (!app) {
return;
}
aManifestURL.Assign(manifestURL);
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::GetAppManifestURL(nsAString& aOut)
{
aOut.Truncate();
// At the moment, you can't be an app without being a browser.
if (!nsIMozBrowserFrame::GetReallyIsBrowserOrApp()) {
return NS_OK;
}
// Only allow content process to embed an app when nested content
// process is enabled.
if (!XRE_IsParentProcess() &&
!(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;
}
nsAutoString appManifestURL;
GetManifestURL(appManifestURL);
bool isApp = !appManifestURL.IsEmpty();
if (!isApp) {
// No valid case to get manifest
return NS_OK;
}
if (isApp) {
NS_WARNING("Can not simultaneously be mozapp");
return NS_OK;
}
nsAutoString manifestURL;
if (isApp) {
manifestURL.Assign(appManifestURL);
}
aOut.Assign(manifestURL);
return NS_OK;
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::DisallowCreateFrameLoader()
{