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
|
2013-12-09 22:03:21 -08:00
|
|
|
#include "nsContentPermissionHelper.h"
|
|
|
|
#include "nsIContentPermissionPrompt.h"
|
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"
|
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"
|
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
|
|
|
|
|
|
|
nsContentPermissionRequestProxy::nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-12-09 22:03:21 -08:00
|
|
|
nsContentPermissionRequestProxy::Init(const nsACString & type,
|
|
|
|
const nsACString & access,
|
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;
|
2013-12-09 22:03:21 -08:00
|
|
|
mType = type;
|
|
|
|
mAccess = access;
|
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
|
|
|
}
|
|
|
|
|
2013-01-11 02:14:04 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(nsContentPermissionRequestProxy, nsIContentPermissionRequest)
|
2010-09-13 12:49:27 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-12-09 22:03:21 -08:00
|
|
|
nsContentPermissionRequestProxy::GetType(nsACString & aType)
|
2013-11-05 19:32:42 -08:00
|
|
|
{
|
2013-12-09 22:03:21 -08:00
|
|
|
aType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetAccess(nsACString & aAccess)
|
|
|
|
{
|
|
|
|
aAccess = mAccess;
|
|
|
|
return NS_OK;
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::Allow()
|
|
|
|
{
|
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
|
2013-12-09 22:03:21 -08:00
|
|
|
if (mType.Equals("audio-capture")) {
|
|
|
|
GonkPermissionService::GetInstance()->addGrantInfo(
|
|
|
|
"android.permission.RECORD_AUDIO",
|
|
|
|
static_cast<TabParent*>(mParent->Manager())->Manager()->Pid());
|
2013-12-05 06:29:07 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, true);
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2010-09-13 12:49:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-12-09 22:03:21 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
ContentPermissionRequestParent::ContentPermissionRequestParent(const nsACString& aType,
|
|
|
|
const nsACString& aAccess,
|
|
|
|
Element* aElement,
|
|
|
|
const IPC::Principal& aPrincipal)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ContentPermissionRequestParent);
|
|
|
|
|
|
|
|
mPrincipal = aPrincipal;
|
|
|
|
mElement = aElement;
|
|
|
|
mType = aType;
|
|
|
|
mAccess = aAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(mType, mAccess, 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|