security/manager/pki/src/nsNSSDialogHelper.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/pki/src/nsNSSDialogHelper.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsNSSDialogHelper.h"
    1.11 +#include "nsIWindowWatcher.h"
    1.12 +#include "nsCOMPtr.h"
    1.13 +#include "nsIComponentManager.h"
    1.14 +#include "nsIServiceManager.h"
    1.15 +#include "nsIInterfaceRequestor.h"
    1.16 +#include "nsIInterfaceRequestorUtils.h"
    1.17 +#include "mozilla/dom/ScriptSettings.h"
    1.18 +
    1.19 +static const char kOpenDialogParam[] = "centerscreen,chrome,modal,titlebar";
    1.20 +static const char kOpenWindowParam[] = "centerscreen,chrome,titlebar";
    1.21 +
    1.22 +nsresult
    1.23 +nsNSSDialogHelper::openDialog(
    1.24 +    nsIDOMWindow *window,
    1.25 +    const char *url,
    1.26 +    nsISupports *params,
    1.27 +    bool modal)
    1.28 +{
    1.29 +  nsresult rv;
    1.30 +  nsCOMPtr<nsIWindowWatcher> windowWatcher = 
    1.31 +           do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
    1.32 +  if (NS_FAILED(rv)) return rv;
    1.33 +
    1.34 +  nsCOMPtr<nsIDOMWindow> parent = window;
    1.35 +
    1.36 +  if (!parent) {
    1.37 +    windowWatcher->GetActiveWindow(getter_AddRefs(parent));
    1.38 +  }
    1.39 +
    1.40 +  // We're loading XUL into this window, and it's happening on behalf of the
    1.41 +  // system, not on behalf of content. Make sure the initial about:blank window
    1.42 +  // gets a system principal, otherwise we'll bork when trying to wrap the
    1.43 +  // nsIKeyGenThread |arguments| property into the unprivileged scoope.
    1.44 +  MOZ_ASSERT(!strncmp("chrome://", url, strlen("chrome://")));
    1.45 +  mozilla::dom::AutoNoJSAPI nojsapi;
    1.46 +
    1.47 +  nsCOMPtr<nsIDOMWindow> newWindow;
    1.48 +  rv = windowWatcher->OpenWindow(parent,
    1.49 +                                 url,
    1.50 +                                 "_blank",
    1.51 +                                 modal
    1.52 +                                 ? kOpenDialogParam
    1.53 +                                 : kOpenWindowParam,
    1.54 +                                 params,
    1.55 +                                 getter_AddRefs(newWindow));
    1.56 +  return rv;
    1.57 +}
    1.58 +

mercurial