OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "ppapi/cpp/instance.h" | 7 #include "ppapi/cpp/instance.h" |
8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
9 #include "ppapi/cpp/var.h" | 9 #include "ppapi/cpp/var.h" |
10 #include "ppapi/cpp/var_dictionary.h" | |
11 #include "ppapi/tests/test_utils.h" | |
10 | 12 |
11 // When compiling natively on Windows, PostMessage can be #define-d to | 13 // When compiling natively on Windows, PostMessage can be #define-d to |
12 // something else. | 14 // something else. |
13 #ifdef PostMessage | 15 #ifdef PostMessage |
14 #undef PostMessage | 16 #undef PostMessage |
15 #endif | 17 #endif |
16 | 18 |
17 // This is a simple C++ Pepper plugin that demonstrates HandleMessage and | 19 // This is a simple C++ Pepper plugin that demonstrates HandleMessage and |
18 // PostMessage. | 20 // PostMessage. |
raymes
2015/04/20 01:05:32
nit: please change the comment
tommycli
2015/04/20 18:04:00
Done.
| |
19 | 21 |
20 // This object represents one time the page says <embed>. | 22 // This object represents one time the page says <embed>. |
raymes
2015/04/20 01:05:31
nit remove the comment
tommycli
2015/04/20 18:04:00
Done.
| |
21 class MyInstance : public pp::Instance { | 23 class PowerSaverTestInstance : public pp::Instance { |
22 public: | 24 public: |
23 explicit MyInstance(PP_Instance instance) : pp::Instance(instance) {} | 25 explicit PowerSaverTestInstance(PP_Instance instance) |
24 virtual ~MyInstance() {} | 26 : pp::Instance(instance) {} |
27 virtual ~PowerSaverTestInstance() {} | |
25 virtual void HandleMessage(const pp::Var& message_data); | 28 virtual void HandleMessage(const pp::Var& message_data); |
26 }; | 29 }; |
27 | 30 |
28 // HandleMessage gets invoked when postMessage is called on the DOM element | 31 // HandleMessage gets invoked when postMessage is called on the DOM element |
29 // associated with this plugin instance. | 32 // associated with this plugin instance. |
30 // In this case, if we are given a string, we'll post a message back to | 33 // In this case, if we are given a string, we'll post a message back to |
31 // JavaScript indicating whether or not that string is a palindrome. | 34 // JavaScript indicating whether or not that string is a palindrome. |
raymes
2015/04/20 01:05:31
nit: please change the comment
tommycli
2015/04/20 18:04:00
Done.
| |
32 void MyInstance::HandleMessage(const pp::Var& message_data) { | 35 void PowerSaverTestInstance::HandleMessage(const pp::Var& message_data) { |
33 if (message_data.is_string()) { | 36 if (message_data.is_string() && (message_data.AsString() == "isPeripheral")) { |
34 std::string string_copy(message_data.AsString()); | 37 pp::VarDictionary message; |
35 std::reverse(string_copy.begin(), string_copy.end()); | 38 message.Set( |
36 bool is_palindrome(message_data.AsString() == string_copy); | 39 "isPeripheral", |
37 | 40 pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); |
38 PostMessage(pp::Var(is_palindrome)); | 41 PostMessage(message); |
39 } | 42 } |
40 } | 43 } |
41 | 44 |
42 // This object is the global object representing this plugin library as long | 45 // This object is the global object representing this plugin library as long |
43 // as it is loaded. | 46 // as it is loaded. |
raymes
2015/04/20 01:05:32
nit remove the comment
tommycli
2015/04/20 18:04:00
Done.
| |
44 class MyModule : public pp::Module { | 47 class PowerSaverTestModule : public pp::Module { |
45 public: | 48 public: |
46 MyModule() : pp::Module() {} | 49 PowerSaverTestModule() : pp::Module() {} |
47 virtual ~MyModule() {} | 50 virtual ~PowerSaverTestModule() {} |
48 | 51 |
49 // Override CreateInstance to create your customized Instance object. | 52 // Override CreateInstance to create your customized Instance object. |
raymes
2015/04/20 01:05:31
nit remove the comment
tommycli
2015/04/20 18:04:00
Done.
| |
50 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 53 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
51 return new MyInstance(instance); | 54 return new PowerSaverTestInstance(instance); |
52 } | 55 } |
53 }; | 56 }; |
54 | 57 |
55 namespace pp { | 58 namespace pp { |
56 | 59 |
57 // Factory function for your specialization of the Module object. | 60 // Factory function for your specialization of the Module object. |
raymes
2015/04/20 01:05:31
nit: remove the comment
tommycli
2015/04/20 18:04:01
Done.
| |
58 Module* CreateModule() { | 61 Module* CreateModule() { |
59 return new MyModule(); | 62 return new PowerSaverTestModule(); |
60 } | 63 } |
61 | 64 |
62 } // namespace pp | 65 } // namespace pp |
63 | |
OLD | NEW |