mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 776649, part 3: Add an API for checking whether apps loaded in PBrowserParent/PContentParent have a given permission. r=jlebar sr=bz
This commit is contained in:
parent
063981263a
commit
12e956867e
54
dom/ipc/AppProcessPermissions.cpp
Normal file
54
dom/ipc/AppProcessPermissions.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- 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 "nsIDOMApplicationRegistry.h"
|
||||
#include "TabParent.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::services;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
bool
|
||||
AppProcessHasPermission(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->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;
|
||||
return (NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission)) &&
|
||||
hasPermission);
|
||||
}
|
||||
|
||||
bool
|
||||
AppProcessHasPermission(PContentParent* aActor, const char* aPermission)
|
||||
{
|
||||
const InfallibleTArray<PBrowserParent*>& browsers =
|
||||
aActor->ManagedPBrowserParent();
|
||||
for (uint32_t i = 0; i < browsers.Length(); ++i) {
|
||||
if (AppProcessHasPermission(browsers[i], aPermission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
43
dom/ipc/AppProcessPermissions.h
Normal file
43
dom/ipc/AppProcessPermissions.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#ifndef mozilla_Capabilities_h
|
||||
#define mozilla_Capabilities_h
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
class PBrowserParent;
|
||||
class PContentParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true iff the specified browser has the specified capability.
|
||||
*/
|
||||
bool
|
||||
AppProcessHasPermissions(mozilla::dom::PBrowserParent* aActor,
|
||||
const char* aPermission);
|
||||
|
||||
/**
|
||||
* Return true iff any of the PBrowsers loaded in this content process
|
||||
* has the specified capability.
|
||||
*/
|
||||
bool
|
||||
AppProcessHasPermission(mozilla::dom::PContentParent* aActor,
|
||||
const char* aPermission);
|
||||
|
||||
// NB: when adding capability checks for other IPDL actors, please add
|
||||
// them to this file and have them delegate to the two functions above
|
||||
// as appropriate. For example,
|
||||
//
|
||||
// bool AppProcessHasCapability(PNeckoParent* aActor) {
|
||||
// return AppProcessHasCapability(aActor->Manager());
|
||||
// }
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_Capabilities_h
|
@ -23,10 +23,15 @@ endif
|
||||
EXPORTS = PCOMContentPermissionRequestChild.h
|
||||
|
||||
EXPORTS_NAMESPACES = \
|
||||
mozilla \
|
||||
mozilla/dom \
|
||||
mozilla/dom/ipc \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_mozilla = \
|
||||
AppProcessPermissions.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_mozilla/dom = \
|
||||
ContentChild.h \
|
||||
ContentParent.h \
|
||||
@ -47,6 +52,7 @@ EXPORTS_mozilla/dom/ipc = \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
AppProcessPermissions.cpp \
|
||||
Blob.cpp \
|
||||
ContentProcess.cpp \
|
||||
ContentParent.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user