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