2012-08-09 02:58:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-12-22 11:53:38 +00:00
|
|
|
#include "AppProcessChecker.h"
|
2012-08-09 02:58:06 +00:00
|
|
|
#include "ContentParent.h"
|
|
|
|
#include "mozIApplication.h"
|
2012-08-16 19:34:53 +00:00
|
|
|
#include "mozilla/hal_sandbox/PHalParent.h"
|
2012-08-09 02:58:06 +00:00
|
|
|
#include "nsIDOMApplicationRegistry.h"
|
|
|
|
#include "TabParent.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2012-08-16 19:34:53 +00:00
|
|
|
using namespace mozilla::hal_sandbox;
|
2012-08-09 02:58:06 +00:00
|
|
|
using namespace mozilla::services;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool
|
2012-12-22 11:53:38 +00:00
|
|
|
AssertAppProcess(PBrowserParent* aActor,
|
|
|
|
AssertAppProcessType aType,
|
|
|
|
const char* aCapability)
|
2012-08-09 02:58:06 +00:00
|
|
|
{
|
|
|
|
if (!aActor) {
|
2012-12-22 11:53:38 +00:00
|
|
|
NS_WARNING("Testing process capability for null actor");
|
2012-08-09 02:58:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabParent* tab = static_cast<TabParent*>(aActor);
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 18:32:37 +00:00
|
|
|
nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
|
2012-12-22 11:53:38 +00:00
|
|
|
bool aValid = false;
|
2012-09-28 17:29:36 +00:00
|
|
|
|
2012-08-09 02:58:06 +00:00
|
|
|
// isBrowser frames inherit their app descriptor to identify their
|
2012-12-22 11:53:38 +00:00
|
|
|
// data storage, but they don't inherit the capability associated
|
2012-08-09 02:58:06 +00:00
|
|
|
// with that descriptor.
|
2013-01-14 10:08:55 +00:00
|
|
|
if (app && (aType == ASSERT_APP_HAS_PERMISSION || !tab->IsBrowserElement())) {
|
2012-12-22 11:53:38 +00:00
|
|
|
switch (aType) {
|
2013-01-14 10:08:55 +00:00
|
|
|
case ASSERT_APP_HAS_PERMISSION:
|
2012-12-22 11:53:38 +00:00
|
|
|
case ASSERT_APP_PROCESS_PERMISSION:
|
|
|
|
if (!NS_SUCCEEDED(app->HasPermission(aCapability, &aValid))) {
|
|
|
|
aValid = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ASSERT_APP_PROCESS_MANIFEST_URL: {
|
|
|
|
nsAutoString manifestURL;
|
|
|
|
if (NS_SUCCEEDED(app->GetManifestURL(manifestURL)) &&
|
|
|
|
manifestURL.EqualsASCII(aCapability)) {
|
|
|
|
aValid = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2012-09-28 17:29:36 +00:00
|
|
|
}
|
2012-08-09 02:58:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 11:53:38 +00:00
|
|
|
if (!aValid) {
|
|
|
|
printf_stderr("Security problem: Content process does not have `%s'. It will be killed.\n", aCapability);
|
2013-07-10 17:07:51 +00:00
|
|
|
ContentParent* process = tab->Manager();
|
2012-09-05 22:18:48 +00:00
|
|
|
process->KillHard();
|
2012-08-25 22:38:04 +00:00
|
|
|
}
|
2012-12-22 11:53:38 +00:00
|
|
|
return aValid;
|
2012-08-09 02:58:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 10:52:16 +00:00
|
|
|
bool
|
|
|
|
AssertAppStatus(PBrowserParent* aActor,
|
|
|
|
unsigned short aStatus)
|
|
|
|
{
|
|
|
|
if (!aActor) {
|
|
|
|
NS_WARNING("Testing process capability for null actor");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabParent* tab = static_cast<TabParent*>(aActor);
|
|
|
|
nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
|
|
|
|
|
|
|
|
if (app) {
|
|
|
|
unsigned short appStatus = 0;
|
|
|
|
if (NS_SUCCEEDED(app->GetAppStatus(&appStatus))) {
|
|
|
|
return appStatus == aStatus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-09 02:58:06 +00:00
|
|
|
bool
|
2012-12-22 11:53:38 +00:00
|
|
|
AssertAppProcess(PContentParent* aActor,
|
|
|
|
AssertAppProcessType aType,
|
|
|
|
const char* aCapability)
|
2012-08-09 02:58:06 +00:00
|
|
|
{
|
|
|
|
const InfallibleTArray<PBrowserParent*>& browsers =
|
|
|
|
aActor->ManagedPBrowserParent();
|
|
|
|
for (uint32_t i = 0; i < browsers.Length(); ++i) {
|
2012-12-22 11:53:38 +00:00
|
|
|
if (AssertAppProcess(browsers[i], aType, aCapability)) {
|
2012-08-09 02:58:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-29 10:52:16 +00:00
|
|
|
bool
|
|
|
|
AssertAppStatus(PContentParent* aActor,
|
|
|
|
unsigned short aStatus)
|
|
|
|
{
|
|
|
|
const InfallibleTArray<PBrowserParent*>& browsers =
|
|
|
|
aActor->ManagedPBrowserParent();
|
|
|
|
for (uint32_t i = 0; i < browsers.Length(); ++i) {
|
|
|
|
if (AssertAppStatus(browsers[i], aStatus)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-16 19:34:53 +00:00
|
|
|
bool
|
2012-12-22 11:53:38 +00:00
|
|
|
AssertAppProcess(PHalParent* aActor,
|
|
|
|
AssertAppProcessType aType,
|
|
|
|
const char* aCapability)
|
2012-08-16 19:34:53 +00:00
|
|
|
{
|
2012-12-22 11:53:38 +00:00
|
|
|
return AssertAppProcess(aActor->Manager(), aType, aCapability);
|
2012-08-16 19:34:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 02:58:06 +00:00
|
|
|
} // namespace mozilla
|