bug 580128 - Now that we use a proxy for the outer window, nsOuterWindowSH is unused (except for PreCreate). Nuke it. r=peterv

This commit is contained in:
Blake Kaplan 2010-09-17 14:54:40 -07:00
parent b548e78f8a
commit 6f88d76769
5 changed files with 69 additions and 451 deletions

View File

@ -503,7 +503,7 @@ static const char kDOMStringBundleURL[] =
// NOTE: DEFAULT_SCRIPTABLE_FLAGS and DOM_DEFAULT_SCRIPTABLE_FLAGS
// are defined in nsIDOMClassInfo.h.
#define COMMON_WINDOW_SCRIPTABLE_FLAGS \
#define WINDOW_SCRIPTABLE_FLAGS \
(nsIXPCScriptable::WANT_GETPROPERTY | \
nsIXPCScriptable::WANT_SETPROPERTY | \
nsIXPCScriptable::WANT_PRECREATE | \
@ -511,16 +511,8 @@ static const char kDOMStringBundleURL[] =
nsIXPCScriptable::WANT_DELPROPERTY | \
nsIXPCScriptable::WANT_FINALIZE | \
nsIXPCScriptable::WANT_EQUALITY | \
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
#define INNER_WINDOW_SCRIPTABLE_FLAGS \
(COMMON_WINDOW_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_OUTER_OBJECT) \
#define OUTER_WINDOW_SCRIPTABLE_FLAGS \
(COMMON_WINDOW_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_INNER_OBJECT | \
nsIXPCScriptable::WANT_NEWENUMERATE)
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \
nsIXPCScriptable::WANT_OUTER_OBJECT)
#define NODE_SCRIPTABLE_FLAGS \
((DOM_DEFAULT_SCRIPTABLE_FLAGS | \
@ -645,13 +637,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
// to JS.
NS_DEFINE_CLASSINFO_DATA(Window, nsOuterWindowSH,
NS_DEFINE_CLASSINFO_DATA(Window, nsWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
OUTER_WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(InnerWindow, nsInnerWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
INNER_WINDOW_SCRIPTABLE_FLAGS)
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Location, nsLocationSH,
(DOM_DEFAULT_SCRIPTABLE_FLAGS &
@ -944,13 +932,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
// DOM Chrome Window class.
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsOuterWindowSH,
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
OUTER_WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(InnerChromeWindow, nsInnerWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
INNER_WINDOW_SCRIPTABLE_FLAGS)
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSRGBColor, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -1331,13 +1315,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(FileReader, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ModalContentWindow, nsOuterWindowSH,
NS_DEFINE_CLASSINFO_DATA(ModalContentWindow, nsWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
OUTER_WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(InnerModalContentWindow, nsInnerWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
INNER_WINDOW_SCRIPTABLE_FLAGS)
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DataContainerEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -2260,17 +2240,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(InnerWindow, nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WindowUtils, nsIDOMWindowUtils)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowUtils)
DOM_CLASSINFO_MAP_END
@ -2968,18 +2937,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(InnerChromeWindow, nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(RangeException, nsIDOMRangeException)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMRangeException)
DOM_CLASSINFO_MAP_ENTRY(nsIException)
@ -3859,18 +3816,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMModalContentWindow)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(InnerModalContentWindow, nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMModalContentWindow)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DataContainerEvent, nsIDOMDataContainerEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDataContainerEvent)
DOM_CLASSINFO_EVENT_MAP_ENTRIES
@ -4708,15 +4653,7 @@ nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * proto)
if (if_info) {
nsXPIDLCString name;
if_info->GetName(getter_Copies(name));
// Allow for inner/non-inner mismatch.
static const char inner[] = "Inner";
const char *dataname = mData->mName;
if (!strncmp(dataname, "Inner", sizeof(inner) - 1)) {
dataname += sizeof(inner) - 1;
}
NS_ASSERTION(nsCRT::strcmp(CutPrefix(name), dataname) == 0,
NS_ASSERTION(nsCRT::strcmp(CutPrefix(name), mData->mName) == 0,
"Class name and proto chain interface name mismatch!");
}
}
@ -4953,8 +4890,8 @@ nsDOMClassInfo::ShutDown()
// Window helper
NS_IMETHODIMP
nsInnerWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
nsWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
{
// Normally ::PreCreate() is used to give XPConnect the parent
// object for the object that's being wrapped, this parent object is
@ -4972,6 +4909,15 @@ nsInnerWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
NS_ASSERTION(sgo, "nativeObj not a global object!");
nsGlobalWindow *win = nsGlobalWindow::FromSupports(nativeObj);
if (win->IsOuterWindow()) {
if (!win->EnsureInnerWindow()) {
return NS_ERROR_FAILURE;
}
*parentObj = win->GetCurrentInnerWindowInternal()->FastGetGlobalJSObject();
return win->IsChromeWindow() ? NS_OK : NS_SUCCESS_NEEDS_XOW;
}
JSObject *winObj = win->FastGetGlobalJSObject();
if (!winObj) {
NS_ASSERTION(win->GetOuterWindowInternal()->IsCreatingInnerWindow(),
@ -4983,34 +4929,17 @@ nsInnerWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
return NS_OK;
}
NS_IMETHODIMP
nsOuterWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
{
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nativeObj));
NS_ASSERTION(sgo, "nativeObj not a global object!");
nsGlobalWindow *win = nsGlobalWindow::FromSupports(nativeObj);
if (!win->EnsureInnerWindow()) {
return NS_ERROR_FAILURE;
}
*parentObj = win->GetCurrentInnerWindowInternal()->FastGetGlobalJSObject();
return win->IsChromeWindow() ? NS_OK : NS_SUCCESS_NEEDS_XOW;
}
// This JS class piggybacks on nsHTMLDocumentSH::ReleaseDocument()...
static JSClass sGlobalScopePolluterClass = {
"Global Scope Polluter",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_NEW_RESOLVE,
nsCommonWindowSH::SecurityCheckOnSetProp,
nsCommonWindowSH::SecurityCheckOnSetProp,
nsCommonWindowSH::GlobalScopePolluterGetProperty,
nsCommonWindowSH::SecurityCheckOnSetProp,
nsWindowSH::SecurityCheckOnSetProp,
nsWindowSH::SecurityCheckOnSetProp,
nsWindowSH::GlobalScopePolluterGetProperty,
nsWindowSH::SecurityCheckOnSetProp,
JS_EnumerateStub,
(JSResolveOp)nsCommonWindowSH::GlobalScopePolluterNewResolve,
(JSResolveOp)nsWindowSH::GlobalScopePolluterNewResolve,
JS_ConvertStub,
nsHTMLDocumentSH::ReleaseDocument
};
@ -5018,8 +4947,8 @@ static JSClass sGlobalScopePolluterClass = {
// static
JSBool
nsCommonWindowSH::GlobalScopePolluterGetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp)
nsWindowSH::GlobalScopePolluterGetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp)
{
// Someone is accessing a element by referencing its name/id in the
// global scope, do a security check to make sure that's ok.
@ -5045,8 +4974,8 @@ nsCommonWindowSH::GlobalScopePolluterGetProperty(JSContext *cx, JSObject *obj,
// static
JSBool
nsCommonWindowSH::SecurityCheckOnSetProp(JSContext *cx, JSObject *obj, jsid id,
jsval *vp)
nsWindowSH::SecurityCheckOnSetProp(JSContext *cx, JSObject *obj, jsid id,
jsval *vp)
{
// Someone is accessing a element by referencing its name/id in the
// global scope, do a security check to make sure that's ok.
@ -5070,8 +4999,8 @@ GetDocument(JSContext *cx, JSObject *obj)
// static
JSBool
nsCommonWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
jsid id, uintN flags,
nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
jsid id, uintN flags,
JSObject **objp)
{
if (flags & (JSRESOLVE_ASSIGNING | JSRESOLVE_DECLARING |
@ -5140,7 +5069,7 @@ nsCommonWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
// static
void
nsCommonWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
nsWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
{
JSObject *proto;
@ -5167,8 +5096,8 @@ nsCommonWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
// static
nsresult
nsCommonWindowSH::InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
nsIHTMLDocument *doc)
nsWindowSH::InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
nsIHTMLDocument *doc)
{
// If global scope pollution is disabled, or if our document is not
// a HTML document, do nothing
@ -5235,8 +5164,8 @@ GetChildFrame(nsGlobalWindow *win, jsid id)
}
NS_IMETHODIMP
nsCommonWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
@ -5325,7 +5254,7 @@ nsCommonWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (JSID_IS_STRING(id) && !JSVAL_IS_PRIMITIVE(*vp) &&
::JS_TypeOfValue(cx, *vp) != JSTYPE_FUNCTION) {
// A named property accessed which could have been resolved to a
// child frame in nsCommonWindowSH::NewResolve() (*vp will tell us if
// child frame in nsWindowSH::NewResolve() (*vp will tell us if
// that's the case). If *vp is a window object (i.e. a child
// frame), return without doing a security check.
//
@ -5363,8 +5292,8 @@ nsCommonWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
NS_IMETHODIMP
nsCommonWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
nsWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
@ -5440,49 +5369,8 @@ nsCommonWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
NS_IMETHODIMP
nsOuterWindowSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp,
PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
JSObject *realObj;
wrapper->GetJSObject(&realObj);
if (obj == realObj) {
nsGlobalWindow *innerWin = win->GetCurrentInnerWindowInternal();
JSObject *innerObj;
if (innerWin && (innerObj = innerWin->GetGlobalJSObject())) {
if (sResolving) {
return NS_OK;
}
#ifdef DEBUG_SH_FORWARDING
printf(" --- Forwarding add to inner window %p\n", (void *)innerWin);
#endif
JSPropertyDescriptor desc;
if (!JS_GetPropertyDescriptorById(cx, obj, id,
JSRESOLVE_QUALIFIED, &desc)) {
*_retval = JS_FALSE;
return NS_OK;
}
// Forward the add to the inner object
*_retval = JS_DefinePropertyById(cx, innerObj, id, *vp,
desc.getter, desc.setter,
desc.attrs | JSPROP_ENUMERATE);
return NS_OK;
}
}
return nsEventReceiverSH::AddProperty(wrapper, cx, obj, id, vp, _retval);
}
NS_IMETHODIMP
nsCommonWindowSH::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp,
PRBool *_retval)
nsWindowSH::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
@ -6309,8 +6197,8 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
// static
nsresult
nsCommonWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
JSObject *obj, JSString *str, PRBool *did_resolve)
nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
JSObject *obj, JSString *str, PRBool *did_resolve)
{
*did_resolve = PR_FALSE;
@ -6552,111 +6440,10 @@ ContentWindowGetter(JSContext *cx, uintN argc, jsval *vp)
return ::JS_GetProperty(cx, obj, "content", vp);
}
PRBool
nsOuterWindowSH::sResolving = PR_FALSE;
NS_IMETHODIMP
nsOuterWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, PRUint32 flags,
JSObject **objp, PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
// Note, we won't forward resolve of the location property to the
// inner window, we need to deal with that one for the outer too
// since we've got special security protection code for that
// property. Also note that we want to enter this block even for
// native wrappers, so that we'll ensure an inner window to wrap
// against for the result of whatever we're getting.
if (id != sLocation_id) {
// XXXjst: Do security checks here when we remove the security
// checks on the inner window.
nsGlobalWindow *innerWin = win->GetCurrentInnerWindowInternal();
if ((!innerWin || !innerWin->GetExtantDocument()) &&
!win->IsCreatingInnerWindow()) {
// We're resolving a property on an outer window for which there
// is no inner window yet, and we're not in the midst of
// creating the inner window or in the middle of initializing
// XPConnect classes on it. If the context is already
// initialized, force creation of a new inner window. This will
// create a synthetic about:blank document, and an inner window
// which may be reused by the actual document being loaded into
// this outer window. This way properties defined on the window
// before the document load started will be visible to the
// document once it's loaded, assuming same origin etc.
nsIScriptContext *scx = win->GetContextInternal();
if (scx && scx->IsContextInitialized()) {
// Grab the new inner window.
innerWin = win->EnsureInnerWindowInternal();
if (!innerWin) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
}
JSObject *innerObj;
JSObject *realObj;
wrapper->GetJSObject(&realObj);
if (realObj == obj &&
innerWin && (innerObj = innerWin->GetGlobalJSObject())) {
#ifdef DEBUG_SH_FORWARDING
printf(" --- Forwarding resolve to inner window %p\n", (void *)innerWin);
#endif
JSPropertyDescriptor desc;
*_retval = JS_GetPropertyDescriptorById(cx, innerObj, id, flags, &desc);
if (*_retval && desc.obj) {
#ifdef DEBUG_SH_FORWARDING
printf(" --- Resolve on inner window found property.\n");
#endif
// The JS engine assumes that the object that we return in objp is on
// our prototype chain. As a result, for an assignment, it wants to
// shadow the property by defining one on our object (unless the
// property has a setter). This confuses our code and, for fast
// expandos, we end up overriding the fast expando with a slow one. So
// detect when we're about to get a new property from the JS engine
// that would shadow a fast expando and define it ourselves, sending
// ourselves a signal via sResolving that we are doing this. Note that
// we only care about fast expandos on the innerObj itself, things
// found further up the prototype chain need to fend for themselves.
if ((flags & JSRESOLVE_ASSIGNING) &&
!(desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) &&
desc.obj == innerObj) {
PRBool oldResolving = sResolving;
sResolving = PR_TRUE;
*_retval = JS_DefinePropertyById(cx, obj, id, JSVAL_VOID,
nsnull, nsnull,
desc.attrs & JSPROP_ENUMERATE);
sResolving = oldResolving;
if (!*_retval) {
return NS_OK;
}
}
*objp = desc.obj;
}
return NS_OK;
}
}
return nsCommonWindowSH::NewResolve(wrapper, cx, obj, id, flags, objp,
_retval);
}
NS_IMETHODIMP
nsCommonWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, PRUint32 flags,
JSObject **objp, PRBool *_retval)
nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, PRUint32 flags,
JSObject **objp, PRBool *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
@ -6807,15 +6594,6 @@ nsCommonWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
#ifdef DEBUG
if (!win->IsChromeWindow()) {
NS_ASSERTION(JSVAL_IS_OBJECT(v) &&
!strcmp(JSVAL_TO_OBJECT(v)->getClass()->name,
"XPCCrossOriginWrapper"),
"Didn't wrap a window!");
}
#endif
JSAutoRequest ar(cx);
PRBool ok = ::JS_DefinePropertyById(cx, obj, id, v, nsnull, nsnull, 0);
@ -7159,70 +6937,8 @@ nsCommonWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
NS_IMETHODIMP
nsOuterWindowSH::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 enum_op, jsval *statep,
jsid *idp, PRBool *_retval)
{
switch ((JSIterateOp)enum_op) {
/* FIXME bug 576449: non-enumerable property support */
case JSENUMERATE_INIT_ALL:
case JSENUMERATE_INIT:
{
#ifdef DEBUG
// First, do the security check that nsDOMClassInfo does to see
// if we need to do any work at all.
nsDOMClassInfo::Enumerate(wrapper, cx, obj, _retval);
if (!*_retval) {
NS_ERROR("security wrappers failed us");
return NS_OK;
}
#endif
// The security check passed, let's see if we need to get the inner
// window's JS object or if we can just start enumerating.
nsGlobalWindow *win =
nsGlobalWindow::FromWrapper(wrapper)->GetCurrentInnerWindowInternal();
JSObject *enumobj = win->FastGetGlobalJSObject();
// Great, we have the js object, now let's enumerate it.
JSObject *iterator = JS_NewPropertyIterator(cx, enumobj);
if (!iterator) {
return NS_ERROR_OUT_OF_MEMORY;
}
*statep = OBJECT_TO_JSVAL(iterator);
if (idp) {
// Note: With these property iterators, we can't tell ahead of time how
// many properties we're going to be iterating over.
*idp = INT_TO_JSID(0);
}
break;
}
case JSENUMERATE_NEXT:
{
JSObject *iterator = (JSObject*)JSVAL_TO_OBJECT(*statep);
if (!JS_NextProperty(cx, iterator, idp)) {
return NS_ERROR_UNEXPECTED;
}
if (*idp != JSID_VOID) {
break;
}
// Fall through.
}
case JSENUMERATE_DESTROY:
// Let GC at our iterator object.
*statep = JSVAL_NULL;
break;
}
return NS_OK;
}
NS_IMETHODIMP
nsCommonWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
nsWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
{
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryWrappedNative(wrapper));
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
@ -7233,8 +6949,8 @@ nsCommonWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
NS_IMETHODIMP
nsCommonWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, const jsval &val, PRBool *bp)
nsWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, const jsval &val, PRBool *bp)
{
*bp = PR_FALSE;
@ -7270,8 +6986,8 @@ nsCommonWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
}
NS_IMETHODIMP
nsInnerWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval)
nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval)
{
nsGlobalWindow *origWin = nsGlobalWindow::FromWrapper(wrapper);
nsGlobalWindow *win = origWin->GetOuterWindowInternal();
@ -7297,36 +7013,6 @@ nsInnerWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
return NS_OK;
}
NS_IMETHODIMP
nsOuterWindowSH::InnerObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval)
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
if (win->IsFrozen()) {
// Return the inner window, or the outer if we're dealing with a
// frozen outer.
*_retval = obj;
} else {
// Try to find the current inner window.
nsGlobalWindow *inner = win->GetCurrentInnerWindowInternal();
if (!inner) {
// Yikes! No inner window! Instead of leaking the outer window into the
// scope chain, let's return an error.
NS_ERROR("using an outer that doesn't have an inner?");
*_retval = nsnull;
return NS_ERROR_UNEXPECTED;
}
*_retval = inner->FastGetGlobalJSObject();
}
return NS_OK;
}
// DOM Location helper
NS_IMETHODIMP

View File

@ -501,14 +501,14 @@ public:
// Window scriptable helper
class nsCommonWindowSH : public nsEventReceiverSH
class nsWindowSH : public nsEventReceiverSH
{
protected:
nsCommonWindowSH(nsDOMClassInfoData *aData) : nsEventReceiverSH(aData)
nsWindowSH(nsDOMClassInfoData *aData) : nsEventReceiverSH(aData)
{
}
virtual ~nsCommonWindowSH()
virtual ~nsWindowSH()
{
}
@ -517,6 +517,8 @@ protected:
PRBool *did_resolve);
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
#ifdef DEBUG
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
@ -552,6 +554,8 @@ public:
JSObject *obj);
NS_IMETHOD Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, const jsval &val, PRBool *bp);
NS_IMETHOD OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval);
static JSBool GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
jsid id, uintN flags,
@ -563,66 +567,12 @@ public:
static void InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj);
static nsresult InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
nsIHTMLDocument *doc);
};
class nsOuterWindowSH : public nsCommonWindowSH
{
protected:
nsOuterWindowSH(nsDOMClassInfoData* aData) : nsCommonWindowSH(aData)
{
}
virtual ~nsOuterWindowSH()
{
}
static PRBool sResolving;
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, PRUint32 flags,
JSObject **objp, PRBool *_retval);
NS_IMETHOD NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 enum_op, jsval *statep,
jsid *idp, PRBool *_retval);
NS_IMETHOD InnerObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsOuterWindowSH(aData);
return new nsWindowSH(aData);
}
};
class nsInnerWindowSH : public nsCommonWindowSH
{
protected:
nsInnerWindowSH(nsDOMClassInfoData* aData) : nsCommonWindowSH(aData)
{
}
virtual ~nsInnerWindowSH()
{
}
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
// We WANT_ADDPROPERTY, but are content to inherit it from nsEventReceiverSH.
NS_IMETHOD OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
JSObject * obj, JSObject * *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsInnerWindowSH(aData);
}
};
// Location scriptable helper
class nsLocationSH : public nsDOMGenericSH

View File

@ -37,7 +37,6 @@
* ***** END LICENSE BLOCK ***** */
DOMCI_CLASS(Window)
DOMCI_CLASS(InnerWindow)
DOMCI_CLASS(Location)
DOMCI_CLASS(Navigator)
DOMCI_CLASS(Plugin)
@ -189,7 +188,6 @@ DOMCI_CLASS(CSSRect)
// DOM Chrome Window class, almost identical to Window
DOMCI_CLASS(ChromeWindow)
DOMCI_CLASS(InnerChromeWindow)
// RGBColor object used by getComputedStyle
DOMCI_CLASS(CSSRGBColor)
@ -409,7 +407,6 @@ DOMCI_CLASS(FileReader)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)
DOMCI_CLASS(InnerModalContentWindow)
// Data Events
DOMCI_CLASS(DataContainerEvent)

View File

@ -1169,18 +1169,6 @@ nsGlobalWindow::FreeInnerObjects(PRBool aClearScope)
// nsGlobalWindow::nsISupports
//*****************************************************************************
#define WINDOW_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \
if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \
aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \
foundInterface = NS_GetDOMClassInfoInstance(IsInnerWindow() \
? eDOMClassInfo_Inner##_class##_id \
: eDOMClassInfo_##_class##_id);\
if (!foundInterface) { \
*aInstancePtr = nsnull; \
return NS_ERROR_OUT_OF_MEMORY; \
} \
} else
#define OUTER_WINDOW_ONLY \
if (IsOuterWindow()) {
@ -1191,7 +1179,6 @@ nsGlobalWindow::FreeInnerObjects(PRBool aClearScope)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalWindow)
DOMCI_DATA(Window, nsGlobalWindow)
DOMCI_DATA(InnerWindow, nsGlobalWindow)
// QueryInterface implementation for nsGlobalWindow
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindow)
@ -1213,7 +1200,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMStorageWindow)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
WINDOW_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Window)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Window)
OUTER_WINDOW_ONLY
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
END_OUTER_WINDOW_ONLY
@ -1806,7 +1793,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
newInnerWindow = currentInner;
if (aDocument != oldDoc) {
nsCommonWindowSH::InvalidateGlobalScopePolluter(cx, currentInner->mJSObject);
nsWindowSH::InvalidateGlobalScopePolluter(cx, currentInner->mJSObject);
}
} else {
if (aState) {
@ -2018,8 +2005,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
if ((!reUseInnerWindow || aDocument != oldDoc) && !aState) {
nsCOMPtr<nsIHTMLDocument> html_doc(do_QueryInterface(mDocument));
nsCommonWindowSH::InstallGlobalScopePolluter(cx, newInnerWindow->mJSObject,
html_doc);
nsWindowSH::InstallGlobalScopePolluter(cx, newInnerWindow->mJSObject,
html_doc);
}
if (aDocument) {
@ -2627,7 +2614,7 @@ nsGlobalWindow::DefineArgumentsProperty(nsIArray *aArguments)
if (mIsModalContentWindow) {
// Modal content windows don't have an "arguments" property, they
// have a "dialogArguments" property which is handled
// separately. See nsCommonWindowSH::NewResolve().
// separately. See nsWindowSH::NewResolve().
return NS_OK;
}
@ -9710,12 +9697,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalChromeWindow,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
DOMCI_DATA(ChromeWindow, nsGlobalChromeWindow)
DOMCI_DATA(InnerChromeWindow, nsGlobalChromeWindow)
// QueryInterface implementation for nsGlobalChromeWindow
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsGlobalChromeWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
WINDOW_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ChromeWindow)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ChromeWindow)
NS_INTERFACE_MAP_END_INHERITING(nsGlobalWindow)
NS_IMPL_ADDREF_INHERITED(nsGlobalChromeWindow, nsGlobalWindow)
@ -9994,11 +9980,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalModalWindow,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
DOMCI_DATA(ModalContentWindow, nsGlobalModalWindow)
DOMCI_DATA(InnerModalContentWindow, nsGlobalModalWindow)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsGlobalModalWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMModalContentWindow)
WINDOW_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ModalContentWindow)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ModalContentWindow)
NS_INTERFACE_MAP_END_INHERITING(nsGlobalWindow)
NS_IMPL_ADDREF_INHERITED(nsGlobalModalWindow, nsGlobalWindow)

View File

@ -3355,7 +3355,7 @@ nsJSContext::ClearScope(void *aGlobalObj, PRBool aClearFromProtoChain)
// chain when we're clearing an outer window whose current inner we
// still want.
if (aClearFromProtoChain) {
nsCommonWindowSH::InvalidateGlobalScopePolluter(mContext, obj);
nsWindowSH::InvalidateGlobalScopePolluter(mContext, obj);
// Clear up obj's prototype chain, but not Object.prototype.
for (JSObject *o = ::JS_GetPrototype(mContext, obj), *next;