Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- #import <AppKit/AppKit.h>
- #import <WebKit/WebKit.h>
- #import "TinyController.h"
- int main (int argc, const char * argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- NSApp = [NSApplication sharedApplication];
- TinyController * controller = [[TinyController alloc] init];
- [NSApp setDelegate:controller];
- [controller navigate:[NSString stringWithCString:(argc > 1 ? argv[1] : "http://ya.ru/")]];
- [NSApp run];
- [controller release];
- [NSApp release];
- [pool release];
- return EXIT_SUCCESS;
- }
- #import <Foundation/Foundation.h>
- #import <AppKit/AppKit.h>
- #import <WebKit/WebKit.h>
- @interface TinyController : NSObject {
- NSWindow * window;
- WebView * view;
- }
- -(id)init;
- -(void)dealloc;
- -(void)navigate:(NSString *)url_string;
- -(void)applicationDidFinishLaunching:(NSNotification *)notification;
- -(void)windowWillClose:(NSNotification *)notification;
- -(void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame;
- @end
- #import "TinyController.h"
- @implementation TinyController
- -(id)init {
- [super init];
- NSRect geometry = NSMakeRect(0,0,1024,768);
- view = [[WebView alloc] initWithFrame:geometry];
- [view setFrameLoadDelegate:self];
- window = [[NSWindow alloc] initWithContentRect:geometry
- styleMask:NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask
- backing:NSBackingStoreBuffered
- defer:NO];
- [window setTitle:@"Tiny Browser"];
- [window setContentView:view];
- [window setInitialFirstResponder:view];
- [window setDelegate:self];
- [window center];
- return self;
- }
- -(void)dealloc {
- [window release];
- [view release];
- [super dealloc];
- }
- -(void)navigate:(NSString *)url_string {
- [[view mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url_string]]];
- }
- -(void)applicationDidFinishLaunching:(NSNotification *)notification {
- [NSApp activateIgnoringOtherApps:YES];
- [window makeKeyAndOrderFront:self];
- }
- -(void)windowWillClose:(NSNotification *)notification {
- [NSApp terminate:self];
- }
- -(void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
- NSLog(@"%@ %@",[error localizedFailureReason],[error localizedDescription]);
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement