github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/ppapi/ppapi_nacl.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package ppapi provides the Pepper API (PPAPI) to Native Client applications. 6 // Native Client (NaCl) is a sandbox for running compiled code in the browser 7 // efficiently and securely, independent of the user’s operating system. See 8 // http://developer.chrome.com/native-client for an overview. 9 // 10 // This package is based on the Pepper C API, which is documented at 11 // https://developer.chrome.com/native-client/pepper_dev/c/index#pepper-dev-c-index. 12 // The functions and types implemented in this package mirror the C API, 13 // with some reorganization for a more interface-based presentation. 14 // 15 // See ${GOROOT}/test/ppapi for some examples of how to use the API. The main 16 // parts include 1) a web page to be viewed in the browser, 2) a "manifest" file 17 // that specifies executable files, and 3) the executable itself, compiled using 18 // GOOS=nacl. 19 // 20 // For example, here is how to set up a basic "Hello world" executable. The 21 // HTML file contains an <embed> for the application, where "hello.nmf" is the 22 // manifest file. 23 // 24 // <div> 25 // <embed width=640 height=480 src="hello.nmf" type="application/x-nacl"/> 26 // </div> 27 // 28 // The manifest file "hello.nmf" lists the executable, using JSON syntax. 29 // 30 // { 31 // "program": { 32 // "x86-32": { 33 // "url": "hello_x86_32.nexe" 34 // } 35 // } 36 // } 37 // 38 // Finally, the interesting part is the application. Each <embed> on the page 39 // creates a PPAPI Instance. You have to provide a factory for creating these 40 // instances (this is like the "main" function for program instance). Your 41 // instance must implement the ppapi.InstanceHandlers to receive callbacks from 42 // the browser. Here is an example. For brevity, we'll elide most of the 43 // callbacks. 44 // 45 // package main 46 // 47 // type myInstance struct { 48 // ppapi.Instance 49 // } 50 // 51 // // Called when an instance is created (due to an <embed ...>). 52 // func (inst *myInstance) DidCreate(argv map[string]string) bool { 53 // inst.LogString(ppapi.PP_LOGLEVEL_LOG, "Hello world") 54 // } 55 // 56 // // ...other InstanceHandlers methods... 57 // 58 // // In the main function, call ppapi.Init with your instance factory. 59 // func main() { 60 // ppapi.Init(func (inst ppapi.Instance) ppapi.InstanceHandlers { 61 // return &myInstance{Instance: inst} 62 // }) 63 // } 64 // 65 // Compile with GOOS=nacl. You can compile the normal way and copy the binary 66 // from your bin directory, or else just compile this single file. 67 // 68 // $ GOOS=nacl GOARCH=386 go build -o hello_x86_32.nexe hello.go 69 // 70 // Copy your files (hello.html, hello.nmf, hello_x86_32.nexe) to your web server 71 // and you are done. See the NaCl documentation for techniques on how to use 72 // the Javascript console, and how to debug NaCl applications using gdb. 73 package ppapi 74 75 import ( 76 "fmt" 77 "runtime" 78 ) 79 80 // Init is the main entry point to start PPAPI. Never returns. Call this 81 // function at most once. 82 func Init(factory func(inst Instance) InstanceHandlers) { 83 configureCallbackHandlers(factory) 84 // This is not supposed to return. 85 runtime.UnlockOSThread() 86 var c chan bool = make(chan bool) 87 fmt.Printf("Thread that called Init() going to sleep forever.") 88 <-c 89 }