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
This commit is contained in:
Johnny Stenback 2010-11-09 18:00:01 -05:00
parent bf0f0e4481
commit 6ac980ac46
3 changed files with 71 additions and 4 deletions

View File

@ -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<nsISupports> 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<nsIXPConnectJSObjectHolder> holder;
nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native));
@ -6438,6 +6439,19 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
prop_val = OBJECT_TO_JSVAL(prop_obj);
} else {
nsCOMPtr<nsIDOMGlobalPropertyInitializer> 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()) {

View File

@ -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

View File

@ -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 <jst@mozilla.com> (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);
};