2014-04-03 11:58:00 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=99: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2010-06-25 22:58:09 +00:00
|
|
|
|
2012-03-23 21:59:07 +00:00
|
|
|
#ifndef _xpc_WRAPPERFACTORY_H
|
|
|
|
#define _xpc_WRAPPERFACTORY_H
|
|
|
|
|
2010-06-25 22:58:09 +00:00
|
|
|
#include "jswrapper.h"
|
|
|
|
|
|
|
|
namespace xpc {
|
|
|
|
|
|
|
|
class WrapperFactory {
|
2010-07-02 20:54:53 +00:00
|
|
|
public:
|
2011-09-09 03:29:15 +00:00
|
|
|
enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1,
|
2013-05-07 02:38:23 +00:00
|
|
|
IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1 };
|
2010-07-02 20:54:53 +00:00
|
|
|
|
|
|
|
// Return true if any of any of the nested wrappers have the flag set.
|
2012-02-28 23:11:11 +00:00
|
|
|
static bool HasWrapperFlag(JSObject *wrapper, unsigned flag) {
|
|
|
|
unsigned flags = 0;
|
2013-04-11 18:50:18 +00:00
|
|
|
js::UncheckedUnwrap(wrapper, true, &flags);
|
2010-07-02 20:54:53 +00:00
|
|
|
return !!(flags & flag);
|
|
|
|
}
|
|
|
|
|
2010-10-10 22:36:04 +00:00
|
|
|
static bool IsXrayWrapper(JSObject *wrapper) {
|
|
|
|
return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG);
|
|
|
|
}
|
|
|
|
|
2010-10-10 22:47:22 +00:00
|
|
|
static bool HasWaiveXrayFlag(JSObject *wrapper) {
|
|
|
|
return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG);
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:20:42 +00:00
|
|
|
static bool IsSecurityWrapper(JSObject *obj) {
|
2013-04-11 18:50:18 +00:00
|
|
|
return !js::CheckedUnwrap(obj);
|
2013-03-21 15:20:42 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 15:20:44 +00:00
|
|
|
static bool IsCOW(JSObject *wrapper);
|
|
|
|
|
2013-11-19 18:12:10 +00:00
|
|
|
static JSObject *GetXrayWaiver(JS::HandleObject obj);
|
2013-04-12 09:50:43 +00:00
|
|
|
static JSObject *CreateXrayWaiver(JSContext *cx, JS::HandleObject obj);
|
2011-01-13 21:03:44 +00:00
|
|
|
static JSObject *WaiveXray(JSContext *cx, JSObject *obj);
|
|
|
|
|
2013-04-12 09:50:43 +00:00
|
|
|
static JSObject *DoubleWrap(JSContext *cx, JS::HandleObject obj, unsigned flags);
|
2011-01-13 21:03:44 +00:00
|
|
|
|
2010-10-10 22:36:38 +00:00
|
|
|
// Prepare a given object for wrapping in a new compartment.
|
|
|
|
static JSObject *PrepareForWrapping(JSContext *cx,
|
2013-04-15 17:32:55 +00:00
|
|
|
JS::HandleObject scope,
|
|
|
|
JS::HandleObject obj,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags);
|
2010-10-10 22:36:38 +00:00
|
|
|
|
2010-07-02 20:54:53 +00:00
|
|
|
// Rewrap an object that is about to cross compartment boundaries.
|
|
|
|
static JSObject *Rewrap(JSContext *cx,
|
2013-04-15 17:32:55 +00:00
|
|
|
JS::HandleObject existing,
|
|
|
|
JS::HandleObject obj,
|
|
|
|
JS::HandleObject wrappedProto,
|
|
|
|
JS::HandleObject parent,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags);
|
2010-09-29 17:00:52 +00:00
|
|
|
|
2010-10-10 22:48:29 +00:00
|
|
|
// Wrap wrapped object into a waiver wrapper and then re-wrap it.
|
2013-10-26 16:19:05 +00:00
|
|
|
static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleValue vp);
|
2013-12-13 20:01:30 +00:00
|
|
|
static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleObject object);
|
2010-10-10 22:48:55 +00:00
|
|
|
|
2012-08-27 13:06:34 +00:00
|
|
|
// Returns true if the wrapper is in not shadowing mode for the id.
|
|
|
|
static bool XrayWrapperNotShadowing(JSObject *wrapper, jsid id);
|
2010-06-25 22:58:09 +00:00
|
|
|
};
|
|
|
|
|
2012-10-29 15:52:53 +00:00
|
|
|
extern js::Wrapper XrayWaiver;
|
2010-10-10 22:47:22 +00:00
|
|
|
|
2010-06-25 22:58:09 +00:00
|
|
|
}
|
2012-03-23 21:59:07 +00:00
|
|
|
|
|
|
|
#endif /* _xpc_WRAPPERFACTORY_H */
|