Skip to content

Commit

Permalink
Bug 760109 - Introduce an explicit ChromeObjectWrapper. r=mrbkap For …
Browse files Browse the repository at this point in the history
…now it's identical to ChromeObjectWrapperBase. Custom behavior comes in the next patch.
  • Loading branch information
bholley committed Aug 6, 2012
1 parent dcb3dbd commit db788da
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
5 changes: 5 additions & 0 deletions js/xpconnect/wrappers/AccessCheck.h
Expand Up @@ -5,6 +5,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __AccessCheck_h__
#define __AccessCheck_h__

#include "jsapi.h"
#include "jswrapper.h"
#include "WrapperFactory.h"
Expand Down Expand Up @@ -150,3 +153,5 @@ struct ComponentsObjectPolicy : public Policy {
};

}

#endif /* __AccessCheck_h__ */
7 changes: 7 additions & 0 deletions js/xpconnect/wrappers/ChromeObjectWrapper.cpp
@@ -0,0 +1,7 @@
#include "ChromeObjectWrapper.h"

namespace xpc {

ChromeObjectWrapper ChromeObjectWrapper::singleton;

}
34 changes: 34 additions & 0 deletions js/xpconnect/wrappers/ChromeObjectWrapper.h
@@ -0,0 +1,34 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __ChromeObjectWrapper_h__
#define __ChromeObjectWrapper_h__

#include "FilteringWrapper.h"
#include "AccessCheck.h"

namespace xpc {

// When chrome JS objects are exposed to content, they get a ChromeObjectWrapper.
//
// The base filtering wrapper here does most of the work for us. We define a
// custom class here to introduce custom behavior with respect to the prototype
// chain.
#define ChromeObjectWrapperBase \
FilteringWrapper<js::CrossCompartmentSecurityWrapper, ExposedPropertiesOnly>

class ChromeObjectWrapper : public ChromeObjectWrapperBase
{
public:
ChromeObjectWrapper() : ChromeObjectWrapperBase(0) {};

static ChromeObjectWrapper singleton;
};

} /* namespace xpc */

#endif /* __ChromeObjectWrapper_h__ */
6 changes: 2 additions & 4 deletions js/xpconnect/wrappers/FilteringWrapper.cpp
Expand Up @@ -7,6 +7,7 @@
#include "FilteringWrapper.h"
#include "AccessCheck.h"
#include "CrossOriginWrapper.h"
#include "ChromeObjectWrapper.h"
#include "XrayWrapper.h"
#include "WrapperFactory.h"

Expand Down Expand Up @@ -104,7 +105,6 @@ FilteringWrapper<Base, Policy>::enter(JSContext *cx, JSObject *wrapper, jsid id,

#define SOW FilteringWrapper<CrossCompartmentSecurityWrapper, OnlyIfSubjectIsSystem>
#define SCSOW FilteringWrapper<SameCompartmentSecurityWrapper, OnlyIfSubjectIsSystem>
#define COW FilteringWrapper<CrossCompartmentSecurityWrapper, ExposedPropertiesOnly>
#define XOW FilteringWrapper<XrayWrapper<CrossCompartmentSecurityWrapper>, \
CrossOriginAccessiblePropertiesOnly>
#define PXOW FilteringWrapper<XrayProxy, \
Expand All @@ -125,7 +125,6 @@ template<> SOW SOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::SOW_FLAG);
template<> SCSOW SCSOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::SOW_FLAG);
template<> COW COW::singleton(0);
template<> XOW XOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
template<> PXOW PXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
Expand All @@ -141,12 +140,11 @@ template<> CW CW::singleton(0);
template<> XCW XCW::singleton(0);

template class SOW;
template class COW;
template class XOW;
template class PXOW;
template class DXOW;
template class NNXOW;
template class LW;
template class XLW;

template class ChromeObjectWrapperBase;
}
5 changes: 5 additions & 0 deletions js/xpconnect/wrappers/FilteringWrapper.h
Expand Up @@ -5,6 +5,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __FilteringWrapper_h__
#define __FilteringWrapper_h__

#include <jsapi.h>
#include <jswrapper.h>

Expand All @@ -27,3 +30,5 @@ class FilteringWrapper : public Base {
};

}

#endif /* __FilteringWrapper_h__ */
13 changes: 8 additions & 5 deletions js/xpconnect/wrappers/Makefile.in
Expand Up @@ -14,11 +14,14 @@ LIBRARY_NAME = xpcwrappers_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1

CPPSRCS = AccessCheck.cpp \
CrossOriginWrapper.cpp \
FilteringWrapper.cpp \
XrayWrapper.cpp \
WrapperFactory.cpp
CPPSRCS = \
AccessCheck.cpp \
ChromeObjectWrapper.cpp \
CrossOriginWrapper.cpp \
FilteringWrapper.cpp \
WrapperFactory.cpp \
XrayWrapper.cpp \
$(NULL)

LOCAL_INCLUDES = \
-I$(srcdir)/../src \
Expand Down
4 changes: 2 additions & 2 deletions js/xpconnect/wrappers/WrapperFactory.cpp
Expand Up @@ -10,6 +10,7 @@
#include "XrayWrapper.h"
#include "AccessCheck.h"
#include "XPCWrapper.h"
#include "ChromeObjectWrapper.h"

#include "xpcprivate.h"
#include "dombindings.h"
Expand Down Expand Up @@ -376,8 +377,7 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ComponentsObjectPolicy>::singleton;
} else {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ExposedPropertiesOnly>::singleton;
wrapper = &ChromeObjectWrapper::singleton;

// If the prototype of the chrome object being wrapped is a prototype
// for a standard class, use the one from the content compartment so
Expand Down

0 comments on commit db788da

Please sign in to comment.