mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
Implement new content wrappers (574502, r=mrbkap).
This commit is contained in:
parent
0a3ff16881
commit
28f5731857
@ -43,6 +43,7 @@
|
||||
#include "jscntxt.h"
|
||||
#include "jsiter.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsregexp.h"
|
||||
#include "jswrapper.h"
|
||||
|
||||
#include "jsobjinlines.h"
|
||||
@ -400,7 +401,9 @@ AutoCompartment::AutoCompartment(JSContext *cx, JSObject *target)
|
||||
: context(cx),
|
||||
origin(cx->compartment),
|
||||
target(target),
|
||||
destination(target->getCompartment(cx))
|
||||
destination(target->getCompartment(cx)),
|
||||
statics(cx),
|
||||
input(cx)
|
||||
{
|
||||
JS_ASSERT(origin != destination); // necessary for entered() implementation
|
||||
}
|
||||
@ -422,6 +425,7 @@ AutoCompartment::enter()
|
||||
frame.destroy();
|
||||
context->compartment = origin;
|
||||
}
|
||||
js_SaveAndClearRegExpStatics(context, &statics, &input);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -429,6 +433,7 @@ void
|
||||
AutoCompartment::leave()
|
||||
{
|
||||
JS_ASSERT(entered());
|
||||
js_RestoreRegExpStatics(context, &statics, &input);
|
||||
frame.destroy();
|
||||
context->compartment = origin;
|
||||
origin->wrapException(context);
|
||||
|
@ -98,10 +98,10 @@ class JSWrapper : public js::JSProxyHandler {
|
||||
/* Base class for all cross compartment wrapper handlers. */
|
||||
class JSCrossCompartmentWrapper : public JSWrapper {
|
||||
protected:
|
||||
JSCrossCompartmentWrapper();
|
||||
JS_FRIEND_API(JSCrossCompartmentWrapper());
|
||||
|
||||
public:
|
||||
virtual ~JSCrossCompartmentWrapper();
|
||||
virtual JS_FRIEND_API(~JSCrossCompartmentWrapper());
|
||||
|
||||
/* ES5 Harmony fundamental proxy traps. */
|
||||
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
|
||||
@ -153,6 +153,8 @@ class AutoCompartment
|
||||
private:
|
||||
LazilyConstructed<ExecuteFrameGuard> frame;
|
||||
JSFrameRegs regs;
|
||||
JSRegExpStatics statics;
|
||||
AutoValueRooter input;
|
||||
|
||||
public:
|
||||
AutoCompartment(JSContext *cx, JSObject *target);
|
||||
|
@ -46,6 +46,8 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpconnect
|
||||
|
||||
DIRS = wrappers
|
||||
|
||||
ifeq (xpconnect, $(findstring xpconnect, $(BUILD_MODULES)))
|
||||
LIBRARY_NAME = xpconnect
|
||||
EXPORT_LIBRARY = 1
|
||||
@ -116,6 +118,7 @@ endif
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/wrappers \
|
||||
-I$(srcdir)/../loader \
|
||||
-I$(topsrcdir)/js/src \
|
||||
-I$(topsrcdir)/js/src/nanojit \
|
||||
@ -131,6 +134,8 @@ EXTRA_DSO_LDOPTS += \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
LIBS = wrappers/$(LIB_PREFIX)wrappers.$(LIB_SUFFIX)
|
||||
|
||||
ifdef MOZ_JSLOADER
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
../loader/$(LIB_PREFIX)jsloader_s.$(LIB_SUFFIX) \
|
||||
|
106
js/src/xpconnect/src/wrappers/ContentWrapper.cpp
Normal file
106
js/src/xpconnect/src/wrappers/ContentWrapper.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
||||
*
|
||||
* ***** 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 SpiderMonkey JavaScript 1.9.1 code, released
|
||||
* June 30, 2009.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
*
|
||||
* Contributor(s):
|
||||
* Andreas Gal <gal@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 "jsapi.h"
|
||||
#include "jswrapper.h"
|
||||
|
||||
#include "XPCWrapper.h"
|
||||
|
||||
#include "nsJSPrincipals.h"
|
||||
|
||||
namespace xpc {
|
||||
|
||||
class ContentWrapper : public JSCrossCompartmentWrapper {
|
||||
public:
|
||||
ContentWrapper();
|
||||
virtual ~ContentWrapper();
|
||||
|
||||
virtual bool enter(JSContext *cx, JSObject *proxy, jsid id);
|
||||
virtual void leave(JSContext *cx, JSObject *proxy);
|
||||
|
||||
static ContentWrapper singleton;
|
||||
};
|
||||
|
||||
ContentWrapper::ContentWrapper() : JSCrossCompartmentWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
ContentWrapper::~ContentWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ContentWrapper::enter(JSContext *cx, JSObject *wrapper, jsid id)
|
||||
{
|
||||
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
||||
if(!ssm) {
|
||||
return true;
|
||||
}
|
||||
JSPrincipals *subjectPrincipals = wrapper->getCompartment(cx)->principals;
|
||||
JSPrincipals *objectPrincipals = wrappedObject(wrapper)->getCompartment(cx)->principals;
|
||||
if(!subjectPrincipals->subsume(subjectPrincipals, objectPrincipals)) {
|
||||
if(id == JSVAL_VOID) {
|
||||
JS_ReportError(cx, "Permission denied to access object");
|
||||
} else {
|
||||
JSString *str = JS_ValueToString(cx, id);
|
||||
JS_ReportError(cx, "Permission denied to access property '%hs'", str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
JSStackFrame *fp = nsnull;
|
||||
nsIPrincipal *principal = static_cast<nsJSPrincipals *>(objectPrincipals)->nsIPrincipalPtr;
|
||||
nsresult rv = ssm->PushContextPrincipal(cx, JS_FrameIterator(cx, &fp), principal);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Not allowing call because we're out of memory");
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ContentWrapper::leave(JSContext *cx, JSObject *proxy)
|
||||
{
|
||||
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
||||
if (ssm) {
|
||||
ssm->PopContextPrincipal(cx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
55
js/src/xpconnect/src/wrappers/Makefile.in
Normal file
55
js/src/xpconnect/src/wrappers/Makefile.in
Normal file
@ -0,0 +1,55 @@
|
||||
# ***** 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 code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Andreas Gal <gal@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of 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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpcwrappers
|
||||
LIBRARY_NAME = xpcwrappers_s
|
||||
FORCE_STATIC_LIB = 1
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
||||
CPPSRCS = ContentWrapper.cpp
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/.. \
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
Loading…
Reference in New Issue
Block a user