github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/ppapi/instance_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 6 7 import ( 8 "fmt" 9 "runtime" 10 ) 11 12 // Instance represents one instance of the module on a web page. 13 // This corresponds to one <embed ...> occurrence. 14 type Instance struct { 15 id pp_Instance 16 } 17 18 func makeInstance(id pp_Instance) (inst Instance) { 19 inst.id = id 20 return 21 } 22 23 // IsFullFrame returns true if the instance is full-frame. 24 func (inst Instance) IsFullFrame() bool { 25 return ppb_instance_is_full_frame(inst.id) != 0 26 } 27 28 // PostMessage sends a message to the browser. 29 func (inst Instance) PostMessage(v Var) { 30 ppb_messaging_post_message(inst.id, v.toPPVar()) 31 } 32 33 // Log writes a message to the console. 34 func (inst Instance) Log(level LogLevel, v Var) { 35 ppb_console_log(inst.id, level, v.toPPVar()) 36 } 37 38 // LogWithSource writes a message to the console, using the source information rather than the plugin name. 39 func (inst Instance) LogWithSource(level LogLevel, src, v Var) { 40 ppb_console_log_with_source(inst.id, level, src.toPPVar(), v.toPPVar()) 41 } 42 43 func (inst Instance) LogWithSourceString(level LogLevel, src, msg string) { 44 v1 := VarFromString(src) 45 v2 := VarFromString(msg) 46 inst.LogWithSource(level, v1, v2) 47 v1.Release() 48 v2.Release() 49 } 50 51 // LogString writes a message to the console. 52 func (inst Instance) LogString(level LogLevel, msg string) { 53 _, file, line, _ := runtime.Caller(2) 54 loc := fmt.Sprintf("%s:%d", file, line) 55 inst.LogWithSourceString(level, loc, msg) 56 } 57 58 // Logf writes a formatted message to the console. 59 func (inst Instance) Logf(level LogLevel, format string, args ...interface{}) { 60 _, file, line, _ := runtime.Caller(2) 61 loc := fmt.Sprintf("%s:%d", file, line) 62 msg := fmt.Sprintf(format, args...) 63 inst.LogWithSourceString(level, loc, msg) 64 } 65 66 // Printf writes a formatted message to the console. 67 func (inst Instance) Printf(format string, args ...interface{}) { 68 inst.Logf(PP_LOGLEVEL_LOG, format, args...) 69 } 70 71 // Warningf writes a formatted message to the console. 72 func (inst Instance) Warningf(format string, args ...interface{}) { 73 inst.Logf(PP_LOGLEVEL_WARNING, format, args...) 74 } 75 76 // Errorf writes a formatted message to the console. 77 func (inst Instance) Errorf(format string, args ...interface{}) { 78 inst.Logf(PP_LOGLEVEL_ERROR, format, args...) 79 }