michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsNSSDialogHelper.h" michael@0: #include "nsIWindowWatcher.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsIInterfaceRequestorUtils.h" michael@0: #include "mozilla/dom/ScriptSettings.h" michael@0: michael@0: static const char kOpenDialogParam[] = "centerscreen,chrome,modal,titlebar"; michael@0: static const char kOpenWindowParam[] = "centerscreen,chrome,titlebar"; michael@0: michael@0: nsresult michael@0: nsNSSDialogHelper::openDialog( michael@0: nsIDOMWindow *window, michael@0: const char *url, michael@0: nsISupports *params, michael@0: bool modal) michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr windowWatcher = michael@0: do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: nsCOMPtr parent = window; michael@0: michael@0: if (!parent) { michael@0: windowWatcher->GetActiveWindow(getter_AddRefs(parent)); michael@0: } michael@0: michael@0: // We're loading XUL into this window, and it's happening on behalf of the michael@0: // system, not on behalf of content. Make sure the initial about:blank window michael@0: // gets a system principal, otherwise we'll bork when trying to wrap the michael@0: // nsIKeyGenThread |arguments| property into the unprivileged scoope. michael@0: MOZ_ASSERT(!strncmp("chrome://", url, strlen("chrome://"))); michael@0: mozilla::dom::AutoNoJSAPI nojsapi; michael@0: michael@0: nsCOMPtr newWindow; michael@0: rv = windowWatcher->OpenWindow(parent, michael@0: url, michael@0: "_blank", michael@0: modal michael@0: ? kOpenDialogParam michael@0: : kOpenWindowParam, michael@0: params, michael@0: getter_AddRefs(newWindow)); michael@0: return rv; michael@0: } michael@0: