Created
October 30, 2015 09:27
-
-
Save deepak1556/cdb701cba6a3afc29844 to your computer and use it in GitHub Desktop.
Simple electron app to test pepper plugin load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
g++ ./hello.cc -shared -o libppapi_hello.so -I/home/robo/github/nacl_sdk/pepper_43/include -L/home/robo/github/nacl_sdk/pepper_43/lib/linux_host/Release -lppapi_cpp -lppapi -lpthread -Wall -fPIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2013 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. | |
/// @file hello_tutorial.cc | |
/// This example demonstrates loading, running and scripting a very simple NaCl | |
/// module. To load the NaCl module, the browser first looks for the | |
/// CreateModule() factory method (at the end of this file). It calls | |
/// CreateModule() once to load the module code. After the code is loaded, | |
/// CreateModule() is not called again. | |
/// | |
/// Once the code is loaded, the browser calls the CreateInstance() | |
/// method on the object returned by CreateModule(). It calls CreateInstance() | |
/// each time it encounters an <embed> tag that references your NaCl module. | |
/// | |
/// The browser can talk to your NaCl module via the postMessage() Javascript | |
/// function. When you call postMessage() on your NaCl module from the browser, | |
/// this becomes a call to the HandleMessage() method of your pp::Instance | |
/// subclass. You can send messages back to the browser by calling the | |
/// PostMessage() method on your pp::Instance. Note that these two methods | |
/// (postMessage() in Javascript and PostMessage() in C++) are asynchronous. | |
/// This means they return immediately - there is no waiting for the message | |
/// to be handled. This has implications in your program design, particularly | |
/// when mutating property values that are exposed to both the browser and the | |
/// NaCl module. | |
#include "ppapi/cpp/instance.h" | |
#include "ppapi/cpp/module.h" | |
#include "ppapi/cpp/var.h" | |
/// The Instance class. One of these exists for each instance of your NaCl | |
/// module on the web page. The browser will ask the Module object to create | |
/// a new Instance for each occurrence of the <embed> tag that has these | |
/// attributes: | |
/// src="hello_tutorial.nmf" | |
/// type="application/x-pnacl" | |
/// To communicate with the browser, you must override HandleMessage() to | |
/// receive messages from the browser, and use PostMessage() to send messages | |
/// back to the browser. Note that this interface is asynchronous. | |
class HelloTutorialInstance : public pp::Instance { | |
public: | |
/// The constructor creates the plugin-side instance. | |
/// @param[in] instance the handle to the browser-side plugin instance. | |
explicit HelloTutorialInstance(PP_Instance instance) : pp::Instance(instance) | |
{ | |
pp::Var var_reply = pp::Var("hello from Pepper Plugin"); | |
PostMessage(var_reply); | |
} | |
virtual ~HelloTutorialInstance() {} | |
/// Handler for messages coming in from the browser via postMessage(). The | |
/// @a var_message can contain be any pp:Var type; for example int, string | |
/// Array or Dictinary. Please see the pp:Var documentation for more details. | |
/// @param[in] var_message The message posted by the browser. | |
virtual void HandleMessage(const pp::Var& var_message) { | |
// TODO(sdk_user): 1. Make this function handle the incoming message. | |
} | |
}; | |
/// The Module class. The browser calls the CreateInstance() method to create | |
/// an instance of your NaCl module on the web page. The browser creates a new | |
/// instance for each <embed> tag with type="application/x-pnacl". | |
class HelloTutorialModule : public pp::Module { | |
public: | |
HelloTutorialModule() : pp::Module() {} | |
virtual ~HelloTutorialModule() {} | |
/// Create and return a HelloTutorialInstance object. | |
/// @param[in] instance The browser-side instance. | |
/// @return the plugin-side instance. | |
virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
return new HelloTutorialInstance(instance); | |
} | |
}; | |
namespace pp { | |
/// Factory function called by the browser when the module is first loaded. | |
/// The browser keeps a singleton of this module. It calls the | |
/// CreateInstance() method on the object you return to make instances. There | |
/// is one instance per <embed> tag on the page. This is the main binding | |
/// point for your NaCl module with the browser. | |
Module* CreateModule() { | |
return new HelloTutorialModule(); | |
} | |
} // namespace pp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('app'); | |
var BrowserWindow = require('browser-window'); | |
var path = require('path') | |
var mainWindow = null; | |
app.commandLine.appendSwitch('register-pepper-plugins', path.join(__dirname, 'libppapi_hello.so;application/x-hello')) | |
app.on('ready', function() { | |
mainWindow = new BrowserWindow({ | |
height: 800, | |
width: 1024, | |
'web-preferences' : { | |
'plugins': true | |
} | |
}); | |
mainWindow.loadUrl('file://' + __dirname + '/nacl.html'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<!-- | |
Copyright (c) 2013 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. | |
--> | |
<head> | |
<title>hello_tutorial</title> | |
<script type="text/javascript"> | |
// The 'message' event handler. This handler is fired when the NaCl module | |
// posts a message to the browser by calling PPB_Messaging.PostMessage() | |
// (in C) or pp::Instance.PostMessage() (in C++). This implementation | |
// simply displays the content of the message in an alert panel. | |
function handleMessage(message_event) { | |
alert(message_event.data); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>NaCl C++ Tutorial: Getting Started</h1> | |
<p> | |
<div id="listener"> | |
<script type="text/javascript"> | |
var listener = document.getElementById('listener'); | |
listener.addEventListener('message', handleMessage, true); | |
</script> | |
<embed id="hello_tutorial" | |
width=0 height=0 | |
type="application/x-hello" /> | |
</div> | |
</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "main.js", | |
"name": "Pepper plugin test", | |
"description": "testing third party plugin load", | |
"version": "0.0.1", | |
"license": "MIT" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone wondering why it won't work, the key in the new BrowserWindow needs to be
webPreferences
- I suppose it was changed fromweb-preferences
.Cheers, deepack1556!