Created
March 4, 2012 23:17
-
-
Save jarek-foksa/1975318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MainWindowController.h" | |
#import <WebKit2/WKProcessGroup.h> | |
#import <WebKit2/WKBrowsingContextGroup.h> | |
#import <WebKit2/WebKit2.h> | |
#import <WebKit2/WKPreferencesPrivate.h> | |
#import <WebKit2/WKPageGroup.h> | |
#import <WebKit2/WKPagePrivate.h> | |
#import <WebKit2/WKStringCF.h> | |
#import <WebKit2/WKURLCF.h> | |
//#import <WebKit2/WKInspector.h> | |
#import <WebKit2/WKPage.h> | |
#import <WebKit2/WKProcessGroup.h> | |
#import <WebKit2/WKBrowsingContextGroup.h> | |
#import <WebKit2/WKBrowsingContextController.h> | |
#import <WebKit2/WKContextPrivate.h> | |
#import <WebKit2/WKBrowsingContextLoadDelegate.h> | |
#import <WebKit2/WKProcessGroup.h> | |
#import <WebKit2/WKView.h> | |
#import <WebKit2/WKViewPrivate.h> | |
@implementation MainWindowController | |
// Properties | |
@synthesize processGroup; | |
@synthesize browsingContextGroup; | |
@synthesize view; | |
// overwrite | |
- (void)windowDidLoad { | |
[super windowDidLoad]; | |
NSLog(@"Main window loaded"); | |
} | |
// overwrite | |
- (void)awakeFromNib { | |
NSLog(@"Awaking from Nib"); | |
// Create WebKit2 process | |
processGroup = [[WKProcessGroup alloc] init]; | |
browsingContextGroup = browsingContextGroup = [[WKBrowsingContextGroup alloc] initWithIdentifier:@"Type Fu"]; | |
webView = [[WKView alloc] initWithFrame:[view bounds] processGroup:processGroup browsingContextGroup:browsingContextGroup]; | |
[webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; | |
[view addSubview:webView]; | |
page = webView.pageRef; | |
pageGroup = WKPageGetPageGroup(page); | |
//inspector = WKPageGetInspector(page); | |
// | |
// WebView callbacks | |
// | |
WKPageLoaderClient loadClient = { | |
kWKPageLoaderClientCurrentVersion, | |
0, // clientInfo | |
0, //didStartProvisionalLoadForFrame, | |
0, //didReceiveServerRedirectForProvisionalLoadForFrame, | |
0, //didFailProvisionalLoadWithErrorForFrame, | |
0, //didCommitLoadForFrame, | |
0, //didFinishDocumentLoadForFrame, | |
0, //didFinishLoadForFrame, | |
0, //didFailLoadWithErrorForFrame, | |
0, //didSameDocumentNavigationForFrame, | |
0, //didReceiveTitleForFrame, | |
0, //didFirstLayoutForFrame, | |
0, //didFirstVisuallyNonEmptyLayoutForFrame, | |
0, //didRemoveFrameFromHierarchy, | |
0, //didDisplayInsecureContentForFrame, | |
0, //didRunInsecureContentForFrame, | |
0, // canAuthenticateAgainstProtectionSpaceInFrame | |
0, // didReceiveAuthenticationChallengeInFrame | |
0, //didStartProgress, | |
0, //didChangeProgress, | |
0, //didFinishProgress, | |
0, //didBecomeUnresponsive, | |
0, //didBecomeResponsive, | |
0, ///processDidExit, | |
0, //didChangeBackForwardList, | |
0, // shouldGoToBackForwardItem | |
0, // didFailToInitializePlugin | |
0, //didDetectXSSForFrame, | |
}; | |
WKPageUIClient uiClient = { | |
kWKPageUIClientCurrentVersion, | |
0, //clientInfo | |
0, //createNewPage_deprecatedForUseWithV0 | |
0, //showPage, | |
0, //closePage, | |
0, //takeFocus | |
0, // focus | |
0, // unfocus | |
0, //runJavaScriptAlert, | |
0, //runJavaScriptConfirm, | |
0, //runJavaScriptPrompt, | |
0, //setStatusText, | |
0, // mouseDidMoveOverElement_deprecatedForUseWithV0 | |
0, // missingPluginButtonClicked | |
0, // didNotHandleKeyEvent | |
0, // didNotHandleWheelEvent | |
0, // toolbarsAreVisible | |
0, // setToolbarsAreVisible | |
0, // menuBarIsVisible | |
0, // setMenuBarIsVisible | |
0, // statusBarIsVisible | |
0, // setStatusBarIsVisible | |
0, // isResizable | |
0, // setIsResizable | |
0, //getWindowFrame, | |
0, //setWindowFrame, | |
0, //runBeforeUnloadConfirmPanel, | |
0, // didDraw | |
0, // pageDidScroll | |
0, // exceededDatabaseQuota | |
0, //runOpenPanel, | |
0, // decidePolicyForGeolocationPermissionRequest | |
0, // headerHeight | |
0, // footerHeight | |
0, // drawHeader | |
0, // drawFooter | |
0, // printFrame | |
0, // showModal | |
0, // didCompleteRubberBandForMainFrame | |
0, // saveDataToFileInDownloadsFolder | |
0, // shouldInterruptJavaScript | |
0, //createNewPage, | |
0, //mouseDidMoveOverElement, | |
0, // decidePolicyForNotificationPermissionRequest | |
}; | |
WKPageSetPageLoaderClient(webView.pageRef, &loadClient); | |
WKPageSetPageUIClient(webView.pageRef, &uiClient); | |
// | |
// WebView preferences | |
// | |
WKPreferencesRef prefs = WKPreferencesCreate(); | |
WKPreferencesSetDeveloperExtrasEnabled(prefs, YES); | |
WKPreferencesSetJavaScriptCanAccessClipboard(prefs, YES); | |
WKPreferencesSetFullScreenEnabled(prefs, YES); | |
WKPreferencesSetAcceleratedDrawingEnabled(prefs, NO); | |
WKPreferencesSetCanvasUsesAcceleratedDrawing(prefs, YES); | |
WKPreferencesSetAcceleratedCompositingEnabled(prefs, NO); | |
WKPreferencesSetCompositingBordersVisible(prefs, NO); | |
WKPreferencesSetCompositingRepaintCountersVisible(prefs, NO); | |
WKPreferencesSetWebGLEnabled(prefs, YES); | |
WKPreferencesSetPageCacheEnabled(prefs, NO); | |
WKPreferencesSetDOMPasteAllowed(prefs, YES); | |
WKPreferencesSetWebSecurityEnabled(prefs, NO); | |
WKPreferencesSetUniversalAccessFromFileURLsAllowed(prefs, YES); | |
WKPreferencesSetFileAccessFromFileURLsAllowed(prefs, YES); | |
WKPageGroupSetPreferences(pageGroup, prefs); | |
[self loadURL:@"/client/main.html"]; | |
} | |
- (void)loadURL:(NSString*)relURL { | |
NSString *fullURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:relURL]; | |
NSURL *url = [NSURL fileURLWithPath:fullURL]; | |
[[webView browsingContextController] loadFileURL:url restrictToFilesWithin:url]; | |
} | |
@end // end of implementation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment