webkit programming in cocoa

Post on 19-May-2015

6.245 Views

Category:

Business

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Overview of the WebKit framework in Objective-C for programmers.

TRANSCRIPT

#include <Cocoa/Cocoa.h>#include <WebKit/WebKit.h>

@author Jason Harwig

[webkit description]

"WebKit begins where the chrome ends."

- Surfin' Safari Blog

"WebKit begins where the chrome ends."

- Surfin' Safari Blog

Safari featuresURL field, Tabs, Bookmarks, Find

WebKit featuresAnything in the webpage itself:

(frames, form controls, kick-ass CSS3 features, blazing page load speeds)

[webkit history]

KHTML

KHTML2003

WebKit

[webkit usage]

[webkit usage]

Reminder

add WebKit.Framework import WebKit.h

WebView

WebFrame

WebFrameWebFrameWebFrame

mainFrame

childFrames

WebView

WebFrame

WebFrameWebFrameWebFrame

WebFrameViewWebFrameViewWebFrameView

WebFrameView

mainFrame

childFrames

webView

mainFrame

loadRequest:

loadRequest:

• Runs asyncronously in current NSRunLoop

• Calls delegates:

WebResourceLoadDelegate WebFrameLoadDelegate

WebPolicyDelegate WebUIDelegate

• decidePolicyForNewWindowAction:

• decidePolicyForNavigationAction:

• decidePolicyForMIMEType:

WebPolicyDelegate

WebFrameLoadDelegate

• didFinishLoadForFrame:

• didFailLoadWithError:forFrame:

didFinishLoadForFrame:(WebFrame *)frame{

if (frame != [webView mainFrame]) return;

}

WebResourceLoadDelegate

WebResourceLoadDelegate

willSendRequest:

WebResourceLoadDelegate

willSendRequest:

didFinishLoading:

WebResourceLoadDelegate

willSendRequest:

didFinishLoading:

didReceiveContentLength:

didReceiveResponse:

didFailLoadingWithError:

WebResourceLoadDelegate

willSendRequest:

didFinishLoading:

didReceiveContentLength:

didReceiveResponse:

didFailLoadingWithError:

WebResourceLoadDelegate

willSendRequest:

didFinishLoading:

didReceiveAuthenticationChallenge:

WebUIDelegate

• runJavaScriptAlertPanelWithMessage:

• mouseDidMoveOverElement:

• contextMenuItemsForElement:

• willPerformDragDestinationAction:

... many more (see documentation)

[[[webView mainFrame] dataSource] webArchive];

[webView mainFrame] loadData:[webArchive data]...];

WebArchive

Accessing the DOM

DOMDocument *doc =

[webView mainFrameDocument];

[doc createElement:@"div"];// Returns DOMElement

[[doc documentElement] innerHTML];

Calling JavaScript

WebScriptObject *wso = [webView windowScriptObject];

[wso callWebScriptMethod:@"f" withArguments:nil];

/* or */[wso evaluateWebScript:@"f()"];

id location = [wso valueForKey:@"location"];

NSString *href = [location valueForKey:@"href"];

Calling Objective-C

[wso setValue:foo forKey:@"foo"];

// in JSfoo.bar();

[webkit demo:JS]

[webkit demo:HtmlUI]

5

6

5 x 6 = 30

5

6

5 x 6 = 30

5

6

2 ^ 30 = 1,073,741,824

5 x 6 = 30

5

6

2 ^ 30 = 1,073,741,824

[webkit demo:Delish]

[webkit performSelector:@selector(demo:) withObject:Matt afterDelay:COUPLE_MINUTES]

[webkit more]

• Site-Specific Browsers

• WebKit Plugins

• SIMBL (culater.net)

Resources

• Webkit "Surfin' Safari Blog" (webkit.org/blog)

• Webkit Wiki (trac.webkit.org/wiki)

• Apple Documentation

• Delish (http://pinepointsoftware.com)

top related