1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsNSSDialogHelper.h"
9 #include "mozIDOMWindow.h"
10 #include "mozilla/dom/ScriptSettings.h"
12 #include "nsIWindowWatcher.h"
13 #include "nsServiceManagerUtils.h"
15 static const char kOpenDialogParam
[] = "centerscreen,chrome,modal,titlebar";
16 static const char kOpenWindowParam
[] = "centerscreen,chrome,titlebar";
18 nsresult
nsNSSDialogHelper::openDialog(mozIDOMWindowProxy
* window
,
19 const char* url
, nsISupports
* params
,
22 nsCOMPtr
<nsIWindowWatcher
> windowWatcher
=
23 do_GetService(NS_WINDOWWATCHER_CONTRACTID
, &rv
);
24 if (NS_FAILED(rv
)) return rv
;
26 nsCOMPtr
<mozIDOMWindowProxy
> parent
= window
;
29 windowWatcher
->GetActiveWindow(getter_AddRefs(parent
));
32 // We're loading XUL into this window, and it's happening on behalf of the
33 // system, not on behalf of content. Make sure the initial about:blank window
34 // gets a system principal, otherwise we'll bork when trying to wrap the
35 // nsIKeyGenThread |arguments| property into the unprivileged scoope.
36 MOZ_ASSERT(!strncmp("chrome://", url
, strlen("chrome://")));
37 mozilla::dom::AutoNoJSAPI nojsapi
;
39 nsCOMPtr
<mozIDOMWindowProxy
> newWindow
;
40 rv
= windowWatcher
->OpenWindow(
41 parent
, nsDependentCString(url
), "_blank"_ns
,
42 nsDependentCString(modal
? kOpenDialogParam
: kOpenWindowParam
), params
,
43 getter_AddRefs(newWindow
));