OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <algorithm> |
| 6 |
| 7 #include "ppapi/cpp/instance.h" |
| 8 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/cpp/var.h" |
| 10 #include "ppapi/cpp/var_dictionary.h" |
| 11 #include "ppapi/tests/test_utils.h" |
| 12 |
| 13 // When compiling natively on Windows, PostMessage can be #define-d to |
| 14 // something else. |
| 15 #ifdef PostMessage |
| 16 #undef PostMessage |
| 17 #endif |
| 18 |
| 19 // This is a simple C++ Pepper plugin that enables Plugin Power Saver tests. |
| 20 class PowerSaverTestInstance : public pp::Instance { |
| 21 public: |
| 22 explicit PowerSaverTestInstance(PP_Instance instance) |
| 23 : pp::Instance(instance) {} |
| 24 virtual ~PowerSaverTestInstance() {} |
| 25 virtual void HandleMessage(const pp::Var& message_data); |
| 26 }; |
| 27 |
| 28 // When postMessage("isPeripheral") is called on the DOM element associated |
| 29 // with this plugin instance, we respond with a Javascript object containing |
| 30 // a boolean indicating if the plugin has been marked peripheral. |
| 31 void PowerSaverTestInstance::HandleMessage(const pp::Var& message_data) { |
| 32 if (message_data.is_string() && (message_data.AsString() == "isPeripheral")) { |
| 33 pp::VarDictionary message; |
| 34 message.Set( |
| 35 "isPeripheral", |
| 36 pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); |
| 37 PostMessage(message); |
| 38 } |
| 39 } |
| 40 |
| 41 class PowerSaverTestModule : public pp::Module { |
| 42 public: |
| 43 PowerSaverTestModule() : pp::Module() {} |
| 44 virtual ~PowerSaverTestModule() {} |
| 45 |
| 46 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 47 return new PowerSaverTestInstance(instance); |
| 48 } |
| 49 }; |
| 50 |
| 51 namespace pp { |
| 52 |
| 53 Module* CreateModule() { |
| 54 return new PowerSaverTestModule(); |
| 55 } |
| 56 |
| 57 } // namespace pp |
OLD | NEW |