From 635454b71ed9830ccaae251b7ae229c4b401195c Mon Sep 17 00:00:00 2001 From: Johnny Stenback Date: Tue, 9 Nov 2010 18:00:01 -0500 Subject: [PATCH] Bug 610714: Add nsIDOMGlobalPropertyInitializer, which allows "JavaScript Global Properties" to know about the window they're being attached to, r=mrbkap, a=blocking --HG-- extra : rebase_source : c66b23c40e111102c36364f55e01359390012612 --- dom/base/nsDOMClassInfo.cpp | 16 +++++- dom/interfaces/base/Makefile.in | 7 +-- .../base/nsIDOMGlobalPropertyInitializer.idl | 52 +++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 dom/interfaces/base/nsIDOMGlobalPropertyInitializer.idl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 594f74fb6d1..618960a855a 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -89,6 +89,7 @@ #include "nsIDOMPopStateEvent.h" #include "nsContentUtils.h" #include "nsDOMWindowUtils.h" +#include "nsIDOMGlobalPropertyInitializer.h" // Window scriptable helper includes #include "nsIDocShell.h" @@ -6424,7 +6425,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, nsCOMPtr native(do_CreateInstance(name_struct->mCID, &rv)); NS_ENSURE_SUCCESS(rv, rv); - jsval prop_val; // Property value. + jsval prop_val = JSVAL_VOID; // Property value. nsCOMPtr holder; nsCOMPtr owner(do_QueryInterface(native)); @@ -6438,6 +6439,19 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, prop_val = OBJECT_TO_JSVAL(prop_obj); } else { + nsCOMPtr gpi(do_QueryInterface(native)); + + if (gpi) { + rv = gpi->Init(aWin, &prop_val); + NS_ENSURE_SUCCESS(rv, rv); + + if (!JS_WrapValue(cx, &prop_val)) { + return NS_ERROR_UNEXPECTED; + } + } + } + + if (JSVAL_IS_PRIMITIVE(prop_val)) { JSObject *scope; if (aWin->IsOuterWindow()) { diff --git a/dom/interfaces/base/Makefile.in b/dom/interfaces/base/Makefile.in index bf114d36485..2b3f04a08b8 100644 --- a/dom/interfaces/base/Makefile.in +++ b/dom/interfaces/base/Makefile.in @@ -60,7 +60,7 @@ XPIDLSRCS = \ nsIBrowserDOMWindow.idl \ nsIContentPermissionPrompt.idl \ nsIContentPrefService.idl \ - nsIContentURIGrouper.idl \ + nsIContentURIGrouper.idl \ nsIDOMClientInformation.idl \ nsIDOMConstructor.idl \ nsIDOMCRMFObject.idl \ @@ -83,8 +83,9 @@ XPIDLSRCS = \ nsIDOMClientRectList.idl \ nsIFocusManager.idl \ nsIQueryContentEventResult.idl \ - nsITabChild.idl \ - nsITabParent.idl \ + nsITabChild.idl \ + nsITabParent.idl \ + nsIDOMGlobalPropertyInitializer.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/interfaces/base/nsIDOMGlobalPropertyInitializer.idl b/dom/interfaces/base/nsIDOMGlobalPropertyInitializer.idl new file mode 100644 index 00000000000..16454b991c2 --- /dev/null +++ b/dom/interfaces/base/nsIDOMGlobalPropertyInitializer.idl @@ -0,0 +1,52 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Johnny Stenback (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIDOMWindow.idl" + +[scriptable, uuid(6368a821-d3e2-4cbd-9699-5a8ba569e2f3)] +interface nsIDOMGlobalPropertyInitializer : nsISupports +{ + /* + * Initialize the global property. + * + * @param window the global object on which the property is being retrieved. + * + * @returns a JS Object to use use as the property's value. + */ + jsval init(in nsIDOMWindow window); +};