1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * The Mozilla Foundation
18 * Portions created by the Initial Developer are Copyright (C) 2010
19 * the Initial Developer. All Rights Reserved.
22 * Doug Turner <dougt@mozilla.com> (Original Author)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsContentPermissionHelper.h"
39 #include "nsIContentPermissionPrompt.h"
41 #include "nsIDOMWindow.h"
42 #include "nsIDOMElement.h"
44 #include "mozilla/unused.h"
46 using mozilla::unused
; // <snicker>
48 nsContentPermissionRequestProxy::nsContentPermissionRequestProxy()
50 MOZ_COUNT_CTOR(nsContentPermissionRequestProxy
);
53 nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy()
55 MOZ_COUNT_DTOR(nsContentPermissionRequestProxy
);
59 nsContentPermissionRequestProxy::Init(const nsACString
& type
,
60 mozilla::dom::ContentPermissionRequestParent
* parent
)
62 NS_ASSERTION(parent
, "null parent");
66 nsCOMPtr
<nsIContentPermissionPrompt
> prompt
= do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID
);
68 return NS_ERROR_FAILURE
;
76 nsContentPermissionRequestProxy::OnParentDestroyed()
81 NS_IMPL_ISUPPORTS1(nsContentPermissionRequestProxy
, nsIContentPermissionRequest
);
84 nsContentPermissionRequestProxy::GetType(nsACString
& aType
)
91 nsContentPermissionRequestProxy::GetWindow(nsIDOMWindow
* *aRequestingWindow
)
93 NS_ENSURE_ARG_POINTER(aRequestingWindow
);
94 *aRequestingWindow
= nsnull
; // ipc doesn't have a window
99 nsContentPermissionRequestProxy::GetUri(nsIURI
* *aRequestingURI
)
101 NS_ENSURE_ARG_POINTER(aRequestingURI
);
102 if (mParent
== nsnull
)
103 return NS_ERROR_FAILURE
;
105 NS_ADDREF(*aRequestingURI
= mParent
->mURI
);
110 nsContentPermissionRequestProxy::GetElement(nsIDOMElement
* *aRequestingElement
)
112 NS_ENSURE_ARG_POINTER(aRequestingElement
);
113 if (mParent
== nsnull
)
114 return NS_ERROR_FAILURE
;
115 NS_ADDREF(*aRequestingElement
= mParent
->mElement
);
120 nsContentPermissionRequestProxy::Cancel()
122 if (mParent
== nsnull
)
123 return NS_ERROR_FAILURE
;
124 unused
<< mozilla::dom::ContentPermissionRequestParent::Send__delete__(mParent
, false);
130 nsContentPermissionRequestProxy::Allow()
132 if (mParent
== nsnull
)
133 return NS_ERROR_FAILURE
;
134 unused
<< mozilla::dom::ContentPermissionRequestParent::Send__delete__(mParent
, true);
142 ContentPermissionRequestParent::ContentPermissionRequestParent(const nsACString
& aType
,
143 nsIDOMElement
*aElement
,
144 const IPC::URI
& aUri
)
146 MOZ_COUNT_CTOR(ContentPermissionRequestParent
);
153 ContentPermissionRequestParent::~ContentPermissionRequestParent()
155 MOZ_COUNT_DTOR(ContentPermissionRequestParent
);
159 ContentPermissionRequestParent::Recvprompt()
161 mProxy
= new nsContentPermissionRequestProxy();
162 NS_ASSERTION(mProxy
, "Alloc of request proxy failed");
163 if (NS_FAILED(mProxy
->Init(mType
, this)))
169 ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why
)
171 mProxy
->OnParentDestroyed();
175 } // namespace mozilla