|
From: John M M. <jo...@us...> - 2004-01-07 05:24:13
|
Update of /cvsroot/squeak/squeak/platforms/Mac OS/vm
In directory sc8-pr-cvs1:/tmp/cvs-serv32555/squeak/platforms/Mac OS/vm
Modified Files:
sqMacNSPlugin.c
Log Message:
3.7.1b2 Add locking clean for termination to prevent race conditions. Add unicode vmpath name support. Add post/get url logic that used apis that respect proxy settings. Note that Safari has broken post/get url browser callbacks which are unfixed as of Jan 2004
Index: sqMacNSPlugin.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/Mac OS/vm/sqMacNSPlugin.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** sqMacNSPlugin.c 20 Nov 2003 01:33:43 -0000 1.14
--- sqMacNSPlugin.c 7 Jan 2004 05:24:10 -0000 1.15
***************
*** 65,68 ****
--- 65,69 ----
Aug 2001 JMM 3.0.24 rework of security logic, remove explicit call
May 2002 JMM 3.2.7b1 Ok lets see if the sucker will compile again
+ 3.7.0bx Nov 24th, 2003 JMM gCurrentVMEncoding
**********/
***************
*** 73,76 ****
--- 74,80 ----
#include "sqMacTime.h"
#include "npapi.h"
+ #include "sqMacUIConstants.h"
+ #include "sqMacImageIO.h"
+ #include "sqMacEncoding.h"
#include <Events.h>
***************
*** 111,115 ****
//#define ENABLE_URL_FETCH
#define IMAGE_NAME "SqueakPlugin.image"
- #define VMPATH_SIZE 300
/*** Exported Primitives ***/
--- 115,118 ----
***************
*** 161,169 ****
extern int setFullScreenFlag(int value);
- extern char documentName[]; /* full path to document file */
- extern char imageName[]; /* full path to image file */
- extern char shortImageName[]; /* just the image file name */
- extern char vmPath[]; /* full path to interpreter's directory */
-
extern struct VirtualMachine *interpreterProxy;
--- 164,167 ----
***************
*** 255,258 ****
--- 253,258 ----
NP_Port *getNP_Port(void);
void waitAFewMilliseconds(void);
+ void GetTempFSSpec(FSSpec *spec);
+
/*** Initialize/Shutdown ***/
***************
*** 302,305 ****
--- 302,306 ----
void NPP_Shutdown(void) {
+ exitRequested = true;
#if defined ( __APPLE__ ) && defined ( __MACH__ )
pthread_mutex_unlock(&gEventDrawLock);
***************
*** 370,373 ****
--- 371,375 ----
long i;
+ exitRequested = true;
#if defined ( __APPLE__ ) && defined ( __MACH__ )
pthread_mutex_unlock(&gEventDrawLock);
***************
*** 753,756 ****
--- 755,760 ----
void EndDraw(void) {
+ if (exitRequested)
+ return;
SetOrigin(gSavePortPortRect.left, gSavePortPortRect.top);
SetClip(gSavePortClipRgn);
***************
*** 769,773 ****
pthread_mutex_lock(&gEventDrawLock);
#endif
!
port = (NP_Port *) netscapeWindow->window;
--- 773,782 ----
pthread_mutex_lock(&gEventDrawLock);
#endif
! if (exitRequested) {
! #if defined ( __APPLE__ ) && defined ( __MACH__ )
! pthread_mutex_unlock(&gEventDrawLock);
! #endif
! return;
! }
port = (NP_Port *) netscapeWindow->window;
***************
*** 811,814 ****
--- 820,825 ----
StartDraw();
+ if (exitRequested)
+ return;
dstRect.right = width;
***************
*** 898,901 ****
--- 909,913 ----
/*** URL Requests ***/
+ int CFNetworkGoGetURL(NPP instance, const char* url, const char* window, void* notifyData);
int URLRequestCreate(char *url, char *target, int semaIndex) {
***************
*** 920,927 ****
--- 932,943 ----
strncpy(mail,url,7);
mail[7] = 0x00;
+ #ifdef TARGET_API_MAC_CARBON
+ err = CFNetworkGoGetURL(thisInstance, url, target, (void *) notifyData);
+ #else
if (CaseInsensitiveMatch(mail,"mailto:"))
NPN_GetURLNotify(thisInstance, url, "_self", (void *) notifyData);
else
NPN_GetURLNotify(thisInstance, url, target, (void *) notifyData);
+ #endif
return handle;
***************
*** 945,952 ****
--- 961,1004 ----
notifyData = (urlRequests[handle].id << 8) + handle;
+ #ifdef TARGET_API_MAC_CARBON
+ {
+ OSStatus status; //kURLDisplayProgressFlag
+ URLState currentState;
+ URLReference URLRef;
+
+ status = URLNewReference(url, &URLRef);
+ if (status == noErr) {
+ FSSpec tempFileSpec;
+ char fileName[MAX_STRING_LENGTH + 1];
+
+ // The URLSetProperty function enables you to set those property values identified by the following
+ // constants: kURLPassword, kURLUserName, kURLPassword, kURLHTTPRequestMethod, kURLHTTPRequestHeader,
+ // kURLHTTPRequestBody, and kURLHTTPUserAgent.
+ URLSetProperty(URLRef, kURLHTTPRequestMethod, "POST", 4);
+ URLSetProperty(URLRef, kURLHTTPRequestBody, buffer, strlen(buffer));
+ GetTempFSSpec(&tempFileSpec);
+ status = URLOpen(URLRef, &tempFileSpec, 0, NULL, NULL, NULL);
+ currentState = kURLNullState;
+ while (status == noErr && !(currentState == kURLCompletedState || currentState == kURLErrorOccurredState)){
+ URLIdle();
+ status = URLGetCurrentState (URLRef, ¤tState);
+ }
+ URLGetError(URLRef,&status);
+ URLDisposeReference(URLRef);
+ if (status != noErr)
+ return -1;
+ PathToFile(fileName,MAX_STRING_LENGTH, &tempFileSpec,gCurrentVMEncoding);
+ URLRequestCompleted(notifyData, fileName);
+ } else
+ return -1;
+ }
+
+ #else
error = NPN_PostURLNotify(thisInstance, url, window, strlen(buffer), buffer, false, (void *) notifyData);
if (error != NPERR_NO_ERROR) {
return -1;
}
+ #endif
+
return handle;
***************
*** 962,967 ****
--- 1014,1026 ----
urlRequests[requestHandle].status = STATUS_IDLE;
urlRequests[requestHandle].semaIndex = 0;
+
+ if (urlRequests[requestHandle].fileName[0] != NULL) {
+ sqFileDeleteNameSize((int) &urlRequests[requestHandle].fileName, strlen(urlRequests[requestHandle].fileName));
+ urlRequests[requestHandle].fileName[0] = 0x00;
+ }
+
urlRequests[requestHandle].fileName[0] = 0;
urlRequests[requestHandle].buffer = null;
+
}
***************
*** 1012,1017 ****
}
if (urlRequests[handle].id == (notifyData >> 8)) {
! if (fileName != null)
strncpy(urlRequests[handle].fileName, fileName, MAX_STRING_LENGTH);
if (urlRequests[handle].buffer != null) {
NPN_MemFree(urlRequests[handle].buffer);
--- 1071,1077 ----
}
if (urlRequests[handle].id == (notifyData >> 8)) {
! if (fileName != null) {
strncpy(urlRequests[handle].fileName, fileName, MAX_STRING_LENGTH);
+ }
if (urlRequests[handle].buffer != null) {
NPN_MemFree(urlRequests[handle].buffer);
***************
*** 1175,1183 ****
OSErr err;
FSSpec fileSpec;
/* clear all path and file names */
! imageName[0] = shortImageName[0] = documentName[0] = vmPath[0] = 0;
!
! strcpy(shortImageName, squeakPluginImageName);
/* get the path to the sytem folder preference area*/
--- 1235,1242 ----
OSErr err;
FSSpec fileSpec;
+ char path[VMPATH_SIZE+1];
/* clear all path and file names */
! SetShortImageNameViaString(squeakPluginImageName,gCurrentVMEncoding);
/* get the path to the sytem folder preference area*/
***************
*** 1189,1204 ****
// Look for folder, if not found abort */
strcpy(imageInPreferenceFolder,":Squeak:Internet:");
! strcat(imageInPreferenceFolder,shortImageName);
CopyCStringToPascal(imageInPreferenceFolder,(unsigned char *) imageInPreferenceFolder);
err = FSMakeFSSpecCompat(vRefNum, dirID,(unsigned char *) imageInPreferenceFolder , &fileSpec);
if (err != noErr) {
! strcpy(imageName,"Problems finding the Internet folder in the Squeak Preference folder or finding the SqueakPlugin.image");
! return err;
}
/* set the vmPath */
! PathToDir(vmPath,VMPATH_SIZE, &fileSpec);
! strcpy(imageName, vmPath);
! strcat(imageName, shortImageName);
! return noErr;
}
--- 1248,1277 ----
// Look for folder, if not found abort */
strcpy(imageInPreferenceFolder,":Squeak:Internet:");
! strcat(imageInPreferenceFolder,squeakPluginImageName);
CopyCStringToPascal(imageInPreferenceFolder,(unsigned char *) imageInPreferenceFolder);
err = FSMakeFSSpecCompat(vRefNum, dirID,(unsigned char *) imageInPreferenceFolder , &fileSpec);
if (err != noErr) {
! /* New Behavior try to find the SqueakLand Folder in the Application's Folder */
! err = FindFolder(domain, kApplicationsFolderType, kDontCreateFolder, &vRefNum, &dirID);
! if (err != noErr)
! goto error;
! strcpy(imageInPreferenceFolder,":SqueakLand:Squeak:Internet:");
! strcat(imageInPreferenceFolder,squeakPluginImageName);
! CopyCStringToPascal(imageInPreferenceFolder,(unsigned char *) imageInPreferenceFolder);
! err = FSMakeFSSpecCompat(vRefNum, dirID,(unsigned char *) imageInPreferenceFolder , &fileSpec);
! if (err != noErr)
! goto error;
}
/* set the vmPath */
! SetVMPath(&fileSpec);
! getVMPathWithEncoding(path,gCurrentVMEncoding);
! strcat(path, squeakPluginImageName);
! SetImageNameViaString(path,gCurrentVMEncoding);
! return noErr;
!
! error:
! SetImageNameViaString("Problems finding the Internet folder in the Squeak Preference folder or finding the SqueakPlugin.image",gCurrentVMEncoding);
! return err;
!
}
***************
*** 1240,1243 ****
--- 1313,1350 ----
/*** Optional URL Fetch Primitives ***/
#ifdef ENABLE_URL_FETCH
+ #ifdef TARGET_API_MAC_CARBON
+
+ int CFNetworkGoGetURL(NPP instance, const char* url, const char* window, void* notifyData)
+ {
+ OSStatus error;
+ FSSpec tempFileSpec;
+ char fileName[MAX_STRING_LENGTH + 1];
+
+ GetTempFSSpec(&tempFileSpec);
+ error = URLSimpleDownload (url,&tempFileSpec,NULL,NULL,NULL,notifyData);
+ PathToFile(fileName,MAX_STRING_LENGTH, &tempFileSpec,gCurrentVMEncoding);
+ URLRequestCompleted(notifyData, fileName);
+ }
+
+ void GetTempFSSpec(FSSpec *spec) {
+ char tempName[1024+1];
+ CFURLRef sillyThing;
+ CFStringRef filePath;
+ FSRef theFSRef;
+ OSErr err;
+
+ strcpy(tempName,tmpnam(0));
+
+ filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) tempName,strlen(tempName),kCFStringEncodingUTF8,false);
+ sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLPOSIXPathStyle,false);
+ CFRelease(filePath);
+ filePath = CFURLCopyFileSystemPath (sillyThing, kCFURLHFSPathStyle);
+ CFRelease(sillyThing);
+ CFStringGetCString (filePath,tempName, 1024, kCFStringEncodingMacRoman);
+ CFRelease(filePath);
+ makeFSSpec(tempName, strlen(tempName),spec);
+ }
+
+ #endif
int primitivePluginDestroyRequest(void) {
/* Args: handle.
***************
*** 1523,1527 ****
}
-
void OpenFileReadOnly(SQFile *f, char *MacfileName) {
/* Opens the given file for reading using the supplied sqFile
--- 1630,1633 ----
***************
*** 1532,1536 ****
failure flag if not successful. */
char fileName[1024];
- sqImageFile remember;
if (*MacfileName == NULL) {
--- 1638,1641 ----
***************
*** 1539,1544 ****
}
sqFilenameFromStringOpen(fileName,(long) MacfileName, strlen(MacfileName));
-
f->file = fopen(fileName, "rb");
f->writable = false;
--- 1644,1649 ----
}
sqFilenameFromStringOpen(fileName,(long) MacfileName, strlen(MacfileName));
f->file = fopen(fileName, "rb");
+
f->writable = false;
***************
*** 1727,1731 ****
int AbortIfFileURL(char *url)
{ char lookFor[6];
! int i=0,placement=0;
lookFor[5] = 0x00;
--- 1832,1836 ----
int AbortIfFileURL(char *url)
{ char lookFor[6];
! int placement=0;
lookFor[5] = 0x00;
|