OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A simple C++ Pepper plugin for exercising deprecated PPAPI interfaces in | 5 // A simple C++ Pepper plugin for exercising deprecated PPAPI interfaces in |
6 // Blink layout tests. | 6 // Blink layout tests. |
7 // | 7 // |
8 // Most layout tests should prefer to use the normal Blink test plugin, with the | 8 // Most layout tests should prefer to use the normal Blink test plugin, with the |
9 // MIME type application/x-blink-test-plugin. For layout tests that absolutely | 9 // MIME type application/x-blink-test-plugin. For layout tests that absolutely |
10 // need to test deprecated synchronous scripting interfaces, this plugin can be | 10 // need to test deprecated synchronous scripting interfaces, this plugin can be |
(...skipping 13 matching lines...) Expand all Loading... |
24 // | 24 // |
25 // | 25 // |
26 // Functions: | 26 // Functions: |
27 // * plugin.normalize(): synchronously calls window.pluginCallback. | 27 // * plugin.normalize(): synchronously calls window.pluginCallback. |
28 // | 28 // |
29 // * plugin.remember(value): keeps a reference on |value| in the plugin. | 29 // * plugin.remember(value): keeps a reference on |value| in the plugin. |
30 // | 30 // |
31 // * plugin.testCloneObject(): creates and returns another instance of the | 31 // * plugin.testCloneObject(): creates and returns another instance of the |
32 // plugin object. | 32 // plugin object. |
33 // | 33 // |
| 34 // * plugin.testCreateTestObject(): creates and returns a new TestObject |
| 35 // instance (see below). |
| 36 // |
34 // * plugin.testExecuteScript(script): synchronously evaluates |script| and | 37 // * plugin.testExecuteScript(script): synchronously evaluates |script| and |
35 // returns the result. | 38 // returns the result. |
36 // | 39 // |
37 // * plugin.testGetProperty(property): returns the property named |property| | 40 // * plugin.testGetProperty(property): returns the property named |property| |
38 // from the window object. | 41 // from the window object. |
39 // | 42 // |
40 // * plugin.testPassTestObject(function, object): synchronously calls the | 43 // * plugin.testPassTestObject(function, object): synchronously calls the |
41 // function named |function| on the window object, passing it |object| as a | 44 // function named |function| on the window object, passing it |object| as a |
42 // parameter, and returns its result. | 45 // parameter, and returns its result. |
43 // | 46 // |
44 // * plugin.testScriptObjectInvoke(function, value): synchronously calls the | 47 // * plugin.testScriptObjectInvoke(function, value): synchronously calls the |
45 // function named |function| on the window object, passing it |value| as a | 48 // function named |function| on the window object, passing it |value| as a |
46 // parameter, and returns its result. | 49 // parameter, and returns its result. |
47 // | 50 // |
48 // | 51 // |
49 // Properties: | 52 // Properties: |
50 // * plugin.testObject (read-only): a TestObject instance (see below). | 53 // * plugin.testObject (read-only): a TestObject instance (see below). |
51 // | 54 // |
| 55 // * plugin.testObjectCount (read-only): the number of TestObject instance |
| 56 // created. |
| 57 // |
52 // * plugin.testGetUndefined (read-only): returns undefined. | 58 // * plugin.testGetUndefined (read-only): returns undefined. |
53 // | 59 // |
54 // | 60 // |
55 // TestObject exposes the following interface: | 61 // TestObject exposes the following interface: |
56 // Properties: | 62 // Properties: |
57 // * object.testObject (read-only: another TestObject instance. | 63 // * object.testObject (read-only: another TestObject instance. |
58 | 64 |
59 #include <stdint.h> | 65 #include <stdint.h> |
60 | 66 |
61 #include <map> | 67 #include <map> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 150 |
145 pp::InstancePrivate* const instance_; | 151 pp::InstancePrivate* const instance_; |
146 MethodMap methods_; | 152 MethodMap methods_; |
147 PropertyMap properties_; | 153 PropertyMap properties_; |
148 }; | 154 }; |
149 | 155 |
150 class TestObjectSO : public ScriptableBase { | 156 class TestObjectSO : public ScriptableBase { |
151 public: | 157 public: |
152 explicit TestObjectSO(pp::InstancePrivate* instance) | 158 explicit TestObjectSO(pp::InstancePrivate* instance) |
153 : ScriptableBase(instance) { | 159 : ScriptableBase(instance) { |
| 160 ++count_; |
154 properties_.insert(std::make_pair( | 161 properties_.insert(std::make_pair( |
155 "testObject", | 162 "testObject", |
156 base::Bind(&TestObjectSO::TestObjectAccessor, base::Unretained(this)))); | 163 base::Bind(&TestObjectSO::TestObjectAccessor, base::Unretained(this)))); |
157 } | 164 } |
158 ~TestObjectSO() override {} | 165 ~TestObjectSO() override { |
| 166 --count_; |
| 167 } |
| 168 |
| 169 static int32_t count() { return count_; } |
159 | 170 |
160 private: | 171 private: |
161 void TestObjectAccessor(bool set, pp::Var* var) { | 172 void TestObjectAccessor(bool set, pp::Var* var) { |
162 if (set) | 173 if (set) |
163 return; | 174 return; |
164 if (test_object_.is_undefined()) | 175 if (test_object_.is_undefined()) |
165 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_)); | 176 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_)); |
166 *var = test_object_; | 177 *var = test_object_; |
167 } | 178 } |
168 | 179 |
| 180 static int32_t count_; |
| 181 |
169 pp::VarPrivate test_object_; | 182 pp::VarPrivate test_object_; |
170 }; | 183 }; |
171 | 184 |
| 185 int32_t TestObjectSO::count_ = 0; |
| 186 |
172 class InstanceSO : public ScriptableBase { | 187 class InstanceSO : public ScriptableBase { |
173 public: | 188 public: |
174 explicit InstanceSO(pp::InstancePrivate* instance) | 189 explicit InstanceSO(pp::InstancePrivate* instance) |
175 : ScriptableBase(instance) { | 190 : ScriptableBase(instance) { |
176 methods_.insert(std::make_pair( | 191 methods_.insert(std::make_pair( |
177 "normalize", | 192 "normalize", |
178 base::Bind(&InstanceSO::Normalize, base::Unretained(this)))); | 193 base::Bind(&InstanceSO::Normalize, base::Unretained(this)))); |
179 methods_.insert(std::make_pair( | 194 methods_.insert(std::make_pair( |
180 "remember", | 195 "remember", |
181 base::Bind(&InstanceSO::Remember, base::Unretained(this)))); | 196 base::Bind(&InstanceSO::Remember, base::Unretained(this)))); |
182 methods_.insert(std::make_pair( | 197 methods_.insert(std::make_pair( |
183 "testCloneObject", | 198 "testCloneObject", |
184 base::Bind(&InstanceSO::TestCloneObject, base::Unretained(this)))); | 199 base::Bind(&InstanceSO::TestCloneObject, base::Unretained(this)))); |
185 methods_.insert(std::make_pair( | 200 methods_.insert(std::make_pair( |
| 201 "testCreateTestObject", |
| 202 base::Bind(&InstanceSO::TestCreateTestObject, base::Unretained(this)))); |
| 203 methods_.insert(std::make_pair( |
186 "testExecuteScript", | 204 "testExecuteScript", |
187 base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this)))); | 205 base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this)))); |
188 methods_.insert(std::make_pair( | 206 methods_.insert(std::make_pair( |
189 "testGetProperty", | 207 "testGetProperty", |
190 base::Bind(&InstanceSO::TestGetProperty, base::Unretained(this)))); | 208 base::Bind(&InstanceSO::TestGetProperty, base::Unretained(this)))); |
191 methods_.insert(std::make_pair( | 209 methods_.insert(std::make_pair( |
192 "testPassTestObject", | 210 "testPassTestObject", |
193 base::Bind(&InstanceSO::TestPassTestObject, base::Unretained(this)))); | 211 base::Bind(&InstanceSO::TestPassTestObject, base::Unretained(this)))); |
194 // Note: the semantics of testScriptObjectInvoke are identical to the | 212 // Note: the semantics of testScriptObjectInvoke are identical to the |
195 // semantics of testPassTestObject: call args[0] with args[1] as a | 213 // semantics of testPassTestObject: call args[0] with args[1] as a |
196 // parameter. | 214 // parameter. |
197 methods_.insert( | 215 methods_.insert( |
198 std::make_pair("testScriptObjectInvoke", | 216 std::make_pair("testScriptObjectInvoke", |
199 base::Bind(&InstanceSO::TestPassTestObject, | 217 base::Bind(&InstanceSO::TestPassTestObject, |
200 base::Unretained(this)))); | 218 base::Unretained(this)))); |
201 properties_.insert(std::make_pair( | 219 properties_.insert(std::make_pair( |
202 "testObject", base::Bind(&InstanceSO::TestObjectAccessor, | 220 "testObject", base::Bind(&InstanceSO::TestObjectAccessor, |
203 base::Unretained(this)))); | 221 base::Unretained(this)))); |
204 properties_.insert(std::make_pair( | 222 properties_.insert(std::make_pair( |
| 223 "testObjectCount", base::Bind(&InstanceSO::TestObjectCountAccessor, |
| 224 base::Unretained(this)))); |
| 225 properties_.insert(std::make_pair( |
205 "testGetUndefined", base::Bind(&InstanceSO::TestGetUndefinedAccessor, | 226 "testGetUndefined", base::Bind(&InstanceSO::TestGetUndefinedAccessor, |
206 base::Unretained(this)))); | 227 base::Unretained(this)))); |
207 } | 228 } |
208 ~InstanceSO() override {} | 229 ~InstanceSO() override {} |
209 | 230 |
210 private: | 231 private: |
211 // Requires no argument. | 232 // Requires no argument. |
212 pp::Var Normalize(const std::vector<pp::Var>& args, pp::Var* exception) { | 233 pp::Var Normalize(const std::vector<pp::Var>& args, pp::Var* exception) { |
213 pp::VarPrivate object = instance_->GetWindowObject(); | 234 pp::VarPrivate object = instance_->GetWindowObject(); |
214 return object.Call(pp::Var("pluginCallback"), exception); | 235 return object.Call(pp::Var("pluginCallback"), exception); |
215 } | 236 } |
216 | 237 |
217 // Requires 1 argument. The argument is retained into remembered_ | 238 // Requires 1 argument. The argument is retained into remembered_ |
218 pp::Var Remember(const std::vector<pp::Var>& args, pp::Var* exception) { | 239 pp::Var Remember(const std::vector<pp::Var>& args, pp::Var* exception) { |
219 if (args.size() != 1) { | 240 if (args.size() != 1) { |
220 *exception = pp::Var("remember requires one argument"); | 241 *exception = pp::Var("remember requires one argument"); |
221 return pp::Var(); | 242 return pp::Var(); |
222 } | 243 } |
223 remembered_ = args[0]; | 244 remembered_ = args[0]; |
224 return pp::Var(); | 245 return pp::Var(); |
225 } | 246 } |
226 | 247 |
227 // Requires no argument. | 248 // Requires no argument. |
228 pp::Var TestCloneObject(const std::vector<pp::Var>& args, | 249 pp::Var TestCloneObject(const std::vector<pp::Var>& args, |
229 pp::Var* exception) { | 250 pp::Var* exception) { |
230 return pp::VarPrivate(instance_, new InstanceSO(instance_)); | 251 return pp::VarPrivate(instance_, new InstanceSO(instance_)); |
231 } | 252 } |
232 | 253 |
| 254 // Requires no argument. |
| 255 pp::Var TestCreateTestObject(const std::vector<pp::Var>& args, |
| 256 pp::Var* exception) { |
| 257 return pp::VarPrivate(instance_, new TestObjectSO(instance_)); |
| 258 } |
| 259 |
233 // Requires one argument. The argument is passed through as-is to | 260 // Requires one argument. The argument is passed through as-is to |
234 // pp::InstancePrivate::ExecuteScript(). | 261 // pp::InstancePrivate::ExecuteScript(). |
235 pp::Var TestExecuteScript(const std::vector<pp::Var>& args, | 262 pp::Var TestExecuteScript(const std::vector<pp::Var>& args, |
236 pp::Var* exception) { | 263 pp::Var* exception) { |
237 if (args.size() != 1) { | 264 if (args.size() != 1) { |
238 *exception = pp::Var("testExecuteScript requires one argument"); | 265 *exception = pp::Var("testExecuteScript requires one argument"); |
239 return pp::Var(); | 266 return pp::Var(); |
240 } | 267 } |
241 return instance_->ExecuteScript(args[0], exception); | 268 return instance_->ExecuteScript(args[0], exception); |
242 } | 269 } |
(...skipping 29 matching lines...) Expand all Loading... |
272 } | 299 } |
273 | 300 |
274 void TestObjectAccessor(bool set, pp::Var* var) { | 301 void TestObjectAccessor(bool set, pp::Var* var) { |
275 if (set) | 302 if (set) |
276 return; | 303 return; |
277 if (test_object_.is_undefined()) | 304 if (test_object_.is_undefined()) |
278 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_)); | 305 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_)); |
279 *var = test_object_; | 306 *var = test_object_; |
280 } | 307 } |
281 | 308 |
| 309 void TestObjectCountAccessor(bool set, pp::Var* var) { |
| 310 if (set) |
| 311 return; |
| 312 *var = pp::Var(TestObjectSO::count()); |
| 313 } |
| 314 |
282 void TestGetUndefinedAccessor(bool set, pp::Var* var) { | 315 void TestGetUndefinedAccessor(bool set, pp::Var* var) { |
283 if (set) | 316 if (set) |
284 return; | 317 return; |
285 *var = pp::Var(); | 318 *var = pp::Var(); |
286 } | 319 } |
287 | 320 |
288 pp::VarPrivate test_object_; | 321 pp::VarPrivate test_object_; |
289 pp::Var remembered_; | 322 pp::Var remembered_; |
290 }; | 323 }; |
291 | 324 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 417 |
385 } // namespace | 418 } // namespace |
386 | 419 |
387 namespace pp { | 420 namespace pp { |
388 | 421 |
389 Module* CreateModule() { | 422 Module* CreateModule() { |
390 return new BlinkDeprecatedTestModule(); | 423 return new BlinkDeprecatedTestModule(); |
391 } | 424 } |
392 | 425 |
393 } // namespace pp | 426 } // namespace pp |
OLD | NEW |