nsNSSDialogHelper.cpp (1759B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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/. */ 6 7 #include "nsNSSDialogHelper.h" 8 9 #include "mozIDOMWindow.h" 10 #include "mozilla/dom/ScriptSettings.h" 11 #include "nsCOMPtr.h" 12 #include "nsIWindowWatcher.h" 13 #include "nsServiceManagerUtils.h" 14 15 static const char kOpenDialogParam[] = "centerscreen,chrome,modal,titlebar"; 16 static const char kOpenWindowParam[] = "centerscreen,chrome,titlebar"; 17 18 nsresult nsNSSDialogHelper::openDialog(mozIDOMWindowProxy* window, 19 const char* url, nsISupports* params, 20 bool modal) { 21 nsresult rv; 22 nsCOMPtr<nsIWindowWatcher> windowWatcher = 23 do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); 24 if (NS_FAILED(rv)) return rv; 25 26 nsCOMPtr<mozIDOMWindowProxy> parent = window; 27 28 if (!parent) { 29 windowWatcher->GetActiveWindow(getter_AddRefs(parent)); 30 } 31 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; 38 39 nsCOMPtr<mozIDOMWindowProxy> newWindow; 40 rv = windowWatcher->OpenWindow( 41 parent, nsDependentCString(url), "_blank"_ns, 42 nsDependentCString(modal ? kOpenDialogParam : kOpenWindowParam), params, 43 getter_AddRefs(newWindow)); 44 return rv; 45 }