1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsContentPermissionHelper.h"
6 #include "nsIContentPermissionPrompt.h"
8 #include "nsIDOMElement.h"
9 #include "nsIPrincipal.h"
10 #include "mozilla/dom/Element.h"
11 #include "mozilla/unused.h"
13 using mozilla::unused
; // <snicker>
14 using namespace mozilla::dom
;
16 nsContentPermissionRequestProxy::nsContentPermissionRequestProxy()
18 MOZ_COUNT_CTOR(nsContentPermissionRequestProxy
);
21 nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy()
23 MOZ_COUNT_DTOR(nsContentPermissionRequestProxy
);
27 nsContentPermissionRequestProxy::Init(const nsACString
& type
,
28 const nsACString
& access
,
29 ContentPermissionRequestParent
* parent
)
31 NS_ASSERTION(parent
, "null parent");
36 nsCOMPtr
<nsIContentPermissionPrompt
> prompt
= do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID
);
38 return NS_ERROR_FAILURE
;
46 nsContentPermissionRequestProxy::OnParentDestroyed()
51 NS_IMPL_ISUPPORTS1(nsContentPermissionRequestProxy
, nsIContentPermissionRequest
)
54 nsContentPermissionRequestProxy::GetType(nsACString
& aType
)
61 nsContentPermissionRequestProxy::GetAccess(nsACString
& aAccess
)
68 nsContentPermissionRequestProxy::GetWindow(nsIDOMWindow
* *aRequestingWindow
)
70 NS_ENSURE_ARG_POINTER(aRequestingWindow
);
71 *aRequestingWindow
= nullptr; // ipc doesn't have a window
76 nsContentPermissionRequestProxy::GetPrincipal(nsIPrincipal
* *aRequestingPrincipal
)
78 NS_ENSURE_ARG_POINTER(aRequestingPrincipal
);
79 if (mParent
== nullptr) {
80 return NS_ERROR_FAILURE
;
83 NS_ADDREF(*aRequestingPrincipal
= mParent
->mPrincipal
);
88 nsContentPermissionRequestProxy::GetElement(nsIDOMElement
* *aRequestingElement
)
90 NS_ENSURE_ARG_POINTER(aRequestingElement
);
91 if (mParent
== nullptr) {
92 return NS_ERROR_FAILURE
;
95 nsCOMPtr
<nsIDOMElement
> elem
= do_QueryInterface(mParent
->mElement
);
96 elem
.forget(aRequestingElement
);
101 nsContentPermissionRequestProxy::Cancel()
103 if (mParent
== nullptr) {
104 return NS_ERROR_FAILURE
;
107 unused
<< ContentPermissionRequestParent::Send__delete__(mParent
, false);
113 nsContentPermissionRequestProxy::Allow()
115 if (mParent
== nullptr) {
116 return NS_ERROR_FAILURE
;
118 unused
<< ContentPermissionRequestParent::Send__delete__(mParent
, true);
126 ContentPermissionRequestParent::ContentPermissionRequestParent(const nsACString
& aType
,
127 const nsACString
& aAccess
,
129 const IPC::Principal
& aPrincipal
)
131 MOZ_COUNT_CTOR(ContentPermissionRequestParent
);
133 mPrincipal
= aPrincipal
;
139 ContentPermissionRequestParent::~ContentPermissionRequestParent()
141 MOZ_COUNT_DTOR(ContentPermissionRequestParent
);
145 ContentPermissionRequestParent::Recvprompt()
147 mProxy
= new nsContentPermissionRequestProxy();
148 NS_ASSERTION(mProxy
, "Alloc of request proxy failed");
149 if (NS_FAILED(mProxy
->Init(mType
, mAccess
, this))) {
156 ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why
)
159 mProxy
->OnParentDestroyed();
164 } // namespace mozilla