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 | |
Lei Zhang
2015/04/22 23:35:20
Is this needed? ppapi/cpp/instance.h already does
tommycli
2015/04/23 20:11:23
I tried removing this, and the Windows trybots fai
| |
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), received_first_did_change_view_(false) {} | |
24 ~PowerSaverTestInstance() override {} | |
25 | |
26 // For browser tests, responds to: | |
27 // - When postMessage("isPeripheral") is called on the plugin DOM element. | |
28 // - When the plugin throttler posts a message notifying us that our | |
29 // peripheral status has changed. | |
30 void HandleMessage(const pp::Var& message_data) override { | |
31 if (message_data.is_string()) { | |
32 if (message_data.AsString() == "getPeripheralStatus") | |
33 BroadcastIsPeripheralStatus("getPeripheralStatusResponse"); | |
34 else if (message_data.AsString() == "peripheralStatusChange") | |
35 BroadcastIsPeripheralStatus("peripheralStatusChange"); | |
36 } | |
37 } | |
38 | |
39 // Broadcast our peripheral status after the initial view data. This is for | |
40 // tests that await initial plugin creation. | |
41 void DidChangeView(const pp::View& view) override { | |
42 if (!received_first_did_change_view_) { | |
43 BroadcastIsPeripheralStatus("initial"); | |
44 received_first_did_change_view_ = true; | |
45 } | |
46 } | |
47 | |
48 private: | |
49 void BroadcastIsPeripheralStatus(const std::string& source) { | |
50 pp::VarDictionary message; | |
51 message.Set( | |
52 "isPeripheral", | |
53 pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); | |
54 message.Set("source", pp::Var(source)); | |
55 PostMessage(message); | |
56 } | |
57 | |
58 bool received_first_did_change_view_; | |
59 }; | |
60 | |
61 class PowerSaverTestModule : public pp::Module { | |
62 public: | |
63 PowerSaverTestModule() : pp::Module() {} | |
64 virtual ~PowerSaverTestModule() {} | |
65 | |
66 virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
67 return new PowerSaverTestInstance(instance); | |
68 } | |
69 }; | |
70 | |
71 namespace pp { | |
72 | |
73 Module* CreateModule() { | |
74 return new PowerSaverTestModule(); | |
75 } | |
76 | |
77 } // namespace pp | |
OLD | NEW |