diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 669f21122..abd703591 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -172,6 +172,7 @@ var CPViewHighDPIDrawingEnabled = YES; CPArray _registeredDraggedTypesArray; BOOL _isHidden; + BOOL _isHiddenOrHasHiddenAncestor; BOOL _hitTests; BOOL _clipsToBounds; @@ -372,6 +373,7 @@ var CPViewHighDPIDrawingEnabled = YES; _opacity = 1.0; _isHidden = NO; + _isHiddenOrHasHiddenAncestor = NO; _hitTests = YES; _hierarchyScaleSize = CGSizeMake(1.0 , 1.0); @@ -598,7 +600,7 @@ var CPViewHighDPIDrawingEnabled = YES; [aSubview _removeFromSuperview]; // Set ourselves as the superview. - aSubview._superview = self; + [aSubview _setSuperview:self]; } if (anIndex === CPNotFound || anIndex >= count) @@ -623,11 +625,6 @@ var CPViewHighDPIDrawingEnabled = YES; [aSubview setNextResponder:self]; [aSubview _scaleSizeUnitSquareToSize:[self _hierarchyScaleSize]]; - // If the subview is not hidden and one of its ancestors is hidden, - // notify the subview that it is now hidden. - if (![aSubview isHidden] && [self isHiddenOrHasHiddenAncestor]) - [aSubview _notifyViewDidHide]; - [aSubview viewDidMoveToSuperview]; // Set the subview's window to our own. @@ -697,13 +694,10 @@ var CPViewHighDPIDrawingEnabled = YES; // If the view is not hidden and one of its ancestors is hidden, // notify the view that it is now unhidden. - if (!_isHidden && [_superview isHiddenOrHasHiddenAncestor]) - [self _notifyViewDidUnhide]; + [self _setSuperview:nil]; [self _notifyWindowDidResignKey]; [self _notifyViewDidResignFirstResponder]; - - _superview = nil; } /*! @@ -1599,10 +1593,8 @@ var CPViewHighDPIDrawingEnabled = YES; // FIXME: Should we return to visibility? This breaks in FireFox, Opera, and IE. // _DOMElement.style.visibility = (_isHidden = aFlag) ? "hidden" : "visible"; - _isHidden = aFlag; - #if PLATFORM(DOM) - _DOMElement.style.display = _isHidden ? "none" : "block"; + _DOMElement.style.display = aFlag ? "none" : "block"; #endif if (aFlag) @@ -1622,33 +1614,61 @@ var CPViewHighDPIDrawingEnabled = YES; while (view = [view superview]); } - [self _notifyViewDidHide]; + [self _recursiveGainedHiddenAncestor]; } else { [self setNeedsDisplay:YES]; - [self _notifyViewDidUnhide]; + + [self _recursiveLostHiddenAncestor]; } + + _isHidden = aFlag; } -- (void)_notifyViewDidHide +- (void)_setSuperview:(CPView)aSuperview { - [self viewDidHide]; + var hasOldSuperview = (_superview !== nil), + hasNewSuperview = (aSuperview !== nil), + oldSuperviewIsHidden = hasOldSuperview && [_superview isHiddenOrHasHiddenAncestor], + newSuperviewIsHidden = hasNewSuperview && [aSuperview isHiddenOrHasHiddenAncestor]; - var count = [_subviews count]; + if (!newSuperviewIsHidden && oldSuperviewIsHidden) + [self _recursiveLostHiddenAncestor]; - while (count--) - [_subviews[count] _notifyViewDidHide]; + if (newSuperviewIsHidden && !oldSuperviewIsHidden) + [self _recursiveGainedHiddenAncestor]; + + _superview = aSuperview; } -- (void)_notifyViewDidUnhide +- (void)_recursiveLostHiddenAncestor { - [self viewDidUnhide]; + if (_isHiddenOrHasHiddenAncestor) + { + _isHiddenOrHasHiddenAncestor = NO; + [self viewDidUnhide]; + } - var count = [_subviews count]; + [_subviews enumerateObjectsUsingBlock:function(view, idx, stop) + { + [view _recursiveLostHiddenAncestor]; + }]; +} - while (count--) - [_subviews[count] _notifyViewDidUnhide]; +- (void)_recursiveGainedHiddenAncestor +{ + if (!_isHidden) + { + [self viewDidHide]; + } + + _isHiddenOrHasHiddenAncestor = YES; + + [_subviews enumerateObjectsUsingBlock:function(view, idx, stop) + { + [view _recursiveGainedHiddenAncestor]; + }]; } /*! @@ -1718,12 +1738,7 @@ var CPViewHighDPIDrawingEnabled = YES; */ - (BOOL)isHiddenOrHasHiddenAncestor { - var view = self; - - while (view && ![view isHidden]) - view = [view superview]; - - return view !== nil; + return _isHiddenOrHasHiddenAncestor; } /*! @@ -3494,14 +3509,14 @@ setBoundsOrigin: Invoked automatically when the view’s geometry changes such that its tracking areas need to be recalculated. You should override this method to remove out of date tracking areas and add recomputed tracking areas; - + Cocoa calls this on every view, whereas they have tracking area(s) or not. Cappuccino behaves differently : - updateTrackingAreas is called when placing a view in the view hierarchy (that is in a window) - if you have only CPTrackingInVisibleRect tracking areas attached to a view, it will not be called again (until you move the view in the hierarchy) - if you have at least one non-CPTrackingInVisibleRect tracking area attached, it will be called every time the view geometry could be modified You don't have to touch to CPTrackingInVisibleRect tracking areas, they will be automatically updated - + Please note that it is the owner of a tracking area who is called for updateTrackingAreas. But, if a view without any tracking area is inserted in the view hierarchy (that is, in a window), the view is called for updateTrackingAreas. This enables you to use updateTrackingArea to initially attach your tracking areas to the view. @@ -3513,16 +3528,16 @@ setBoundsOrigin: /*! This utility method is intended for CPView subclasses overriding updateTrackingAreas - + Typical use would be : - + - (void)updateTrackingAreas { [self removeAllTrackingAreas]; - + ... add your specific updated tracking areas ... } - + */ - (void)removeAllTrackingAreas { @@ -3707,6 +3722,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", #endif [self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]]; + _isHiddenOrHasHiddenAncestor = NO; if ([aCoder containsValueForKey:CPViewOpacityKey]) [self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]]; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 9c4880938..c9e8381aa 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -308,7 +308,7 @@ CPTexturedBackgroundWindowMask [self setPlatformWindow:[CPPlatformWindow primaryPlatformWindow]]; else { - // give zero sized borderless bridge windows a default size if we're not in the browser so they show up in NativeHost. + // give zero sized borderless bridge windows a default size. if ((aStyleMask & CPBorderlessBridgeWindowMask) && aContentRect.size.width === 0 && aContentRect.size.height === 0) { var visibleFrame = [[[CPScreen alloc] init] visibleFrame]; @@ -655,7 +655,6 @@ CPTexturedBackgroundWindowMask CPBorderlessWindowMask CPTitledWindowMask CPClosableWindowMask - CPMiniaturizableWindowMask (NOTE: only available in NativeHost) CPResizableWindowMask CPTexturedBackgroundWindowMask CPBorderlessBridgeWindowMask diff --git a/CommonJS/lib/cappuccino/nativehost.js b/CommonJS/lib/cappuccino/nativehost.js deleted file mode 100644 index 8def87642..000000000 --- a/CommonJS/lib/cappuccino/nativehost.js +++ /dev/null @@ -1,70 +0,0 @@ -var FILE = require("file"); -var OS = require("os"); - -var NATIVEHOST_SOURCE = FILE.path(module.path).dirname().dirname().dirname().join("support", "NativeHost.app"); - -exports.buildNativeHost = function(rootPath, buildNative, options) { - options = options || {}; - options.index = options.index || "index.html"; - - rootPath = FILE.path(rootPath); - buildNative = FILE.path(buildNative); - - if (buildNative.exists()) - buildNative.rmtree(); - - buildNative.dirname().mkdirs(); - // FIXME: Narwhal doesn't preserve permissions - // FILE.copyTree(NATIVEHOST_SOURCE, buildNative); - OS.system(["cp", "-r", NATIVEHOST_SOURCE, buildNative]); - FILE.chmod(buildNative.join("Contents", "MacOS", "NativeHost"), 0755); - - var rootBaseName = rootPath.basename(); - var buildClientDirectory = buildNative.join("Contents", "Resources", rootBaseName); - - FILE.mkdirs(FILE.dirname(buildClientDirectory)); - // FILE.copyTree(rootPath, buildClientDirectory); - OS.system(["cp", "-r", rootPath, buildClientDirectory]); - - var defaultBundleName = buildNative.basename().match(/^(.*)(\.app)?$/)[1]; - - function mergePlist(plist, path) { - var otherPlist = CFPropertyList.readPropertyListFromFile(String(path)); - - otherPlist.keys().forEach(function(key) { - var value = otherPlist.valueForKey(key); - plist.setValueForKey(key, value); - - if (key === "CPBundleName") - plist.setValueForKey("CFBundleName", value); - - if (key === "CFBundleIconFile") { - var iconPath = rootPath.join("Resources", value); - if (iconPath.isFile()) - iconPath.copy(buildNative.join("Contents", "Resources", value)); - else - print("Warning: CFBundleIconFile references " + value + " but does not exist in the resources directory."); - } - - if (key === "CFBundleExecutable") { - buildNative.join("Contents", "MacOS", "NativeHost").rename(value); - // FIXME: - FILE.chmod(buildNative.join("Contents", "MacOS", value), 0755); - } - }); - } - - CFPropertyList.modifyPlist(buildNative.join("Contents", "Info.plist"), function(plist) { - - plist.setValueForKey("CFBundleName", defaultBundleName); - plist.setValueForKey("NHInitialResource", FILE.join(rootBaseName, options.index)); - - // merge Cappuccino plist - var cappPlistPath = rootPath.join("Info.plist"); - if (cappPlistPath.isFile()) - mergePlist(plist, cappPlistPath); - - if (options.extraPlistPath) - mergePlist(plist, options.extraPlistPath); - }); -} diff --git a/Tests/AppKit/CPViewTest.j b/Tests/AppKit/CPViewTest.j index 383db1a99..78812d2fc 100644 --- a/Tests/AppKit/CPViewTest.j +++ b/Tests/AppKit/CPViewTest.j @@ -895,70 +895,167 @@ var updateTrackingAreasCalls, [self assert:nil equals:[view effectiveAppearance]]; } +- (void)testViewDidHideDidUnhide +{ + var expectedResult = [@"viewDidHide_view1", @"viewDidUnhide_view1"]; + + [view1 setHidden:YES]; + [view1 setHidden:NO]; + + [self assert:expectedResult equals:methodCalled]; +} + +- (void)testViewGainedHiddenAncestor +{ + var expectedResult = [@"viewDidHide_view1", + @"viewWillMoveToSuperview_view3", + @"viewDidMoveToSuperview_view3", + @"viewWillMoveToSuperview_view2", + @"viewDidHide_view2", + @"viewDidHide_view3", + @"viewDidMoveToSuperview_view2"]; + + [view1 setHidden:YES]; + [view2 addSubview:view3]; + [view1 addSubview:view2]; + + [self assert:expectedResult equals:methodCalled]; + [self assertTrue: [view2 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = YES"]; + [self assertTrue: [view3 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = YES"]; + + [self assertFalse:[view2 isHidden]]; + [self assertFalse:[view3 isHidden]]; +} + +- (void)testRemoveViewsHiddenByAncestor +{ + var expectedResult = @[ + @"viewWillMoveToSuperview_view2", + @"viewDidUnhide_view2", + @"viewDidUnhide_view3", + @"viewDidMoveToSuperview_view2", + @"viewWillMoveToWindow_view2", + @"viewWillMoveToWindow_view3", + @"viewDidMoveToWindow_view3", + @"viewDidMoveToWindow_view2" +]; + + [view1 setHidden:YES]; + [view1 addSubview:view2]; + [view2 addSubview:view3]; + + [self assertTrue: [view2 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = YES" ]; + [self assertFalse:[view2 isHidden]]; + + [self assertTrue: [view3 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = YES" ]; + [self assertFalse:[view3 isHidden]]; + + methodCalled = []; + + [view2 removeFromSuperview]; + + [self assertFalse: [view2 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = NO" ]; + [self assertFalse: [view3 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = NO" ]; + + [self assert:expectedResult equals:methodCalled]; +} + +- (void)testRemoveHiddenView +{ + var expectedResult = [@"viewWillMoveToSuperview_view2", @"viewDidMoveToSuperview_view2", @"viewWillMoveToWindow_view2", @"viewDidMoveToWindow_view2"]; + + [view1 addSubview:view2]; + [view2 setHidden:YES]; + + methodCalled = []; + + [view2 removeFromSuperview]; + [self assertTrue: [view2 isHiddenOrHasHiddenAncestor] message:@"Expected isHiddenOrHasHiddenAncestor = YES" ]; + [self assert:expectedResult equals:methodCalled]; +} + +- (void)testLostHiddenAncestorAfterMovingToNewSuperview +{ + var expectedResult = @[ + @"viewWillMoveToSuperview_view2", + @"viewDidMoveToSuperview_view2", + @"viewDidHide_view1", + @"viewDidHide_view2", + @"viewWillMoveToSuperview_view2", + @"viewDidUnhide_view2", + @"viewDidMoveToSuperview_view2" +]; + + [view1 addSubview:view2]; + [view1 setHidden:YES]; + [view3 addSubview:view2]; + + [self assert:expectedResult equals:methodCalled]; +} // TrackingAreaAdditions - (void)testTrackingAreas { var trackingArea = [[CPTrackingArea alloc] initWithRect:CGRectMakeZero() options:CPTrackingMouseEnteredAndExited | CPTrackingActiveInKeyWindow | CPTrackingInVisibleRect owner:self userInfo:nil]; - + [self assert:0 equals:[[view trackingAreas] count] message:@"Initially, a view has no tracking area"]; // - + [view addTrackingArea:trackingArea]; [self assert:1 equals:[[view trackingAreas] count] message:@"After adding a tracking area"]; [self assert:view equals:[trackingArea view] message:@"Tracking area should be linked to view"]; // - + [view removeTrackingArea:trackingArea]; [self assert:0 equals:[[view trackingAreas] count] message:@"After removing the only tracking area"]; [self assert:nil equals:[trackingArea view] message:@"Tracking area should be unlinked"]; - + // - + [view addTrackingArea:trackingArea]; [view addTrackingArea:trackingArea]; [view addTrackingArea:trackingArea]; [self assert:1 equals:[[view trackingAreas] count] message:@"Adding the same tracking area multiple times should add it once"]; [self assert:view equals:[trackingArea view] message:@"Tracking area should be linked to view"]; - + var trackingArea2 = [[CPTrackingArea alloc] initWithRect:CGRectMakeZero() options:CPTrackingMouseEnteredAndExited | CPTrackingActiveInKeyWindow owner:self userInfo:nil]; // - + [view addTrackingArea:trackingArea2]; [self assert:2 equals:[[view trackingAreas] count] message:@"After adding a second tracking area"]; [self assert:view equals:[trackingArea2 view] message:@"Tracking area should be linked to view"]; // - + [view removeAllTrackingAreas]; [self assert:0 equals:[[view trackingAreas] count] message:@"After removing all tracking areas"]; [self assert:nil equals:[trackingArea view] message:@"Tracking area should be unlinked"]; [self assert:nil equals:[trackingArea2 view] message:@"Tracking area should be unlinked"]; // - + [view addTrackingArea:trackingArea]; - + var contentView = [window contentView]; [contentView addSubview:view]; [self assert:0 equals:updateTrackingAreasCalls message:@"Putting a view with a CPTrackingAreaInVisibleRect in a window should not call updateTrackingAreas"]; - + [view removeFromSuperview]; // - + [view addTrackingArea:trackingArea2]; [contentView addSubview:view]; [self assert:1 equals:updateTrackingAreasCalls message:@"Putting a view with a non CPTrackingAreaInVisibleRect in a window should call updateTrackingAreas"]; - + [view removeAllTrackingAreas]; - + // - + var viewTA = [[CPTrackingAreaView alloc] initWithFrame:CGRectMakeZero()]; updateTrackingAreasCalls = 0; @@ -966,17 +1063,17 @@ var updateTrackingAreasCalls, [self assert:1 equals:updateTrackingAreasCalls message:@"Putting a view with no tracking areas in a window should call updateTrackingAreas"]; // - + updateTrackingAreasCalls = 0; [viewTA addTrackingArea:trackingArea]; [viewTA setFrame:CGRectMake(10, 10, 10, 10)]; [self assert:0 equals:updateTrackingAreasCalls message:@"Changing geometry of a view with a CPTrackingAreaInVisibleRect should not call updateTrackingAreas"]; - + // - + updateTrackingAreasCalls = 0; - + [viewTA addTrackingArea:trackingArea2]; [viewTA setFrame:CGRectMake(20, 20, 20, 20)]; [self assert:1 equals:updateTrackingAreasCalls message:@"Changing geometry of a view with a non CPTrackingAreaInVisibleRect should call updateTrackingAreas"]; @@ -1048,7 +1145,7 @@ var updateTrackingAreasCalls, [viewTA removeAllTrackingAreas]; [viewTA addTrackingArea:trackingAreaAllWithDrag]; - + // Mouse enters the tracking area while dragging (option set) [self moveMouseAtPoint:CGPointMake(21, 21) dragging:YES]; @@ -1103,7 +1200,7 @@ var updateTrackingAreasCalls, [self assert:0 equals:mouseExitedCalls message:@"Mouse entering inner tracking area should not call mouseExited"]; [self assert:1 equals:mouseMovedCalls message:@"Mouse entering inner tracking area should call mouseMoved"]; [self assert:1 equals:cursorUpdateCalls message:@"Mouse entering inner tracking area should call cursorUpdate"]; - + // Mouse moves in inner view [self moveMouseAtPoint:CGPointMake(27, 27) dragging:NO]; @@ -1112,7 +1209,7 @@ var updateTrackingAreasCalls, [self assert:0 equals:mouseExitedCalls message:@"Mouse moving in inner tracking area should not call mouseExited"]; [self assert:2 equals:mouseMovedCalls message:@"Mouse moving in inner tracking area should call mouseMoved for both views"]; [self assert:0 equals:cursorUpdateCalls message:@"Mouse moving in inner tracking area should not call cursorUpdate"]; - + // Mouse leaves inner view but remains in outer view [self moveMouseAtPoint:CGPointMake(36, 36) dragging:NO]; @@ -1121,7 +1218,7 @@ var updateTrackingAreasCalls, [self assert:1 equals:mouseExitedCalls message:@"Mouse moving from inner to outer tracking area should call mouseExited (for inner)"]; [self assert:1 equals:mouseMovedCalls message:@"Mouse moving from inner to outer tracking area should call mouseMoved (for outer)"]; [self assert:1 equals:cursorUpdateCalls message:@"Mouse moving from inner to outer tracking area should call cursorUpdate (for outer)"]; - + [self assert:innerViewTA equals:involvedViewForMouseExited message:@"Inner view should receive mouseExited"]; [self assert:viewTA equals:involvedViewForCursorUpdate message:@"Outer view should receive cursorUpdate"]; @@ -1278,7 +1375,7 @@ var updateTrackingAreasCalls, [self mouseUpAtPoint:CGPointMake(10, 10)]; [self assert:[CPCursor arrowCursor] equals:[CPCursor currentCursor] message:@"Step 1.7 : cursor should be an arrow"]; - + // [self moveMouseAtPoint:CGPointMake(1, 1) dragging:NO]; @@ -1292,7 +1389,7 @@ var updateTrackingAreasCalls, [self moveMouseAtPoint:CGPointMake(5, 5) dragging:NO]; [self assert:[CPCursor arrowCursor] equals:[CPCursor currentCursor] message:@"Step 2.1 : cursor should be an arrow"]; - + // Step 2.2 : inside the superview / outside the subview [self moveMouseAtPoint:CGPointMake(15, 15) dragging:NO]; @@ -1310,7 +1407,7 @@ var updateTrackingAreasCalls, [self moveMouseAtPoint:CGPointMake(15, 15) dragging:NO]; [self assert:[CPCursor crosshairCursor] equals:[CPCursor currentCursor] message:@"Step 2.4 : cursor should be a crosshair"]; - + // Step 2.5 : outside the superview [self moveMouseAtPoint:CGPointMake(5, 5) dragging:NO]; @@ -1355,14 +1452,14 @@ var updateTrackingAreasCalls, [self moveMouseAtPoint:CGPointMake(5, 5) dragging:NO]; [self assert:[CPCursor arrowCursor] equals:[CPCursor currentCursor] message:@"Step 3.5 : cursor should be an arrow"]; - + } - (void)testTrackingAreasLiveViewHierarchyModification { // 1. viewB inside viewA with mouseEntered removing itself - var viewA = [[CPTrackingAreaViewWithCursorUpdate alloc] initWithFrame:CGRectMake(20, 20, 40, 40)] + var viewA = [[CPTrackingAreaViewWithCursorUpdate alloc] initWithFrame:CGRectMake(20, 20, 40, 40)], viewB = [[CPTrackingAreaViewLiveRemoval alloc] initWithFrame:CGRectMake(10, 10, 20, 20)]; [[window contentView] setSubviews:[CPArray arrayWithObject:viewA]]; @@ -1691,6 +1788,18 @@ var updateTrackingAreasCalls, [methodCalled addObject:string]; } +- (void)viewDidUnhide +{ + var string = _cmd + @"_" + [self identifier]; + [methodCalled addObject:string]; +} + +- (void)viewDidHide +{ + var string = _cmd + @"_" + [self identifier]; + [methodCalled addObject:string]; +} + - (BOOL)acceptsFirstResponder { return YES; diff --git a/Tests/Manual/UndoRedoWithMenuUpdate/AppController.j b/Tests/Manual/UndoRedoWithMenuUpdate/AppController.j index 8eb717751..a7df34795 100644 --- a/Tests/Manual/UndoRedoWithMenuUpdate/AppController.j +++ b/Tests/Manual/UndoRedoWithMenuUpdate/AppController.j @@ -142,7 +142,7 @@ [_menuItemView setDirty]; } -// Performs autoenable processing, returns isEnabled to propagate state to NativeHost +// Performs autoenable processing, returns isEnabled to propagate state - (BOOL)_performAutoenable { if ([_menu autoenablesItems]) @@ -162,7 +162,7 @@ } else { - // XXX: will toggle state as part of _target check, required to sync stane with NativeHost + // XXX: will toggle state as part of _target check _isEnabled = isEnabled; [_menuItemView setDirty]; diff --git a/Tools/NativeHost/.gitignore b/Tools/NativeHost/.gitignore deleted file mode 100644 index f921bd442..000000000 --- a/Tools/NativeHost/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.DS_Store -*.mode1v3 -*.pbxuser -*.perspectivev3 -build diff --git a/Tools/NativeHost/AppController+MainMenu.m b/Tools/NativeHost/AppController+MainMenu.m deleted file mode 100644 index dbc98e63e..000000000 --- a/Tools/NativeHost/AppController+MainMenu.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// AppController+MainMenu.m -// NativeHost -// -// Created by Francisco Tolmasky on 9/2/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - -#import "MenuBridge.h" -#import "AppController.h" - - -@interface NSApplication (MenuMethods) - -- (void)setAppleMenu:(NSMenu *)aMenu; - -@end - -@implementation AppController (MainMenu) - -- (void)setMainMenuObject:(WebScriptObject *)aMenuObject -{ - NSMenu * mainMenu = [[MenuBridge alloc] initWithMenuObject:aMenuObject]; - - [NSApp setAppleMenu:[[mainMenu itemArray] objectAtIndex:0]]; - [NSApp setMainMenu:mainMenu]; - - [mainMenu release]; -} - -@end diff --git a/Tools/NativeHost/AppController+WebFrameLoadDelegate.m b/Tools/NativeHost/AppController+WebFrameLoadDelegate.m deleted file mode 100644 index fdce4d601..000000000 --- a/Tools/NativeHost/AppController+WebFrameLoadDelegate.m +++ /dev/null @@ -1,26 +0,0 @@ - - -// -// AppController+WebFrameLoadDelegate.m -// NativeHost -// -// Created by Francisco Tolmasky on 7/28/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "AppController.h" - -#import "BridgedMethods.h" - - -@implementation AppController (WebFrameLoadDelegate) - -- (void)webView:(WebView *)aWebView didClearWindowObject:(WebScriptObject *)aWindowObject forFrame:(WebFrame *)aFrame -{ - if (aWebView == webView) - [GlobalMethods enhanceWindowObject:aWindowObject ofWebView:aWebView]; - else - [WindowMethods enhanceWindowObject:aWindowObject ofWebView:aWebView]; -} - -@end diff --git a/Tools/NativeHost/AppController+WebPolicyDelegate.m b/Tools/NativeHost/AppController+WebPolicyDelegate.m deleted file mode 100644 index 2c098dcd0..000000000 --- a/Tools/NativeHost/AppController+WebPolicyDelegate.m +++ /dev/null @@ -1,35 +0,0 @@ -// -// AppController+WebPolicyDelegate.m -// NativeHost -// -// Created by Francisco Tolmasky on 5/11/10. -// Copyright 2010 280 North, Inc. All rights reserved. -// - -#import "NSURL+Additions.h" -#import "AppController.h" - - -@implementation AppController (WebPolicyDelegate) - -- (void)webView:(WebView *)aWebView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)aRequest newFrameName:(NSString *)aFrameName decisionListener:(id /*< WebPolicyDecisionListener >*/)aListener -{ - [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]]; - [aListener ignore]; -} - -- (void)webView:(WebView *)aWebView decidePolicyForNavigationAction:(NSDictionary *)aDictionary request:(NSURLRequest *)aRequest frame:(WebFrame *)aWebFrame decisionListener:(id /**/)aDecisionListener -{ - NSURL * requestURL = [aRequest URL]; - - if([aWebView mainFrame] != aWebFrame || - [[baseURL scheme] isEqualTo:[requestURL scheme]] && - ![baseURL host] || [[baseURL host] isEqualTo:[requestURL host]] && - ![baseURL port] || [[baseURL port] isEqualTo:[requestURL port]]) - return [aDecisionListener use]; - - [[NSWorkspace sharedWorkspace] openURL:[aDictionary objectForKey:WebActionOriginalURLKey]]; - [aDecisionListener ignore]; -} - -@end diff --git a/Tools/NativeHost/AppController+WebResourceLoadDelegate.m b/Tools/NativeHost/AppController+WebResourceLoadDelegate.m deleted file mode 100644 index a60540b75..000000000 --- a/Tools/NativeHost/AppController+WebResourceLoadDelegate.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// AppController+WebResourceLoadDelegate.m -// NativeHost -// -// Created by Francisco Tolmasky on 7/28/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "AppController.h" -#import "SSCrypto.h" - -NSString *authHeader = nil; - -@implementation AppController (WebResourceLoadDelegate) - -- (NSURLRequest *)webView:(WebView *)aSender resource:(id)anIdentifier willSendRequest:(NSURLRequest *)aRequest redirectResponse:(NSURLResponse *)aRedirectResponse fromDataSource:(WebDataSource *)aDataSource -{ - aRequest = [[aRequest mutableCopy] autorelease]; - - if (!authHeader) - { - NSString *plaintext = [NSString stringWithFormat:@"%@:%@", SERVER_USER, SERVER_PASSWORD]; - NSData *data = [plaintext dataUsingEncoding:NSASCIIStringEncoding]; - authHeader = [[NSString alloc] initWithFormat:@"Basic %@", [data encodeBase64WithNewlines:NO]]; - } - - [(NSMutableURLRequest *)aRequest setValue:authHeader forHTTPHeaderField:@"Authorization"]; - - return aRequest; -} - -@end diff --git a/Tools/NativeHost/AppController+WebUIDelegate.m b/Tools/NativeHost/AppController+WebUIDelegate.m deleted file mode 100644 index a75f9d6a9..000000000 --- a/Tools/NativeHost/AppController+WebUIDelegate.m +++ /dev/null @@ -1,71 +0,0 @@ -// -// AppController+WebUIDelegate.m -// NativeHost -// -// Created by Francisco Tolmasky on 7/28/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "AppController.h" -#import "WebWindow.h" - - -@implementation AppController (WebUIDelegate) - -- (void)webView:(WebView *)aWebView setFrame:(NSRect)aFrame -{ - [[aWebView window] setFrame:aFrame display:YES]; -} - -- (NSRect)webViewFrame:(WebView *)aWebView -{ - return [[aWebView window] frame]; -} - -- (WebView *)webView:(WebView *)aWebView createWebViewWithRequest:(NSURLRequest *)aRequest -{ - return [[WebWindow webWindow] webView]; -} - -- (void)webViewClose:(WebView *)aWebView -{ - // Important to call close and not: - // -performClose:, which beeps without the presence of a close button. - // -orderOut:, which doesn't release the window. - [[aWebView window] close]; - //[[aWebView window] orderOut:self]; -} - -- (void)webViewShow:(WebView *)aWebView -{ - [[aWebView window] makeKeyAndOrderFront:self]; -} - -- (NSAttributedString *)loggedOutput; -{ - return loggedOutput; -} - -- (void)webView:(WebView *)aWebView addMessageToConsole:(NSDictionary *)aDictionary -{ - NSString * message = [aDictionary objectForKey:@"message"]; - NSAttributedString * attributedString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", message, nil]]; - - [loggedOutput appendAttributedString:attributedString]; - - [attributedString release]; - NHLog(@"CONSOLE", message); -} - -- (void)webView:(WebView *)aSender runJavaScriptAlertPanelWithMessage:(NSString *)aMessage initiatedByFrame:(WebFrame *)aFrame -{ - WebDataSource * dataSource = [aFrame dataSource]; - NSString * title = [dataSource pageTitle]; - - if (![title length]) - title = [[[dataSource request] URL] absoluteString]; - - [[NSAlert alertWithMessageText:title defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", aMessage, nil] runModal]; -} - -@end diff --git a/Tools/NativeHost/AppController.h b/Tools/NativeHost/AppController.h deleted file mode 100644 index 69e1d2358..000000000 --- a/Tools/NativeHost/AppController.h +++ /dev/null @@ -1,54 +0,0 @@ -// -// AppController.h -// NativeHost -// -// Created by Francisco Tolmasky on 6/4/09. -// Copyright 2009 280 North, Inc. All rights reserved. -// - -#import - -extern int SERVER_PORT; -extern NSString *SERVER_PASSWORD; -extern NSString *SERVER_USER; - -@class Server; -@class WebScriptObject; - -@interface AppController : NSObject -{ - NSWindow * webViewWindow; - WebView * webView; - - NSMutableArray * openingFilenames; - NSMutableArray * openingURLStrings; - - Server * server; - NSFileHandle * stdinFileHandle; - - NSMutableAttributedString * loggedOutput; - - NSURL * baseURL; -} - -- (void)configureLocalStorage; -- (NSURL *)baseURL; - -- (void)startServer; -- (void)startCappuccinoApplication; - -- (NSArray *)openingURLStrings; - -- (NSView *)keyView; -- (WebView *)webView; -- (WebScriptObject *)windowScriptObject; - -@end - -@interface AppController (MainMenu) - -- (void)setMainMenuObject:(WebScriptObject *)aMenuObject; - -@end - -void NHLog(NSString *type, NSString *message); \ No newline at end of file diff --git a/Tools/NativeHost/AppController.m b/Tools/NativeHost/AppController.m deleted file mode 100644 index fa64a749d..000000000 --- a/Tools/NativeHost/AppController.m +++ /dev/null @@ -1,221 +0,0 @@ -// -// AppController.m -// NativeHost -// -// Created by Francisco Tolmasky on 6/4/09. -// Copyright 2009 280 North, Inc. All rights reserved. -// - -#import "Console.h" -#import "Server.h" -#import "AppController.h" -#import "NSURL+Additions.h" -#import "BridgedMethods.h" -#import "WebWindow.h" -#import "WebScripObject+Objective-J.h" - -extern int interactive; - -int SERVER_PORT = 9191; -NSString *SERVER_PASSWORD = nil; -NSString *SERVER_USER = nil; - - -@implementation AppController - -- (id)init -{ - self = [super init]; - - if (self) - openingURLStrings = [NSMutableArray new]; - - return self; -} - -- (void)dealloc -{ - [webView release]; - [webViewWindow release]; - - [openingURLStrings release]; - - [super dealloc]; -} - -- (BOOL)application:(NSApplication *)anApplication openFile:(NSString *)aFilename -{ - id canOpenFilesImmediately = [[webView windowScriptObject] evaluateWebScript:@"CPApp && CPApp._finishedLaunching"]; - - NSString *path = [[[NSURL fileURLWithPath:aFilename] HTTPFileSystemURL] absoluteString]; - if ([canOpenFilesImmediately isKindOfClass:[NSNumber class]] && [canOpenFilesImmediately boolValue]) - [[webView windowScriptObject] evaluateObjectiveJ:[NSString stringWithFormat:@"[CPApp _openURL:[CPURL URLWithString:\"%@\"]]", path]]; - else - [openingURLStrings addObject:path]; - - return NO; -} - -- (void)applicationWillFinishLaunching:(NSNotification *)aNotification -{ - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - - [defaults registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"WebKitDeveloperExtras"]]; - - [self startServer]; -} - -- (void)applicationDidFinishLaunching:(NSNotification *)notification -{ - [self startCappuccinoApplication]; -} - -- (void)applicationDidResignActive:(NSNotification *)aNotification -{ - // FIXME: handle this better. - [[self windowScriptObject] evaluateObjectiveJ:@"[CPApp _willResignActive];"]; - [[self windowScriptObject] evaluateObjectiveJ:@"CPApp._isActive = NO;"]; - [[self windowScriptObject] evaluateObjectiveJ:@"[CPApp _didResignActive];"]; -} - -- (void)applicationDidBecomeActive:(NSNotification *)aNotification -{ - // FIXME: handle this better. - [[self windowScriptObject] evaluateObjectiveJ:@"[CPApp _willBecomeActive];"]; - [[self windowScriptObject] evaluateObjectiveJ:@"CPApp._isActive = YES;"]; - [[self windowScriptObject] evaluateObjectiveJ:@"[CPApp _didBecomeActive];"]; -} - -- (NSArray *)openingURLStrings -{ - return openingURLStrings; -} - -- (NSView *)keyView -{ - return [[[webView mainFrame] frameView] documentView]; -} - -- (WebView *)webView -{ - return webView; -} - -- (WebScriptObject *)windowScriptObject -{ - return [webView windowScriptObject]; -} - -- (void)startServer -{ - server = [[Server alloc] init]; - - if (![server start]) - exit(0); - - if (interactive) - { - stdinFileHandle = [[NSFileHandle fileHandleWithStandardInput] retain]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(didReadStdin:) - name:NSFileHandleReadCompletionNotification - object:stdinFileHandle]; - - fprintf(stdout, "objj> "); - fflush(stdout); - [stdinFileHandle readInBackgroundAndNotify]; - } -} - -- (void)didReadStdin:(NSNotification *)aNotification -{ - NSString *string = [[NSString alloc] initWithData:[[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem] encoding:NSASCIIStringEncoding]; - NSString *result = [[self windowScriptObject] evaluateObjectiveJReturningString:string]; - [string release]; - if ([result respondsToSelector:@selector(UTF8String)]) - fprintf(stdout, "%s\n", [result UTF8String]); - fprintf(stdout, "objj> "); - fflush(stdout); - [stdinFileHandle readInBackgroundAndNotify]; -} - -- (NSURL *)baseURL -{ - return baseURL; -} - -- (void)startCappuccinoApplication -{ - NSString *initialURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NHInitialURL"]; - BOOL prependServer = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"NHInitialURLPrependServer"] boolValue]; - - if (!initialURL) - { - NSString *initialResource = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NHInitialResource"]; - - if (!initialResource) - initialResource = @"Application/index.html"; - - initialURL = [[NSString stringWithFormat:@"file://%@/%@", [[NSBundle mainBundle] resourcePath], initialResource] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - baseURL = [[NSURL alloc] initWithString:@"file:///"]; - } - else if (prependServer) - { - initialURL = [NSString stringWithFormat:@"http://127.0.0.1:%d/%@", SERVER_PORT, initialURL]; - baseURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", SERVER_PORT]]; - } - - NHLog(@"STARTUP", [initialURL description]); - - [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:initialURL]]]; -} - -- (void)applicationWillTerminate:(NSNotification *)aNotification -{ - [server stop]; -} - -- (void)configureLocalStorage -{ - WebPreferences *webConfiguration = [WebPreferences standardPreferences]; - NSBundle *mainBundle = [NSBundle mainBundle]; - NSString *cappBundleName = [mainBundle objectForInfoDictionaryKey:@"CPBundleName"]; - NSString *applicationSupportFile = [@"~/Library/Application Support/" stringByExpandingTildeInPath]; - NSString *savePath = [NSString pathWithComponents:[NSArray arrayWithObjects:applicationSupportFile, cappBundleName, @"LocalStorage", nil]]; - - if ([webConfiguration respondsToSelector:@selector(setLocalStorageDatabasePath:)]) - [webConfiguration setLocalStorageDatabasePath:savePath]; - else - [webConfiguration _setLocalStorageDatabasePath:savePath]; - - [webView setPreferences:webConfiguration]; -} - -- (void)awakeFromNib -{ - webView = [[WebView alloc] init]; - - [webView setUIDelegate:self]; - [webView setFrameLoadDelegate:self]; - [webView setResourceLoadDelegate:self]; - [webView setPolicyDelegate:self]; - - [self configureLocalStorage]; - - webViewWindow = [[NSWindow alloc] init]; - - [webViewWindow setContentView:webView]; -} - -@end - -void NHLog(NSString *type, NSString *message) -{ - NSArray *lines = [message componentsSeparatedByString:@"\n"]; - for (NSString *line in lines) - { - if ([line length] > 0) - NSLog(@"%10@: %@", type, line); - } -} diff --git a/Tools/NativeHost/Application.h b/Tools/NativeHost/Application.h deleted file mode 100644 index d09086a9f..000000000 --- a/Tools/NativeHost/Application.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Application.h -// NativeHost -// -// Created by Francisco Tolmasky on 10/8/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@interface Application : NSApplication -{ -} - -- (void)_reallyTerminate:(id)sender; - -@end diff --git a/Tools/NativeHost/Application.m b/Tools/NativeHost/Application.m deleted file mode 100644 index 2234f307d..000000000 --- a/Tools/NativeHost/Application.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// Application.m -// NativeHost -// -// Created by Francisco Tolmasky on 10/8/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "Application.h" -#import "AppController.h" -#import "WebScripObject+Objective-J.h" -#import "WebWindow.h" - -@implementation Application - -- (void)sendEvent:(NSEvent *)anEvent -{ - [WebWindow enableAllWindows]; - - NSWindow * window = [anEvent window]; - - if (!window || [window isKindOfClass:[WebWindow class]]) - { - NSResponder * firstResponder = window ? [window firstResponder] : [(AppController *)[self delegate] keyView]; - - switch ([anEvent type]) - { - case NSKeyDown: return [firstResponder keyDown:anEvent]; - case NSKeyUp: return [firstResponder keyUp:anEvent]; - } - } - - [super sendEvent:anEvent]; -} - -- (void)terminate:(id)sender -{ - if ([[[self delegate] windowScriptObject] evaluateObjectiveJ:@"(CPApp)"] == [WebUndefined undefined]) - [self _reallyTerminate:sender]; - else - [[(AppController *)[self delegate] windowScriptObject] evaluateObjectiveJ:@"[CPApp terminate:nil]"]; -} - -- (void)_reallyTerminate:(id)sender -{ - [super terminate:sender]; -} - -@end diff --git a/Tools/NativeHost/BridgedMethods.h b/Tools/NativeHost/BridgedMethods.h deleted file mode 100644 index a9af18f1f..000000000 --- a/Tools/NativeHost/BridgedMethods.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// BridgedMethods.h -// NativeHost -// -// Created by Francisco Tolmasky on 10/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@interface BridgedMethods : NSObject -{ - WebView * webView; -} -+ (NSMutableArray *)arrayFromWebScriptObject:(WebScriptObject *)incomingObject; -+ (void)enhanceWindowObject:(WebScriptObject *)aWindowObject ofWebView:(WebView *)aWebView; -@end - -@interface GlobalMethods : BridgedMethods -{ -} -- (id)isDesktop; - -- (id)openingURLStrings; - -- (id)setMainMenu:(id)arguments; - -- (id)terminate; -- (id)activateIgnoringOtherApps:(NSArray *)arguments; -- (id)deactivate; -- (id)hide; -- (id)hideOtherApplications; - -- (id)savePanel:(NSArray *)arguments; // FIXME: This should be implemented in Cappuccino. -- (id)openPanel; // FIXME: This should be implemented in Cappuccino. - -- (id)clearRecentDocuments; -- (id)noteNewRecentDocumentPath:(NSArray *)aURL; -- (id)recentDocumentURLs; - -- (id)pasteboardWithName:(NSArray *)arguments; - -@end - -@interface WindowMethods : BridgedMethods -{ -} -- (id)miniaturize; -- (id)deminiaturize; - -- (id)level; -- (id)setLevel:(NSArray *)arguments; - -- (id)hasShadow; -- (id)setHasShadow:(NSArray *)arguments; - -- (id)shadowStyle; -- (id)setShadowStyle:(NSArray *)arguments; - -- (id)frame; -- (id)setFrame:(NSArray *)arguments; - -@end - diff --git a/Tools/NativeHost/BridgedMethods.m b/Tools/NativeHost/BridgedMethods.m deleted file mode 100644 index 7e637692a..000000000 --- a/Tools/NativeHost/BridgedMethods.m +++ /dev/null @@ -1,345 +0,0 @@ -// -// BridgedMethods.m -// NativeHost -// -// Created by Francisco Tolmasky on 10/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - - -#import -#import "Application.h" -#import "AppController.h" -#import "BridgedMethods.h" -#import "NSObject+WebAdditions.h" -#import "NSURL+Additions.h" -#import "WebWindow.h" -#import "WebPasteboardProxy.h" - -static NSMutableDictionary * MethodClasses; - -@implementation GlobalMethods - -- (id)isDesktop -{ - return [NSNumber numberWithBool:YES]; -} - -- (id)openingURLStrings -{ - return [(AppController *)[NSApp delegate] openingURLStrings]; -} - -- (id)setMainMenu:(id)arguments -{ - [[NSApp delegate] setMainMenuObject:[arguments objectAtIndex:0]]; - - return [WebUndefined undefined]; -} - -- (id)terminate -{ - [(Application *)NSApp _reallyTerminate:self]; - - return [WebUndefined undefined]; -} - -- (id)activateIgnoringOtherApps:(NSArray *)arguments -{ - id argument = [arguments objectAtIndex:0]; - - [(NSApplication *)NSApp activateIgnoringOtherApps:[argument isKindOfClass:[NSNumber class]] && [(NSNumber *)argument boolValue]]; - - return [WebUndefined undefined]; -} - -- (id)deactivate -{ - [(NSApplication *)NSApp deactivate]; - return [WebUndefined undefined]; -} - -- (id)hide -{ - [NSApp hide:self]; - return [WebUndefined undefined]; -} - -- (id)hideOtherApplications -{ - [NSApp hideOtherApplications:self]; - return [WebUndefined undefined]; -} - -- (id)openPanel -{ - NSOpenPanel * openPanel = [NSOpenPanel openPanel]; - - NSInteger result = [openPanel runModal]; - - NSMutableString * resultObject = [NSMutableString stringWithFormat:@"({ button:%d, URLs:", result]; - - NSMutableArray * fileSystemURLs = [NSMutableArray array]; - - for (NSURL * URL in [openPanel URLs]) - [fileSystemURLs addObject:[URL HTTPFileSystemURL]]; - - if (result == NSFileHandlingPanelOKButton) - [resultObject appendString:[NSString stringWithFormat:@"[\"%@\"] })", [fileSystemURLs componentsJoinedByString:@"\", \""]]]; - - else - [resultObject appendString:@"[] })"]; - - return [[webView windowScriptObject] evaluateWebScript:resultObject]; -} - -- (id)savePanel:(NSArray *)arguments -{ - NSSavePanel * savePanel = [NSSavePanel savePanel]; - WebScriptObject *args = [arguments objectAtIndex:0]; - - [savePanel setAllowedFileTypes:[BridgedMethods arrayFromWebScriptObject:[args valueForKey:@"allowedFileTypes"]]]; - - id allowsOtherFileTypes = [args valueForKey:@"allowsOtherFileTypes"]; - - [savePanel setAllowsOtherFileTypes:allowsOtherFileTypes && [allowsOtherFileTypes webBoolValue]]; - - id isExtensionHidden = [args valueForKey:@"isExtensionHidden"]; - - [savePanel setExtensionHidden:isExtensionHidden && [isExtensionHidden webBoolValue]]; - - id canSelectHiddenExtension = [args valueForKey:@"canSelectHiddenExtension"]; - - [savePanel setCanSelectHiddenExtension:canSelectHiddenExtension && canSelectHiddenExtension]; - - id canCreateDirectories = [args valueForKey:@"canCreateDirectories"]; - - [savePanel setCanCreateDirectories:canCreateDirectories && [canCreateDirectories webBoolValue]]; - - NSInteger result = [savePanel runModal]; - - return [[webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"({ button:%d, URL:\"%@\" })", result, [[[savePanel URL] HTTPFileSystemURL] absoluteString]]]; -} - -- (id)clearRecentDocuments -{ - [[NSDocumentController sharedDocumentController] clearRecentDocuments:self]; - return [WebUndefined undefined]; -} - -- (id)noteNewRecentDocumentPath:(NSArray *)arguments -{ - if (![arguments count]) - return [WebUndefined undefined]; - - NSString *aURL = [arguments objectAtIndex:0]; - NSURL *fileURL = [NSURL fileSystemURLFromHTTPFileSystemString:aURL]; - - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:fileURL]; - - return [WebUndefined undefined]; -} - -- (id)recentDocumentURLs -{ - NSArray *existingURLs = [[NSDocumentController sharedDocumentController] recentDocumentURLs]; - NSMutableArray *urlsAsStrings = [NSMutableArray array]; - - for (int i=0, count = [existingURLs count]; i < count; i++) - [urlsAsStrings addObject:[[existingURLs objectAtIndex:i] absoluteString]]; - - return urlsAsStrings; -} - -- (id)pasteboardWithName:(NSArray *)arguments -{ - if (![arguments count]) - return [WebUndefined undefined]; - - return [WebPasteboardProxy pasteboardWithName:[arguments objectAtIndex:0]]; -} - -@end - -@implementation WindowMethods - -- (id)miniaturize -{ - [[webView window] miniaturize:nil]; - return [WebUndefined undefined]; -} - -- (id)deminiaturize -{ - [[webView window] deminiaturize:nil]; - return [WebUndefined undefined]; -} - -- (id)level -{ - return [NSNumber numberWithInt:[[webView window] level]]; -} - -- (id)setLevel:(NSArray *)arguments -{ - [[webView window] setLevel:[[arguments objectAtIndex:0] intValue]]; - - return [WebUndefined undefined]; -} - -- (id)hasShadow -{ - return [NSNumber numberWithBool:[[webView window] hasShadow]]; -} - -- (id)setHasShadow:(NSArray *)arguments -{ - [[webView window] setHasShadow:[[arguments objectAtIndex:0] boolValue]]; - - return [WebUndefined undefined]; -} - -- (id)frame -{ - NSRect frame = [[webView window] frame]; - - return [[webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"({ origin:{%f, %f}, size:{%f, %f}})", NSMinX(frame), NSMinY(frame), NSWidth(frame), NSHeight(frame)]]; -} - -- (id)setFrame:(NSArray *)arguments -{ - id origin = [[arguments objectAtIndex:0] valueForKey:@"origin"], - size = [[arguments objectAtIndex:0] valueForKey:@"size"]; - - NSWindow * window = [webView window]; - NSScreen * screen = [window screen]; - - if (!screen) - screen = [NSScreen mainScreen]; // Is this correct? - - float height = [[size valueForKey:@"height"] floatValue]; - - [[webView window] setFrame:NSMakeRect([[origin valueForKey:@"x"] floatValue], NSMaxY([screen frame]) - [[origin valueForKey:@"y"] floatValue] - height, [[size valueForKey:@"width"] floatValue], height) display:YES]; - /* - NSLog([webView description]); - NSLog(@"%@ %@", [window screen], NSStringFromRect([window frame])); - NSLog(@"%f - %f - %f = %f", NSMaxY([[window screen] frame]), [[origin valueForKey:@"y"] floatValue], height, NSMaxY([[window screen] frame]) - [[origin valueForKey:@"y"] floatValue] - height); - NSLog(@"FROM: %@", NSStringFromRect(NSMakeRect([[origin valueForKey:@"x"] floatValue], [[origin valueForKey:@"y"] floatValue], [[size valueForKey:@"width"] floatValue], height))); - NSLog(@" TO: %@", NSStringFromRect([[webView window] frame])); - */ - - return [WebUndefined undefined]; -} - -- (id)shadowStyle -{ - WebWindow * window = (WebWindow *)[webView window]; - - return [NSNumber numberWithInt:[window shadowStyle]]; -} - -- (id)setShadowStyle:(id)arguments -{ - int type = [[arguments objectAtIndex:0] intValue]; - - WebWindow * window = (WebWindow *)[webView window]; - - [window setShadowStyle:type]; - - return [WebUndefined undefined]; -} - -@end - - -@interface WindowScriptObjectMethod : NSObject -{ - WebView * webView; -} - -- (id)initWithWebView:(WebView *)aWebView; - -@end - -@implementation WindowScriptObjectMethod - -- (id)initWithWebView:(WebView *)aWebView -{ - self = [super init]; - - if (self) - webView = aWebView; - - return self; -} - -@end - -@implementation BridgedMethods - -+ (NSMutableArray *)arrayFromWebScriptObject:(WebScriptObject *)incomingObject -{ - if (!incomingObject) - return nil; - - NSMutableArray * newItems = [[NSMutableArray alloc] init]; - - for (int i=0; [incomingObject webScriptValueAtIndex:i]!=[WebUndefined undefined]; i++) - { - id oneItem =[incomingObject webScriptValueAtIndex:i]; - [newItems addObject:oneItem]; - } - - return [newItems autorelease]; -} - -+ (void)enhanceWindowObject:(WebScriptObject *)aWindowObject ofWebView:(WebView *)aWebView -{ - NSDictionary * classMethods = [MethodClasses objectForKey:[self className]]; - NSString * key = nil; - NSEnumerator * keyEnumerator = [classMethods keyEnumerator]; - - while (key = [keyEnumerator nextObject]) - [aWindowObject setValue:[(WindowScriptObjectMethod *)[[[classMethods objectForKey:key] alloc] initWithWebView:aWebView] autorelease] forKey:key]; -} - -+ (void)bridgeMethod:(Method)aMethod dictionary:(NSMutableDictionary *)aDictionary -{ - NSString * methodName = NSStringFromSelector(method_getName(aMethod)), - * publicMethodName = [NSString stringWithFormat:@"cp%@", [[NSString stringWithFormat:@"%@%@", [[methodName substringToIndex:1] uppercaseString], [methodName substringFromIndex:1]] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@":"]]]; - - Class methodClass = objc_allocateClassPair([WindowScriptObjectMethod class], [[NSString stringWithFormat:@"WebScriptObjectMethod_%@", publicMethodName] cString], 0); - - class_addMethod(methodClass, @selector(invokeDefaultMethodWithArguments:), method_getImplementation(aMethod), "@@:@"); - - objc_registerClassPair(methodClass); - - [aDictionary setObject:methodClass forKey:publicMethodName]; -} - -+ (void)initialize -{ - if (!MethodClasses) - MethodClasses = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * dictionary = [[NSMutableDictionary alloc] init]; - - [MethodClasses setObject:dictionary forKey:[self className]]; - [dictionary release]; - - unsigned int methodCount = 0; - Method * methods = class_copyMethodList(self, &methodCount); - - if (!methods) - return; - - int index = 0; - - for (; index < methodCount; ++index) - [self bridgeMethod:methods[index] dictionary:dictionary]; - - free(methods); - methods = NULL; -} - -@end diff --git a/Tools/NativeHost/Console.h b/Tools/NativeHost/Console.h deleted file mode 100644 index a4d9b6c42..000000000 --- a/Tools/NativeHost/Console.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Console.h -// NativeHost -// -// Created by Francisco Tolmasky on 6/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@interface Console : NSObject -{ - NSMutableAttributedString * contents; -} - -+ (id)sharedConsole; - -- (NSAttributedString *)contents; - -@end diff --git a/Tools/NativeHost/Console.m b/Tools/NativeHost/Console.m deleted file mode 100644 index 2118f999b..000000000 --- a/Tools/NativeHost/Console.m +++ /dev/null @@ -1,69 +0,0 @@ -// -// Console.m -// NativeHost -// -// Created by Francisco Tolmasky on 6/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "Console.h" - -#import "AppController.h" - - -@implementation Console - -+ (id)sharedConsole -{ - static Console * console = nil; - - if (!console) - console = [[Console alloc] init]; - - return console; -} - -- (id)init -{ - self = [super init]; - - if (self) - contents = [[NSMutableAttributedString alloc] init]; - - return self; -} - -- (void)dealloc -{ - [contents release]; - [super dealloc]; -} - -- (NSAttributedString *)contents -{ - return contents; -} - -- (void)webView:(WebView *)aWebView addMessageToConsole:(NSDictionary *)aDictionary -{ - NSString * message = [aDictionary objectForKey:@"message"]; - - NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", message, nil]]; - [contents appendAttributedString:attrString]; - [attrString release]; - - NHLog(@"CONSOLE", message); -} - -- (void)webView:(WebView *)aSender runJavaScriptAlertPanelWithMessage:(NSString *)aMessage initiatedByFrame:(WebFrame *)aFrame -{ - WebDataSource * dataSource = [aFrame dataSource]; - NSString * title = [dataSource pageTitle]; - - if (![title length]) - title = [[[dataSource request] URL] absoluteString]; - - [[NSAlert alertWithMessageText:title defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:aMessage, nil] runModal]; -} - -@end diff --git a/Tools/NativeHost/English.lproj/InfoPlist.strings b/Tools/NativeHost/English.lproj/InfoPlist.strings deleted file mode 100644 index 5e45963c3..000000000 Binary files a/Tools/NativeHost/English.lproj/InfoPlist.strings and /dev/null differ diff --git a/Tools/NativeHost/English.lproj/MainMenu.cib b/Tools/NativeHost/English.lproj/MainMenu.cib deleted file mode 100644 index 36815f025..000000000 --- a/Tools/NativeHost/English.lproj/MainMenu.cib +++ /dev/null @@ -1 +0,0 @@ -280NPLIST;1.0;D;K;4;$topD;K;18;CPCibObjectDataKeyD;K;6;CP$UIDd;1;2E;E;K;8;$objectsA;S;5;$nullD;K;10;$classnameS;16;_CPCibObjectDataK;8;$classesA;S;16;_CPCibObjectDataS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;1E;K;28;_CPCibObjectDataNamesKeysKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataNamesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataClassesKeysKeyD;K;6;CP$UIDd;1;0E;K;32;_CPCibObjectDataClassesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataConnectionsKeyD;K;6;CP$UIDd;1;4E;K;28;_CPCibObjectDataFrameworkKeyD;K;6;CP$UIDd;1;0E;K;26;_CPCibObjectDataNextOidKeyD;K;6;CP$UIDd;1;5E;K;30;_CPCibObjectDataObjectsKeysKeyD;K;6;CP$UIDd;1;6E;K;32;_CPCibObjectDataObjectsValuesKeyD;K;6;CP$UIDd;1;7E;K;26;_CPCibObjectDataOidKeysKeyD;K;6;CP$UIDd;1;8E;K;28;_CPCibObjectDataOidValuesKeyD;K;6;CP$UIDd;1;9E;K;28;_CPCibObjectDataFileOwnerKeyD;K;6;CP$UIDd;2;11E;K;33;_CPCibObjectDataVisibleWindowsKeyD;K;6;CP$UIDd;2;13E;E;D;K;10;$classnameS;7;CPArrayK;8;$classesA;S;7;CPArrayS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;15E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;16E;D;K;6;CP$UIDd;2;17E;D;K;6;CP$UIDd;2;18E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;11E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;10;$classnameS;18;_CPCibCustomObjectK;8;$classesA;S;18;_CPCibCustomObjectS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;19E;E;D;K;10;$classnameS;5;CPSetK;8;$classesA;S;5;CPSetS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;12E;K;15;CPSetObjectsKeyD;K;6;CP$UIDd;2;20E;E;D;K;10;$classnameS;20;CPCibOutletConnectorK;8;$classesA;S;20;CPCibOutletConnectorS;14;CPCibConnectorS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;14E;K;24;_CPCibConnectorSourceKeyD;K;6;CP$UIDd;2;16E;K;29;_CPCibConnectorDestinationKeyD;K;6;CP$UIDd;2;18E;K;23;_CPCibConnectorLabelKeyD;K;6;CP$UIDd;2;21E;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;19E;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;22E;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;23E;E;S;13;CPApplicationD;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;S;8;delegateS;13;NSFontManagerS;13;AppControllerE;K;9;$archiverS;15;CPKeyedArchiverK;8;$versionS;6;100000E; \ No newline at end of file diff --git a/Tools/NativeHost/English.lproj/MainMenu.xib b/Tools/NativeHost/English.lproj/MainMenu.xib deleted file mode 100644 index 2bce8a810..000000000 --- a/Tools/NativeHost/English.lproj/MainMenu.xib +++ /dev/null @@ -1,548 +0,0 @@ - - - - 1050 - 10C540 - 732 - 1038.25 - 458.00 - - com.apple.InterfaceBuilder.CocoaPlugin - 732 - - - YES - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - - - YES - - YES - - - YES - - - - YES - - NSApplication - - - FirstResponder - - - NSApplication - - - NSFontManager - - - AppController - - - - - YES - - - delegate - - - - 519 - - - - - YES - - 0 - - - - - - -2 - - - File's Owner - - - -1 - - - First Responder - - - -3 - - - Application - - - 420 - - - - - 487 - - - - - - - -3.IBPluginDependency - com.apple.InterfaceBuilder.CocoaPlugin - - - YES - - - YES - - - - - YES - - - YES - - - - 677 - - - - YES - - AppController - NSObject - - IBProjectSource - AppController.h - - - - NSObject - - IBProjectSource - NSObject+WebAdditions.h - - - - - YES - - NSApplication - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSApplication.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSApplicationScripting.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSColorPanel.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSHelpManager.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSPageLayout.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSUserInterfaceItemSearching.h - - - - NSFontManager - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSFontManager.h - - - - NSMenu - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSMenu.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSAccessibility.h - - - - NSObject - - - - NSObject - - - - NSObject - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSControl.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSDictionaryController.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSDragging.h - - - - NSObject - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSFontPanel.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSKeyValueBinding.h - - - - NSObject - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSNibLoading.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSOutlineView.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSPasteboard.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSSavePanel.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSTableView.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSToolbarItem.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSView.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSClassDescription.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSError.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFileManager.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueObserving.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyedArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObject.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObjectScripting.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSPortCoder.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSRunLoop.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptClassDescription.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptObjectSpecifiers.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptWhoseTests.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSThread.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURL.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURLConnection.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURLDownload.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebDownload.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebEditingDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebFrameLoadDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebJavaPlugIn.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPlugin.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPluginContainer.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPolicyDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebResourceLoadDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebScriptObject.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebUIDelegate.h - - - - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSInterfaceStyle.h - - - - NSResponder - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSResponder.h - - - - - 0 - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 - - - YES - ../NativeHost.xcodeproj - 3 - - diff --git a/Tools/NativeHost/Info.plist b/Tools/NativeHost/Info.plist deleted file mode 100644 index 2f8dbca99..000000000 --- a/Tools/NativeHost/Info.plist +++ /dev/null @@ -1,30 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - icon - CFBundleShortVersionString - 0.9 - CFBundleIdentifier - com.280north.${PRODUCT_NAME:identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - NativeHost - CFBundlePackageType - APPL - CFBundleSignature - ???? - CFBundleVersion - 1.0 - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - - diff --git a/Tools/NativeHost/Jakefile b/Tools/NativeHost/Jakefile deleted file mode 100644 index 8df9bce4b..000000000 --- a/Tools/NativeHost/Jakefile +++ /dev/null @@ -1,45 +0,0 @@ - -require("../../common.jake"); - -var OS = require("os"); -var task = require("jake").task -var stream = require("narwhal/term").stream; - -task ("build", function() -{ - if (executableExists("xcodebuild")) - { - var args = "-alltargets -configuration Release"; - - if (xcodebuildHasTenPointFiveSDK()) - args = "-sdk macosx10.5 " + args; - - else - args = "-sdk macosx " + args; - - if (OS.system("xcodebuild " + args)) - OS.exit(1); - - rm_rf(FILE.join($BUILD_CJS_CAPPUCCINO, "support", "NativeHost.app")); - FILE.mkdirs(FILE.join($BUILD_CJS_CAPPUCCINO, "support")) - cp_r(FILE.join("build", "Release", "NativeHost.app"), FILE.join($BUILD_CJS_CAPPUCCINO, "support", "NativeHost.app")); - } - else - { - print("Building NativeHost requires Xcode."); - } -}); - -task ("clean", function() -{ - if (OS.system("xcodebuild clean")) - OS.exit(1); -}); - -task ("clobber", function() -{ - if (OS.system("xcodebuild clean")) - OS.exit(1); -}); - -task ("default", ["build"]); diff --git a/Tools/NativeHost/MenuBridge.h b/Tools/NativeHost/MenuBridge.h deleted file mode 100644 index 847237409..000000000 --- a/Tools/NativeHost/MenuBridge.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// MenuBridge.h -// NativeHost -// -// Created by Francisco Tolmasky on 9/2/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@class WebScriptObject; - -@interface MenuBridge : NSMenu -{ - WebScriptObject * menuObject; -} - -+ (id)menuBridgeWithMenuObject:(WebScriptObject *)aMenuObject; -- (id)initWithMenuObject:(WebScriptObject *)aMenuObject; - -@end diff --git a/Tools/NativeHost/MenuBridge.m b/Tools/NativeHost/MenuBridge.m deleted file mode 100644 index ad14a7191..000000000 --- a/Tools/NativeHost/MenuBridge.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// MenuBridge.m -// NativeHost -// -// Created by Francisco Tolmasky on 9/2/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "WebScripObject+Objective-J.h" -#import "MenuItemBridge.h" -#import "MenuBridge.h" - - -@implementation MenuBridge - -+ (id)menuBridgeWithMenuObject:(WebScriptObject *)aMenuObject -{ - if (!aMenuObject) - return nil; - - static NSMapTable * cache = nil; - - if (!cache) - cache = [[NSMapTable mapTableWithStrongToStrongObjects] retain]; - - MenuBridge * menuBridge = [cache objectForKey:aMenuObject]; - - if (!menuBridge) - { - menuBridge = [MenuBridge alloc]; - - [cache setObject:menuBridge forKey:aMenuObject]; - - [[menuBridge initWithMenuObject:aMenuObject] autorelease]; - } - - return menuBridge; -} - -- (id)initWithMenuObject:(WebScriptObject *)aMenuObject -{ - self = [super initWithTitle:[aMenuObject bridgeSelector:@selector(title)]]; - - if (self) - { - menuObject = aMenuObject; - - NSInteger index = 0, - count = [[aMenuObject bridgeSelector:@selector(numberOfItems)] intValue]; - - for (; index < count; ++index) - [self addItem:[[[MenuItemBridge alloc] initWithMenuItemObject:[aMenuObject bridgeSelector:@selector(itemAtIndex:) withObject:[NSNumber numberWithInt:index]]] autorelease]]; - } - - return self; -} - -- (void)performActionForItemAtIndex:(NSInteger)anIndex -{ - [menuObject bridgeSelector:@selector(performActionForItemAtIndex:) withObject:[NSNumber numberWithInt:anIndex]]; -} - -@end diff --git a/Tools/NativeHost/MenuItemBridge.h b/Tools/NativeHost/MenuItemBridge.h deleted file mode 100644 index 86e70d6f2..000000000 --- a/Tools/NativeHost/MenuItemBridge.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// ReflectMenuItem.h -// NativeHost -// -// Created by Francisco Tolmasky on 9/2/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@class WebScriptObject; - -@interface MenuItemBridge : NSMenuItem -{ - WebScriptObject * menuItemObject; -} - -+ (id)menuItemBridgeWithMenuItemObject:(WebScriptObject *)aMenuItemObject; -- (id)initWithMenuItemObject:(WebScriptObject *)aMenuItemObject; - -- (void)updateFromMenuItemObject; - -@end diff --git a/Tools/NativeHost/MenuItemBridge.m b/Tools/NativeHost/MenuItemBridge.m deleted file mode 100644 index b661f35e8..000000000 --- a/Tools/NativeHost/MenuItemBridge.m +++ /dev/null @@ -1,77 +0,0 @@ -// -// ReflectMenuItem.m -// NativeHost -// -// Created by Francisco Tolmasky on 9/2/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "WebScripObject+Objective-J.h" -#import "MenuBridge.h" -#import "MenuItemBridge.h" - - -@implementation MenuItemBridge - -+ (id)menuItemBridgeWithMenuItemObject:(WebScriptObject *)aMenuItemObject -{ - if (!aMenuItemObject) - return nil; - - static NSMapTable * cache = nil; - - if (!cache) - cache = [[NSMapTable mapTableWithStrongToStrongObjects] retain]; - - MenuItemBridge * menuItemBridge = [cache objectForKey:aMenuItemObject]; - - if (!menuItemBridge) - { - menuItemBridge = [MenuBridge alloc]; - - [cache setObject:menuItemBridge forKey:aMenuItemObject]; - - [[menuItemBridge initWithMenuItemObject:aMenuItemObject] autorelease]; - } - - return menuItemBridge; -} - -- (id)initWithMenuItemObject:(WebScriptObject *)aMenuItemObject -{ - if ([[aMenuItemObject bridgeSelector:@selector(isSeparatorItem)] boolValue]) - return [[NSMenuItem separatorItem] retain]; - - self = [super init]; - - if (self) - { - menuItemObject = aMenuItemObject; - - [self updateFromMenuItemObject]; - } - - return self; -} -/* -- (BOOL)isSeparatorItem -{ - return [[menuItemObject bridgeSelector:@selector(isSeparatorItem)] boolValue]; -} -*/ -- (void)updateFromMenuItemObject -{ - [self setTitle:[menuItemObject bridgeSelector:@selector(title)]]; - [self setSubmenu:[MenuBridge menuBridgeWithMenuObject:[menuItemObject bridgeSelector:@selector(submenu)]]]; - [self setKeyEquivalent:[menuItemObject bridgeSelector:@selector(keyEquivalent)]]; - [self setKeyEquivalentModifierMask:[[menuItemObject evaluateObjectiveJ:[NSString stringWithFormat:@"(function() { var mask = %u; return (((mask & CPAlphaShiftKeyMask) ? %u : 0) | ((mask & CPShiftKeyMask) ? %u : 0) | ((mask & CPControlKeyMask) ? %u : 0) | ((mask & CPAlternateKeyMask) ? %u : 0) | ((mask & CPCommandKeyMask) ? %u : 0) | ((mask & CPNumericPadKeyMask) ? %u : 0) | ((mask & CPHelpKeyMask) ? %u : 0) | ((mask & CPFunctionKeyMask) ? %u : 0)) }())", [[menuItemObject bridgeSelector:@selector(keyEquivalentModifierMask)] unsignedIntegerValue], NSAlphaShiftKeyMask, NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, NSCommandKeyMask, NSNumericPadKeyMask, NSHelpKeyMask, NSFunctionKeyMask, NSDeviceIndependentModifierFlagsMask]] unsignedIntegerValue]];[self setAction:@selector(bridgeAction:)]; - [self setTarget:self]; - [self setAction:@selector(bridgeAction:)]; -} - -// This exists so that the menu items are enabled. -- (void)bridgeAction:(id)aSender -{ -} - -@end diff --git a/Tools/NativeHost/NSObject+WebAdditions.h b/Tools/NativeHost/NSObject+WebAdditions.h deleted file mode 100644 index b4ab41035..000000000 --- a/Tools/NativeHost/NSObject+WebAdditions.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// NSObject+WebAdditions.h -// NativeHost -// -// Created by Francisco Tolmasky on 11/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -@interface NSObject (WebAdditions) - -- (BOOL)webBoolValue; - -@end diff --git a/Tools/NativeHost/NSObject+WebAdditions.m b/Tools/NativeHost/NSObject+WebAdditions.m deleted file mode 100644 index 1ffd942a1..000000000 --- a/Tools/NativeHost/NSObject+WebAdditions.m +++ /dev/null @@ -1,19 +0,0 @@ -// -// NSObject+WebAdditions.m -// NativeHost -// -// Created by Francisco Tolmasky on 11/16/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "NSObject+WebAdditions.h" - - -@implementation NSObject (WebAdditions) - -- (BOOL)webBoolValue -{ - return [self isKindOfClass:[NSNumber class]] && [(NSNumber *)self boolValue]; -} - -@end diff --git a/Tools/NativeHost/NSURL+Additions.h b/Tools/NativeHost/NSURL+Additions.h deleted file mode 100644 index 32cee28f6..000000000 --- a/Tools/NativeHost/NSURL+Additions.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// NSURL+Additions.h -// NativeHost -// -// Created by Francisco Tolmasky on 6/3/09. -// Copyright 2009 280 North, Inc. All rights reserved. -// - -#import - - -@interface NSURL (Additions) - -- (NSURL *)HTTPFileSystemURL; -+ (NSURL *)fileSystemURLFromHTTPFileSystemString:(NSString *)aString; - -@end diff --git a/Tools/NativeHost/NSURL+Additions.m b/Tools/NativeHost/NSURL+Additions.m deleted file mode 100644 index 39cabb1a3..000000000 --- a/Tools/NativeHost/NSURL+Additions.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// NSURL+Additions.m -// NativeHost -// -// Created by Francisco Tolmasky on 6/3/09. -// Copyright 2009 280 North, Inc. All rights reserved. -// - -#import "NSURL+Additions.h" -#import "AppController.h" - -@implementation NSURL (Additions) - -- (NSURL *)HTTPFileSystemURL -{ - if ([[self scheme] caseInsensitiveCompare:@"file"] == NSOrderedSame) - return [[[NSURL alloc] initWithScheme:@"http" - host:[NSString stringWithFormat:@"127.0.0.1:%d", SERVER_PORT] - path:[@"/filesystem/" stringByAppendingString:[self path]]] autorelease]; - - return [[self copy] autorelease]; -} - -+ (NSURL *)fileSystemURLFromHTTPFileSystemString:(NSString *)aString -{ - NSURL *httpURL = [NSURL URLWithString:aString]; - NSString *path = [httpURL path]; - NSRange range = [path rangeOfString:@"/filesystem"]; - - if (range.location == 0 && NSMaxRange(range) < [path length]) - path = [path substringFromIndex:[@"/filesystem" length]]; - - return [[[NSURL alloc] initFileURLWithPath:path] autorelease]; -} - -@end diff --git a/Tools/NativeHost/NativeHost.xcodeproj/TemplateIcon.icns b/Tools/NativeHost/NativeHost.xcodeproj/TemplateIcon.icns deleted file mode 100644 index 62cb7015e..000000000 Binary files a/Tools/NativeHost/NativeHost.xcodeproj/TemplateIcon.icns and /dev/null differ diff --git a/Tools/NativeHost/NativeHost.xcodeproj/project.pbxproj b/Tools/NativeHost/NativeHost.xcodeproj/project.pbxproj deleted file mode 100644 index b40dc518a..000000000 --- a/Tools/NativeHost/NativeHost.xcodeproj/project.pbxproj +++ /dev/null @@ -1,424 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; }; - 4D55A7941180F1E000B5187D /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 4D55A7931180F1BE00B5187D /* icon.icns */; }; - 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; - 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; - 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; - 9E2E533A103B33CB00DF2D13 /* Server.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E2E5339103B33CB00DF2D13 /* Server.m */; }; - 9E43AC84104DB51400263989 /* WebScripObject+Objective-J.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E43AC83104DB51400263989 /* WebScripObject+Objective-J.m */; }; - 9E44CA9D0FD798FE00860A54 /* NSURL+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E44CA9C0FD798FE00860A54 /* NSURL+Additions.m */; }; - 9E4EBB4210892BDE0091C8E9 /* BridgedMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E4EBB4110892BDE0091C8E9 /* BridgedMethods.m */; }; - 9E52D2F9119B05EF00B831FC /* AppController+WebPolicyDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E52D2F8119B05EF00B831FC /* AppController+WebPolicyDelegate.m */; }; - 9E535D05104F6F4900C119FA /* AppController+MainMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E535D04104F6F4900C119FA /* AppController+MainMenu.m */; }; - 9E535D32104F73FB00C119FA /* MenuBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E535D31104F73FB00C119FA /* MenuBridge.m */; }; - 9E535D37104F761F00C119FA /* MenuItemBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E535D36104F761F00C119FA /* MenuItemBridge.m */; }; - 9E55CFE50FE8750C007D1D64 /* Console.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E55CFE40FE8750C007D1D64 /* Console.m */; }; - 9E5D4F0D1090FB6E00E76B38 /* WebWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E5D4F0C1090FB6E00E76B38 /* WebWindow.m */; }; - 9E9DD6C00FC93C7A0001EF2E /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9DD6BF0FC93C7A0001EF2E /* WebKit.framework */; }; - 9EA1BEF7107E7EE500CDE684 /* Application.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EA1BEF6107E7EE500CDE684 /* Application.m */; }; - 9EB99C960FD8968100AA94A2 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EB99C950FD8968100AA94A2 /* AppController.m */; }; - 9EBC421E10B1D07100C2AE33 /* NSObject+WebAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EBC421D10B1D07100C2AE33 /* NSObject+WebAdditions.m */; }; - 9ED96C8A1020072300D24B9C /* AppController+WebUIDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9ED96C871020072300D24B9C /* AppController+WebUIDelegate.m */; }; - 9ED96C8B1020072300D24B9C /* AppController+WebFrameLoadDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9ED96C881020072300D24B9C /* AppController+WebFrameLoadDelegate.m */; }; - 9ED96C8C1020072300D24B9C /* AppController+WebResourceLoadDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9ED96C891020072300D24B9C /* AppController+WebResourceLoadDelegate.m */; }; - AD8D31C6108F98B00008F7C4 /* SSCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = AD8D31C5108F98B00008F7C4 /* SSCrypto.m */; }; - AD8D31C9108F98E40008F7C4 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AD8D31C8108F98E40008F7C4 /* libssl.dylib */; }; - AD8D31CB108F98EF0008F7C4 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AD8D31CA108F98EF0008F7C4 /* libcrypto.dylib */; }; - AD8D350F109040300008F7C4 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD8D350E109040300008F7C4 /* IOKit.framework */; }; - ADCCEF6810D43C970055BDFD /* WebPasteboardProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = ADCCEF3310D4370F0055BDFD /* WebPasteboardProxy.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; - 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; - 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; - 1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; - 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; - 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; - 32CA4F630368D1EE00C91783 /* NativeHost_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeHost_Prefix.pch; sourceTree = ""; }; - 4D55A7931180F1BE00B5187D /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = ""; }; - 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8D1107320486CEB800E47090 /* NativeHost.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NativeHost.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 9E2E5338103B33CB00DF2D13 /* Server.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Server.h; sourceTree = ""; }; - 9E2E5339103B33CB00DF2D13 /* Server.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Server.m; sourceTree = ""; }; - 9E43AC82104DB51400263989 /* WebScripObject+Objective-J.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WebScripObject+Objective-J.h"; sourceTree = ""; }; - 9E43AC83104DB51400263989 /* WebScripObject+Objective-J.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WebScripObject+Objective-J.m"; sourceTree = ""; }; - 9E44CA9B0FD798FE00860A54 /* NSURL+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+Additions.h"; sourceTree = ""; }; - 9E44CA9C0FD798FE00860A54 /* NSURL+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+Additions.m"; sourceTree = ""; }; - 9E4EBB4010892BDE0091C8E9 /* BridgedMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BridgedMethods.h; sourceTree = ""; }; - 9E4EBB4110892BDE0091C8E9 /* BridgedMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BridgedMethods.m; sourceTree = ""; }; - 9E52D2F8119B05EF00B831FC /* AppController+WebPolicyDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppController+WebPolicyDelegate.m"; sourceTree = ""; }; - 9E535D04104F6F4900C119FA /* AppController+MainMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppController+MainMenu.m"; sourceTree = ""; }; - 9E535D30104F73FB00C119FA /* MenuBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuBridge.h; sourceTree = ""; }; - 9E535D31104F73FB00C119FA /* MenuBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuBridge.m; sourceTree = ""; }; - 9E535D35104F761F00C119FA /* MenuItemBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuItemBridge.h; sourceTree = ""; }; - 9E535D36104F761F00C119FA /* MenuItemBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuItemBridge.m; sourceTree = ""; }; - 9E55CFE30FE8750C007D1D64 /* Console.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Console.h; sourceTree = ""; }; - 9E55CFE40FE8750C007D1D64 /* Console.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Console.m; sourceTree = ""; }; - 9E5D4F0B1090FB6E00E76B38 /* WebWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebWindow.h; sourceTree = ""; }; - 9E5D4F0C1090FB6E00E76B38 /* WebWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebWindow.m; sourceTree = ""; }; - 9E9DD6BF0FC93C7A0001EF2E /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; - 9EA1BEF5107E7EE500CDE684 /* Application.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Application.h; sourceTree = ""; }; - 9EA1BEF6107E7EE500CDE684 /* Application.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Application.m; sourceTree = ""; }; - 9EB99C940FD8968100AA94A2 /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = ""; }; - 9EB99C950FD8968100AA94A2 /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = ""; }; - 9EBC421C10B1D07100C2AE33 /* NSObject+WebAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+WebAdditions.h"; sourceTree = ""; }; - 9EBC421D10B1D07100C2AE33 /* NSObject+WebAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+WebAdditions.m"; sourceTree = ""; }; - 9ED96C871020072300D24B9C /* AppController+WebUIDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppController+WebUIDelegate.m"; sourceTree = ""; }; - 9ED96C881020072300D24B9C /* AppController+WebFrameLoadDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppController+WebFrameLoadDelegate.m"; sourceTree = ""; }; - 9ED96C891020072300D24B9C /* AppController+WebResourceLoadDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppController+WebResourceLoadDelegate.m"; sourceTree = ""; }; - AD8D31C4108F98B00008F7C4 /* SSCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSCrypto.h; sourceTree = ""; }; - AD8D31C5108F98B00008F7C4 /* SSCrypto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSCrypto.m; sourceTree = ""; }; - AD8D31C8108F98E40008F7C4 /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = /usr/lib/libssl.dylib; sourceTree = ""; }; - AD8D31CA108F98EF0008F7C4 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = /usr/lib/libcrypto.dylib; sourceTree = ""; }; - AD8D350E109040300008F7C4 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; - ADCCEF3210D4370F0055BDFD /* WebPasteboardProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPasteboardProxy.h; sourceTree = ""; }; - ADCCEF3310D4370F0055BDFD /* WebPasteboardProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebPasteboardProxy.m; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 8D11072E0486CEB800E47090 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, - 9E9DD6C00FC93C7A0001EF2E /* WebKit.framework in Frameworks */, - AD8D31C9108F98E40008F7C4 /* libssl.dylib in Frameworks */, - AD8D31CB108F98EF0008F7C4 /* libcrypto.dylib in Frameworks */, - AD8D350F109040300008F7C4 /* IOKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 080E96DDFE201D6D7F000001 /* Classes */ = { - isa = PBXGroup; - children = ( - 9E535D04104F6F4900C119FA /* AppController+MainMenu.m */, - 9ED96C881020072300D24B9C /* AppController+WebFrameLoadDelegate.m */, - 9ED96C891020072300D24B9C /* AppController+WebResourceLoadDelegate.m */, - 9ED96C871020072300D24B9C /* AppController+WebUIDelegate.m */, - 9E52D2F8119B05EF00B831FC /* AppController+WebPolicyDelegate.m */, - 9EB99C940FD8968100AA94A2 /* AppController.h */, - 9EB99C950FD8968100AA94A2 /* AppController.m */, - 9EA1BEF5107E7EE500CDE684 /* Application.h */, - 9EA1BEF6107E7EE500CDE684 /* Application.m */, - 9E55CFE30FE8750C007D1D64 /* Console.h */, - 9E55CFE40FE8750C007D1D64 /* Console.m */, - 9E2E5338103B33CB00DF2D13 /* Server.h */, - 9E2E5339103B33CB00DF2D13 /* Server.m */, - AD8D31C4108F98B00008F7C4 /* SSCrypto.h */, - AD8D31C5108F98B00008F7C4 /* SSCrypto.m */, - 9E5D4F0B1090FB6E00E76B38 /* WebWindow.h */, - 9E5D4F0C1090FB6E00E76B38 /* WebWindow.m */, - 9E1E34190FCC82A5007F8CA0 /* Bridge */, - ); - name = Classes; - sourceTree = ""; - }; - 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { - isa = PBXGroup; - children = ( - AD8D31CA108F98EF0008F7C4 /* libcrypto.dylib */, - AD8D31C8108F98E40008F7C4 /* libssl.dylib */, - 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, - AD8D350E109040300008F7C4 /* IOKit.framework */, - ); - name = "Linked Frameworks"; - sourceTree = ""; - }; - 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { - isa = PBXGroup; - children = ( - 29B97324FDCFA39411CA2CEA /* AppKit.framework */, - 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */, - 29B97325FDCFA39411CA2CEA /* Foundation.framework */, - 9E9DD6BF0FC93C7A0001EF2E /* WebKit.framework */, - ); - name = "Other Frameworks"; - sourceTree = ""; - }; - 19C28FACFE9D520D11CA2CBB /* Products */ = { - isa = PBXGroup; - children = ( - 8D1107320486CEB800E47090 /* NativeHost.app */, - ); - name = Products; - sourceTree = ""; - }; - 29B97314FDCFA39411CA2CEA /* NativeHost */ = { - isa = PBXGroup; - children = ( - 080E96DDFE201D6D7F000001 /* Classes */, - 29B97315FDCFA39411CA2CEA /* Other Sources */, - 29B97317FDCFA39411CA2CEA /* Resources */, - 29B97323FDCFA39411CA2CEA /* Frameworks */, - 19C28FACFE9D520D11CA2CBB /* Products */, - ); - name = NativeHost; - sourceTree = ""; - }; - 29B97315FDCFA39411CA2CEA /* Other Sources */ = { - isa = PBXGroup; - children = ( - 29B97316FDCFA39411CA2CEA /* main.m */, - 32CA4F630368D1EE00C91783 /* NativeHost_Prefix.pch */, - ); - name = "Other Sources"; - sourceTree = ""; - }; - 29B97317FDCFA39411CA2CEA /* Resources */ = { - isa = PBXGroup; - children = ( - 4D55A7931180F1BE00B5187D /* icon.icns */, - 8D1107310486CEB800E47090 /* Info.plist */, - 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, - 1DDD58140DA1D0A300B32029 /* MainMenu.xib */, - ); - name = Resources; - sourceTree = ""; - }; - 29B97323FDCFA39411CA2CEA /* Frameworks */ = { - isa = PBXGroup; - children = ( - 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, - 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, - ); - name = Frameworks; - sourceTree = ""; - }; - 9E1E34190FCC82A5007F8CA0 /* Bridge */ = { - isa = PBXGroup; - children = ( - 9E535DB7104F923E00C119FA /* Menus */, - 9E4EBB4010892BDE0091C8E9 /* BridgedMethods.h */, - 9E4EBB4110892BDE0091C8E9 /* BridgedMethods.m */, - 9EBC421C10B1D07100C2AE33 /* NSObject+WebAdditions.h */, - 9EBC421D10B1D07100C2AE33 /* NSObject+WebAdditions.m */, - 9E44CA9B0FD798FE00860A54 /* NSURL+Additions.h */, - 9E44CA9C0FD798FE00860A54 /* NSURL+Additions.m */, - ADCCEF3210D4370F0055BDFD /* WebPasteboardProxy.h */, - ADCCEF3310D4370F0055BDFD /* WebPasteboardProxy.m */, - 9E43AC82104DB51400263989 /* WebScripObject+Objective-J.h */, - 9E43AC83104DB51400263989 /* WebScripObject+Objective-J.m */, - ); - name = Bridge; - sourceTree = ""; - }; - 9E535DB7104F923E00C119FA /* Menus */ = { - isa = PBXGroup; - children = ( - 9E535D30104F73FB00C119FA /* MenuBridge.h */, - 9E535D31104F73FB00C119FA /* MenuBridge.m */, - 9E535D35104F761F00C119FA /* MenuItemBridge.h */, - 9E535D36104F761F00C119FA /* MenuItemBridge.m */, - ); - name = Menus; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 8D1107260486CEB800E47090 /* NativeHost */ = { - isa = PBXNativeTarget; - buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "NativeHost" */; - buildPhases = ( - 8D1107290486CEB800E47090 /* Resources */, - 8D11072C0486CEB800E47090 /* Sources */, - 8D11072E0486CEB800E47090 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = NativeHost; - productInstallPath = "$(HOME)/Applications"; - productName = NativeHost; - productReference = 8D1107320486CEB800E47090 /* NativeHost.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 29B97313FDCFA39411CA2CEA /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0440; - }; - buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "NativeHost" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 1; - knownRegions = ( - en, - ); - mainGroup = 29B97314FDCFA39411CA2CEA /* NativeHost */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 8D1107260486CEB800E47090 /* NativeHost */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 8D1107290486CEB800E47090 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, - 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */, - 4D55A7941180F1E000B5187D /* icon.icns in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 8D11072C0486CEB800E47090 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9E535D05104F6F4900C119FA /* AppController+MainMenu.m in Sources */, - 9ED96C8B1020072300D24B9C /* AppController+WebFrameLoadDelegate.m in Sources */, - 9ED96C8C1020072300D24B9C /* AppController+WebResourceLoadDelegate.m in Sources */, - 9ED96C8A1020072300D24B9C /* AppController+WebUIDelegate.m in Sources */, - 9EB99C960FD8968100AA94A2 /* AppController.m in Sources */, - 9EA1BEF7107E7EE500CDE684 /* Application.m in Sources */, - 9E4EBB4210892BDE0091C8E9 /* BridgedMethods.m in Sources */, - 9E55CFE50FE8750C007D1D64 /* Console.m in Sources */, - 8D11072D0486CEB800E47090 /* main.m in Sources */, - 9E535D32104F73FB00C119FA /* MenuBridge.m in Sources */, - 9E535D37104F761F00C119FA /* MenuItemBridge.m in Sources */, - 9EBC421E10B1D07100C2AE33 /* NSObject+WebAdditions.m in Sources */, - 9E44CA9D0FD798FE00860A54 /* NSURL+Additions.m in Sources */, - 9E2E533A103B33CB00DF2D13 /* Server.m in Sources */, - AD8D31C6108F98B00008F7C4 /* SSCrypto.m in Sources */, - ADCCEF6810D43C970055BDFD /* WebPasteboardProxy.m in Sources */, - 9E43AC84104DB51400263989 /* WebScripObject+Objective-J.m in Sources */, - 9E5D4F0D1090FB6E00E76B38 /* WebWindow.m in Sources */, - 9E52D2F9119B05EF00B831FC /* AppController+WebPolicyDelegate.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { - isa = PBXVariantGroup; - children = ( - 089C165DFE840E0CC02AAC07 /* English */, - ); - name = InfoPlist.strings; - sourceTree = ""; - }; - 1DDD58140DA1D0A300B32029 /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - 1DDD58150DA1D0A300B32029 /* English */, - ); - name = MainMenu.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - C01FCF4B08A954540054247B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = NativeHost_Prefix.pch; - GCC_PREPROCESSOR_DEFINITIONS = "ACTIVATION=0"; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - INFOPLIST_FILE = Info.plist; - INFOPLIST_PREPROCESS = YES; - INFOPLIST_PREPROCESSOR_DEFINITIONS = "ACTIVATION=0"; - INSTALL_PATH = "$(HOME)/Applications"; - PRODUCT_NAME = NativeHost; - }; - name = Debug; - }; - C01FCF4C08A954540054247B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = NativeHost_Prefix.pch; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - INFOPLIST_FILE = Info.plist; - INFOPLIST_PREPROCESS = YES; - INFOPLIST_PREPROCESSOR_DEFINITIONS = "ACTIVATION=0"; - INSTALL_PATH = "$(HOME)/Applications"; - PRODUCT_NAME = NativeHost; - }; - name = Release; - }; - C01FCF4F08A954540054247B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - GCC_C_LANGUAGE_STANDARD = c99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_VERSION = 4.2; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - C01FCF5008A954540054247B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - GCC_C_LANGUAGE_STANDARD = c99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - SDKROOT = macosx; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "NativeHost" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C01FCF4B08A954540054247B /* Debug */, - C01FCF4C08A954540054247B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - C01FCF4E08A954540054247B /* Build configuration list for PBXProject "NativeHost" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C01FCF4F08A954540054247B /* Debug */, - C01FCF5008A954540054247B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; -} diff --git a/Tools/NativeHost/NativeHost_Prefix.pch b/Tools/NativeHost/NativeHost_Prefix.pch deleted file mode 100644 index 17e44cd86..000000000 --- a/Tools/NativeHost/NativeHost_Prefix.pch +++ /dev/null @@ -1,8 +0,0 @@ -// -// Prefix header for all source files of the 'NativeHost' target in the 'NativeHost' project -// - -#ifdef __OBJC__ - #import - #import -#endif diff --git a/Tools/NativeHost/SSCrypto.h b/Tools/NativeHost/SSCrypto.h deleted file mode 100644 index 89ff70a9e..000000000 --- a/Tools/NativeHost/SSCrypto.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - Copyright (c) 2003-2006, Septicus Software All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Septicus Software nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -// -// SSCrypto.h -// -// Created by Ed Silva on Sat May 31 2003. -// Copyright (c) 2003-2006 Septicus Software. All rights reserved. -// - - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -@interface NSData (HexDump) -- (NSString *)encodeBase64; -- (NSString *)encodeBase64WithNewlines:(BOOL)encodeWithNewlines; -- (NSData *)decodeBase64; -- (NSData *)decodeBase64WithNewLines:(BOOL)decodeWithNewLines; -- (NSString *)hexval; -- (NSString *)hexdump; -@end - -@interface SSCrypto : NSObject -{ - NSData *symmetricKey; - NSData *cipherText; - NSData *clearText; - NSData *publicKey; - NSData *privateKey; - - BOOL isSymmetric; -} - -- (id)init; -- (id)initWithSymmetricKey:(NSData *)k; -- (id)initWithPublicKey:(NSData *)pub; -- (id)initWithPrivateKey:(NSData *)priv; -- (id)initWithPublicKey:(NSData *)pub privateKey:(NSData *)priv; - -- (BOOL)isSymmetric; -- (void)setIsSymmetric:(BOOL)flag; - -- (NSData *)symmetricKey; -- (void)setSymmetricKey:(NSData *)k; - -- (NSData *)publicKey; -- (void)setPublicKey:(NSData *)k; - -- (NSData *)privateKey; -- (void)setPrivateKey:(NSData *)k; - -- (NSData *)clearTextAsData; -- (NSString *)clearTextAsString; -- (void)setClearTextWithData:(NSData *)c; -- (void)setClearTextWithString:(NSString *)c; - -- (NSData *)cipherTextAsData; -- (NSString *)cipherTextAsString; -- (void)setCipherText:(NSData *)c; - -- (NSData *)decrypt; -- (NSData *)decrypt:(NSString *)cipherName; - -- (NSData *)verify; - -- (NSData *)encrypt; -- (NSData *)encrypt:(NSString *)cipherName; - -- (NSData *)sign; - -- (NSData *)digest:(NSString *)digestName; - -+ (NSData *)generateRSAPrivateKeyWithLength:(int)length; -+ (NSData *)generateRSAPublicKeyFromPrivateKey:(NSData *)privateKey; -+ (NSData *)getKeyDataWithLength:(int)length; -+ (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt; -+ (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt withIterations:(int)count; -+ (NSData *)getSHA1ForData:(NSData *)d; -+ (NSData *)getMD5ForData:(NSData *)d; - -@end diff --git a/Tools/NativeHost/SSCrypto.m b/Tools/NativeHost/SSCrypto.m deleted file mode 100644 index 09c557531..000000000 --- a/Tools/NativeHost/SSCrypto.m +++ /dev/null @@ -1,1214 +0,0 @@ -/* - Copyright (c) 2003-2006, Septicus Software All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Septicus Software nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -// -// SSCrypto.m -// SimpleWebCam -// -// Created by Ed Silva on Sat May 31 2003. -// Copyright (c) 2003-2006 Septicus Software. All rights reserved. -// - -#import "SSCrypto.h" - -@implementation NSData (HexDump) - -/** - * Encodes the current data in base64, and creates and returns an NSString from the result. - * This is the same as piping data through "... | openssl enc -base64" on the command line. - * - * Code courtesy of DaveDribin (http://www.dribin.org/dave/) - * Taken from http://www.cocoadev.com/index.pl?BaseSixtyFour -**/ -- (NSString *)encodeBase64 -{ - return [self encodeBase64WithNewlines: YES]; -} - -/** - * Encodes the current data in base64, and creates and returns an NSString from the result. - * This is the same as piping data through "... | openssl enc -base64" on the command line. - * - * Code courtesy of DaveDribin (http://www.dribin.org/dave/) - * Taken from http://www.cocoadev.com/index.pl?BaseSixtyFour -**/ -- (NSString *)encodeBase64WithNewlines:(BOOL)encodeWithNewlines -{ - // Create a memory buffer which will contain the Base64 encoded string - BIO * mem = BIO_new(BIO_s_mem()); - - // Push on a Base64 filter so that writing to the buffer encodes the data - BIO * b64 = BIO_new(BIO_f_base64()); - if (!encodeWithNewlines) - BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); - mem = BIO_push(b64, mem); - - // Encode all the data - BIO_write(mem, [self bytes], [self length]); - BIO_flush(mem); - - // Create a new string from the data in the memory buffer - char * base64Pointer; - long base64Length = BIO_get_mem_data(mem, &base64Pointer); - // we use an NSData here since the base64pointer is not null terminated - // the byte array the NSData return should be - // so making an NSString from that will be okay - NSData * base64data = [NSData dataWithBytes:base64Pointer length:base64Length]; - NSString * base64String = [NSString stringWithUTF8String:[base64data bytes]]; - - // Clean up and go home - BIO_free_all(mem); - - if (!encodeWithNewlines) - base64String = [[base64String componentsSeparatedByString:@"\n"] componentsJoinedByString:@""]; - - return base64String; -} - -- (NSData *)decodeBase64 -{ - return [self decodeBase64WithNewLines:YES]; -} - -- (NSData *)decodeBase64WithNewLines:(BOOL)encodedWithNewlines -{ - // Create a memory buffer containing Base64 encoded string data - BIO * mem = BIO_new_mem_buf((void *) [self bytes], [self length]); - - // Push a Base64 filter so that reading from the buffer decodes it - BIO * b64 = BIO_new(BIO_f_base64()); - if (!encodedWithNewlines) - BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); - mem = BIO_push(b64, mem); - - // Decode into an NSMutableData - NSMutableData * data = [NSMutableData data]; - char inbuf[512]; - int inlen; - while ((inlen = BIO_read(mem, inbuf, sizeof(inbuf))) > 0) - [data appendBytes: inbuf length: inlen]; - - // Clean up and go home - BIO_free_all(mem); - return data; -} - -- (NSString *)hexval -{ - NSMutableString *hex = [NSMutableString string]; - unsigned char *bytes = (unsigned char *)[self bytes]; - char temp[3]; - int i = 0; - - for (i = 0; i < [self length]; i++) { - temp[0] = temp[1] = temp[2] = 0; - (void)sprintf(temp, "%02x", bytes[i]); - [hex appendString:[NSString stringWithUTF8String:temp]]; - } - - return hex; -} - -- (NSString *)hexdump -{ - NSMutableString *ret=[NSMutableString stringWithCapacity:[self length]*2]; - /* dumps size bytes of *data to string. Looks like: - * [0000] 75 6E 6B 6E 6F 77 6E 20 - * 30 FF 00 00 00 00 39 00 unknown 0.....9. - * (in a single line of course) - */ - unsigned int size= [self length]; - const unsigned char *p = [self bytes]; - unsigned char c; - int n; - char bytestr[4] = {0}; - char addrstr[10] = {0}; - char hexstr[ 16*3 + 5] = {0}; - char charstr[16*1 + 5] = {0}; - for(n=1;n<=size;n++) { - if (n%16 == 1) { - /* store address for this line */ - snprintf(addrstr, sizeof(addrstr), "%.4x", - (unsigned int)((long)p-(long)self) ); - } - - c = *p; - if (isalnum(c) == 0) { - c = '.'; - } - - /* store hex str (for left side) */ - snprintf(bytestr, sizeof(bytestr), "%02X ", *p); - strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); - - /* store char str (for right side) */ - snprintf(bytestr, sizeof(bytestr), "%c", c); - strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); - - if(n%16 == 0) { - /* line completed */ - //printf("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); - [ret appendString:[NSString stringWithFormat:@"[%4.4s] %-50.50s %s\n", - addrstr, hexstr, charstr]]; - hexstr[0] = 0; - charstr[0] = 0; - } else if(n%8 == 0) { - /* half line: add whitespaces */ - strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); - strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); - } - p++; /* next byte */ - } - - if (strlen(hexstr) > 0) { - /* print rest of buffer if not empty */ - //printf("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); - [ret appendString:[NSString stringWithFormat:@"[%4.4s] %-50.50s %s\n", - addrstr, hexstr, charstr]]; - } - return ret; -} - -@end - -@interface SSCrypto (PrivateAPI) -- (void)setupOpenSSL; -- (void)cleanupOpenSSL; -@end - -// SSCrypto object -@implementation SSCrypto - -/** - * Generic constructor. - * Simply configures internal OpenSSL setup. -**/ -- (id)init -{ - if(self = [super init]) - { - // Call private method to handle the setup for internal OpenSSL stuff - [self setupOpenSSL]; - } - return self; -} - -/** - * Symmetric key constructor. - * Configures the instance to use symmetric encryption/decryption using the given symmetric key. -**/ -- (id)initWithSymmetricKey:(NSData *)k -{ - if(self = [super init]) - { - // Call private method to handle the setup for internal OpenSSL stuff - [self setupOpenSSL]; - - [self setSymmetricKey:k]; - [self setIsSymmetric:YES]; - } - return self; -} - -/** - * Public key only constructor. - * Configures the instance to use non-symmetric encryption/decryption, and to use the given public key. -**/ -- (id)initWithPublicKey:(NSData *)pub -{ - return [self initWithPublicKey:pub privateKey:nil]; -} - -/** - * Private key only constructor. - * Configures the instance to use non-symmetric encryption/decryption, and to use the given private key. -**/ -- (id)initWithPrivateKey:(NSData *)priv -{ - return [self initWithPublicKey:nil privateKey:priv]; -} - -/** - * Public and Private key constructor. - * Configures the instance to use non-symmetric encryption/decryption, and to use the given public and private keys. -**/ -- (id)initWithPublicKey:(NSData *)pub privateKey:(NSData *)priv; -{ - if(self = [super init]) - { - // Call private method to handle the setup for internal OpenSSL stuff - [self setupOpenSSL]; - - // Store the publicKey variable (if not nil) - if(pub != nil) - [self setPublicKey:pub]; - - // Store the privateKey variable (if not nil) - if(priv != nil) - [self setPrivateKey:priv]; - - // Since we're using public and private keys, we can assume we're not using symmetric encryption - [self setIsSymmetric:NO]; - } - return self; -} - -/** - * This method sets up everything needed to use the OpenSSL libraries later within the code. - * This method should be called by every constructor. -**/ -- (void)setupOpenSSL -{ - // OpenSSL keeps an internal table of digest algorithms and ciphers. - // It uses this table to lookup ciphers via functions such as EVP_get_cipher_byname(). - // OpenSSL_add_all_digests() adds all digest algorithms to the table. - // OpenSSL_add_all_ciphers() adds all cipher algorithms to the table. - // OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and ciphers). - // EVP_cleanup() removes all ciphers and digests from the table. - // - // A typical application will call OpenSSL_add_all_algorithms() initially and EVP_cleanup() before exiting. - - OpenSSL_add_all_algorithms(); - - // ERR_load_crypto_strings() registers the error strings for all libcrypto functions. - // SSL_load_error_strings() does the same, but also registers the libssl error strings. - // ERR_free_strings() frees all previously loaded error strings. - // - // One of these functions should be called before generating textual error messages. - // However, this is not required when memory usage is an issue. - - ERR_load_crypto_strings(); -} - -/** - * Standard deallocation method. -**/ -- (void)dealloc -{ - // Cleanup all OpenSSL stuff - [self cleanupOpenSSL]; - - // Release all instance variables - [symmetricKey release]; - [cipherText release]; - [clearText release]; - [publicKey release]; - [privateKey release]; - - // Move up the inheritance chain - [super dealloc]; -} - -- (void)cleanupOpenSSL -{ - // EVP_cleanup() removes all ciphers and digests from the table. - EVP_cleanup(); - - // ERR_free_strings() frees all previously loaded error strings. - ERR_free_strings(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark Getter, Setter Methods: -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Returns whether or not symmetric encryption is to be used. - * If symmetric encryption is in use, then calls to encrypt or decrypt operate using symmetric encryption/decryption. - * Otherwise, it is assumed that asymmetric encryption/decryption is to be used. -**/ -- (BOOL)isSymmetric -{ - return isSymmetric; -} - -- (void)setIsSymmetric:(BOOL)flag -{ - isSymmetric = flag; -} - -- (NSData *)symmetricKey -{ - return symmetricKey; -} - -- (void)setSymmetricKey:(NSData *)k -{ - [k retain]; - [symmetricKey release]; - symmetricKey = k; -} - -/** - * Returns the public key currently in use. -**/ -- (NSData *)publicKey -{ - return publicKey; -} - -/** - * Sets the public key to use. - * Public keys are used to verify signed data, or to encrypt data. (ToDo) -**/ -- (void)setPublicKey:(NSData *)k -{ - [k retain]; - [publicKey release]; - publicKey = k; -} - -/** - * Returns the private key currently in use. -**/ -- (NSData *)privateKey -{ - return privateKey; -} - -/** - * Sets the private key to use. - * Private keys are used to sign data, or to decrypt data. (ToDo) - * - * The data that is provided should from a file (such as private.pem) that was generated by openssl. -**/ -- (void)setPrivateKey:(NSData *)k -{ - [k retain]; - [privateKey release]; - privateKey = k; -} - -/** - * Returns the clear text as plain NSData. - * The plain text contains the text that was previously set. - * It's the known text, which is to be encrypted, decrypted, etc. -**/ -- (NSData *)clearTextAsData -{ - return clearText; -} - -/** - * Returns the clear text formatted as an NSString. - * The plain text contains the text that was previously set. - * It's the known text, which is to be encrypted, decrypted, etc. -**/ -- (NSString *)clearTextAsString -{ - return [[[NSString alloc] initWithData:[self clearTextAsData] encoding:NSUTF8StringEncoding] autorelease]; -} - -/** - * Sets the clear text using the given data. - * The clear text will be used for encryption, decryption, etc. - * - * Note that the given data reference is retained and later used, so it shouldn't be externally modified. -**/ -- (void)setClearTextWithData:(NSData *)c -{ - [c retain]; - [clearText release]; - clearText = c; -} - -/** - * Sets the clear text using the given string. - * The clear text will be used for encryption, signing, and digests. - **/ -- (void)setClearTextWithString:(NSString *)c -{ - [clearText release]; - - // BUG FIX : PLL (2009/02/21) - // - // [c length] : Returns the number of Unicode characters in the receiver. - // For example "‚àö¬©‚àö‚Ć‚àö√ü test" in UTF8 is 11 bytes (c3 a9 c3 a0 c3 a7 20 74 65 73 74) - // but only 8 Unicode characters. - // So this will truncate the text and result in one error. - // - // clearText = [[NSData alloc] initWithBytes:[c UTF8String] length:[c length]]; - - // The number of bytes required to store the receiver in the encoding enc in a non-external representation. The length does not include space for a terminating NULL character. - unsigned int length = [c lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; - clearText = [[NSData alloc] initWithBytes:[c UTF8String] length:length]; -} - -/** - * Returns the cipher text as plain NSData. - * The cipher text contains the most recent encrypted data. (Result of call to encrypt) -**/ -- (NSData *)cipherTextAsData -{ - return cipherText; -} - -/** - * Returns the ciper text formatted as an NSString. - * The ciper text contains the most recent encrypted data. (Result of call to encrypt) -**/ -- (NSString *)cipherTextAsString -{ - return [[[NSString alloc] initWithData:[self cipherTextAsData] encoding:NSUTF8StringEncoding] autorelease]; -} - -/** - * Sets the cipher text using the given data. - * The cipher text will be used for decryption and verifying. -**/ -- (void)setCipherText:(NSData *)c -{ - [c retain]; - [cipherText release]; - cipherText = c; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark Decryption methods: -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Peforms decryption, and returns resulting clear text data. - * If symmetric decryption is being used, performs symmetric decryption using aes128. - * Otherwise, performs decryption using the private key. -**/ -- (NSData *)decrypt -{ - if([self isSymmetric] && [self symmetricKey]) - { - return [self decrypt:@"aes128"]; - } - else if([self privateKey]) - { - return [self decrypt:nil]; - } - else - { - NSLog(@"No symmetric key or private key is set!"); - return nil; - } -} - -/** - * Decrypts the cipher text data. - * If symmetric decryption is being used, then the decryption is done using the given cipher. - * Otherwise, asymmetric decryptions is used, and the data is encrypted using the private key. - * - * Returns the clear text data that is the result of the decryption. - * The resulting clear text data may also be later retrieved with the clearTextAsData or clearTextAsString methods. -**/ -- (NSData *)decrypt:(NSString *)cipherName -{ - // If there is no cipher text set, or the cipher text is an empty string (zero length data) - // then there is nothing to decrypt, and we may as well return nil - if(cipherText == nil || [cipherText length] == 0) - { - return nil; - } - - unsigned char *outbuf, iv[EVP_MAX_IV_LENGTH]; - int outlen, templen, inlen; - inlen = [cipherText length]; - unsigned char *input = (unsigned char *)[cipherText bytes]; - - if([self isSymmetric]) - { - // Use symmetric decryption... - - unsigned char evp_key[EVP_MAX_KEY_LENGTH] = {"\0"}; - EVP_CIPHER_CTX cCtx; - const EVP_CIPHER *cipher; - - if(cipherName) - { - cipher = EVP_get_cipherbyname((const char *)[cipherName UTF8String]); - if(!cipher) - { - NSLog(@"cannot get cipher with name %@", cipherName); - return nil; - } - } - else - { - cipher = EVP_bf_cbc(); - if(!cipher) - { - NSLog(@"cannot get cipher with name %@", @"EVP_bf_cbc"); - return nil; - } - } - - // Sometimes OpenSSL encrypted data contains an 8 byte salt. - // This is indicated by the "Salted__" prefix in the encrypted data. - - NSData *salt = nil; - - if([cipherText length] > 8+8) - { - if(strncmp((const char *)[cipherText bytes], "Salted__", 8) == 0) - { - salt = [cipherText subdataWithRange:NSMakeRange(8, 8)]; - - input += 16; - inlen -= 16; - } - } - - EVP_BytesToKey(cipher, EVP_md5(), [salt bytes], - [symmetricKey bytes], [symmetricKey length], 1, evp_key, iv); - - EVP_CIPHER_CTX_init(&cCtx); - - if (!EVP_DecryptInit(&cCtx, cipher, evp_key, iv)) - { - NSLog(@"EVP_DecryptInit() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - EVP_CIPHER_CTX_set_key_length(&cCtx, EVP_MAX_KEY_LENGTH); - - // The data buffer passed to EVP_DecryptUpdate() should have sufficient room for - // (input_length + cipher_block_size) bytes unless the cipher block size is 1 in which - // case input_length bytes is sufficient. - - if(EVP_CIPHER_CTX_block_size(&cCtx) > 1) - outbuf = (unsigned char *)calloc(inlen + EVP_CIPHER_CTX_block_size(&cCtx), sizeof(unsigned char)); - else - outbuf = (unsigned char *)calloc(inlen, sizeof(unsigned char)); - - NSAssert(outbuf, @"Cannot allocate memory for buffer!"); - - if (!EVP_DecryptUpdate(&cCtx, outbuf, &outlen, input, inlen)) - { - NSLog(@"EVP_DecryptUpdate() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - - if (!EVP_DecryptFinal(&cCtx, outbuf + outlen, &templen)) - { - NSLog(@"EVP_DecryptFinal() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - - outlen += templen; - EVP_CIPHER_CTX_cleanup(&cCtx); - } - else - { - // Use asymmetric decryption... - - if([self privateKey] == nil) - { - NSLog(@"Cannot decrypt without the private key, which is currently nil"); - return nil; - } - - BIO *privateBIO = NULL; - RSA *privateRSA = NULL; - - if(!(privateBIO = BIO_new_mem_buf((unsigned char*)[[self privateKey] bytes], [[self privateKey] length]))) - { - NSLog(@"BIO_new_mem_buf() failed!"); - return nil; - } - - if(!PEM_read_bio_RSAPrivateKey(privateBIO, &privateRSA, NULL, NULL)) - { - NSLog(@"PEM_read_bio_RSAPrivateKey() failed!"); - return nil; - } - - // RSA_check_key() returns 1 if rsa is a valid RSA key, and 0 otherwise. - - unsigned long check = RSA_check_key(privateRSA); - if(check != 1) - { - NSLog(@"RSA_check_key() failed with result %d!", check); - return nil; - } - - // RSA_size() returns the RSA modulus size in bytes. - // It can be used to determine how much memory must be allocated for an RSA encrypted value. - - outbuf = (unsigned char *)malloc(RSA_size(privateRSA)); - - if(!(outlen = RSA_private_decrypt(inlen, input, outbuf, privateRSA, RSA_PKCS1_PADDING))) - { - NSLog(@"RSA_private_decrypt() failed!"); - return nil; - } - - if(outlen == -1) - { - NSLog(@"Decrypt error: %s (%s)", - ERR_error_string(ERR_get_error(), NULL), - ERR_reason_error_string(ERR_get_error())); - return nil; - } - - if (privateBIO) BIO_free(privateBIO); - if (privateRSA) RSA_free(privateRSA); - } - - // Store the decrypted data as the clear text - [self setClearTextWithData:[NSData dataWithBytes:outbuf length:outlen]]; - - // Release the outbuf, since it was malloc'd - if (outbuf) { - free(outbuf); - } - - return [self clearTextAsData]; -} - -/** - * Verifies (decrypts) the cipher text data using the public key. - * The resulting clear text data is returned. - * - * The resulting clear text data may also be later retrieved with the clearTextAsData or clearTextAsString methods. - **/ -- (NSData *)verify -{ - // If there is no cipher text set, or the cipher text is an empty string (zero length data) - // then there is nothing to decrypt, and we may as well return nil - if(cipherText == nil || [cipherText length] == 0) - { - return nil; - } - - unsigned char *outbuf; - int outlen, inlen; - inlen = [cipherText length]; - unsigned char *input = (unsigned char *)[cipherText bytes]; - - if([self publicKey] == nil) - { - NSLog(@"Cannot verify (decrypt) without the public key, which is currently nil"); - return nil; - } - - BIO *publicBIO = NULL; - RSA *publicRSA = NULL; - - if(!(publicBIO = BIO_new_mem_buf((unsigned char *)[[self publicKey] bytes], [[self publicKey] length]))) - { - NSLog(@"BIO_new_mem_buf() failed!"); - return nil; - } - - if(!PEM_read_bio_RSA_PUBKEY(publicBIO, &publicRSA, NULL, NULL)) - { - NSLog(@"PEM_read_bio_RSA_PUBKEY() failed!"); - return nil; - } - - // RSA_size() returns the RSA modulus size in bytes. - // It can be used to determine how much memory must be allocated for an RSA encrypted value. - - outbuf = (unsigned char *)malloc(RSA_size(publicRSA)); - - if(!(outlen = RSA_public_decrypt(inlen, input, outbuf, publicRSA, RSA_PKCS1_PADDING))) - { - NSLog(@"RSA_public_decrypt() failed!"); - return nil; - } - - if(outlen == -1) - { - NSLog(@"Decrypt error: %s (%s)", - ERR_error_string(ERR_get_error(), NULL), - ERR_reason_error_string(ERR_get_error())); - return nil; - } - - if (publicBIO) BIO_free(publicBIO); - if (publicRSA) RSA_free(publicRSA); - - // Store the decrypted data as the clear text - [self setClearTextWithData:[NSData dataWithBytes:outbuf length:outlen]]; - - // Release the outbuf, since it was malloc'd - if (outbuf) { - free(outbuf); - } - - return [self clearTextAsData]; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark Encryption methods: -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Peforms encryption, and returns resulting ciper text data. - * If symmetric encryption is being used, performs symmetric encryption using aes128. - * Otherwise, performs encryption using the public key. -**/ -- (NSData *)encrypt -{ - if([self isSymmetric] && [self symmetricKey]) - { - return [self encrypt:@"aes128"]; - } - else if([self publicKey]) - { - return [self encrypt:nil]; - } - else - { - NSLog(@"No symmetric key or public key is set!"); - return nil; - } -} - -/** - * Encrypts the clear text data. - * If symmetric encryption is being used, then the encryption is done using the given cipher. - * Otherwise, asymmetric encryption is used, and the data is encrypted using the public key. - * - * Returns the cipher text data that is the result of the encryption. - * The resulting cipher text data may also be later retrieved with the cipherTextAsData or cipherTextAsString methods. -**/ -- (NSData *)encrypt:(NSString *)cipherName -{ - // If there is no clear text set, or the clear text is an empty string (zero length data) - // then there is nothing to encrypt, and we may as well return nil - if(clearText == nil || [clearText length] == 0) - { - return nil; - } - - unsigned char *input = (unsigned char *)[clearText bytes]; - unsigned char *outbuf, iv[EVP_MAX_IV_LENGTH]; - int outlen, templen, inlen; - inlen = [clearText length]; - - if([self isSymmetric]) - { - // Perform symmetric encryption... - - unsigned char evp_key[EVP_MAX_KEY_LENGTH] = {"\0"}; - EVP_CIPHER_CTX cCtx; - const EVP_CIPHER *cipher; - - if (cipherName){ - cipher = EVP_get_cipherbyname((const char *)[cipherName UTF8String]); - if (!cipher){ - NSLog(@"cannot get cipher with name %@", cipherName); - return nil; - } - } else { - cipher = EVP_bf_cbc(); - if (!cipher){ - NSLog(@"cannot get cipher with name %@", @"EVP_bf_cbc"); - return nil; - } - } - - EVP_BytesToKey(cipher, EVP_md5(), NULL, - [[self symmetricKey] bytes], [[self symmetricKey] length], 1, evp_key, iv); - EVP_CIPHER_CTX_init(&cCtx); - - if (!EVP_EncryptInit(&cCtx, cipher, evp_key, iv)) { - NSLog(@"EVP_EncryptInit() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - EVP_CIPHER_CTX_set_key_length(&cCtx, EVP_MAX_KEY_LENGTH); - - // The data buffer passed to EVP_EncryptUpdate() should have sufficient room for - // (input_length + cipher_block_size - 1) - - outbuf = (unsigned char *)calloc(inlen + EVP_CIPHER_CTX_block_size(&cCtx) - 1, sizeof(unsigned char)); - NSAssert(outbuf, @"Cannot allocate memory for buffer!"); - - if (!EVP_EncryptUpdate(&cCtx, outbuf, &outlen, input, inlen)) - { - NSLog(@"EVP_EncryptUpdate() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - if (!EVP_EncryptFinal(&cCtx, outbuf + outlen, &templen)) - { - NSLog(@"EVP_EncryptFinal() failed!"); - EVP_CIPHER_CTX_cleanup(&cCtx); - return nil; - } - outlen += templen; - EVP_CIPHER_CTX_cleanup(&cCtx); - - } - else - { - // Perform asymmetric encryption... - - if([self publicKey] == nil) - { - NSLog(@"Cannot encrypt without the public key, which is currently nil"); - return nil; - } - - BIO *publicBIO = NULL; - RSA *publicRSA = NULL; - - if(!(publicBIO = BIO_new_mem_buf((unsigned char*)[[self publicKey] bytes], [[self publicKey] length]))) - { - NSLog(@"BIO_new_mem_buf() failed!"); - return nil; - } - - if(!PEM_read_bio_RSA_PUBKEY(publicBIO, &publicRSA, NULL, NULL)) - { - NSLog(@"PEM_read_bio_RSA_PUBKEY() failed!"); - return nil; - } - - // RSA_size() returns the RSA modulus size in bytes. - // It can be used to determine how much memory must be allocated for an RSA encrypted value. - - outbuf = (unsigned char *)malloc(RSA_size(publicRSA)); - - if(!(outlen = RSA_public_encrypt(inlen, input, (unsigned char*)outbuf, publicRSA, RSA_PKCS1_PADDING))) - { - NSLog(@"RSA_public_encrypt failed!"); - return nil; - } - - if(outlen == -1) - { - NSLog(@"Encrypt error: %s (%s)", - ERR_error_string(ERR_get_error(), NULL), - ERR_reason_error_string(ERR_get_error())); - return nil; - } - - if (publicBIO) BIO_free(publicBIO); - if (publicRSA) RSA_free(publicRSA); - } - - // Store the encrypted data as the cipher text - [self setCipherText:[NSData dataWithBytes:outbuf length:outlen]]; - - // Release the outbuf, since it was malloc'd - if(outbuf) { - free(outbuf); - } - - return [self cipherTextAsData]; -} - -/** - * Signs (encrypts) the clear text data using the private key. - * The resulting cipher text data is returned, and may later be verified (decrypted) using the public key. - * - * The resulting cipher text data may also be later retrieved with the cipherTextAsData or cipherTextAsString methods. -**/ -- (NSData *)sign -{ - // If there is no clear text set, or the clear text is an empty string (zero length data) - // then there is nothing to encrypt, and we may as well return nil - if(clearText == nil || [clearText length] == 0) - { - return nil; - } - - unsigned char *input = (unsigned char *)[clearText bytes]; - unsigned char *outbuf; - int outlen, inlen; - inlen = [clearText length]; - - if([self privateKey] == nil) - { - NSLog(@"Cannot sign (encrypt) without the private key, which is currently nil"); - return nil; - } - - BIO *privateBIO = NULL; - RSA *privateRSA = NULL; - - if(!(privateBIO = BIO_new_mem_buf((unsigned char*)[[self privateKey] bytes], [[self privateKey] length]))) - { - NSLog(@"BIO_new_mem_buf() failed!"); - return nil; - } - - if(!PEM_read_bio_RSAPrivateKey(privateBIO, &privateRSA, NULL, NULL)) - { - NSLog(@"PEM_read_bio_RSAPrivateKey() failed!"); - return nil; - } - - // RSA_check_key() returns 1 if rsa is a valid RSA key, and 0 otherwise. - - unsigned long check = RSA_check_key(privateRSA); - if(check != 1) - { - NSLog(@"RSA_check_key() failed with result %d!", check); - return nil; - } - - // RSA_size() returns the RSA modulus size in bytes. - // It can be used to determine how much memory must be allocated for an RSA encrypted value. - - outbuf = (unsigned char *)malloc(RSA_size(privateRSA)); - - if(!(outlen = RSA_private_encrypt(inlen, input, (unsigned char*)outbuf, privateRSA, RSA_PKCS1_PADDING))) - { - NSLog(@"RSA_private_encrypt failed!"); - return nil; - } - - if(outlen == -1) - { - NSLog(@"Encrypt error: %s (%s)", - ERR_error_string(ERR_get_error(), NULL), - ERR_reason_error_string(ERR_get_error())); - return nil; - } - - if (privateBIO) BIO_free(privateBIO); - if (privateRSA) RSA_free(privateRSA); - - // Store the encrypted data as the cipher text - [self setCipherText:[NSData dataWithBytes:outbuf length:outlen]]; - - // Release the outbuf, since it was malloc'd - if(outbuf) { - free(outbuf); - } - - return [self cipherTextAsData]; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark Other methods: -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Description forthcoming... -**/ -- (NSData *)digest:(NSString *)digestName -{ - if(clearText == nil) { - return nil; - } - - unsigned char outbuf[EVP_MAX_MD_SIZE]; - unsigned int templen, inlen; - unsigned char *input=(unsigned char*)[clearText bytes]; - EVP_MD_CTX ctx; - const EVP_MD *digest = NULL; - - inlen = [clearText length]; - - if(inlen==0) - return nil; - if(digestName) { - digest = EVP_get_digestbyname((const char*)[digestName UTF8String]); - if (!digest) { - NSLog(@"cannot get digest with name %@",digestName); - return nil; - } - } else { - digest=EVP_md5(); - if(!digest) { - NSLog(@"cannot get digest with name %@",@"MD5"); - return nil; - } - } - - EVP_MD_CTX_init(&ctx); - EVP_DigestInit(&ctx,digest); - if(!EVP_DigestUpdate(&ctx,input,inlen)) { - NSLog(@"EVP_DigestUpdate() failed!"); - EVP_MD_CTX_cleanup(&ctx); - return nil; - } - if (!EVP_DigestFinal(&ctx, outbuf, &templen)) { - NSLog(@"EVP_DigesttFinal() failed!"); - EVP_MD_CTX_cleanup(&ctx); - return nil; - } - EVP_MD_CTX_cleanup(&ctx); - - return [NSData dataWithBytes:outbuf length:templen]; -} - -- (NSString *)description -{ - NSString *format = @"clearText: %@, cipherText: %@, symmetricKey: %@, publicKey: %@, privateKey: %@"; - NSString *desc = [NSString stringWithFormat:format, [clearText hexdump], [cipherText hexdump], - [symmetricKey hexdump], [publicKey hexdump], [privateKey hexdump]]; - return desc; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark Class methods: -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -+ (NSData *)generateRSAPrivateKeyWithLength:(int)length -{ - RSA *key = NULL; - do { - key = RSA_generate_key(length, RSA_F4, NULL, NULL); - } while (1 != RSA_check_key(key)); - - BIO *bio = BIO_new(BIO_s_mem()); - - if (!PEM_write_bio_RSAPrivateKey(bio, key, NULL, NULL, 0, NULL, NULL)) - { - NSLog(@"cannot write private key to memory"); - return nil; - } - if (key) RSA_free(key); - - char *pbio_data = NULL; - int data_len = BIO_get_mem_data(bio, &pbio_data); - NSData *result = [NSData dataWithBytes:pbio_data length:data_len]; - - if (bio) - BIO_free(bio); - - return result; -} - -+ (NSData *)generateRSAPublicKeyFromPrivateKey:(NSData *)privateKey -{ - BIO *privateBIO = NULL; - RSA *privateRSA = NULL; - - if (!(privateBIO = BIO_new_mem_buf((unsigned char*)[privateKey bytes], [privateKey length]))) - { - NSLog(@"BIO_new_mem_buf() failed!"); - return nil; - } - - if (!PEM_read_bio_RSAPrivateKey(privateBIO, &privateRSA, NULL, NULL)) - { - NSLog(@"PEM_read_bio_RSAPrivateKey() failed!"); - return nil; - } - - // RSA_check_key() returns 1 if rsa is a valid RSA key, and 0 otherwise. - - unsigned long check = RSA_check_key(privateRSA); - if (check != 1) - { - NSLog(@"RSA_check_key() failed with result %d!", check); - return nil; - } - - BIO *bio = BIO_new(BIO_s_mem()); - - if (!PEM_write_bio_RSA_PUBKEY(bio, privateRSA)) - { - NSLog(@"cannot write public key to memory"); - return nil; - } - if (privateRSA) RSA_free(privateRSA); - - char *pbio_data = NULL; - int data_len = BIO_get_mem_data(bio, &pbio_data); - NSData *result = [NSData dataWithBytes:pbio_data length:data_len]; - - if (bio) - BIO_free(bio); - - return result; -} - -+ (NSData *)getKeyDataWithLength:(int)length -{ - NSData *randData = nil; - unsigned char *buffer; - - buffer = (unsigned char *)calloc(length*4, sizeof(unsigned char)); - NSAssert((buffer != NULL), @"Cannot calloc memory for buffer."); - - if (!RAND_bytes(buffer, length)){ - free(buffer); - } - - randData = [NSData dataWithBytes:buffer length:length]; - free(buffer); - - return randData; -} - -// PBKDF2 support functions -// Thanks to Chris Benedict (chrisbdaemon@gmail.com) for the code -+ (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt -{ - return [SSCrypto getKeyDataWithLength:length fromPassword:pass withSalt:salt withIterations:1000]; -} - -+ (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt withIterations:(int)count -{ - NSData *key = nil; - unsigned char *buffer = (unsigned char *)calloc(length, sizeof(unsigned char)); - NSAssert((buffer != NULL), @"Cannot calloc memory for buffer."); - const char *password = [pass UTF8String]; - const char *saltVal = [salt UTF8String]; - - if(!PKCS5_PBKDF2_HMAC_SHA1(password, [pass length], (unsigned char *)saltVal, [salt length], count, length, buffer)) { - return nil; - } - - key = [NSData dataWithBytes:buffer length:length]; - free(buffer); - - return key; -} - -+ (NSData *)getSHA1ForData:(NSData *)d -{ - unsigned length = [d length]; - const void *buffer = [d bytes]; - unsigned char *md = (unsigned char *)calloc(SHA_DIGEST_LENGTH, sizeof(unsigned char)); - NSAssert((md != NULL), @"Cannot calloc memory for buffer."); - - (void)SHA1(buffer, length, md); - - return [NSData dataWithBytesNoCopy:md length:SHA_DIGEST_LENGTH freeWhenDone:YES]; -} - -+ (NSData *)getMD5ForData:(NSData *)d -{ - unsigned length = [d length]; - const void *buffer = [d bytes]; - unsigned char *md = (unsigned char *)calloc(MD5_DIGEST_LENGTH, sizeof(unsigned char)); - NSAssert((md != NULL), @"Cannot calloc memory for buffer."); - - (void)MD5(buffer, length, md); - - return [NSData dataWithBytesNoCopy:md length:MD5_DIGEST_LENGTH freeWhenDone:YES]; -} - -@end diff --git a/Tools/NativeHost/Server.h b/Tools/NativeHost/Server.h deleted file mode 100644 index a11e9d701..000000000 --- a/Tools/NativeHost/Server.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Server.h -// NativeHost -// -// Created by Francisco Tolmasky on 8/18/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - -@interface Server : NSObject -{ - NSFileHandle * outputFile; - NSFileHandle * errorFile; - NSTask * process; -} - -- (BOOL)start; -- (void)stop; - -@end diff --git a/Tools/NativeHost/Server.m b/Tools/NativeHost/Server.m deleted file mode 100644 index 5439bc967..000000000 --- a/Tools/NativeHost/Server.m +++ /dev/null @@ -1,193 +0,0 @@ -// -// Server.m -// NativeHost -// -// Created by Francisco Tolmasky on 8/18/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "Server.h" -#import "AppController.h" - -#import -#import - -@implementation Server - -- (BOOL)start -{ - NSBundle *mainBundle = [NSBundle mainBundle]; - NSString *serverPath = [mainBundle pathForResource:@"NativeHostServer" ofType:@"" inDirectory:@"Server"]; - - if (!serverPath) - { - return YES; - } - - // find an available port - struct sockaddr_in addr; - int sockfd; - int attempts = 0; - - while (SERVER_PORT == 9191 && attempts++ < 5) - { - // Create a socket - sockfd = socket( AF_INET, SOCK_STREAM, 0 ); - - // Setup its address structure - bzero( &addr, sizeof(struct sockaddr_in)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl( INADDR_ANY ); - addr.sin_port = htons( 0 ); - - // Bind it to an address and port - bind( sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr)); - - // Set it listening for connections - listen( sockfd, 5 ); - - // Find out what port the socket was bound to - socklen_t namelen = sizeof(struct sockaddr_in); - getsockname( sockfd, (struct sockaddr *)&addr, &namelen ); - - if (addr.sin_port <= 1024) - addr.sin_port = 9191; - else - SERVER_PORT = addr.sin_port; - - shutdown(sockfd, 2); - } - - if (SERVER_PASSWORD == nil) - { - CFUUIDRef uuidObj = CFUUIDCreate(nil); - SERVER_PASSWORD = (NSString*)CFUUIDCreateString(nil, uuidObj); - CFRelease(uuidObj); - } - - if (SERVER_USER == nil) - { - CFUUIDRef uuidObj = CFUUIDCreate(nil); - SERVER_USER = (NSString*)CFUUIDCreateString(nil, uuidObj); - CFRelease(uuidObj); - // usernames can't have "-" in them - SERVER_USER = [[SERVER_USER autorelease] stringByReplacingOccurrencesOfString:@"-" withString:@""]; - } - - // setup environment variables - NSDictionary *env = [[[NSProcessInfo processInfo] environment] mutableCopy]; - [env setValue:[mainBundle resourcePath] forKey:@"NATIVEHOST_RESOURCES"]; - [env setValue:[[NSNumber numberWithInt:SERVER_PORT] stringValue] forKey:@"NATIVEHOST_SERVER_PORT"]; - [env setValue:SERVER_USER forKey:@"NATIVEHOST_SERVER_USER"]; - [env setValue:SERVER_PASSWORD forKey:@"NATIVEHOST_SERVER_PASSWORD"]; - - // create pipes for stdout and stderr - NSPipe * outputPipe = [NSPipe pipe]; - outputFile = [outputPipe fileHandleForReading]; - NSPipe * errorPipe = [NSPipe pipe]; - errorFile = [errorPipe fileHandleForReading]; - - // setup the process - process = [[NSTask alloc] init]; - [process setLaunchPath:serverPath]; - [process setStandardOutput:outputPipe]; - [process setStandardError:errorPipe]; - [process setEnvironment:env]; - [env release]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(serverDidTerminate:) - name:NSTaskDidTerminateNotification - object:process]; - - [process launch]; - - BOOL didStartup = NO; - NSData * data = nil; - - while (!didStartup && (data = [outputFile availableData]) && [data length]) - { - NSString * string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - if (string) - { - NHLog(@"SERVER-OUT", string); - - didStartup = [string rangeOfString:@"Jack is starting up"].location != NSNotFound; - - [string release]; - } - } - NSLog(@"Server has started."); - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(didReadStdOut:) - name:NSFileHandleReadCompletionNotification - object:outputFile]; - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(didReadStdErr:) - name:NSFileHandleReadCompletionNotification - object:errorFile]; - - [outputFile readInBackgroundAndNotify]; - [errorFile readInBackgroundAndNotify]; - - return didStartup; -} - -- (void)stop -{ - [process terminate]; -} - -- (void)didReadStdOut:(NSNotification *)aNotification -{ - NSString * string = [[NSString alloc] initWithData:[[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem] - encoding:NSASCIIStringEncoding]; - NHLog(@"SERVER-OUT", string); - [string release]; - [outputFile readInBackgroundAndNotify]; -} - -- (void)didReadStdErr:(NSNotification *)aNotification -{ - NSString * string = [[NSString alloc] initWithData:[[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem] - encoding:NSASCIIStringEncoding]; - NHLog(@"SERVER-ERR", string); - [string release]; - [errorFile readInBackgroundAndNotify]; -} - -- (void)serverDidTerminate:(NSNotification *)note -{ - if ([process terminationStatus] != 0) - { - NSString *appName = [[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:@"CFBundleDisplayName"]; - if (appName == nil) - appName = [[NSProcessInfo processInfo] processName]; - - if (SERVER_PORT != 9191 && [self start]) - { - NSRunAlertPanel(@"Unexpected Error", - [NSString stringWithFormat:@"%@ was not able to complete the last action you performed. Try again, and report the problem if it continues to occur.", appName], - @"OK", nil, nil); - } - else - { - NSRunAlertPanel(@"Unexpected Error", - [NSString stringWithFormat:@"A fatal error occurred. %@ could not recover and must terminate.", appName], - @"Terminate", nil, nil); - exit(1); - } - } -} - -- (void)dealloc -{ - [process release]; - [super dealloc]; -} - -@end diff --git a/Tools/NativeHost/WebPasteboardProxy.h b/Tools/NativeHost/WebPasteboardProxy.h deleted file mode 100644 index 887b95f4c..000000000 --- a/Tools/NativeHost/WebPasteboardProxy.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// WebPasteboardProxy.h -// NativeHost -// -// Created by Ross Boucher on 12/12/09. -// Copyright 2009 280 North. All rights reserved. -// - -#import - - -@interface WebPasteboardProxy : NSObject -{ - NSPasteboard *pasteboard; -} - -+ (id)pasteboardWithName:(NSString *)aName; - -@end diff --git a/Tools/NativeHost/WebPasteboardProxy.m b/Tools/NativeHost/WebPasteboardProxy.m deleted file mode 100644 index 6eba5c038..000000000 --- a/Tools/NativeHost/WebPasteboardProxy.m +++ /dev/null @@ -1,95 +0,0 @@ -// -// WebPasteboardProxy.m -// NativeHost -// -// Created by Ross Boucher on 12/12/09. -// Copyright 2009 280 North. All rights reserved. -// - -#import "WebPasteboardProxy.h" -#import "WebScripObject+Objective-J.h" -#import "BridgedMethods.h" - -NSMutableDictionary *WebPasteboardDictionary = nil; - -@implementation WebPasteboardProxy - -+ (void)initialize -{ - WebPasteboardDictionary = [[NSMutableDictionary dictionary] retain]; -} - -+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector -{ - return NO; -} - -+ (id)pasteboardWithName:(NSString *)aName -{ - if ([aName isEqual:@"CPGeneralPboard"]) - return [self pasteboardWithName:NSGeneralPboard]; - - id proxy = [WebPasteboardDictionary objectForKey:aName]; - if (!proxy) - { - proxy = [[self alloc] initWithPasteboard:[NSPasteboard pasteboardWithName:aName]]; - [WebPasteboardDictionary setObject:proxy forKey:aName]; - [proxy release]; - } - - return proxy; -} - -- (id)initWithPasteboard:(NSPasteboard *)aPasteboard -{ - if (self = [super init]) - { - pasteboard = [aPasteboard retain]; - } - - return self; -} - -- (void)dealloc -{ - [pasteboard release]; - [super dealloc]; -} - -- (int)changeCount -{ - return [pasteboard changeCount]; -} - -- (void)declareTypes:(WebScriptObject *)args -{ - [pasteboard declareTypes:[BridgedMethods arrayFromWebScriptObject:args] owner:self]; -} - -- (void)addTypes:(WebScriptObject *)args -{ - [pasteboard addTypes:[BridgedMethods arrayFromWebScriptObject:args ] owner:self]; -} - -- (NSArray *)types -{ - return [pasteboard types]; -} - -- (NSString *)stringForType:(NSString *)aType -{ - return [pasteboard stringForType:aType]; -} - -- (void)pasteboard:(NSPasteboard *)aPasteboard provideDataForType:(NSString *)aType -{ - NSString *name = aPasteboard == [NSPasteboard generalPasteboard] ? @"CPGeneralPboard" : [aPasteboard name]; - - NSString *data = [[[NSApp delegate] windowScriptObject] evaluateObjectiveJReturningString: - [NSString stringWithFormat:@"[[CPPasteboard pasteboardWithName:'%@'] stringForType:'%@']", name, aType] - ]; - - [aPasteboard setString:data forType:aType]; -} - -@end diff --git a/Tools/NativeHost/WebScripObject+Objective-J.h b/Tools/NativeHost/WebScripObject+Objective-J.h deleted file mode 100644 index 4b448574d..000000000 --- a/Tools/NativeHost/WebScripObject+Objective-J.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// WebScripObject+Objective-J.h -// NativeHost -// -// Created by Francisco Tolmasky on 9/1/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import -#import - - -@interface WebScriptObject (ObjectiveJ) - -- (id)evaluateObjectiveJ:(NSString *)aString; -- (NSString *)evaluateObjectiveJReturningString:(NSString *)aString; - -- (id)bridgeSelector:(SEL)aSelector; -- (id)bridgeSelector:(SEL)aSelector withObject:(id)anObject; -- (id)bridgeSelector:(SEL)aSelector withObjects:(NSArray *)array; - -@end diff --git a/Tools/NativeHost/WebScripObject+Objective-J.m b/Tools/NativeHost/WebScripObject+Objective-J.m deleted file mode 100644 index d1be2df47..000000000 --- a/Tools/NativeHost/WebScripObject+Objective-J.m +++ /dev/null @@ -1,46 +0,0 @@ -// -// WebScripObject+Objective-J.m -// NativeHost -// -// Created by Francisco Tolmasky on 9/1/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "WebScripObject+Objective-J.h" - - -@implementation WebScriptObject (ObjectiveJ) - -- (id)evaluateObjectiveJ:(NSString *)aString -{ - return [self evaluateWebScript:[NSString stringWithFormat:@"(ObjectiveJ.eval(decodeURIComponent(\"%@\")))", [aString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], nil]]; -} - -- (NSString *)evaluateObjectiveJReturningString:(NSString *)aString -{ - return [self evaluateWebScript:[NSString stringWithFormat:@"String(ObjectiveJ.eval(decodeURIComponent(\"%@\")))", [aString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], nil]]; -} - -- (id)bridgeSelector:(SEL)aSelector -{ - return [self bridgeSelector:aSelector withObjects:nil]; -} - -- (id)bridgeSelector:(SEL)aSelector withObject:(id)anObject -{ - return [self bridgeSelector:aSelector withObjects:[NSArray arrayWithObject:anObject]]; -} - -- (id)bridgeSelector:(SEL)aSelector withObjects:(NSArray *)objects -{ - [self evaluateWebScript:@"objj_object.prototype.__objj_msgSend = function() { return objj_msgSend.apply(null, arguments); }"]; - - NSArray * arguments = [NSArray arrayWithObjects:self, NSStringFromSelector(aSelector), nil]; - - if (objects) - arguments = [arguments arrayByAddingObjectsFromArray:objects]; - - return [self callWebScriptMethod:@"__objj_msgSend" withArguments:arguments]; -} - -@end diff --git a/Tools/NativeHost/WebWindow.h b/Tools/NativeHost/WebWindow.h deleted file mode 100644 index a7feb9fac..000000000 --- a/Tools/NativeHost/WebWindow.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// WebWindow.h -// NativeHost -// -// Created by Francisco Tolmasky on 10/18/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import - - -typedef enum _CPWindowShadowStyle -{ - CPStandardWindowShadowStyle = 0, - CPMenuWindowShadowStyle = 1, - CPPanelWindowShadowStyle = 2, - CPCustomWindowShadowStyle = 3 -} CPWindowShadowStyle; - -@interface WebWindow : NSWindow -{ - NSView * leftMouseDownView; - NSView * rightMouseDownView; - - WebView * webView; - NSView * shadowView; - - BOOL hasShadow; - CPWindowShadowStyle shadowStyle; -} - -+ (WebWindow *)webWindow; - -- (WebView *)webView; - -- (BOOL)hitTest:(NSPoint)aPoint; - -- (BOOL)hasShadow; -- (void)setHasShadow:(BOOL)shouldHaveShadow; - -- (void)setShadowStyle:(CPWindowShadowStyle)aStyle; -- (CPWindowShadowStyle)shadowStyle; - -@end diff --git a/Tools/NativeHost/WebWindow.m b/Tools/NativeHost/WebWindow.m deleted file mode 100644 index 1dc25e4a1..000000000 --- a/Tools/NativeHost/WebWindow.m +++ /dev/null @@ -1,515 +0,0 @@ -// -// WebWindow.m -// NativeHost -// -// Created by Francisco Tolmasky on 10/18/09. -// Copyright 2009 280 North, Inc.. All rights reserved. -// - -#import "WebWindow.h" - - -static NSMutableArray * DisabledWindows; - -CFMachPortRef tap_port; - -CGEventRef headTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) -{ - // It's dangerous to fail in this code: could disable mousedown system-wide. So just try catch it all. - @try - { - if (type == kCGEventLeftMouseDown) - { - CGPoint location = CGEventGetLocation(event); - NSPoint NSLocation = NSMakePoint(location.x, location.y); - - for (NSWindow * window in [NSApp windows]) - { - if ([window isKindOfClass:[WebWindow class]] && ![(WebWindow *)window hitTest:NSLocation]) - { - [window setIgnoresMouseEvents:YES]; - [window performSelector:@selector(setIgnoresMouseEvents:) withObject:NO afterDelay:1.0]; - - [DisabledWindows addObject:window]; - } - } - } - else if (type == kCGEventTapDisabledByTimeout) - CGEventTapEnable(tap_port, YES); - - } - @catch (NSException * anException) - { - } - - return event; -} - - -@interface WebWindowContentView : NSView -{ -} -@end - -@implementation WebWindow - -+ (void)enableAllWindows -{ - [DisabledWindows makeObjectsPerformSelector:@selector(stopIgnoringMouseEvents)]; - [DisabledWindows removeAllObjects]; -} - -+ (void)initialize -{ - if (self != [WebWindow class]) - return; - - DisabledWindows = [[NSMutableArray alloc] init]; - - //| CGEventMaskBit(kCGEventTapDisabledByTimeout) - tap_port = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, - kCGEventTapOptionDefault, - CGEventMaskBit(kCGEventLeftMouseDown), - headTapCallback, NULL); - - if (NULL == tap_port) - { - fprintf(stderr, "Error creating event tap\n"); - return; - } - - /* Create a run loop source from the tap port, add it to my run loop - * and start executing the loop - */ - CFRunLoopSourceRef tap_source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, tap_port, 0); - - if (NULL == tap_source) - { - fprintf(stderr, "Error converting port to run loop source\n"); - - if (tap_port != NULL) - CFRelease(tap_port); - - return; - } - - CFRunLoopAddSource(CFRunLoopGetCurrent(), tap_source, kCFRunLoopCommonModes); -} - -- (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)shouldDeferCreation -{ - self = [super initWithContentRect:aContentRect styleMask:NSBorderlessWindowMask backing:aBufferingType defer:shouldDeferCreation]; - - if (self) - { - id delegate = [NSApp delegate]; - - shadowView = [[WebWindowContentView alloc] init]; - - [self setContentView:shadowView]; - - webView = [[WebView alloc] initWithFrame:NSZeroRect]; - - [webView setDrawsBackground:NO]; - [webView setUIDelegate:delegate]; - [webView setFrameLoadDelegate:delegate]; - [webView setResourceLoadDelegate:delegate]; - [webView setPolicyDelegate:delegate]; - [webView setShouldCloseWithWindow:YES]; - - [shadowView addSubview:webView]; - - [self setBackgroundColor:[NSColor clearColor]]; - [self setOpaque:NO]; - [self setIgnoresMouseEvents:NO]; - [self setReleasedWhenClosed:YES]; - [super setHasShadow:NO]; - } - - return self; -} - -- (void)setFrame:(NSRect)aFrame display:(BOOL)shouldDisplay -{ - [webView setFrame:NSMakeRect(33.0, 33.0, NSWidth(aFrame), NSHeight(aFrame))]; - [super setFrame:NSInsetRect(aFrame, -33.0, -33.0) display:YES]; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:self]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeKeyNotification object:self]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResignKeyNotification object:self]; - - [shadowView release]; - [webView release]; - [super dealloc]; -} - -- (BOOL)canBecomeKeyWindow -{ - // Necessary since this apparently returns NO for borderless windows. - return YES; -} - -- (NSView *)webHitTest:(NSPoint)aPoint -{ - NSPoint locationInWebView = [[self contentView] convertPoint:aPoint fromView:nil]; - - return [(NSView *)[self contentView] hitTest:locationInWebView]; -} - -- (void)sendEvent:(NSEvent *)anEvent -{ - NSInteger type = [anEvent type]; - - if (type == NSLeftMouseDown) - { - NSView * view = [self webHitTest:[anEvent locationInWindow]]; - - leftMouseDownView = view; - - [view mouseDown:anEvent]; - } - - else if (type == NSLeftMouseDragged) - [leftMouseDownView mouseDragged:anEvent]; - - else if (type == NSLeftMouseUp) - [leftMouseDownView mouseUp:anEvent]; - - else if (type == NSRightMouseDown) - { - NSView * view = [self webHitTest:[anEvent locationInWindow]]; - - rightMouseDownView = view; - - [view rightMouseDown:anEvent]; - } - else if (type == NSRightMouseDragged) - [rightMouseDownView rightMouseDragged:anEvent]; - - else if (type == NSRightMouseUp) - [rightMouseDownView rightMouseUp:anEvent]; - - else - [super sendEvent:anEvent]; - - // FIXME: other -} - -// Override this to avoid the beep from unhandled events. -- (void)keyDown:(NSEvent *)anEvent -{ -} - -+ (WebWindow *)webWindow -{ - return [[WebWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; -} - -- (WebView *)webView -{ - return webView; -} - -- (void)updateShadow -{ - [super setHasShadow:hasShadow && shadowStyle == CPCustomWindowShadowStyle]; - [shadowView setNeedsDisplay:YES]; -} - -- (BOOL)hasShadow -{ - return hasShadow; -} - -- (void)setHasShadow:(BOOL)shouldHaveShadow -{ - if (hasShadow == shouldHaveShadow) - return; - - hasShadow = shouldHaveShadow; - - [self updateShadow]; -} - -- (CPWindowShadowStyle)shadowStyle -{ - return shadowStyle; -} - -- (void)setShadowStyle:(CPWindowShadowStyle)aStyle -{ - if (shadowStyle == aStyle) - return; - - shadowStyle = aStyle; - - [self updateShadow]; -} - -- (BOOL)hitTest:(NSPoint)aPoint -{ - NSInteger windowNumber = [[[webView windowScriptObject] valueForKey:@"cpWindowNumber"] intValue]; - -#if LOGGING - WebScriptObject * frame = [[[NSApp delegate] windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"(objj_msgSend(objj_msgSend(CPApp, \"windowWithWindowNumber:\", %d), \"frame\"))", windowNumber]], - * origin = [frame valueForKey:@"origin"], - * size = [frame valueForKey:@"size"]; - - NSLog(@"(%f, %f) in { %f, %f, %f, %f }", aPoint.x, aPoint.y, [[origin valueForKey:@"x"] floatValue], [[origin valueForKey:@"y"] floatValue], [[size valueForKey:@"width"] floatValue], [[size valueForKey:@"height"] floatValue]); -#endif - - return [[[[NSApp delegate] windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"(CGRectContainsPoint(objj_msgSend(objj_msgSend(CPApp, \"windowWithWindowNumber:\", %d), \"frame\"), CGPointMake(%f, %f)))", windowNumber, aPoint.x, aPoint.y]] boolValue]; -} - -- (void)stopIgnoringMouseEvents -{ - [self setIgnoresMouseEvents:NO]; -} - -- (void)becomeKeyWindow -{ - [super becomeKeyWindow]; - - [self updateShadow]; -} - -- (void)resignKeyWindow -{ - [super resignKeyWindow]; - - [self updateShadow]; -} - -@end - -@interface NSImage (Additions) - -- (void)drawInRect:(NSRect)aRect slices:(CGFloat [])slices; - -@end - -@implementation NSImage (Additions) - -- (void)drawInRect:(NSRect)aRect slices:(CGFloat [])slices -{ - NSRect imageBounds = NSMakeRect(0.0, 0.0, [self size].width, [self size].height); - - [self drawInRect:NSMakeRect(0.0, 0.0, slices[0], slices[1]) - fromRect:NSMakeRect(0.0, 0.0, slices[0], slices[1]) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(NSMaxX(aRect) - slices[2], 0.0, slices[2], slices[1]) - fromRect:NSMakeRect(NSMaxX(imageBounds) - slices[2], 0.0, slices[2], slices[1]) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(0.0, NSMaxY(aRect) - slices[3], slices[0], slices[3]) - fromRect:NSMakeRect(0.0, NSMaxY(imageBounds) - slices[3], slices[0], slices[3]) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(NSMaxX(aRect) - slices[2], NSMaxY(aRect) - slices[3], slices[2], slices[3]) - fromRect:NSMakeRect(NSMaxX(imageBounds) - slices[2], NSMaxY(imageBounds) - slices[3], slices[2], slices[3]) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(slices[0], 0.0, NSWidth(aRect) - slices[0] - slices[2], slices[1]) - fromRect:NSMakeRect(slices[0], 0.0, 1.0, slices[1]) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(0.0, slices[1], slices[0], NSHeight(aRect) - slices[1] - slices[3]) - fromRect:NSMakeRect(0.0, slices[1], slices[0], 1.0) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(NSMaxX(aRect) - slices[2], slices[1], slices[2], NSHeight(aRect) - slices[1] - slices[3]) - fromRect:NSMakeRect(NSMaxX(imageBounds) - slices[2], slices[1], slices[2], 1.0) - operation:NSCompositeSourceOver - fraction:1.0]; - - [self drawInRect:NSMakeRect(slices[0], NSMaxY(aRect) - slices[3], NSWidth(aRect) - slices[0] - slices[2], slices[3]) - fromRect:NSMakeRect(slices[0], NSMaxY(imageBounds) - slices[3], 1.0, slices[3]) - operation:NSCompositeSourceOver - fraction:1.0]; -} - -@end - -@implementation WebWindowContentView : NSView -{ -} - -static float OUTlINE_HORIZONTAL_INSET = 33.0; -static float OUTlINE_VERTICAL_INSET = 33.0; - -- (void)drawStandardActiveShadowInRect:(NSRect)aRect -{ - CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; - - CGRect bounds = CGRectInset(*(CGRect *)&aRect, OUTlINE_HORIZONTAL_INSET - 0.5, OUTlINE_VERTICAL_INSET - 0.5); - - CGColorRef shadowColor = CGColorCreateGenericGray(0.0, 0.8); - CGContextSetShadowWithColor (context, CGSizeMake(0.0, -10.0), 100.0, shadowColor); - CGColorRelease(shadowColor); - - CGColorRef fillColor = CGColorCreateGenericGray(1.0, 1.0); - CGColorRef strokeColor = CGColorCreateGenericGray(0.0, 0.2); - - CGContextSetFillColorWithColor(context, fillColor); - CGContextSetStrokeColorWithColor(context, strokeColor); - - CGColorRelease(fillColor); - CGColorRelease(strokeColor); - - CGContextBeginPath(context); - - CGContextAddArc(context, CGRectGetMinX(bounds) + 5.0, CGRectGetMaxY(bounds) - 5.0, 5.0, M_PI, M_PI_2, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 5.0, CGRectGetMaxY(bounds) - 5.0, 5.0, M_PI_2, 0, YES); - CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), CGRectGetMinY(bounds)); - CGContextAddLineToPoint(context, CGRectGetMinX(bounds), CGRectGetMinY(bounds)); - - CGContextClosePath(context); - - CGContextDrawPath(context, kCGPathFillStroke); -} - -- (void)drawStandardInactiveShadowInRect:(NSRect)aRect -{ - CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; - - CGRect bounds = CGRectInset(*(CGRect *)&aRect, OUTlINE_HORIZONTAL_INSET - 0.5, OUTlINE_VERTICAL_INSET - 0.5); - - CGColorRef shadowColor = CGColorCreateGenericGray(0.0, 0.5); - CGContextSetShadowWithColor (context, CGSizeMake(0.0, -10.0), 40.0, shadowColor); - CGColorRelease(shadowColor); - - CGColorRef fillColor = CGColorCreateGenericGray(1.0, 1.0); - CGColorRef strokeColor = CGColorCreateGenericGray(0.0, 0.2); - - CGContextSetFillColorWithColor(context, fillColor); - CGContextSetStrokeColorWithColor(context, strokeColor); - - CGColorRelease(fillColor); - CGColorRelease(strokeColor); - - CGContextBeginPath(context); - - CGContextAddArc(context, CGRectGetMinX(bounds) + 5.0, CGRectGetMaxY(bounds) - 5.0, 5.0, M_PI, M_PI_2, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 5.0, CGRectGetMaxY(bounds) - 5.0, 5.0, M_PI_2, 0, YES); - CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), CGRectGetMinY(bounds)); - CGContextAddLineToPoint(context, CGRectGetMinX(bounds), CGRectGetMinY(bounds)); - - CGContextClosePath(context); - - CGContextDrawPath(context, kCGPathFillStroke); -} - -- (void)drawMenuShadowInRect:(NSRect)aRect -{ - CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; - - CGRect bounds = CGRectInset(*(CGRect *)&aRect, OUTlINE_HORIZONTAL_INSET - 0.5, OUTlINE_VERTICAL_INSET - 0.5); - - CGColorRef shadowColor = CGColorCreateGenericGray(0.0, 0.5); - CGContextSetShadowWithColor (context, CGSizeMake(0.0, -10.0), 30.0, shadowColor); - CGColorRelease(shadowColor); - - CGColorRef fillColor = CGColorCreateGenericGray(1.0, 1.0); - CGColorRef strokeColor = CGColorCreateGenericGray(0.0, 0.2); - - CGContextSetFillColorWithColor(context, fillColor); - CGContextSetStrokeColorWithColor(context, strokeColor); - - CGColorRelease(fillColor); - CGColorRelease(strokeColor); - - CGContextBeginPath(context); - - CGContextAddArc(context, CGRectGetMinX(bounds) + 3.0, CGRectGetMaxY(bounds) - 3.0, 2.0, M_PI, M_PI_2, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 3.0, CGRectGetMaxY(bounds) - 3.0, 2.0, M_PI_2, 0, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 3.0, CGRectGetMinY(bounds) + 3.0, 2.0, 0, 3 * M_PI_2, YES); - CGContextAddArc(context, CGRectGetMinX(bounds) + 3.0, CGRectGetMinY(bounds) + 3.0, 2.0, 3 * M_PI_2, M_PI, YES); - - CGContextClosePath(context); - - CGContextDrawPath(context, kCGPathFill);//Stroke); - -/* - CGContextBeginPath(context); - - CGContextAddArc(context, CGRectGetMinX(bounds) + 3.0, CGRectGetMaxY(bounds) - 3.0, 2.0, M_PI, M_PI_2, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 3.0, CGRectGetMaxY(bounds) - 3.0, 2.0, M_PI_2, 0, YES); - CGContextAddArc(context, CGRectGetMaxX(bounds) - 3.0, CGRectGetMinY(bounds) + 3.0, 2.0, 0, 3 * M_PI_2, YES); - CGContextAddArc(context, CGRectGetMinX(bounds) + 3.0, CGRectGetMinY(bounds) + 3.0, 2.0, 3 * M_PI_2, M_PI, YES); - - CGContextClosePath(context); - - CGContextSetFillColorWithColor(context, CGColorGetConstantColor(kCGColorClear)); - - CGContextSetBlendMode(context, kCGBlendModeCopy); - CGContextDrawPath(context, kCGPathFill); -*/ -} - -- (NSImage *)shadowImageWithSelector:(SEL)aSelector -{ - static NSMutableDictionary * images = nil; - - if (!images) - images = [[NSMutableDictionary alloc] init]; - - NSString * name = NSStringFromSelector(aSelector); - NSImage * image = [images objectForKey:name]; - - if (!image) - { - image = [[NSImage alloc] initWithSize:NSMakeSize(100.0, 100.0)]; - - [image lockFocus]; - objc_msgSend(self, aSelector, NSMakeRect(0.0, 0.0, 100.0, 100.0)); - [image unlockFocus]; - - [images setObject:image forKey:name]; - - [image release]; - } - - return image; -} - -- (void)drawShadowWithSelector:(SEL)aSelector inRect:(NSRect)aRect -{ - CGFloat slices[] = { 40.0, 49.0, 40.0, 49.0 }; - - if (NSWidth(aRect) > 100.0 || NSHeight(aRect) > 100.0) - [[self shadowImageWithSelector:aSelector] drawInRect:aRect slices:slices]; - else - objc_msgSend(self, aSelector, aRect); -} - -- (void)drawRect:(NSRect)aRect -{ - WebWindow * window = (WebWindow *)[self window]; - NSRect bounds = [self bounds]; - - if (![window hasShadow]) - return; - - if ([window shadowStyle] == CPStandardWindowShadowStyle) - if ([window isKeyWindow]) - return [self drawShadowWithSelector:@selector(drawStandardActiveShadowInRect:) inRect:bounds]; - else - return [self drawShadowWithSelector:@selector(drawStandardInactiveShadowInRect:) inRect:bounds]; - - - if ([window shadowStyle] == CPMenuWindowShadowStyle) - return [self drawShadowWithSelector:@selector(drawMenuShadowInRect:) inRect:bounds]; -} - -@end - diff --git a/Tools/NativeHost/icon.icns b/Tools/NativeHost/icon.icns deleted file mode 100644 index cd9ecb6bb..000000000 Binary files a/Tools/NativeHost/icon.icns and /dev/null differ diff --git a/Tools/NativeHost/main.m b/Tools/NativeHost/main.m deleted file mode 100644 index 2a040439e..000000000 --- a/Tools/NativeHost/main.m +++ /dev/null @@ -1,23 +0,0 @@ -// -// main.m -// NativeHost -// -// Created by Francisco Tolmasky on 5/24/09. -// Copyright 280 North, Inc. 2009. All rights reserved. -// - -#import -#import "Application.h" - -int interactive = 0; - -int main(int argc, char *argv[]) -{ - if (argc > 1 && strcmp(argv[1], "-i") == 0) { - interactive = 1; - } - - [Application sharedApplication]; - - return NSApplicationMain(argc, (const char **) argv); -} diff --git a/Tools/capp/Resources/Templates/NibApplication/Jakefile b/Tools/capp/Resources/Templates/NibApplication/Jakefile index a25464947..fd053cf00 100644 --- a/Tools/capp/Resources/Templates/NibApplication/Jakefile +++ b/Tools/capp/Resources/Templates/NibApplication/Jakefile @@ -82,18 +82,6 @@ task ("deploy", ["release"], function() printResults("Deployment") }); -task ("desktop", ["release"], function() -{ - FILE.mkdirs(FILE.join("Build", "Desktop", projectName)); - require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", projectName), FILE.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app")); - printResults("Desktop") -}); - -task ("run-desktop", ["desktop"], function() -{ - OS.system([FILE.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app", "Contents", "MacOS", "NativeHost"), "-i"]); -}); - function printResults(configuration) { print("----------------------------");