Mercurial > osx-quasimode
changeset 5:620147798b16
Added a custom 'window.boop' function to the page.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 11 Apr 2010 17:30:57 -0700 |
parents | 11056d446ed6 |
children | ea0dcbf6a0bc |
files | Makefile MyApp.m |
diffstat | 2 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sun Apr 11 13:06:30 2010 -0700 +++ b/Makefile Sun Apr 11 17:30:57 2010 -0700 @@ -1,2 +1,3 @@ all: - clang MyApp.m -oMyApp -framework AppKit -framework WebKit + clang MyApp.m -oMyApp -framework AppKit -framework WebKit \ + -framework JavaScriptCore
--- a/MyApp.m Sun Apr 11 13:06:30 2010 -0700 +++ b/MyApp.m Sun Apr 11 17:30:57 2010 -0700 @@ -7,6 +7,33 @@ #import <WebKit/WebView.h> #import <WebKit/WebFrame.h> #import <WebKit/WebFrameView.h> +#import <JavaScriptCore/JavaScriptCore.h> + +JSValueRef boop(JSContextRef ctx, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + if (argumentCount >= 1 && + JSValueIsNumber(ctx, arguments[0])) { + printf("BOOP IS CALLED WITH %f\n", + JSValueToNumber(ctx, arguments[0], NULL)); + } + return JSValueMakeUndefined(ctx); +} + +void defineJSGlobals(JSGlobalContextRef ctx) +{ + JSGlobalContextRetain(ctx); + JSObjectRef global = JSContextGetGlobalObject(ctx); + JSStringRef boopStr = JSStringCreateWithUTF8CString("boop"); + JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, boopStr, boop); + JSObjectSetProperty(ctx, global, boopStr, func, NULL, + kJSPropertyAttributeNone); + JSGlobalContextRelease(ctx); +} int main(int argc, const char *argv[]) { @@ -37,6 +64,8 @@ [[[view mainFrame] frameView] setAllowsScrolling: NO]; [[view mainFrame] loadRequest: req]; + defineJSGlobals([[view mainFrame] globalContext]); + [window setOpaque: NO]; [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0 green: 0.0