gecko/dom/ipc/AppProcessPermissions.cpp
Justin Lebar e80ccc6058 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 10:32:37 -08:00

70 lines
2.0 KiB
C++

/* -*- 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"
#include "mozilla/hal_sandbox/PHalParent.h"
#include "nsIDOMApplicationRegistry.h"
#include "TabParent.h"
using namespace mozilla::dom;
using namespace mozilla::hal_sandbox;
using namespace mozilla::services;
namespace mozilla {
bool
AssertAppProcessPermission(PBrowserParent* aActor, const char* aPermission)
{
if (!aActor) {
NS_WARNING("Testing permissions for null actor");
return false;
}
TabParent* tab = static_cast<TabParent*>(aActor);
nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
bool hasPermission = false;
// 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()) {
if (!NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission))) {
hasPermission = false;
}
}
if (!hasPermission) {
printf_stderr("Security problem: Content process does not have `%s' permission. It will be killed.\n", aPermission);
ContentParent* process = static_cast<ContentParent*>(aActor->Manager());
process->KillHard();
}
return hasPermission;
}
bool
AssertAppProcessPermission(PContentParent* aActor, const char* aPermission)
{
const InfallibleTArray<PBrowserParent*>& browsers =
aActor->ManagedPBrowserParent();
for (uint32_t i = 0; i < browsers.Length(); ++i) {
if (AssertAppProcessPermission(browsers[i], aPermission)) {
return true;
}
}
return false;
}
bool
AssertAppProcessPermission(PHalParent* aActor, const char* aPermission)
{
return AssertAppProcessPermission(aActor->Manager(), aPermission);
}
} // namespace mozilla