cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / examples / scripting / post_message.cc
blob636a7a8506b009db354e840243baa428815821fd
1 // Copyright (c) 2011 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.
5 #include <algorithm>
7 #include "ppapi/cpp/instance.h"
8 #include "ppapi/cpp/module.h"
9 #include "ppapi/cpp/var.h"
11 // When compiling natively on Windows, PostMessage can be #define-d to
12 // something else.
13 #ifdef PostMessage
14 #undef PostMessage
15 #endif
17 // This is a simple C++ Pepper plugin that demonstrates HandleMessage and
18 // PostMessage.
20 // This object represents one time the page says <embed>.
21 class MyInstance : public pp::Instance {
22 public:
23 explicit MyInstance(PP_Instance instance) : pp::Instance(instance) {}
24 virtual ~MyInstance() {}
25 virtual void HandleMessage(const pp::Var& message_data);
28 // HandleMessage gets invoked when postMessage is called on the DOM element
29 // associated with this plugin instance.
30 // 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.
32 void MyInstance::HandleMessage(const pp::Var& message_data) {
33 if (message_data.is_string()) {
34 std::string string_copy(message_data.AsString());
35 std::reverse(string_copy.begin(), string_copy.end());
36 bool is_palindrome(message_data.AsString() == string_copy);
38 PostMessage(pp::Var(is_palindrome));
42 // This object is the global object representing this plugin library as long
43 // as it is loaded.
44 class MyModule : public pp::Module {
45 public:
46 MyModule() : pp::Module() {}
47 virtual ~MyModule() {}
49 // Override CreateInstance to create your customized Instance object.
50 virtual pp::Instance* CreateInstance(PP_Instance instance) {
51 return new MyInstance(instance);
55 namespace pp {
57 // Factory function for your specialization of the Module object.
58 Module* CreateModule() {
59 return new MyModule();
62 } // namespace pp