Top Banner
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Introducing the Modern WebKit API Session 206 Anders Carlsson Safari and WebKit Engineer Frameworks
182

Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Aug 07, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Introducing the Modern WebKit API

Session 206 Anders Carlsson Safari and WebKit Engineer

Frameworks

Page 2: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WebKit Overview

Page 3: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 4: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 5: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 6: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 7: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 8: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 9: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 10: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 11: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 12: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WebKit in Your App

Page 13: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WebKit in Your App

UIWebView UIKit.framework

Page 14: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WebKit in Your App

WebView WebKit.framework

UIWebView UIKit.framework

Page 15: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What You Will Learn

Page 16: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What You Will Learn

Embedding web content in your app

Page 17: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What You Will Learn

Embedding web content in your app

Taking advantage of new features of the WebKit API

Page 18: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What You Will Learn

Embedding web content in your app

Taking advantage of new features of the WebKit API

Customizing how your app interacts with web content

Page 19: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 20: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 21: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Same on iOS and OS X

Page 22: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Same on iOS and OS X

Modern

Page 23: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Same on iOS and OS X

Modern

Streamlined

Page 24: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Same on iOS and OS X

Modern

Streamlined

Multi-process architecture

Page 25: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit APIFeatures

Page 26: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit APIFeatures

Responsive scrolling

Page 27: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit APIFeatures

Responsive scrolling

Fast JavaScript

Page 28: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit APIFeatures

Responsive scrolling

Fast JavaScript

Built-in gestures

Page 29: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit APIFeatures

Responsive scrolling

Fast JavaScript

Built-in gestures

Easy app-webpage communication

Page 30: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Page 31: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Web content runs in its own process

Page 32: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Web content runs in its own process

WKWebView

Web Content Process

WebKit

Page 33: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Consistently responsive

Page 34: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Consistently responsive

Energy efficient

Page 35: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Page 36: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Page 37: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Web Content Process

WebKit

Page 38: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Web Content Process

WebKit

WKWebView

Page 39: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Web Content Process

WebKit

WKWebView

Web Content Process

WebKit

Page 40: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Web Content Process

WebKit

WKWebView

Web Content Process

WebKit

WKWebView

Page 41: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

WKWebView

Web Content Process

WebKit

WKWebView

Web Content Process

WebKit

WKWebView

Page 42: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Web Content Process

WebKit

WKWebView

Web Content Process

WebKit

WKWebView WKWebView

Page 43: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Web Content Process

WebKit

WKWebView WKWebView

Page 44: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Web Content Process

WebKit

WKWebView

Page 45: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Multi-process Architecture

Page 46: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit API

Page 47: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APIWKPedia—a Wikipedia browsing app

Page 48: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APICreating a WKWebView

Page 49: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APICreating a WKWebView

WKWebView *webView = [[WKWebView alloc] initWithFrame:myFrame];

Page 50: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APILoading a webpage

Page 51: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APILoading a webpage

NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"];

Page 52: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APILoading a webpage

NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"];NSURLRequest *request = [NSURLRequest requestWithURL:URL];

Page 53: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APILoading a webpage

NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"];NSURLRequest *request = [NSURLRequest requestWithURL:URL];

[webView loadRequest:request];

Page 54: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 55: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 56: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APIConfigurations

Configuration

WKWebView WKWebView WKWebView

Page 57: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APIConfigurations

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];

Page 58: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adopting the Modern WebKit APIConfigurations

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];

WKWebView *webView = [[WKWebView alloc] initWithFrame:myFrame configuration:configuration];

Page 59: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 60: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 61: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adding App UI

Page 62: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adding App UI

Page 63: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Actions

Page 64: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Actions

- goBack: - goForward: - reload: - stopLoading:

Page 65: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Actions

- goBack: - goForward: - reload: - stopLoading:

Page 66: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Adding App UI

Page 67: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Properties

Page 68: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Properties

Name Type

title NSString

URL NSURL

loading BOOL

estimatedProgress double

Page 69: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Properties

Name Type

title NSString

URL NSURL

loading BOOL

estimatedProgress double

Page 70: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebView Properties

Name Type

title NSString

URL NSURL

loading BOOL

estimatedProgress double

Page 71: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 72: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 73: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 74: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 75: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page Loading

Page 76: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Page 77: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Page 78: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Link

Page 79: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Page 80: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Actionwindow.location = 'http://www.apple.com/';

Page 81: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Page 82: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action-[WKWebView loadRequest:]

Page 83: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

TriggerAction

Request

Page 84: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Page 85: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Page 86: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Page 87: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Data

Page 88: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Data

01

01 0

11

0

01

1

00

Page 89: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Action

Page Loading

Request

Response

Data

Page 90: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Page Loading

Action

Request

Response

Your App

Data

Your App

Page 91: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page Loading

@property (nonatomic, weak) WKNavigationDelegate *navigationDelegate;

Page 92: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page Loading

@property (nonatomic, weak) WKNavigationDelegate *navigationDelegate;

- webView:decidePolicyForNavigationAction:decisionHandler:

Page 93: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page Loading

@property (nonatomic, weak) WKNavigationDelegate *navigationDelegate;

- webView:decidePolicyForNavigationAction:decisionHandler:- webView:decidePolicyForNavigationResponse:decisionHandler:

Page 94: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationAction

Page 95: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationAction

Name Type

navigationType WKNavigationType

sourceFrame WKFrameInfo

destinationFrame WKFrameInfo

request NSURLRequest

modifierFlags NSEventModifierFlags

Page 96: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationAction

Name Type

navigationType WKNavigationType

sourceFrame WKFrameInfo

destinationFrame WKFrameInfo

request NSURLRequest

modifierFlags NSEventModifierFlags

Link

-[WKWebView loadRequest:]

Page 97: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationAction

Name Type

navigationType WKNavigationType

sourceFrame WKFrameInfo

destinationFrame WKFrameInfo

request NSURLRequest

modifierFlags NSEventModifierFlags

Page 98: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationAction

Name Type

navigationType WKNavigationType

sourceFrame WKFrameInfo

destinationFrame WKFrameInfo

request NSURLRequest

modifierFlags NSEventModifierFlags

Shift

ControlOption

Page 99: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationResponse

Page 100: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationResponse

Name Type

response NSURLResponse

forMainFrame BOOL

canShowMIMEType BOOL

Page 101: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingWKNavigationResponse

Name Type

response NSURLResponse

forMainFrame BOOL

canShowMIMEType BOOL

Page 102: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingDecision Handler

Page 103: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingDecision Handler

You decide whether to cancel or allow

Page 104: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingDecision Handler

You decide whether to cancel or allow

Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow

Page 105: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingDecision Handler

You decide whether to cancel or allow

Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow

Navigation response WKNavigationResponsePolicyCancel WKNavigationResponsePolicyAllow

Page 106: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Page LoadingDecision Handler

You decide whether to cancel or allow

Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow

Navigation response WKNavigationResponsePolicyCancel WKNavigationResponsePolicyAllow

Asynchronous

Page 107: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

DemoWKPedia

Beth Dakin Safari and WebKit Engineer

Page 108: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

GesturesNavigation Gestures

Page 109: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

GesturesNavigation Gestures

webView.allowsBackForwardNavigationGestures = YES;

Page 110: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

GesturesZoom Gestures

Page 111: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

GesturesZoom Gestures

OS X webView.allowsMagnification = YES;

Page 112: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 113: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 114: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 115: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 116: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 117: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 118: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 119: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 120: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 121: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 122: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Webpage Content

Page 123: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Webpage Content

User Scripts

Page 124: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Webpage Content

User Scripts

Script Messages

Page 125: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Customizing Webpage Content

User Scripts

Script Messages

Managed by WKUserContentController

Page 126: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKUserContentController

Page 127: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKUserContentController

Part of WKWebViewConfiguration

Page 128: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKUserContentController

Part of WKWebViewConfiguration@property (nonatomic, strong) WKUserContentController *userContentController;

Page 129: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

Page 130: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

Page 131: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

Page 132: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run

Page 133: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run• Document start

Page 134: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run• Document start

• Document end

Page 135: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run• Document start

• Document end

Where they run

Page 136: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run• Document start

• Document end

Where they run• All frames

Page 137: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

When they run• Document start

• Document end

Where they run• All frames

• Main frame only

Page 138: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

Page 139: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

NSString *myScriptSource = @"alert('Hello, World!')";

Page 140: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

NSString *myScriptSource = @"alert('Hello, World!')";

WKUserScript *myUserScript = [[WKUserScript alloc] initWithSource:myScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];

Page 141: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

User Scripts

NSString *myScriptSource = @"alert('Hello, World!')";

WKUserScript *myUserScript = [[WKUserScript alloc] initWithSource:myScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];[userContentController addUserScript:myUserScript];

Page 142: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Page 143: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Incredibly powerful

Page 144: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Incredibly powerful• Modify the document

Page 145: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Incredibly powerful• Modify the document

• Listen for events

Page 146: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Incredibly powerful• Modify the document

• Listen for events

• Load resources

Page 147: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

What Can User Scripts Do?

Incredibly powerful• Modify the document

• Listen for events

• Load resources

• Communicate back to your application

Page 148: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Page 149: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Page 150: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Page 151: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Sent as JSON

Page 152: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Sent as JSON

Converted to Objective-C types

Page 153: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesRegistering a Script Message Handler

Page 154: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesRegistering a Script Message Handler

WKScriptMessageHandler protocol

Page 155: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesRegistering a Script Message Handler

WKScriptMessageHandler protocol

- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message;

Page 156: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesRegistering a Script Message Handler

WKScriptMessageHandler protocol

- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message;

[userContentController addScriptMessageHandler:handler name:@"myName"];

Page 157: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesPosting messages

Page 158: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesPosting messages

window.webkit.messageHandlers.<name>.postMessage();

Page 159: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesPosting messages

window.webkit.messageHandlers.<name>.postMessage();

function postMyMessage(){ var message = { 'message' : 'Hello, World!', 'numbers' : [ 1, 2, 3 ] }; window.webkit.messageHandlers.myName.postMessage(message);}

Page 160: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesReceiving messages

Page 161: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script MessagesReceiving messages

- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message { NSLog(@"Message: %@", message.body); }

Page 162: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Name Type

body id

webView WKWebView

name NSString

Script MessagesWKScriptMessage

Page 163: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

Page 164: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

The webpage can call postMessage

Page 165: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

The webpage can call postMessage• Great for allowing webpages to interact with your app

Page 166: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Script Messages

The webpage can call postMessage• Great for allowing webpages to interact with your app

• Handle invalid messages

Page 167: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

DemoWKPedia for iPad

Beth Dakin Safari and WebKit Engineer

Page 168: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 169: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 170: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

WKWebView

Web Content Process

WebKit

Page 171: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 172: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 173: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

The Modern WebKit API

Page 174: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your
Page 175: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

WKWebViewConfiguration

WKNavigationDelegate

WKNavigationAction

WKPreferences

WKNavigationResponse

WKScriptMessage

WKUIDelegate

WKBackForwardListItem

WKNavigationType

WKBackForwardList

WKFrameInfo

WKProcessPool

WKNavigation

WKWebView

WKUserContentController

WKUserScript

WKWindowFeatures

WKScriptMessageHandler

Page 176: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Next Steps

Page 177: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Next Steps

Adopt the modern WebKit API

Page 178: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Next Steps

Adopt the modern WebKit API

Give us feedback

Page 179: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

More Information

Evangelism [email protected]

Safari Dev Center http://developer.apple.com/safari/

WebKit Open Source Project http://www.webkit.org/

Apple Developer Forums http://devforums.apple.com/

Page 180: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Related Sessions

• Your App, Your Website, and Safari Nob Hill Tuesday 4:30PM

• Web Inspector and Modern JavaScript Russian Hill Thursday 10:15AM

• Sharing Code Between iOS and OS X Presidio Friday 9:00AM

Page 181: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your

Labs

• Safari and WebKit Lab Media Lab B Tuesday 4:30PM

• Safari and WebKit Lab Media Lab B Wednesday 4:30PM

• Safari and WebKit Lab Media Lab B Thursday 2:00PM

Page 182: Introducing the Modern WebKit API - Apple Inc.€¦ · What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your