Launching a web browser from Squeak?

John M McIntosh johnmci at smalltalkconsulting.com
Fri May 12 00:56:28 UTC 2006


mmm I'm sure there is some mac code that Michael made me write this  
morning.

Actually I'll note if you started a shell you could just do 'open  
URL...'
but using the proper API calls give  you a bit more control to figure  
out what happen.


openOSBrowserOnURI: uri
	MacLaunchServices callLSOpenCFURL: uri

callLSOpenCFURL: aURI
	| aURIString urlRef |

	aURIString := aURI printString.
	urlRef := MacCFURL callCFURLCreateFromString: aURIString.
	self apiLSOpenCFURLRef: urlRef outLaunchedURL: nil.
	MacCFType apiCFRelease: urlRef.

callCFURLCreateFromString: aString
	| byteArray length encoding createdURL |
	byteArray := aString asByteArray.
	length := aString size.
	encoding :=  0. "MacRoman"
	createdURL _ self apiCFURLCreateWithBytes: nil cString: byteArray  
length: length encoding: encoding base: nil.
	^createdURL
	
apiCFURLCreateWithBytes: allocator cString: aByteArray length:  
aLength encoding: aEncoding base: aURL
	<cdecl: MacCFURL* 'CFURLCreateWithBytes' (void* char* long long  
MacCFURL* ) module:'Carbon.framework'>
	^ self externalCallFailed

"CFURLRef CFURLCreateWithBytes (
    CFAllocatorRef allocator,
    const UInt8 *URLBytes,
    CFIndex length,
    CFStringEncoding encoding,
    CFURLRef baseURL
);"

apiLSOpenCFURLRef: inURL  outLaunchedURL: outURL

	<cdecl: long 'LSOpenCFURLRef' ( MacCFURL* MacCFURL*)  
module:'Carbon.framework'>
	^ self externalCallFailed

"OSStatus LSOpenCFURLRef (
    CFURLRef inURL,
    CFURLRef *outLaunchedURL
);"

apiCFRelease: aRef
	<cdecl: void 'CFRelease' (MacCFType*) module:'Carbon.framework'>
	^self externalCallFailed

"void CFRelease (
    CFTypeRef cf
);"

FFI class types are a exercise for the reader...



On 11-May-06, at 3:27 PM, Michael Rueger wrote:

> John Maloney wrote:
>> Does anyone know how to launch a Web browser from within Squeak? I  
>> need to be able to pass the URL to the browser to open. It would  
>> be really great if I could also tell the browser how big to be and  
>> where to open on the screen.
>> I realize the solution will probably be highly platform dependent;  
>> I'm interesting in solutions for Windows, Macs, and Linux.
>
> For Sophie we just solved that problem :-)
> Below is  the windows part, hot of the grill.
> The usual disclaimers about exploding CPUs etc apply...

--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===




More information about the Squeak-dev mailing list