2012-08-08 19:58:06 -07: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/. */
|
|
|
|
|
|
|
|
#include "AppProcessPermissions.h"
|
|
|
|
#include "ContentParent.h"
|
|
|
|
#include "mozIApplication.h"
|
2012-08-16 12:34:53 -07:00
|
|
|
#include "mozilla/hal_sandbox/PHalParent.h"
|
2012-08-08 19:58:06 -07:00
|
|
|
#include "nsIDOMApplicationRegistry.h"
|
|
|
|
#include "TabParent.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2012-08-16 12:34:53 -07:00
|
|
|
using namespace mozilla::hal_sandbox;
|
2012-08-08 19:58:06 -07:00
|
|
|
using namespace mozilla::services;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool
|
2012-09-25 11:52:30 -07:00
|
|
|
AssertAppProcessPermission(PBrowserParent* aActor, const char* aPermission)
|
2012-08-08 19:58:06 -07:00
|
|
|
{
|
|
|
|
if (!aActor) {
|
|
|
|
NS_WARNING("Testing permissions for null actor");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabParent* tab = static_cast<TabParent*>(aActor);
|
|
|
|
nsCOMPtr<mozIApplication> app = tab->GetApp();
|
|
|
|
// isBrowser frames inherit their app descriptor to identify their
|
|
|
|
// data storage, but they don't inherit the permissions associated
|
|
|
|
// with that descriptor.
|
|
|
|
if (!app || tab->IsBrowserElement()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasPermission = false;
|
2012-08-25 15:38:04 -07:00
|
|
|
if (!NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission)) ||
|
|
|
|
!hasPermission) {
|
|
|
|
printf_stderr("Security problem: App process does not have `%s' permission. It will be killed.", aPermission);
|
2012-09-05 15:18:48 -07:00
|
|
|
ContentParent* process = static_cast<ContentParent*>(aActor->Manager());
|
|
|
|
process->KillHard();
|
2012-08-25 15:38:04 -07:00
|
|
|
}
|
|
|
|
return hasPermission;
|
2012-08-08 19:58:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-09-25 11:52:30 -07:00
|
|
|
AssertAppProcessPermission(PContentParent* aActor, const char* aPermission)
|
2012-08-08 19:58:06 -07:00
|
|
|
{
|
|
|
|
const InfallibleTArray<PBrowserParent*>& browsers =
|
|
|
|
aActor->ManagedPBrowserParent();
|
|
|
|
for (uint32_t i = 0; i < browsers.Length(); ++i) {
|
2012-09-25 11:52:30 -07:00
|
|
|
if (AssertAppProcessPermission(browsers[i], aPermission)) {
|
2012-08-08 19:58:06 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-16 12:34:53 -07:00
|
|
|
bool
|
2012-09-25 11:52:30 -07:00
|
|
|
AssertAppProcessPermission(PHalParent* aActor, const char* aPermission)
|
2012-08-16 12:34:53 -07:00
|
|
|
{
|
2012-09-25 11:52:30 -07:00
|
|
|
return AssertAppProcessPermission(aActor->Manager(), aPermission);
|
2012-08-16 12:34:53 -07:00
|
|
|
}
|
|
|
|
|
2012-08-08 19:58:06 -07:00
|
|
|
} // namespace mozilla
|