2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-09-13 12:49:27 -07:00
|
|
|
|
2013-12-05 06:29:07 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "GonkPermission.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#endif // MOZ_WIDGET_GONK
|
2010-09-13 12:49:27 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2012-07-30 07:58:26 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2013-07-23 16:39:17 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-02-09 12:34:40 -08:00
|
|
|
#include "mozilla/dom/PContentPermission.h"
|
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
|
|
|
#include "mozilla/dom/PContentPermissionRequestParent.h"
|
2014-07-07 21:45:23 -07:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2013-10-16 15:25:50 -07:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2010-09-13 12:49:27 -07:00
|
|
|
#include "mozilla/unused.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-02-09 12:34:40 -08:00
|
|
|
#include "nsArrayUtils.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsContentPermissionHelper.h"
|
2013-09-10 08:41:59 -07:00
|
|
|
#include "nsCxPusher.h"
|
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2010-09-13 12:49:27 -07:00
|
|
|
|
|
|
|
using mozilla::unused; // <snicker>
|
2012-07-30 07:58:26 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-12-05 06:29:07 -08:00
|
|
|
using namespace mozilla;
|
2010-09-13 12:49:27 -07:00
|
|
|
|
2014-02-09 12:34:40 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class ContentPermissionRequestParent : public PContentPermissionRequestParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
|
|
|
|
Element* element,
|
|
|
|
const IPC::Principal& principal);
|
|
|
|
virtual ~ContentPermissionRequestParent();
|
|
|
|
|
|
|
|
bool IsBeingDestroyed();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<Element> mElement;
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<nsContentPermissionRequestProxy> mProxy;
|
2014-02-09 12:34:40 -08:00
|
|
|
nsTArray<PermissionRequest> mRequests;
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual bool Recvprompt();
|
|
|
|
virtual void ActorDestroy(ActorDestroyReason why);
|
|
|
|
};
|
|
|
|
|
|
|
|
ContentPermissionRequestParent::ContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
|
|
|
|
Element* aElement,
|
|
|
|
const IPC::Principal& aPrincipal)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ContentPermissionRequestParent);
|
|
|
|
|
|
|
|
mPrincipal = aPrincipal;
|
|
|
|
mElement = aElement;
|
|
|
|
mRequests = aRequests;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentPermissionRequestParent::~ContentPermissionRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ContentPermissionRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentPermissionRequestParent::Recvprompt()
|
|
|
|
{
|
|
|
|
mProxy = new nsContentPermissionRequestProxy();
|
|
|
|
NS_ASSERTION(mProxy, "Alloc of request proxy failed");
|
|
|
|
if (NS_FAILED(mProxy->Init(mRequests, this))) {
|
|
|
|
mProxy->Cancel();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
if (mProxy) {
|
|
|
|
mProxy->OnParentDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentPermissionRequestParent::IsBeingDestroyed()
|
|
|
|
{
|
|
|
|
// When TabParent::Destroy() is called, we are being destroyed. It's unsafe
|
|
|
|
// to send out any message now.
|
|
|
|
TabParent* tabParent = static_cast<TabParent*>(Manager());
|
|
|
|
return tabParent->IsDestroyed();
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(ContentPermissionType, nsIContentPermissionType)
|
2014-02-09 12:34:40 -08:00
|
|
|
|
|
|
|
ContentPermissionType::ContentPermissionType(const nsACString& aType,
|
2013-09-10 08:41:59 -07:00
|
|
|
const nsACString& aAccess,
|
|
|
|
const nsTArray<nsString>& aOptions)
|
2014-02-09 12:34:40 -08:00
|
|
|
{
|
|
|
|
mType = aType;
|
|
|
|
mAccess = aAccess;
|
2013-09-10 08:41:59 -07:00
|
|
|
mOptions = aOptions;
|
2014-02-09 12:34:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ContentPermissionType::~ContentPermissionType()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentPermissionType::GetType(nsACString& aType)
|
|
|
|
{
|
|
|
|
aType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentPermissionType::GetAccess(nsACString& aAccess)
|
|
|
|
{
|
|
|
|
aAccess = mAccess;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-10 08:41:59 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentPermissionType::GetOptions(nsIArray** aOptions)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
|
|
|
|
*aOptions = nullptr;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIMutableArray> options =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// copy options into JS array
|
|
|
|
for (uint32_t i = 0; i < mOptions.Length(); ++i) {
|
|
|
|
nsCOMPtr<nsISupportsString> isupportsString =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = isupportsString->SetData(mOptions[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = options->AppendElement(isupportsString, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aOptions = options);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:34:40 -08:00
|
|
|
uint32_t
|
|
|
|
ConvertPermissionRequestToArray(nsTArray<PermissionRequest>& aSrcArray,
|
|
|
|
nsIMutableArray* aDesArray)
|
|
|
|
{
|
|
|
|
uint32_t len = aSrcArray.Length();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
nsRefPtr<ContentPermissionType> cpt =
|
2013-09-10 08:41:59 -07:00
|
|
|
new ContentPermissionType(aSrcArray[i].type(),
|
|
|
|
aSrcArray[i].access(),
|
|
|
|
aSrcArray[i].options());
|
2014-02-09 12:34:40 -08:00
|
|
|
aDesArray->AppendElement(cpt, false);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreatePermissionArray(const nsACString& aType,
|
|
|
|
const nsACString& aAccess,
|
2013-09-10 08:41:59 -07:00
|
|
|
const nsTArray<nsString>& aOptions,
|
2014-02-09 12:34:40 -08:00
|
|
|
nsIArray** aTypesArray)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMutableArray> types = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
nsRefPtr<ContentPermissionType> permType = new ContentPermissionType(aType,
|
2013-09-10 08:41:59 -07:00
|
|
|
aAccess,
|
|
|
|
aOptions);
|
2014-02-09 12:34:40 -08:00
|
|
|
types->AppendElement(permType, false);
|
|
|
|
types.forget(aTypesArray);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PContentPermissionRequestParent*
|
|
|
|
CreateContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
|
|
|
|
Element* element,
|
|
|
|
const IPC::Principal& principal)
|
|
|
|
{
|
|
|
|
return new ContentPermissionRequestParent(aRequests, element, principal);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-09-13 12:49:27 -07:00
|
|
|
nsContentPermissionRequestProxy::nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-09 12:34:40 -08:00
|
|
|
nsContentPermissionRequestProxy::Init(const nsTArray<PermissionRequest>& requests,
|
2012-07-30 07:58:26 -07:00
|
|
|
ContentPermissionRequestParent* parent)
|
2010-09-13 12:49:27 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(parent, "null parent");
|
|
|
|
mParent = parent;
|
2014-02-09 12:34:40 -08:00
|
|
|
mPermissionRequests = requests;
|
2010-09-13 12:49:27 -07:00
|
|
|
|
2012-10-31 10:06:42 -07:00
|
|
|
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
2010-09-13 12:49:27 -07:00
|
|
|
if (!prompt) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt->Prompt(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:07:43 -08:00
|
|
|
void
|
|
|
|
nsContentPermissionRequestProxy::OnParentDestroyed()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2011-02-09 11:07:43 -08:00
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsContentPermissionRequestProxy, nsIContentPermissionRequest)
|
2010-09-13 12:49:27 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-09 12:34:40 -08:00
|
|
|
nsContentPermissionRequestProxy::GetTypes(nsIArray** aTypes)
|
2013-12-09 22:03:21 -08:00
|
|
|
{
|
2014-02-09 12:34:40 -08:00
|
|
|
nsCOMPtr<nsIMutableArray> types = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
if (ConvertPermissionRequestToArray(mPermissionRequests, types)) {
|
|
|
|
types.forget(aTypes);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-11-13 16:06:42 -08:00
|
|
|
}
|
|
|
|
|
2010-09-13 12:49:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aRequestingWindow = nullptr; // ipc doesn't have a window
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-30 07:58:26 -07:00
|
|
|
nsContentPermissionRequestProxy::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
2010-09-13 12:49:27 -07:00
|
|
|
{
|
2012-07-30 07:58:26 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingPrincipal);
|
|
|
|
if (mParent == nullptr) {
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 07:58:26 -07:00
|
|
|
}
|
2010-09-13 12:49:27 -07:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
NS_ADDREF(*aRequestingPrincipal = mParent->mPrincipal);
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetElement(nsIDOMElement * *aRequestingElement)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
2012-07-30 07:58:26 -07:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 07:58:26 -07:00
|
|
|
}
|
|
|
|
|
2013-07-23 16:39:17 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(mParent->mElement);
|
|
|
|
elem.forget(aRequestingElement);
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::Cancel()
|
|
|
|
{
|
2012-07-30 07:58:26 -07:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 07:58:26 -07:00
|
|
|
}
|
|
|
|
|
2013-10-16 15:25:50 -07:00
|
|
|
// Don't send out the delete message when the managing protocol (PBrowser) is
|
|
|
|
// being destroyed and PContentPermissionRequest will soon be.
|
|
|
|
if (mParent->IsBeingDestroyed()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-09-10 08:41:59 -07:00
|
|
|
nsTArray<PermissionChoice> emptyChoices;
|
|
|
|
|
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, false, emptyChoices);
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-09-10 08:41:59 -07:00
|
|
|
nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices)
|
2010-09-13 12:49:27 -07:00
|
|
|
{
|
2012-07-30 07:58:26 -07:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 07:58:26 -07:00
|
|
|
}
|
2013-10-16 15:25:50 -07:00
|
|
|
|
|
|
|
// Don't send out the delete message when the managing protocol (PBrowser) is
|
|
|
|
// being destroyed and PContentPermissionRequest will soon be.
|
|
|
|
if (mParent->IsBeingDestroyed()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-12-05 06:29:07 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-02-09 12:34:40 -08:00
|
|
|
uint32_t len = mPermissionRequests.Length();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
2014-05-21 20:48:51 -07:00
|
|
|
if (mPermissionRequests[i].type().EqualsLiteral("audio-capture")) {
|
2014-02-09 12:34:40 -08:00
|
|
|
GonkPermissionService::GetInstance()->addGrantInfo(
|
|
|
|
"android.permission.RECORD_AUDIO",
|
2014-06-10 22:44:03 -07:00
|
|
|
static_cast<TabParent*>(
|
|
|
|
mParent->Manager())->Manager()->AsContentParent()->Pid());
|
2014-02-09 12:34:40 -08:00
|
|
|
}
|
2014-05-21 20:48:51 -07:00
|
|
|
if (mPermissionRequests[i].type().EqualsLiteral("video-capture")) {
|
2014-02-09 12:34:40 -08:00
|
|
|
GonkPermissionService::GetInstance()->addGrantInfo(
|
|
|
|
"android.permission.CAMERA",
|
2014-06-10 22:44:03 -07:00
|
|
|
static_cast<TabParent*>(
|
|
|
|
mParent->Manager())->Manager()->AsContentParent()->Pid());
|
2014-02-09 12:34:40 -08:00
|
|
|
}
|
2013-12-05 06:29:07 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-10 08:41:59 -07:00
|
|
|
nsTArray<PermissionChoice> choices;
|
|
|
|
if (aChoices.isNullOrUndefined()) {
|
|
|
|
// No choice is specified.
|
|
|
|
} else if (aChoices.isObject()) {
|
|
|
|
// Iterate through all permission types.
|
|
|
|
for (uint32_t i = 0; i < mPermissionRequests.Length(); ++i) {
|
|
|
|
nsCString type = mPermissionRequests[i].type();
|
|
|
|
|
|
|
|
mozilla::AutoSafeJSContext cx;
|
|
|
|
JS::Rooted<JSObject*> obj(cx, &aChoices.toObject());
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> val(cx);
|
|
|
|
|
|
|
|
if (!JS_GetProperty(cx, obj, type.BeginReading(), &val) ||
|
|
|
|
!val.isString()) {
|
|
|
|
// no setting for the permission type, skip it
|
|
|
|
} else {
|
2014-07-05 08:30:54 -07:00
|
|
|
nsAutoJSString choice;
|
2013-09-10 08:41:59 -07:00
|
|
|
if (!choice.init(cx, val)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
choices.AppendElement(PermissionChoice(type, choice));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "SelectedChoices should be undefined or an JS object");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, true, choices);
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-07 21:45:23 -07:00
|
|
|
|
|
|
|
// RemotePermissionRequest
|
|
|
|
|
|
|
|
// static
|
|
|
|
uint32_t
|
|
|
|
RemotePermissionRequest::ConvertArrayToPermissionRequest(
|
|
|
|
nsIArray* aSrcArray,
|
|
|
|
nsTArray<PermissionRequest>& aDesArray)
|
|
|
|
{
|
|
|
|
uint32_t len = 0;
|
|
|
|
aSrcArray->GetLength(&len);
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
nsCOMPtr<nsIContentPermissionType> cpt = do_QueryElementAt(aSrcArray, i);
|
|
|
|
nsAutoCString type;
|
|
|
|
nsAutoCString access;
|
|
|
|
cpt->GetType(type);
|
|
|
|
cpt->GetAccess(access);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIArray> optionArray;
|
|
|
|
cpt->GetOptions(getter_AddRefs(optionArray));
|
|
|
|
uint32_t optionsLength = 0;
|
|
|
|
if (optionArray) {
|
|
|
|
optionArray->GetLength(&optionsLength);
|
|
|
|
}
|
|
|
|
nsTArray<nsString> options;
|
|
|
|
for (uint32_t j = 0; j < optionsLength; ++j) {
|
|
|
|
nsCOMPtr<nsISupportsString> isupportsString = do_QueryElementAt(optionArray, j);
|
|
|
|
if (isupportsString) {
|
|
|
|
nsString option;
|
|
|
|
isupportsString->GetData(option);
|
|
|
|
options.AppendElement(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aDesArray.AppendElement(PermissionRequest(type, access, options));
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(RemotePermissionRequest, nsIContentPermissionRequest)
|
|
|
|
|
|
|
|
RemotePermissionRequest::RemotePermissionRequest(
|
|
|
|
nsIContentPermissionRequest* aRequest,
|
|
|
|
nsPIDOMWindow* aWindow)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mWindow(aWindow)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIContentPermissionRequest methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::GetTypes(nsIArray** aTypes)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRequest, "We need a request");
|
|
|
|
return mRequest->GetTypes(aTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::GetPrincipal(nsIPrincipal **aRequestingPrincipal)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingPrincipal);
|
|
|
|
|
|
|
|
return mRequest->GetPrincipal(aRequestingPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::GetWindow(nsIDOMWindow** aRequestingWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
|
|
|
|
|
|
|
return mRequest->GetWindow(aRequestingWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::GetElement(nsIDOMElement** aRequestingElement)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
|
|
|
*aRequestingElement = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::Cancel()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRequest, "We need a request");
|
|
|
|
return mRequest->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RemotePermissionRequest::Allow(JS::HandleValue aChoices)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRequest, "We need a request");
|
|
|
|
return mRequest->Allow(aChoices);
|
|
|
|
}
|
|
|
|
|
|
|
|
// PCOMContentPermissionRequestChild
|
|
|
|
bool
|
|
|
|
RemotePermissionRequest::Recv__delete__(const bool& aAllow,
|
|
|
|
const nsTArray<PermissionChoice>& aChoices)
|
|
|
|
{
|
|
|
|
if (aAllow && mWindow->IsCurrentInnerWindow()) {
|
|
|
|
// Convert choices to a JS val if any.
|
|
|
|
// {"type1": "choice1", "type2": "choiceA"}
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
|
|
|
return true; // This is not an IPC error.
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
JS::Rooted<JSObject*> obj(cx);
|
|
|
|
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
|
|
|
|
for (uint32_t i = 0; i < aChoices.Length(); ++i) {
|
|
|
|
const nsString& choice = aChoices[i].choice();
|
|
|
|
const nsCString& type = aChoices[i].type();
|
|
|
|
JS::Rooted<JSString*> jChoice(cx, JS_NewUCStringCopyN(cx, choice.get(), choice.Length()));
|
|
|
|
JS::Rooted<JS::Value> vChoice(cx, StringValue(jChoice));
|
|
|
|
if (!JS_SetProperty(cx, obj, type.get(), vChoice)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JS::RootedValue val(cx, JS::ObjectValue(*obj));
|
|
|
|
(void) Allow(val);
|
|
|
|
} else {
|
|
|
|
(void) Cancel();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|