2014-04-03 04:58:00 -07: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 04:12:37 -07: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 15:58:09 -07:00
|
|
|
|
2012-03-23 14:59:07 -07:00
|
|
|
#ifndef _xpc_WRAPPERFACTORY_H
|
|
|
|
#define _xpc_WRAPPERFACTORY_H
|
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
#include "jswrapper.h"
|
|
|
|
|
|
|
|
namespace xpc {
|
|
|
|
|
|
|
|
class WrapperFactory {
|
2010-07-02 13:54:53 -07:00
|
|
|
public:
|
2011-09-08 20:29:15 -07:00
|
|
|
enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1,
|
2013-05-06 19:38:23 -07:00
|
|
|
IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1 };
|
2010-07-02 13:54:53 -07:00
|
|
|
|
|
|
|
// Return true if any of any of the nested wrappers have the flag set.
|
2015-03-28 15:22:11 -07:00
|
|
|
static bool HasWrapperFlag(JSObject* wrapper, unsigned flag) {
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned flags = 0;
|
2013-04-11 11:50:18 -07:00
|
|
|
js::UncheckedUnwrap(wrapper, true, &flags);
|
2010-07-02 13:54:53 -07:00
|
|
|
return !!(flags & flag);
|
|
|
|
}
|
|
|
|
|
2015-03-28 15:22:11 -07:00
|
|
|
static bool IsXrayWrapper(JSObject* wrapper) {
|
2010-10-10 15:36:04 -07:00
|
|
|
return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG);
|
|
|
|
}
|
|
|
|
|
2015-03-28 15:22:11 -07:00
|
|
|
static bool HasWaiveXrayFlag(JSObject* wrapper) {
|
2010-10-10 15:47:22 -07:00
|
|
|
return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG);
|
|
|
|
}
|
|
|
|
|
2015-03-28 15:22:11 -07:00
|
|
|
static bool IsCOW(JSObject* wrapper);
|
2013-03-21 08:20:44 -07:00
|
|
|
|
2015-03-28 15:22:11 -07:00
|
|
|
static JSObject* GetXrayWaiver(JS::HandleObject obj);
|
|
|
|
static JSObject* CreateXrayWaiver(JSContext* cx, JS::HandleObject obj);
|
|
|
|
static JSObject* WaiveXray(JSContext* cx, JSObject* obj);
|
2011-01-13 13:03:44 -08:00
|
|
|
|
2010-10-10 15:36:38 -07:00
|
|
|
// Prepare a given object for wrapping in a new compartment.
|
2015-03-28 15:22:11 -07:00
|
|
|
static JSObject* PrepareForWrapping(JSContext* cx,
|
2013-04-15 10:32:55 -07:00
|
|
|
JS::HandleObject scope,
|
|
|
|
JS::HandleObject obj,
|
2014-07-22 16:14:27 -07:00
|
|
|
JS::HandleObject objectPassedToWrap);
|
2010-10-10 15:36:38 -07:00
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
// Rewrap an object that is about to cross compartment boundaries.
|
2015-03-28 15:22:11 -07:00
|
|
|
static JSObject* Rewrap(JSContext* cx,
|
2013-04-15 10:32:55 -07:00
|
|
|
JS::HandleObject existing,
|
2015-02-26 12:58:59 -08:00
|
|
|
JS::HandleObject obj);
|
2010-09-29 10:00:52 -07:00
|
|
|
|
2010-10-10 15:48:29 -07:00
|
|
|
// Wrap wrapped object into a waiver wrapper and then re-wrap it.
|
2015-03-28 15:22:11 -07:00
|
|
|
static bool WaiveXrayAndWrap(JSContext* cx, JS::MutableHandleValue vp);
|
|
|
|
static bool WaiveXrayAndWrap(JSContext* cx, JS::MutableHandleObject object);
|
2010-06-25 15:58:09 -07:00
|
|
|
};
|
|
|
|
|
2014-06-27 04:44:04 -07:00
|
|
|
extern const js::Wrapper XrayWaiver;
|
2010-10-10 15:47:22 -07:00
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
}
|
2012-03-23 14:59:07 -07:00
|
|
|
|
|
|
|
#endif /* _xpc_WRAPPERFACTORY_H */
|