2012-05-21 15:12:37 +04: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 23:49:27 +04:00
|
|
|
|
|
|
|
#include "nsContentPermissionHelper.h"
|
|
|
|
#include "nsIContentPermissionPrompt.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2012-07-30 18:58:26 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2010-09-13 23:49:27 +04:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
|
|
|
using mozilla::unused; // <snicker>
|
2012-07-30 18:58:26 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-09-13 23:49:27 +04:00
|
|
|
|
|
|
|
nsContentPermissionRequestProxy::nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsContentPermissionRequestProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentPermissionRequestProxy::Init(const nsACString & type,
|
2012-07-30 18:58:26 +04:00
|
|
|
ContentPermissionRequestParent* parent)
|
2010-09-13 23:49:27 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(parent, "null parent");
|
|
|
|
mParent = parent;
|
|
|
|
mType = type;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
|
|
|
if (!prompt) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt->Prompt(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-09 22:07:43 +03:00
|
|
|
void
|
|
|
|
nsContentPermissionRequestProxy::OnParentDestroyed()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2011-02-09 22:07:43 +03:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:49:27 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsContentPermissionRequestProxy, nsIContentPermissionRequest);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetType(nsACString & aType)
|
|
|
|
{
|
|
|
|
aType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aRequestingWindow = nullptr; // ipc doesn't have a window
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-30 18:58:26 +04:00
|
|
|
nsContentPermissionRequestProxy::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
2010-09-13 23:49:27 +04:00
|
|
|
{
|
2012-07-30 18:58:26 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingPrincipal);
|
|
|
|
if (mParent == nullptr) {
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 18:58:26 +04:00
|
|
|
}
|
2010-09-13 23:49:27 +04:00
|
|
|
|
2012-07-30 18:58:26 +04:00
|
|
|
NS_ADDREF(*aRequestingPrincipal = mParent->mPrincipal);
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::GetElement(nsIDOMElement * *aRequestingElement)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
2012-07-30 18:58:26 +04:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 18:58:26 +04:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:49:27 +04:00
|
|
|
NS_ADDREF(*aRequestingElement = mParent->mElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::Cancel()
|
|
|
|
{
|
2012-07-30 18:58:26 +04:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 18:58:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, false);
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentPermissionRequestProxy::Allow()
|
|
|
|
{
|
2012-07-30 18:58:26 +04:00
|
|
|
if (mParent == nullptr) {
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 18:58:26 +04:00
|
|
|
}
|
|
|
|
unused << ContentPermissionRequestParent::Send__delete__(mParent, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2010-09-13 23:49:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
ContentPermissionRequestParent::ContentPermissionRequestParent(const nsACString& aType,
|
|
|
|
nsIDOMElement *aElement,
|
2012-07-30 18:58:26 +04:00
|
|
|
const IPC::Principal& aPrincipal)
|
2010-09-13 23:49:27 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ContentPermissionRequestParent);
|
2012-07-30 18:58:26 +04:00
|
|
|
|
|
|
|
mPrincipal = aPrincipal;
|
2010-09-13 23:49:27 +04:00
|
|
|
mElement = aElement;
|
|
|
|
mType = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentPermissionRequestParent::~ContentPermissionRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ContentPermissionRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentPermissionRequestParent::Recvprompt()
|
|
|
|
{
|
|
|
|
mProxy = new nsContentPermissionRequestProxy();
|
|
|
|
NS_ASSERTION(mProxy, "Alloc of request proxy failed");
|
2012-07-30 18:58:26 +04:00
|
|
|
if (NS_FAILED(mProxy->Init(mType, this))) {
|
2010-09-13 23:49:27 +04:00
|
|
|
mProxy->Cancel();
|
2012-07-30 18:58:26 +04:00
|
|
|
}
|
2010-09-13 23:49:27 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-09 22:07:43 +03:00
|
|
|
void
|
|
|
|
ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
mProxy->OnParentDestroyed();
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:49:27 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|