2010-06-25 22:58:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
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 "jsapi.h"
|
|
|
|
#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,
|
2010-11-16 01:21:25 +00:00
|
|
|
IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1,
|
|
|
|
SCRIPT_ACCESS_ONLY_FLAG = IS_XRAY_WRAPPER_FLAG << 1,
|
2012-11-21 21:20:05 +00:00
|
|
|
SOW_FLAG = SCRIPT_ACCESS_ONLY_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;
|
2012-01-26 13:55:27 +00:00
|
|
|
js::UnwrapObject(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) {
|
|
|
|
return !js::UnwrapObjectChecked(obj);
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:20:44 +00:00
|
|
|
static bool IsCOW(JSObject *wrapper);
|
|
|
|
|
2012-07-23 13:51:18 +00:00
|
|
|
static JSObject *GetXrayWaiver(JSObject *obj);
|
|
|
|
static JSObject *CreateXrayWaiver(JSContext *cx, JSObject *obj);
|
2011-01-13 21:03:44 +00:00
|
|
|
static JSObject *WaiveXray(JSContext *cx, JSObject *obj);
|
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
static JSObject *DoubleWrap(JSContext *cx, JSObject *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,
|
|
|
|
JSObject *scope,
|
|
|
|
JSObject *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,
|
2012-09-12 00:14:24 +00:00
|
|
|
JSObject *existing,
|
2010-07-02 20:54:53 +00:00
|
|
|
JSObject *obj,
|
|
|
|
JSObject *wrappedProto,
|
2010-09-17 21:54:40 +00:00
|
|
|
JSObject *parent,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags);
|
2010-09-29 17:00:52 +00:00
|
|
|
|
2012-05-14 21:30:07 +00:00
|
|
|
// Wrap an object for same-compartment access.
|
|
|
|
static JSObject *WrapForSameCompartment(JSContext *cx,
|
|
|
|
JSObject *obj);
|
|
|
|
|
2010-10-10 22:48:29 +00:00
|
|
|
// Wrap wrapped object into a waiver wrapper and then re-wrap it.
|
|
|
|
static bool WaiveXrayAndWrap(JSContext *cx, jsval *vp);
|
2010-10-10 22:48:55 +00:00
|
|
|
|
|
|
|
// Wrap a (same compartment) object in a SOW.
|
|
|
|
static JSObject *WrapSOWObject(JSContext *cx, JSObject *obj);
|
2012-04-28 13:12:28 +00:00
|
|
|
|
|
|
|
// Return true if this is a Components object.
|
|
|
|
static bool IsComponentsObject(JSObject *obj);
|
|
|
|
|
|
|
|
// Wrap a (same compartment) Components object.
|
|
|
|
static JSObject *WrapComponentsObject(JSContext *cx, JSObject *obj);
|
2012-07-18 11:51:28 +00:00
|
|
|
|
|
|
|
// Wrap a same-compartment object for Xray inspection.
|
|
|
|
static JSObject *WrapForSameCompartmentXray(JSContext *cx, JSObject *obj);
|
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 */
|