Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: ppapi/example/example.cc

Issue 9655019: Fix a crash related to PPAPI scripting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/example/example.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <math.h> 5 #include <math.h>
6 #include <stdio.h> // FIXME(brettw) erase me. 6 #include <stdio.h> // FIXME(brettw) erase me.
7 #ifndef _WIN32 7 #ifndef _WIN32
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #else 9 #else
10 #include <windows.h> 10 #include <windows.h>
11 #endif 11 #endif
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class MyScriptableObject : public pp::deprecated::ScriptableObject { 52 class MyScriptableObject : public pp::deprecated::ScriptableObject {
53 public: 53 public:
54 explicit MyScriptableObject(pp::InstancePrivate* instance) 54 explicit MyScriptableObject(pp::InstancePrivate* instance)
55 : instance_(instance) {} 55 : instance_(instance) {}
56 56
57 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) { 57 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) {
58 return method.AsString() == "toString"; 58 return method.AsString() == "toString";
59 } 59 }
60 60
61 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { 61 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) {
62 if (name.is_string() && name.AsString() == "blah") 62 if (name.is_string()) {
63 return true; 63 if (name.AsString() == "blah") {
64 return true;
65 } else if (name.AsString() == "removePluginWhenHasPropertyCalled") {
66 pp::Var script("var plugin = document.getElementById('plugin');"
67 "plugin.parentElement.removeChild(plugin);");
68 instance_->ExecuteScript(script);
69 }
70 }
64 return false; 71 return false;
65 } 72 }
66 73
67 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception) { 74 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception) {
68 if (name.is_string() && name.AsString() == "blah") 75 if (name.is_string() && name.AsString() == "blah")
69 return pp::VarPrivate(instance_, new MyScriptableObject(instance_)); 76 return pp::VarPrivate(instance_, new MyScriptableObject(instance_));
70 return pp::Var(); 77 return pp::Var();
71 } 78 }
72 79
73 virtual void GetAllPropertyNames(std::vector<pp::Var>* names, 80 virtual void GetAllPropertyNames(std::vector<pp::Var>* names,
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 473
467 // Incremented for each flush we get. 474 // Incremented for each flush we get.
468 int animation_counter_; 475 int animation_counter_;
469 bool print_settings_valid_; 476 bool print_settings_valid_;
470 PP_PrintSettings_Dev print_settings_; 477 PP_PrintSettings_Dev print_settings_;
471 478
472 bool showing_custom_cursor_; 479 bool showing_custom_cursor_;
473 }; 480 };
474 481
475 void FlushCallback(void* data, int32_t result) { 482 void FlushCallback(void* data, int32_t result) {
476 static_cast<MyInstance*>(data)->OnFlush(); 483 if (result == PP_OK)
484 static_cast<MyInstance*>(data)->OnFlush();
477 } 485 }
478 486
479 class MyModule : public pp::Module { 487 class MyModule : public pp::Module {
480 public: 488 public:
481 MyModule() : pp::Module() {} 489 MyModule() : pp::Module() {}
482 virtual ~MyModule() {} 490 virtual ~MyModule() {}
483 491
484 virtual pp::Instance* CreateInstance(PP_Instance instance) { 492 virtual pp::Instance* CreateInstance(PP_Instance instance) {
485 return new MyInstance(instance); 493 return new MyInstance(instance);
486 } 494 }
487 }; 495 };
488 496
489 namespace pp { 497 namespace pp {
490 498
491 // Factory function for your specialization of the Module object. 499 // Factory function for your specialization of the Module object.
492 Module* CreateModule() { 500 Module* CreateModule() {
493 return new MyModule(); 501 return new MyModule();
494 } 502 }
495 503
496 } // namespace pp 504 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | ppapi/example/example.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698