Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=4 et sw=4 tw=99: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef __ChromeObjectWrapper_h__ |
michael@0 | 8 | #define __ChromeObjectWrapper_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "FilteringWrapper.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace xpc { |
michael@0 | 15 | |
michael@0 | 16 | struct ExposedPropertiesOnly; |
michael@0 | 17 | |
michael@0 | 18 | // When chrome JS objects are exposed to content, they get a ChromeObjectWrapper. |
michael@0 | 19 | // |
michael@0 | 20 | // The base filtering wrapper here does most of the work for us. We define a |
michael@0 | 21 | // custom class here to introduce custom behavior with respect to the prototype |
michael@0 | 22 | // chain. |
michael@0 | 23 | #define ChromeObjectWrapperBase \ |
michael@0 | 24 | FilteringWrapper<js::CrossCompartmentSecurityWrapper, ExposedPropertiesOnly> |
michael@0 | 25 | |
michael@0 | 26 | class ChromeObjectWrapper : public ChromeObjectWrapperBase |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | ChromeObjectWrapper() : ChromeObjectWrapperBase(0) {} |
michael@0 | 30 | |
michael@0 | 31 | /* Custom traps. */ |
michael@0 | 32 | virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper, |
michael@0 | 33 | JS::Handle<jsid> id, |
michael@0 | 34 | JS::MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE; |
michael@0 | 35 | virtual bool has(JSContext *cx, JS::Handle<JSObject*> wrapper, |
michael@0 | 36 | JS::Handle<jsid> id, bool *bp) MOZ_OVERRIDE; |
michael@0 | 37 | virtual bool get(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver, |
michael@0 | 38 | JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE; |
michael@0 | 39 | |
michael@0 | 40 | virtual bool objectClassIs(JS::Handle<JSObject*> obj, js::ESClassValue classValue, |
michael@0 | 41 | JSContext *cx) MOZ_OVERRIDE; |
michael@0 | 42 | |
michael@0 | 43 | virtual bool enter(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id, |
michael@0 | 44 | js::Wrapper::Action act, bool *bp) MOZ_OVERRIDE; |
michael@0 | 45 | |
michael@0 | 46 | // NB: One might think we'd need to implement enumerate(), keys(), iterate(), |
michael@0 | 47 | // and getPropertyNames() here. However, ES5 built-in properties aren't |
michael@0 | 48 | // enumerable (and SpiderMonkey's implementation seems to match the spec |
michael@0 | 49 | // modulo Error.prototype.fileName and Error.prototype.lineNumber). Since |
michael@0 | 50 | // we're only remapping the prototypes of standard objects, there would |
michael@0 | 51 | // never be anything more to enumerate up the prototype chain. So we can |
michael@0 | 52 | // atually skip these. |
michael@0 | 53 | |
michael@0 | 54 | static ChromeObjectWrapper singleton; |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | } /* namespace xpc */ |
michael@0 | 58 | |
michael@0 | 59 | #endif /* __ChromeObjectWrapper_h__ */ |