OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 25 matching lines...) Expand all Loading... |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 class V8DOMConfiguration { | 38 class V8DOMConfiguration { |
39 public: | 39 public: |
40 // The following Configuration structs and install methods are used for | 40 // The following Configuration structs and install methods are used for |
41 // setting multiple properties on an ObjectTemplate, used from the | 41 // setting multiple properties on an ObjectTemplate, used from the |
42 // generated bindings initialization (ConfigureXXXTemplate). This greatly | 42 // generated bindings initialization (ConfigureXXXTemplate). This greatly |
43 // reduces the binary size by moving from code driven setup to data table | 43 // reduces the binary size by moving from code driven setup to data table |
44 // driven setup. | 44 // driven setup. |
45 | 45 |
| 46 enum ExposeConfiguration { |
| 47 ExposedToAllScripts, |
| 48 OnlyExposedToPrivateScript, |
| 49 }; |
| 50 |
46 // AttributeConfiguration translates into calls to SetAccessor() on either | 51 // AttributeConfiguration translates into calls to SetAccessor() on either |
47 // the instance or the prototype ObjectTemplate, based on |onPrototype|. | 52 // the instance or the prototype ObjectTemplate, based on |onPrototype|. |
48 struct AttributeConfiguration { | 53 struct AttributeConfiguration { |
49 const char* const name; | 54 const char* const name; |
50 v8::AccessorGetterCallback getter; | 55 v8::AccessorGetterCallback getter; |
51 v8::AccessorSetterCallback setter; | 56 v8::AccessorSetterCallback setter; |
52 v8::AccessorGetterCallback getterForMainWorld; | 57 v8::AccessorGetterCallback getterForMainWorld; |
53 v8::AccessorSetterCallback setterForMainWorld; | 58 v8::AccessorSetterCallback setterForMainWorld; |
54 const WrapperTypeInfo* data; | 59 const WrapperTypeInfo* data; |
55 v8::AccessControl settings; | 60 v8::AccessControl settings; |
56 v8::PropertyAttribute attribute; | 61 v8::PropertyAttribute attribute; |
| 62 ExposeConfiguration exposeConfiguration; |
57 bool onPrototype; | 63 bool onPrototype; |
58 }; | 64 }; |
59 | 65 |
60 // AccessorConfiguration translates into calls to SetAccessorProperty() | 66 // AccessorConfiguration translates into calls to SetAccessorProperty() |
61 // on prototype ObjectTemplate. | 67 // on prototype ObjectTemplate. |
62 struct AccessorConfiguration { | 68 struct AccessorConfiguration { |
63 const char* const name; | 69 const char* const name; |
64 v8::FunctionCallback getter; | 70 v8::FunctionCallback getter; |
65 v8::FunctionCallback setter; | 71 v8::FunctionCallback setter; |
66 v8::FunctionCallback getterForMainWorld; | 72 v8::FunctionCallback getterForMainWorld; |
67 v8::FunctionCallback setterForMainWorld; | 73 v8::FunctionCallback setterForMainWorld; |
68 const WrapperTypeInfo* data; | 74 const WrapperTypeInfo* data; |
69 v8::AccessControl settings; | 75 v8::AccessControl settings; |
70 v8::PropertyAttribute attribute; | 76 v8::PropertyAttribute attribute; |
| 77 ExposeConfiguration exposeConfiguration; |
71 }; | 78 }; |
72 | 79 |
73 static void installAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8:
:ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount, v8::Isol
ate*); | 80 static void installAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8:
:ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount, v8::Isol
ate*); |
74 | 81 |
75 template<class ObjectOrTemplate> | 82 template<class ObjectOrTemplate> |
76 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instanceTem
plate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& att
ribute, v8::Isolate* isolate) | 83 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instanceTem
plate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& att
ribute, v8::Isolate* isolate) |
77 { | 84 { |
| 85 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 86 if (attribute.exposeConfiguration == OnlyExposedToPrivateScript && !worl
d.isPrivateScriptIsolatedWorld()) |
| 87 return; |
| 88 |
78 v8::AccessorGetterCallback getter = attribute.getter; | 89 v8::AccessorGetterCallback getter = attribute.getter; |
79 v8::AccessorSetterCallback setter = attribute.setter; | 90 v8::AccessorSetterCallback setter = attribute.setter; |
80 if (DOMWrapperWorld::current(isolate).isMainWorld()) { | 91 if (world.isMainWorld()) { |
81 if (attribute.getterForMainWorld) | 92 if (attribute.getterForMainWorld) |
82 getter = attribute.getterForMainWorld; | 93 getter = attribute.getterForMainWorld; |
83 if (attribute.setterForMainWorld) | 94 if (attribute.setterForMainWorld) |
84 setter = attribute.setterForMainWorld; | 95 setter = attribute.setterForMainWorld; |
85 } | 96 } |
86 (attribute.onPrototype ? prototype : instanceTemplate)->SetAccessor(v8At
omicString(isolate, attribute.name), | 97 (attribute.onPrototype ? prototype : instanceTemplate)->SetAccessor(v8At
omicString(isolate, attribute.name), |
87 getter, | 98 getter, |
88 setter, | 99 setter, |
89 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.da
ta)), | 100 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.da
ta)), |
90 attribute.settings, | 101 attribute.settings, |
(...skipping 24 matching lines...) Expand all Loading... |
115 static void installConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8
::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount, v8::Isola
te*); | 126 static void installConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8
::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount, v8::Isola
te*); |
116 | 127 |
117 // MethodConfiguration translates into calls to Set() for setting up an | 128 // MethodConfiguration translates into calls to Set() for setting up an |
118 // object's callbacks. It sets the method on both the FunctionTemplate or | 129 // object's callbacks. It sets the method on both the FunctionTemplate or |
119 // the ObjectTemplate. | 130 // the ObjectTemplate. |
120 struct MethodConfiguration { | 131 struct MethodConfiguration { |
121 const char* const name; | 132 const char* const name; |
122 v8::FunctionCallback callback; | 133 v8::FunctionCallback callback; |
123 v8::FunctionCallback callbackForMainWorld; | 134 v8::FunctionCallback callbackForMainWorld; |
124 int length; | 135 int length; |
| 136 ExposeConfiguration exposeConfiguration; |
125 }; | 137 }; |
126 | 138 |
127 static void installMethods(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Si
gnature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCoun
t, v8::Isolate*); | 139 static void installMethods(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Si
gnature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCoun
t, v8::Isolate*); |
128 | 140 |
129 template<class ObjectOrTemplate> | 141 template<class ObjectOrTemplate> |
130 static void installMethodCustomSignature(v8::Handle<ObjectOrTemplate> instan
ceTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute
, const MethodConfiguration& configuration, v8::Isolate* isolate) | 142 static void installMethodCustomSignature(v8::Handle<ObjectOrTemplate> instan
ceTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute
, const MethodConfiguration& configuration, v8::Isolate* isolate) |
131 { | 143 { |
132 v8::FunctionCallback callback = configuration.callback; | 144 v8::FunctionCallback callback = configuration.callback; |
133 if (DOMWrapperWorld::current(isolate).isMainWorld() && configuration.cal
lbackForMainWorld) | 145 if (DOMWrapperWorld::current(isolate).isMainWorld() && configuration.cal
lbackForMainWorld) |
134 callback = configuration.callbackForMainWorld; | 146 callback = configuration.callbackForMainWorld; |
135 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8Undefined(), signature, configuration.length); | 147 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8Undefined(), signature, configuration.length); |
136 instanceTemplate->Set(v8AtomicString(isolate, configuration.name), funct
ionTemplate, attribute); | 148 instanceTemplate->Set(v8AtomicString(isolate, configuration.name), funct
ionTemplate, attribute); |
137 } | 149 } |
138 | 150 |
139 static void installAccessors(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
Signature>, const AccessorConfiguration*, size_t accessorCount, v8::Isolate*); | 151 static void installAccessors(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
Signature>, const AccessorConfiguration*, size_t accessorCount, v8::Isolate*); |
140 | 152 |
141 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
Class, size_t fieldCount, | 153 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
Class, size_t fieldCount, |
142 const AttributeConfiguration*, size_t attributeCount, | 154 const AttributeConfiguration*, size_t attributeCount, |
143 const AccessorConfiguration*, size_t accessorCount, | 155 const AccessorConfiguration*, size_t accessorCount, |
144 const MethodConfiguration*, size_t callbackCount, | 156 const MethodConfiguration*, size_t callbackCount, |
145 v8::Isolate*); | 157 v8::Isolate*); |
146 | 158 |
147 static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp
erTypeInfo*, void (*)(v8::Handle<v8::FunctionTemplate>, v8::Isolate*)); | 159 static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp
erTypeInfo*, void (*)(v8::Handle<v8::FunctionTemplate>, v8::Isolate*)); |
148 }; | 160 }; |
149 | 161 |
150 } // namespace blink | 162 } // namespace blink |
151 | 163 |
152 #endif // V8DOMConfiguration_h | 164 #endif // V8DOMConfiguration_h |
OLD | NEW |