Index: ppapi/tests/power_saver_test_plugin.cc |
diff --git a/ppapi/examples/scripting/post_message.cc b/ppapi/tests/power_saver_test_plugin.cc |
similarity index 58% |
copy from ppapi/examples/scripting/post_message.cc |
copy to ppapi/tests/power_saver_test_plugin.cc |
index 636a7a8506b009db354e840243baa428815821fd..a916938136878e975fd16fc773af2905c49e2565 100644 |
--- a/ppapi/examples/scripting/post_message.cc |
+++ b/ppapi/tests/power_saver_test_plugin.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -7,6 +7,8 @@ |
#include "ppapi/cpp/instance.h" |
#include "ppapi/cpp/module.h" |
#include "ppapi/cpp/var.h" |
+#include "ppapi/cpp/var_dictionary.h" |
+#include "ppapi/tests/test_utils.h" |
// When compiling natively on Windows, PostMessage can be #define-d to |
// something else. |
@@ -18,10 +20,11 @@ |
// PostMessage. |
raymes
2015/04/20 01:05:32
nit: please change the comment
tommycli
2015/04/20 18:04:00
Done.
|
// 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.
|
-class MyInstance : public pp::Instance { |
+class PowerSaverTestInstance : public pp::Instance { |
public: |
- explicit MyInstance(PP_Instance instance) : pp::Instance(instance) {} |
- virtual ~MyInstance() {} |
+ explicit PowerSaverTestInstance(PP_Instance instance) |
+ : pp::Instance(instance) {} |
+ virtual ~PowerSaverTestInstance() {} |
virtual void HandleMessage(const pp::Var& message_data); |
}; |
@@ -29,26 +32,26 @@ class MyInstance : public pp::Instance { |
// associated with this plugin instance. |
// In this case, if we are given a string, we'll post a message back to |
// 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.
|
-void MyInstance::HandleMessage(const pp::Var& message_data) { |
- if (message_data.is_string()) { |
- std::string string_copy(message_data.AsString()); |
- std::reverse(string_copy.begin(), string_copy.end()); |
- bool is_palindrome(message_data.AsString() == string_copy); |
- |
- PostMessage(pp::Var(is_palindrome)); |
+void PowerSaverTestInstance::HandleMessage(const pp::Var& message_data) { |
+ if (message_data.is_string() && (message_data.AsString() == "isPeripheral")) { |
+ pp::VarDictionary message; |
+ message.Set( |
+ "isPeripheral", |
+ pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); |
+ PostMessage(message); |
} |
} |
// This object is the global object representing this plugin library as long |
// as it is loaded. |
raymes
2015/04/20 01:05:32
nit remove the comment
tommycli
2015/04/20 18:04:00
Done.
|
-class MyModule : public pp::Module { |
+class PowerSaverTestModule : public pp::Module { |
public: |
- MyModule() : pp::Module() {} |
- virtual ~MyModule() {} |
+ PowerSaverTestModule() : pp::Module() {} |
+ virtual ~PowerSaverTestModule() {} |
// 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.
|
virtual pp::Instance* CreateInstance(PP_Instance instance) { |
- return new MyInstance(instance); |
+ return new PowerSaverTestInstance(instance); |
} |
}; |
@@ -56,8 +59,7 @@ namespace pp { |
// 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.
|
Module* CreateModule() { |
- return new MyModule(); |
+ return new PowerSaverTestModule(); |
} |
} // namespace pp |
- |