The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone....

89
The new Webkit is AWESOME Cesare Rocchi @_funkyboy

Transcript of The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone....

Page 1: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

The new Webkit is AWESOME

Cesare Rocchi

@_funkyboy

Page 2: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

TOC

• History

• What’s new

• Demo

Page 3: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Who am I?

Page 4: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

UX designer and developer

Page 5: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

studiomagnolia.com

Page 6: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

baasbox.com

Page 7: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

upbeat.it

Page 8: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

@_funkyboy

Page 9: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Who are you?

Page 10: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

History

Page 11: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave exactly like apps on the iPhone.

SJ, 2007

Page 12: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

History

• No plugins

• Flash

• Applets

Page 13: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 14: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Adobe, don’t you even think about it!

Page 15: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 16: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 17: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

History

• Nitro was introduced in iOS 4.3

• Uses JIT

• Transform JS into native code Needs to mark memory w+x

• Security issues

Page 18: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 19: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

var temp = {}; temp[10123] = "yow";

Page 20: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Progress

Page 24: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

iOS 6.1 -> iOS7

https://developer.apple.com/library/IOS/releasenotes/General/iOS70APIDiffs/index.html

Added UIWebView.gapBetweenPages Added UIWebView.pageCount Added UIWebView.pageLength Added UIWebView.paginationBreakingMode Added UIWebView.paginationMode Added UIWebPaginationBreakingMode Added UIWebPaginationBreakingModeColumn Added UIWebPaginationBreakingModePage Added UIWebPaginationMode Added UIWebPaginationModeBottomToTop Added UIWebPaginationModeLeftToRight Added UIWebPaginationModeRightToLeft Added UIWebPaginationModeTopToBottom Added UIWebPaginationModeUnpaginated

Page 25: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

iOS 6.1 -> iOS7

https://developer.apple.com/library/IOS/releasenotes/General/iOS70APIDiffs/index.html

Added #def JSC_OBJC_API_ENABLED Added JSCheckScriptSyntax() Added JSClassRef Added JSContextGroupRef Added JSContextRef Added JSEvaluateScript() Added JSGarbageCollect() Added JSGlobalContextRef Added JSObjectRef Added JSPropertyNameAccumulatorRef Added JSPropertyNameArrayRef Added JSStringRef Added JSValueRef Added #def WTF_EXPORT_PRIVATE Added #def WTF_PLATFORM_IOS Added JSContext Added -[JSContext JSGlobalContextRef] Added +[JSContext contextWithJSGlobalContextRef:] Added +[JSContext currentArguments] Added +[JSContext currentContext] Added +[JSContext currentThis] Added -[JSContext evaluateScript:] Added JSContext.exception Added JSContext.exceptionHandler Added -[JSContext globalObject] Added -[JSContext init] Added -[JSContext initWithVirtualMachine:] Added -[JSContext objectForKeyedSubscript:] Added -[JSContext setObject:forKeyedSubscript:] Added JSContext.virtualMachine Added JSContext(JSContextRefSupport) Added JSContext(SubscriptSupport) Added #def JSContext_h Added JSContextGetGlobalObject() Added JSContextGetGroup() Added JSContextGroupCreate() Added JSContextGroupRelease() Added JSContextGroupRetain() Added JSGlobalContextCreate() Added JSGlobalContextCreateInGroup() Added JSGlobalContextRelease() Added JSGlobalContextRetain() Added JSExport Added #def JSExportAs Added JSManagedValue Added -[JSManagedValue initWithValue:] Added +[JSManagedValue managedValueWithValue:] Added -[JSManagedValue value] Added #def JSManagedValue_h Added JSClassAttributes Added JSClassCreate() Added JSClassDefinition Added JSClassRelease() Added JSClassRetain() Added JSObjectCallAsConstructor() Added JSObjectCallAsConstructorCallback Added JSObjectCallAsFunction() Added JSObjectCallAsFunctionCallback Added JSObjectConvertToTypeCallback Added JSObjectCopyPropertyNames() Added JSObjectDeleteProperty() Added JSObjectDeletePropertyCallback Added JSObjectFinalizeCallback Added JSObjectGetPrivate() Added JSObjectGetProperty() Added JSObjectGetPropertyAtIndex() Added JSObjectGetPropertyCallback Added JSObjectGetPropertyNamesCallback Added JSObjectGetPrototype() Added JSObjectHasInstanceCallback Added JSObjectHasProperty() Added JSObjectHasPropertyCallback Added JSObjectInitializeCallback Added JSObjectIsConstructor() Added JSObjectIsFunction() Added JSObjectMake() Added JSObjectMakeArray() Added JSObjectMakeConstructor() Added JSObjectMakeDate() Added JSObjectMakeError() Added JSObjectMakeFunction() Added JSObjectMakeFunctionWithCallback() Added JSObjectMakeRegExp() Added JSObjectSetPrivate() Added JSObjectSetProperty() Added JSObjectSetPropertyAtIndex() Added JSObjectSetPropertyCallback Added JSObjectSetPrototype() Added JSPropertyAttributes Added JSPropertyNameAccumulatorAddName() Added JSPropertyNameArrayGetCount() Added JSPropertyNameArrayGetNameAtIndex() Added JSPropertyNameArrayRelease() Added JSPropertyNameArrayRetain() Added JSStaticFunction Added JSStaticValue Added kJSClassAttributeNoAutomaticPrototype Added kJSClassAttributeNone Added kJSClassDefinitionEmpty Added kJSPropertyAttributeDontDelete Added kJSPropertyAttributeDontEnum Added kJSPropertyAttributeNone Added kJSPropertyAttributeReadOnly Added JSChar Added JSStringCreateWithCharacters() Added JSStringCreateWithUTF8CString() Added JSStringGetCharactersPtr() Added JSStringGetLength() Added JSStringGetMaximumUTF8CStringSize() Added JSStringGetUTF8CString() Added JSStringIsEqual() Added JSStringIsEqualToUTF8CString() Added JSStringRelease() Added JSStringRetain() Added JSStringCopyCFString() Added JSStringCreateWithCFString() Added JSValue Added -[JSValue JSValueRef] Added -[JSValue callWithArguments:] Added -[JSValue constructWithArguments:] Added JSValue.context Added -[JSValue defineProperty:descriptor:] Added -[JSValue deleteProperty:] Added -[JSValue hasProperty:] Added -[JSValue invokeMethod:withArguments:] Added -[JSValue isBoolean] Added -[JSValue isEqualToObject:] Added -[JSValue isEqualWithTypeCoercionToObject:] Added -[JSValue isInstanceOf:] Added -[JSValue isNull] Added -[JSValue isNumber] Added -[JSValue isObject] Added -[JSValue isString] Added -[JSValue isUndefined] Added -[JSValue objectAtIndexedSubscript:] Added -[JSValue objectForKeyedSubscript:] Added -[JSValue setObject:atIndexedSubscript:] Added -[JSValue setObject:forKeyedSubscript:] Added -[JSValue setValue:atIndex:] Added -[JSValue setValue:forProperty:] Added -[JSValue toArray] Added -[JSValue toBool] Added -[JSValue toDate] Added -[JSValue toDictionary] Added -[JSValue toDouble] Added -[JSValue toInt32] Added -[JSValue toNumber] Added -[JSValue toObject] Added -[JSValue toObjectOfClass:] Added -[JSValue toPoint] Added -[JSValue toRange] Added -[JSValue toRect] Added -[JSValue toSize] Added -[JSValue toString] Added -[JSValue toUInt32] Added -[JSValue valueAtIndex:] Added -[JSValue valueForProperty:] Added +[JSValue valueWithBool:inContext:] Added +[JSValue valueWithDouble:inContext:] Added +[JSValue valueWithInt32:inContext:] Added +[JSValue valueWithJSValueRef:inContext:] Added +[JSValue valueWithNewArrayInContext:] Added +[JSValue valueWithNewErrorFromMessage:inContext:] Added +[JSValue valueWithNewObjectInContext:] Added +[JSValue valueWithNewRegularExpressionFromPattern:flags:inContext:] Added +[JSValue valueWithNullInContext:] Added +[JSValue valueWithObject:inContext:] Added +[JSValue valueWithPoint:inContext:] Added +[JSValue valueWithRange:inContext:] Added +[JSValue valueWithRect:inContext:] Added +[JSValue valueWithSize:inContext:] Added +[JSValue valueWithUInt32:inContext:] Added +[JSValue valueWithUndefinedInContext:] Added JSPropertyDescriptorConfigurableKey Added JSPropertyDescriptorEnumerableKey Added JSPropertyDescriptorGetKey Added JSPropertyDescriptorSetKey Added JSPropertyDescriptorValueKey Added JSPropertyDescriptorWritableKey Added JSValue(JSValueRefSupport) Added JSValue(StructSupport) Added JSValue(SubscriptSupport) Added #def JSValue_h Added JSType Added JSValueCreateJSONString() Added JSValueGetType() Added JSValueIsBoolean() Added JSValueIsEqual() Added JSValueIsInstanceOfConstructor() Added JSValueIsNull() Added JSValueIsNumber() Added JSValueIsObject() Added JSValueIsObjectOfClass() Added JSValueIsStrictEqual() Added JSValueIsString() Added JSValueIsUndefined() Added JSValueMakeBoolean() Added JSValueMakeFromJSONString() Added JSValueMakeNull() Added JSValueMakeNumber() Added JSValueMakeString() Added JSValueMakeUndefined() Added JSValueProtect() Added JSValueToBoolean() Added JSValueToNumber() Added JSValueToObject() Added JSValueToStringCopy() Added JSValueUnprotect() Added kJSTypeBoolean Added kJSTypeNull Added kJSTypeNumber Added kJSTypeObject Added kJSTypeString Added kJSTypeUndefined Added JSVirtualMachine Added -[JSVirtualMachine addManagedReference:withOwner:] Added -[JSVirtualMachine init] Added -[JSVirtualMachine removeManagedReference:withOwner:] Added #def AVAILABLE_AFTER_WEBKIT_VERSION_5_1 Added #def AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_5_1 Added #def WEBKIT_OBJC_METHOD_ANNOTATION Added #def WEBKIT_VERSION_1_0 Added #def WEBKIT_VERSION_1_1 Added #def WEBKIT_VERSION_1_2 Added #def WEBKIT_VERSION_1_3 Added #def WEBKIT_VERSION_2_0 Added #def WEBKIT_VERSION_3_0 Added #def WEBKIT_VERSION_3_1 Added #def WEBKIT_VERSION_4_0 Added #def WEBKIT_VERSION_LATEST Added #def WEBKIT_VERSION_MAX_ALLOWED Added #def WEBKIT_VERSION_MIN_REQUIRED

232 APIs}

Page 26: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 27: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

iOS7 -> iOS8

https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS80APIDiffs/frameworks/WebKit.html

Page 28: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

1 Class 1 Protocol

Page 29: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

UIWebView UIWebViewDelegate

Page 30: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

14 Classes 3 Protocols

Page 31: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

WKWebView WKFrameInfo WKBackForwardList WKBackForwardListItem WKNavigation WKNavigationAction WKNavigationResponse WKPreferences WKProcessPool WKUserContentController WKWebViewConfiguration WKWindowFeatures WKScriptMessage WKUserScript !

WKNavigationDelegate WKScriptMessageHandler WKUIDelegate

Page 32: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

XPC

• Greatly improved in iOS8

• Third party keyboards

• Sharing extensions

Page 33: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

XPC

find /Applications -name \*.xpc | grep Web | wc -l

Page 34: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

XPC

• Split app in multiple processes

• E.g. Sourcekit • http://www.jpsim.com/uncovering-sourcekit/

Page 35: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

r167958

Page 36: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 37: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Optimizing JS

Page 38: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Fun with JS

Page 39: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

jsc

sudo ln -s /System/Library/Frameworks/

JavaScriptCore.framework/Versions/Current/Resources/jsc

/bin/jsc

Page 40: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 41: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

JS bytecode

LLInt JIT DFG

optimization

Page 42: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

function sum(a, b) { return a + b; !

}

Page 43: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLInt JIT DFG

optimization

function sum(a, b) { return a + b; }

Page 44: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLInt

JIT

DFG

Page 45: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLVM

Page 46: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLVM

• Infrastructure

• Meant to optimize *time

• Started by Mr. Swift

Page 47: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLInt

JIT

DFG

Page 48: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

LLInt

JIT

DFG

FTL

Page 49: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

What’s new

Page 50: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Observable values

Page 51: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Observable values

• loading

• title

• URL

• estimatedProgress

Page 52: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Observable values

webView.addObserver(self, forKeyPath: "loading", options: .New, context: nil)

Page 53: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Observable valuesoverride func observeValueForKeyPath(...) { switch keyPath { case "loading": println("\(webView.loading)") case "estimatedProgress": println("\(webView.estimatedProgress)") … !

} }

Page 54: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Injecting

Page 55: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Action

Request

Response

Rendering

Page 56: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Action

Request

Response

Rendering

Page 57: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Action

Request

Page 58: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Action

Request

webView:decidePolicyForNavigationAction:decisionHandler

Page 59: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Response

Rendering

Page 60: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Response

Rendering

webView:decidePolicyForNavigationResponse:decisionHandler:

Page 61: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

func webView(webView: WKWebView!, decidePolicyForNavigationAction navigationAction: WKNavigationAction!, decisionHandler: ((WKNavigationActionPolicy) -> Void)!) { !

if (navigationAction.navigationType == .LinkActivated && navigationAction.request.URL.host?. lowercaseString.hasPrefix("yowconference.com.au/") != nil) { !

// Open Safari UIApplication.sharedApplication().openURL(navigationAction.request.URL); decisionHandler(.Cancel) !

} else { !

decisionHandler(.Allow) !

} !

}

Page 62: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Native code HTML PageJS

Data

Page 63: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Data is serialized into native objects!

Page 64: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Injecting

1. Create configuration

2. Wrap JS script in a WKUserScript

3. Add script to configuration controller

4. Set up handler

5. Use configuration to build a Web view

Page 65: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

let speakersWebViewConfiguration = WKWebViewConfiguration()

Page 66: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

let scriptURL = NSBundle.mainBundle().pathForResource("fetchSpeakers", ofType: “js") !

let jsScript = String.stringWithContentsOfFile(scriptURL!, encoding:NSUTF8StringEncoding, error: nil) !

let fetchAuthorsScript = WKUserScript(source: jsScript, injectionTime: .AtDocumentEnd, forMainFrameOnly: true)

Page 67: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

speakersWebViewConfiguration. userContentController. addUserScript(fetchAuthorsScript)

Page 68: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

speakersWebViewConfiguration. userContentController. addScriptMessageHandler(self, name: MESSAGE_HANDLER)

Page 69: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

speakersWebView = WKWebView(frame: CGRectZero, configuration: speakersWebViewConfiguration)

Page 70: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

speakersWebView!.addObserver(self, forKeyPath: "loading", options: .New, context: nil) !

speakersWebView!.addObserver(self, forKeyPath: "estimatedProgress", options: .New, context: nil)

Page 71: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

let speakersRequest = NSURLRequest(URL:speakersURL) speakersWebView!.loadRequest(speakersRequest)

Page 72: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 73: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 74: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 75: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 76: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 77: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Demo

Page 78: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

https://github.com/funkyboy/YowSpeakers

Page 79: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Caution

Page 80: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

https://developer.apple.com/app-store/review/guidelines/

Page 81: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

https://developer.apple.com/app-store/review/guidelines/

Page 82: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

https://developer.apple.com/app-store/review/guidelines/

Page 83: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

https://developer.apple.com/app-store/review/guidelines/

Page 84: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Building a native app is like building a custom browser

Page 85: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Building a native app is like building a custom browser

Me, now

Page 86: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Summing up

Page 87: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave
Page 88: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Links

• https://www.webkit.org/blog/3362/introducing-the-webkit-ftl-jit/

• http://trac.webkit.org/changeset/167958

• https://github.com/funkyboy/YowSpeakers

• WWDC Video #206

Page 89: The new Webkit is AWESOME - slides.yowconference.com · The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave

Contact

[email protected]

• @_funkyboy