[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
cblu
cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:55:11 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 1dd53417abc3de77d32ec9f54a33300da86b1868
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Feb 5 19:15:51 2002 +0000
Added support for the object tag. Added getPluginForURL in WKPluginDatabase. Now grabbing remaining info from plug-in resources
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@591 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/kwq/KWQKConfigBase.mm b/WebCore/kwq/KWQKConfigBase.mm
index 96f8f3e..05cdbb2 100644
--- a/WebCore/kwq/KWQKConfigBase.mm
+++ b/WebCore/kwq/KWQKConfigBase.mm
@@ -79,6 +79,11 @@ QString KConfigBase::readEntry(const char *pKey,
if(file == pluginsinfo){
WKPlugin *plugin;
+ NSArray *mimeTypes;
+ NSMutableString *bigMimeString;
+ NSString *bigMimeString2;
+ uint i;
+
plugin = [[[WKPluginDatabase installedPlugins] plugins] objectAtIndex:group];
if(strcmp(pKey, "name") == 0){
return NSSTRING_TO_QSTRING([plugin name]);
@@ -86,6 +91,20 @@ QString KConfigBase::readEntry(const char *pKey,
return NSSTRING_TO_QSTRING([plugin filename]);
}else if(strcmp(pKey, "description") == 0){
return NSSTRING_TO_QSTRING([plugin pluginDescription]);
+ }else if(strcmp(pKey, "mime") == 0){
+ mimeTypes = [plugin mimeTypes];
+ bigMimeString = [NSMutableString stringWithCapacity:1000];
+ for(i=0; i<[mimeTypes count]; i++){
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:0]]; // mime type
+ [bigMimeString appendString:@":"];
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:1]]; // mime's extension
+ [bigMimeString appendString:@":"];
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:2]]; // mime's description
+ [bigMimeString appendString:@";"];
+ }
+ bigMimeString2 = [NSString stringWithString:bigMimeString];
+ [bigMimeString2 retain];
+ return NSSTRING_TO_QSTRING(bigMimeString2);
}
}
if(tempQString == NULL) {
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index cda2dc5..4261c21 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -1586,7 +1586,7 @@ bool KHTMLPart::requestObject( khtml::RenderPart *frame, const QString &url, con
#ifdef _KWQ_
WKPluginWidget *pluginWidget;
- if(url.isEmpty() || serviceType.isEmpty()){
+ if(url.isEmpty()){
return FALSE;
}
pluginWidget = new WKPluginWidget(0, url, serviceType, args);
diff --git a/WebCore/kwq/KWQKHTMLPartImpl.mm b/WebCore/kwq/KWQKHTMLPartImpl.mm
index cda2dc5..4261c21 100644
--- a/WebCore/kwq/KWQKHTMLPartImpl.mm
+++ b/WebCore/kwq/KWQKHTMLPartImpl.mm
@@ -1586,7 +1586,7 @@ bool KHTMLPart::requestObject( khtml::RenderPart *frame, const QString &url, con
#ifdef _KWQ_
WKPluginWidget *pluginWidget;
- if(url.isEmpty() || serviceType.isEmpty()){
+ if(url.isEmpty()){
return FALSE;
}
pluginWidget = new WKPluginWidget(0, url, serviceType, args);
diff --git a/WebCore/kwq/WKPlugin.h b/WebCore/kwq/WKPlugin.h
index 397984f..78779cd 100644
--- a/WebCore/kwq/WKPlugin.h
+++ b/WebCore/kwq/WKPlugin.h
@@ -11,7 +11,7 @@
@interface WKPlugin : NSObject {
- NSDictionary *mimeTypes;
+ NSMutableArray *mimeTypes;
NSString *name, *executablePath, *filename, *pluginDescription;
BOOL isLoaded;
NPPluginFuncs pluginFuncs;
@@ -36,9 +36,10 @@
}
- (BOOL)initializeWithPath:(NSString *)plugin;
+- (BOOL)getPluginInfoForResourceFile:(SInt16)resRef;
- (void)load;
- (void)unload;
-- (NSDictionary *)mimeTypes;
+- (NSArray *)mimeTypes;
- (NSString *)name;
- (NSString *)filename;
- (NSString *)executablePath;
@@ -58,6 +59,4 @@
- (NPP_HandleEventProcPtr)NPP_HandleEvent;
@end
-
-NSMutableDictionary *getMimeTypesForResourceFile(SInt16 resRef);
diff --git a/WebCore/kwq/WKPlugin.mm b/WebCore/kwq/WKPlugin.mm
index 6c7adda..59ae3b5 100644
--- a/WebCore/kwq/WKPlugin.mm
+++ b/WebCore/kwq/WKPlugin.mm
@@ -25,9 +25,8 @@
fileManager = [NSFileManager defaultManager];
fileInfo = [fileManager fileAttributesAtPath:plugin traverseLink:YES];
- if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"]){
+ if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"]){ // plug-in with resource fork
if([[fileInfo objectForKey:@"NSFileHFSTypeCode"] unsignedLongValue] == 1112690764){ // 1112690764 = 'BRPL'
- name = [plugin lastPathComponent]; // FIXME: Should the name of the plugin be the filename?
filename = [plugin lastPathComponent];
executablePath = plugin;
err = FSPathMakeRef((UInt8 *)[plugin cString], &fref, NULL);
@@ -40,23 +39,22 @@
KWQDebug("WKPlugin: FSOpenResFile failed. Can't open resource file: %s, Error=%d\n", [plugin cString], err);
return FALSE;
}
- mimeTypes = getMimeTypesForResourceFile(resRef);
- if(mimeTypes == nil) return FALSE;
- //FIXME: Need to get plug-in's description
+ if(![self getPluginInfoForResourceFile:resRef]){
+ return FALSE;
+ }
}else return FALSE;
- }else if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeDirectory"]){
+ }else if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeDirectory"]){ //bundle plug-in
pluginURL = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)plugin, kCFURLPOSIXPathStyle, TRUE);
bundle = CFBundleCreate(NULL, pluginURL);
bundle2 = [NSBundle bundleWithPath:plugin]; // CFBundleCopyExecutableURL doesn't return full path! Have to use NSBundle
CFBundleGetPackageInfo(bundle, &type, NULL);
if(type == 1112690764){ // 1112690764 = 'BRPL'
- name = [plugin lastPathComponent]; // FIXME: Should the name of the plugin be the filename?
filename = [plugin lastPathComponent];
executablePath = [bundle2 executablePath];
resRef = CFBundleOpenBundleResourceMap(bundle);
- mimeTypes = getMimeTypesForResourceFile(resRef);
- if(mimeTypes == nil) return FALSE;
- //FIXME: Need to get plug-in's description
+ if(![self getPluginInfoForResourceFile:resRef]){
+ return FALSE;
+ }
}else return FALSE;
CFRelease(bundle);
CFRelease(pluginURL);
@@ -64,13 +62,55 @@
}else{
return FALSE;
}
- [mimeTypes retain];
- [name retain];
+
[executablePath retain];
+ [filename retain];
isLoaded = FALSE;
return TRUE;
}
+- (BOOL)getPluginInfoForResourceFile:(SInt16)resRef{
+ Str255 theString;
+ char temp[300], description[600]; // I wish I didn't have to use these C strings
+ NSMutableArray *mime; // mime is an array containing the mime type, extension(s) and descriptions for that mime type.
+ NSString *tempString;
+ uint n, i;
+
+ mimeTypes = [NSMutableArray arrayWithCapacity:1];
+ UseResFile(resRef);
+ for(n=1, i=0; 1; n+=2, i++){
+ GetIndString(theString, 128, n);
+ CopyPascalStringToC(theString, temp);
+ if(!strcmp(temp, "")) break;
+ mime = [NSMutableArray arrayWithCapacity:3];
+ [mimeTypes insertObject:mime atIndex:i];
+ tempString = [NSString stringWithCString:temp];
+ [mime insertObject:tempString atIndex:0]; // mime type
+
+ GetIndString(theString, 128, n+1);
+ CopyPascalStringToC(theString, temp);
+ tempString = [NSString stringWithCString:temp];
+ [mime insertObject:tempString atIndex:1]; // mime's extension
+ }
+ for(i=1; i<=[mimeTypes count]; i++){
+ GetIndString(theString, 127, i);
+ CopyPascalStringToC(theString, temp);
+ tempString = [NSString stringWithCString:temp];
+ mime = [mimeTypes objectAtIndex:(i-1)];
+ [mime insertObject:tempString atIndex:2]; // mime's description
+ }
+ GetIndString(theString, 126, 1);
+ CopyPascalStringToC(theString, description);
+ pluginDescription = [NSString stringWithCString:description];
+ [pluginDescription retain];
+
+ GetIndString(theString, 126, 2);
+ CopyPascalStringToC(theString, temp);
+ name = [NSString stringWithCString:temp]; // plugin's name
+ [name retain];
+ [mimeTypes retain];
+ return TRUE;
+}
- (void)load{
OSErr err;
@@ -186,7 +226,7 @@
return NPP_HandleEvent;
}
-- (NSDictionary *)mimeTypes{
+- (NSArray *)mimeTypes{
return mimeTypes;
}
@@ -231,26 +271,10 @@
[desc appendString:@"\n"];
return desc;
}
+
@end
-NSMutableDictionary *getMimeTypesForResourceFile(SInt16 resRef){
- NSMutableDictionary *mimeDict;
- Str255 theString;
- char mimeString[200], extString[200];
- int n;
-
- mimeDict = [NSMutableDictionary dictionaryWithCapacity:1];
- UseResFile(resRef);
- for(n=1; 1; n+=2){
- GetIndString(theString, 128, n);
- CopyPascalStringToC(theString, mimeString);
- if(!strcmp(mimeString, "")) break;
- GetIndString(theString, 128, n+1);
- CopyPascalStringToC(theString, extString);
- [mimeDict setObject:[NSString stringWithCString:extString] forKey:[NSString stringWithCString:mimeString]];
- }
- return mimeDict;
-}
+
diff --git a/WebCore/kwq/WKPluginDatabase.h b/WebCore/kwq/WKPluginDatabase.h
index 8062bef..77ba266 100644
--- a/WebCore/kwq/WKPluginDatabase.h
+++ b/WebCore/kwq/WKPluginDatabase.h
@@ -16,6 +16,7 @@
+ (WKPluginDatabase *)installedPlugins;
- (WKPlugin *)getPluginForMimeType:(NSString *)mimeType;
+- (WKPlugin *)getPluginForURL:(NSString *)URL;
- (NSArray *) plugins;
@end
diff --git a/WebCore/kwq/WKPluginDatabase.mm b/WebCore/kwq/WKPluginDatabase.mm
index 3adc39d..9d3661f 100644
--- a/WebCore/kwq/WKPluginDatabase.mm
+++ b/WebCore/kwq/WKPluginDatabase.mm
@@ -24,21 +24,45 @@ static WKPluginDatabase *__WKPluginDatabase = nil;
// The first plugin with the specified mime type is returned. We may want to tie this to the defaults so that this is configurable.
- (WKPlugin *)getPluginForMimeType:(NSString *)mimeType{
- uint i;
+ uint i, n;
+ WKPlugin *plugin;
+ NSArray *mimeArray;
+
+ for(i=0; i<[plugins count]; i++){
+ plugin = [plugins objectAtIndex:i];
+ mimeArray = [plugin mimeTypes];
+ for(n=0; n<[mimeArray count]; n++){
+ if([[[mimeArray objectAtIndex:n] objectAtIndex:0] isEqualToString:mimeType]){
+ return plugin;
+ }
+ }
+ }
+ return nil;
+}
+
+- (WKPlugin *)getPluginForURL:(NSString *)URL{
+ uint i, n;
WKPlugin *plugin;
- NSDictionary *temp;
+ NSArray *mimeArray;
+ NSRange hasExtension;
+ NSString *extension;
+ extension = [URL pathExtension];
for(i=0; i<[plugins count]; i++){
plugin = [plugins objectAtIndex:i];
- temp = [plugin mimeTypes];
- if([[temp allKeys] containsObject:mimeType]){
- return plugin;
+ mimeArray = [plugin mimeTypes];
+ for(n=0; n<[mimeArray count]; n++){
+ hasExtension = [[[mimeArray objectAtIndex:n] objectAtIndex:1] rangeOfString:extension];
+ if(hasExtension.length){
+ return plugin;
+ }
}
}
- KWQDebug("No plug-in found for mime type: %s\n", [mimeType cString]);
return nil;
}
+
+
- (NSArray *) plugins{
return plugins;
}
diff --git a/WebCore/kwq/WKPluginView.h b/WebCore/kwq/WKPluginView.h
index cc97a98..25c7897 100644
--- a/WebCore/kwq/WKPluginView.h
+++ b/WebCore/kwq/WKPluginView.h
@@ -10,7 +10,6 @@
#include <qwidget.h>
#import <WKPlugin.h>
#include "npapi.h"
-#include <WCURLHandle.h>
typedef NPStream* NPS;
@@ -25,7 +24,7 @@ typedef NPStream* NPS;
-(void)stop;
@end
- at interface WKPluginView : NSQuickDrawView <WCURLHandleClient> {
+ at interface WKPluginView : NSQuickDrawView {
QWidget *widget;
WKPlugin *plugin;
WKPluginViewNullEventSender *eventSender;
@@ -42,8 +41,9 @@ typedef NPStream* NPS;
char **cAttributes, **cValues;
bool isFlipped, transferred, hidden;
- NSString *url, *mime;
+ NSString *url, *mime, *filename;
NSTrackingRectTag trackingTag;
+ NSFileHandle *file;
NPP_NewProcPtr NPP_New;
NPP_DestroyProcPtr NPP_Destroy;
@@ -95,3 +95,4 @@ typedef NPStream* NPS;
@end
+NSString* rootName(void);
diff --git a/WebCore/kwq/WKPluginView.mm b/WebCore/kwq/WKPluginView.mm
index a13fded..9d5428a 100644
--- a/WebCore/kwq/WKPluginView.mm
+++ b/WebCore/kwq/WKPluginView.mm
@@ -7,6 +7,8 @@
//
#import "WKPluginView.h"
+#include <WCURICacheData.h>
+#include <WCURICache.h>
#include <Carbon/Carbon.h>
#include "kwqdebug.h"
@@ -111,6 +113,8 @@
{
NPError npErr;
char cMime[200], cURL[800];
+ id <WCURICache> cache;
+ NSFileManager *fileManager;
//WindowRef windowRef;
//windowRef = [[self window] _windowRef]; // give the window a WindowRef
@@ -132,20 +136,23 @@
npErr = NPP_NewStream(instance, cMime, stream, FALSE, &transferMode);
KWQDebug("NPP_NewStream: %d\n", npErr);
+ cache = WCGetDefaultURICache();
if(transferMode == NP_NORMAL){
KWQDebug("Stream type: NP_NORMAL\n");
- //[cache requestWithString:url requestor:self userData:nil];
- [WCURLHandleCreate([NSURL URLWithString:url], self, nil) loadInBackground];
- }else if(transferMode == NP_ASFILEONLY){
- KWQDebug("Stream type: NP_ASFILEONLY not yet supported\n");
- }else if(transferMode == NP_ASFILE){
- KWQDebug("Stream type: NP_ASFILE not fully supported\n");
- [WCURLHandleCreate([NSURL URLWithString:url], self, nil) loadInBackground];
+ [cache requestWithString:url requestor:self userData:nil];
+ }else if(transferMode == NP_ASFILEONLY || transferMode == NP_ASFILE){
+ KWQDebug("Stream type: NP_ASFILEONLY or NP_ASFILE\n");
+ fileManager = [NSFileManager defaultManager];
+ filename = [NSString stringWithString:[@"/symroots" stringByAppendingPathComponent:[url lastPathComponent]]];
+ [fileManager createFileAtPath:filename contents:nil attributes:nil];
+ file = [NSFileHandle fileHandleForWritingAtPath:filename];
+ [file retain];
+ [filename retain];
+ [cache requestWithString:url requestor:self userData:nil];
}else if(transferMode == NP_SEEK){
KWQDebug("Stream type: NP_SEEK not yet supported\n");
}
transferred = TRUE;
-
}
[self sendUpdateEvent];
}
@@ -184,70 +191,42 @@
// cache methods
-- (void)WCURLHandleResourceDidBeginLoading:(id)sender userData:(void *)userData
-{
-}
-
-- (void)WCURLHandleResourceDidCancelLoading:(id)sender userData:(void *)userData
-{
-}
-
-- (void)WCURLHandleResourceDidFinishLoading:(id)sender userData:(void *)userData
-{
- NPError npErr;
-
- streamOffset = 0;
- if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
- NPP_StreamAsFile(instance, stream, NULL);
- }
- npErr = NPP_DestroyStream(instance, stream, NPRES_DONE);
- KWQDebug("NPP_DestroyStream: %d\n", npErr);
-}
-
-- (void)WCURLHandle:(id)sender resourceDataDidBecomeAvailable:(NSData *)data userData:(void *)userData
-{
- int32 bytes;
-
- bytes = NPP_WriteReady(instance, stream);
- KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
-
- bytes = NPP_Write(instance, stream, streamOffset, [data length], (void *)[data bytes]);
- KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
- streamOffset += [data length];
-}
-
-- (void)WCURLHandle:(id)sender resourceDidFailLoadingWithResult:(int)result userData:(void *)userData
-{
-}
-
-// FIXME: Remove old cache code
-#if 0
-(void)cacheDataAvailable:(NSNotification *)notification
{
id <WCURICacheData> data;
int32 bytes;
data = [notification object];
- bytes = NPP_WriteReady(instance, stream);
- KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
-
- bytes = NPP_Write(instance, stream, streamOffset, [data cacheDataSize], [data cacheData]);
- KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
- streamOffset += [data cacheDataSize];
+ if(transferMode != NP_ASFILEONLY){
+ bytes = NPP_WriteReady(instance, stream);
+ KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
+ bytes = NPP_Write(instance, stream, streamOffset, [data cacheDataSize], [data cacheData]);
+ KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
+ streamOffset += [data cacheDataSize];
+ }
+ if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
+ if(file != nil){
+ [file writeData:[NSData dataWithBytes:[data cacheData] length:[data cacheDataSize]]];
+ }
+ }
}
-(void)cacheFinished:(NSNotification *)notification
{
NPError npErr;
+ char filenameC[400];
streamOffset = 0;
if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
- NPP_StreamAsFile(instance, stream, NULL);
+ [file closeFile];
+ strcpy(filenameC, [rootName() cString]);
+ strcat(filenameC, ":symroots:"); //FIXME: This should be the user's cache directory or somewhere else
+ strcat(filenameC, [[url lastPathComponent] cString]);
+ NPP_StreamAsFile(instance, stream, filenameC);
}
npErr = NPP_DestroyStream(instance, stream, NPRES_DONE);
KWQDebug("NPP_DestroyStream: %d\n", npErr);
}
-#endif
// event methods
@@ -502,15 +481,31 @@
KWQDebug("forceRedraw\n");
}
-
-(void)dealloc
{
NPError npErr;
+ NSFileManager *fileManager;
- [eventSender stop];
+ [eventSender stop];
npErr = NPP_Destroy(instance, NULL);
KWQDebug("NPP_Destroy: %d\n", npErr);
+ fileManager = [NSFileManager defaultManager];
+ [fileManager removeFileAtPath:filename handler:nil];
[super dealloc];
}
@end
+
+NSString* rootName(void)
+{
+ NSString* rootName = nil;
+ FSRef rootRef;
+ if (FSPathMakeRef ((const UInt8 *) "/", & rootRef, NULL /*isDirectory*/) == noErr) {
+ HFSUniStr255 nameString;
+ if (FSGetCatalogInfo (&rootRef, kFSCatInfoNone, NULL /*catalogInfo*/, &nameString, NULL /*fsSpec*/, NULL /*parentRef*/) == noErr) {
+ rootName = [NSString stringWithCharacters:nameString.unicode length:nameString.length];
+ }
+ }
+ return rootName;
+}
+
diff --git a/WebCore/kwq/WKPluginWidget.mm b/WebCore/kwq/WKPluginWidget.mm
index 9b423d2..a61c317 100644
--- a/WebCore/kwq/WKPluginWidget.mm
+++ b/WebCore/kwq/WKPluginWidget.mm
@@ -46,8 +46,14 @@ WKPluginWidget::WKPluginWidget(QWidget *parent, const QString &url, const QStrin
[arguments setObject:[arg substringWithRange:r3] forKey:[arg substringToIndex:r1.location]];
}
plugin = [[WKPluginDatabase installedPlugins] getPluginForMimeType:QSTRING_TO_NSSTRING(serviceType)];
- if(plugin == nil)
+ if(plugin == nil){
+ plugin = [[WKPluginDatabase installedPlugins] getPluginForURL:QSTRING_TO_NSSTRING(url)];
+ }
+ if(plugin == nil){
+ //FIXME: Error dialog should be shown here
+ KWQDebug("Could not find plugin for mime: %s or URL: %s\n", serviceType.latin1(), url.latin1());
return;
+ }
[plugin load];
setView([[[WKPluginView alloc] initWithFrame:NSMakeRect(0,0,0,0) widget:this plugin:plugin url:QSTRING_TO_NSSTRING(url) mime:QSTRING_TO_NSSTRING(serviceType) arguments:arguments] autorelease]);
}
diff --git a/WebCore/src/kwq/KWQKConfigBase.mm b/WebCore/src/kwq/KWQKConfigBase.mm
index 96f8f3e..05cdbb2 100644
--- a/WebCore/src/kwq/KWQKConfigBase.mm
+++ b/WebCore/src/kwq/KWQKConfigBase.mm
@@ -79,6 +79,11 @@ QString KConfigBase::readEntry(const char *pKey,
if(file == pluginsinfo){
WKPlugin *plugin;
+ NSArray *mimeTypes;
+ NSMutableString *bigMimeString;
+ NSString *bigMimeString2;
+ uint i;
+
plugin = [[[WKPluginDatabase installedPlugins] plugins] objectAtIndex:group];
if(strcmp(pKey, "name") == 0){
return NSSTRING_TO_QSTRING([plugin name]);
@@ -86,6 +91,20 @@ QString KConfigBase::readEntry(const char *pKey,
return NSSTRING_TO_QSTRING([plugin filename]);
}else if(strcmp(pKey, "description") == 0){
return NSSTRING_TO_QSTRING([plugin pluginDescription]);
+ }else if(strcmp(pKey, "mime") == 0){
+ mimeTypes = [plugin mimeTypes];
+ bigMimeString = [NSMutableString stringWithCapacity:1000];
+ for(i=0; i<[mimeTypes count]; i++){
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:0]]; // mime type
+ [bigMimeString appendString:@":"];
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:1]]; // mime's extension
+ [bigMimeString appendString:@":"];
+ [bigMimeString appendString:[[mimeTypes objectAtIndex:i] objectAtIndex:2]]; // mime's description
+ [bigMimeString appendString:@";"];
+ }
+ bigMimeString2 = [NSString stringWithString:bigMimeString];
+ [bigMimeString2 retain];
+ return NSSTRING_TO_QSTRING(bigMimeString2);
}
}
if(tempQString == NULL) {
diff --git a/WebCore/src/kwq/KWQKHTMLPart.mm b/WebCore/src/kwq/KWQKHTMLPart.mm
index cda2dc5..4261c21 100644
--- a/WebCore/src/kwq/KWQKHTMLPart.mm
+++ b/WebCore/src/kwq/KWQKHTMLPart.mm
@@ -1586,7 +1586,7 @@ bool KHTMLPart::requestObject( khtml::RenderPart *frame, const QString &url, con
#ifdef _KWQ_
WKPluginWidget *pluginWidget;
- if(url.isEmpty() || serviceType.isEmpty()){
+ if(url.isEmpty()){
return FALSE;
}
pluginWidget = new WKPluginWidget(0, url, serviceType, args);
diff --git a/WebCore/src/kwq/WKPlugin.h b/WebCore/src/kwq/WKPlugin.h
index 397984f..78779cd 100644
--- a/WebCore/src/kwq/WKPlugin.h
+++ b/WebCore/src/kwq/WKPlugin.h
@@ -11,7 +11,7 @@
@interface WKPlugin : NSObject {
- NSDictionary *mimeTypes;
+ NSMutableArray *mimeTypes;
NSString *name, *executablePath, *filename, *pluginDescription;
BOOL isLoaded;
NPPluginFuncs pluginFuncs;
@@ -36,9 +36,10 @@
}
- (BOOL)initializeWithPath:(NSString *)plugin;
+- (BOOL)getPluginInfoForResourceFile:(SInt16)resRef;
- (void)load;
- (void)unload;
-- (NSDictionary *)mimeTypes;
+- (NSArray *)mimeTypes;
- (NSString *)name;
- (NSString *)filename;
- (NSString *)executablePath;
@@ -58,6 +59,4 @@
- (NPP_HandleEventProcPtr)NPP_HandleEvent;
@end
-
-NSMutableDictionary *getMimeTypesForResourceFile(SInt16 resRef);
diff --git a/WebCore/src/kwq/WKPlugin.mm b/WebCore/src/kwq/WKPlugin.mm
index 6c7adda..59ae3b5 100644
--- a/WebCore/src/kwq/WKPlugin.mm
+++ b/WebCore/src/kwq/WKPlugin.mm
@@ -25,9 +25,8 @@
fileManager = [NSFileManager defaultManager];
fileInfo = [fileManager fileAttributesAtPath:plugin traverseLink:YES];
- if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"]){
+ if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"]){ // plug-in with resource fork
if([[fileInfo objectForKey:@"NSFileHFSTypeCode"] unsignedLongValue] == 1112690764){ // 1112690764 = 'BRPL'
- name = [plugin lastPathComponent]; // FIXME: Should the name of the plugin be the filename?
filename = [plugin lastPathComponent];
executablePath = plugin;
err = FSPathMakeRef((UInt8 *)[plugin cString], &fref, NULL);
@@ -40,23 +39,22 @@
KWQDebug("WKPlugin: FSOpenResFile failed. Can't open resource file: %s, Error=%d\n", [plugin cString], err);
return FALSE;
}
- mimeTypes = getMimeTypesForResourceFile(resRef);
- if(mimeTypes == nil) return FALSE;
- //FIXME: Need to get plug-in's description
+ if(![self getPluginInfoForResourceFile:resRef]){
+ return FALSE;
+ }
}else return FALSE;
- }else if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeDirectory"]){
+ }else if([[fileInfo objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeDirectory"]){ //bundle plug-in
pluginURL = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)plugin, kCFURLPOSIXPathStyle, TRUE);
bundle = CFBundleCreate(NULL, pluginURL);
bundle2 = [NSBundle bundleWithPath:plugin]; // CFBundleCopyExecutableURL doesn't return full path! Have to use NSBundle
CFBundleGetPackageInfo(bundle, &type, NULL);
if(type == 1112690764){ // 1112690764 = 'BRPL'
- name = [plugin lastPathComponent]; // FIXME: Should the name of the plugin be the filename?
filename = [plugin lastPathComponent];
executablePath = [bundle2 executablePath];
resRef = CFBundleOpenBundleResourceMap(bundle);
- mimeTypes = getMimeTypesForResourceFile(resRef);
- if(mimeTypes == nil) return FALSE;
- //FIXME: Need to get plug-in's description
+ if(![self getPluginInfoForResourceFile:resRef]){
+ return FALSE;
+ }
}else return FALSE;
CFRelease(bundle);
CFRelease(pluginURL);
@@ -64,13 +62,55 @@
}else{
return FALSE;
}
- [mimeTypes retain];
- [name retain];
+
[executablePath retain];
+ [filename retain];
isLoaded = FALSE;
return TRUE;
}
+- (BOOL)getPluginInfoForResourceFile:(SInt16)resRef{
+ Str255 theString;
+ char temp[300], description[600]; // I wish I didn't have to use these C strings
+ NSMutableArray *mime; // mime is an array containing the mime type, extension(s) and descriptions for that mime type.
+ NSString *tempString;
+ uint n, i;
+
+ mimeTypes = [NSMutableArray arrayWithCapacity:1];
+ UseResFile(resRef);
+ for(n=1, i=0; 1; n+=2, i++){
+ GetIndString(theString, 128, n);
+ CopyPascalStringToC(theString, temp);
+ if(!strcmp(temp, "")) break;
+ mime = [NSMutableArray arrayWithCapacity:3];
+ [mimeTypes insertObject:mime atIndex:i];
+ tempString = [NSString stringWithCString:temp];
+ [mime insertObject:tempString atIndex:0]; // mime type
+
+ GetIndString(theString, 128, n+1);
+ CopyPascalStringToC(theString, temp);
+ tempString = [NSString stringWithCString:temp];
+ [mime insertObject:tempString atIndex:1]; // mime's extension
+ }
+ for(i=1; i<=[mimeTypes count]; i++){
+ GetIndString(theString, 127, i);
+ CopyPascalStringToC(theString, temp);
+ tempString = [NSString stringWithCString:temp];
+ mime = [mimeTypes objectAtIndex:(i-1)];
+ [mime insertObject:tempString atIndex:2]; // mime's description
+ }
+ GetIndString(theString, 126, 1);
+ CopyPascalStringToC(theString, description);
+ pluginDescription = [NSString stringWithCString:description];
+ [pluginDescription retain];
+
+ GetIndString(theString, 126, 2);
+ CopyPascalStringToC(theString, temp);
+ name = [NSString stringWithCString:temp]; // plugin's name
+ [name retain];
+ [mimeTypes retain];
+ return TRUE;
+}
- (void)load{
OSErr err;
@@ -186,7 +226,7 @@
return NPP_HandleEvent;
}
-- (NSDictionary *)mimeTypes{
+- (NSArray *)mimeTypes{
return mimeTypes;
}
@@ -231,26 +271,10 @@
[desc appendString:@"\n"];
return desc;
}
+
@end
-NSMutableDictionary *getMimeTypesForResourceFile(SInt16 resRef){
- NSMutableDictionary *mimeDict;
- Str255 theString;
- char mimeString[200], extString[200];
- int n;
-
- mimeDict = [NSMutableDictionary dictionaryWithCapacity:1];
- UseResFile(resRef);
- for(n=1; 1; n+=2){
- GetIndString(theString, 128, n);
- CopyPascalStringToC(theString, mimeString);
- if(!strcmp(mimeString, "")) break;
- GetIndString(theString, 128, n+1);
- CopyPascalStringToC(theString, extString);
- [mimeDict setObject:[NSString stringWithCString:extString] forKey:[NSString stringWithCString:mimeString]];
- }
- return mimeDict;
-}
+
diff --git a/WebCore/src/kwq/WKPluginDatabase.h b/WebCore/src/kwq/WKPluginDatabase.h
index 8062bef..77ba266 100644
--- a/WebCore/src/kwq/WKPluginDatabase.h
+++ b/WebCore/src/kwq/WKPluginDatabase.h
@@ -16,6 +16,7 @@
+ (WKPluginDatabase *)installedPlugins;
- (WKPlugin *)getPluginForMimeType:(NSString *)mimeType;
+- (WKPlugin *)getPluginForURL:(NSString *)URL;
- (NSArray *) plugins;
@end
diff --git a/WebCore/src/kwq/WKPluginDatabase.mm b/WebCore/src/kwq/WKPluginDatabase.mm
index 3adc39d..9d3661f 100644
--- a/WebCore/src/kwq/WKPluginDatabase.mm
+++ b/WebCore/src/kwq/WKPluginDatabase.mm
@@ -24,21 +24,45 @@ static WKPluginDatabase *__WKPluginDatabase = nil;
// The first plugin with the specified mime type is returned. We may want to tie this to the defaults so that this is configurable.
- (WKPlugin *)getPluginForMimeType:(NSString *)mimeType{
- uint i;
+ uint i, n;
+ WKPlugin *plugin;
+ NSArray *mimeArray;
+
+ for(i=0; i<[plugins count]; i++){
+ plugin = [plugins objectAtIndex:i];
+ mimeArray = [plugin mimeTypes];
+ for(n=0; n<[mimeArray count]; n++){
+ if([[[mimeArray objectAtIndex:n] objectAtIndex:0] isEqualToString:mimeType]){
+ return plugin;
+ }
+ }
+ }
+ return nil;
+}
+
+- (WKPlugin *)getPluginForURL:(NSString *)URL{
+ uint i, n;
WKPlugin *plugin;
- NSDictionary *temp;
+ NSArray *mimeArray;
+ NSRange hasExtension;
+ NSString *extension;
+ extension = [URL pathExtension];
for(i=0; i<[plugins count]; i++){
plugin = [plugins objectAtIndex:i];
- temp = [plugin mimeTypes];
- if([[temp allKeys] containsObject:mimeType]){
- return plugin;
+ mimeArray = [plugin mimeTypes];
+ for(n=0; n<[mimeArray count]; n++){
+ hasExtension = [[[mimeArray objectAtIndex:n] objectAtIndex:1] rangeOfString:extension];
+ if(hasExtension.length){
+ return plugin;
+ }
}
}
- KWQDebug("No plug-in found for mime type: %s\n", [mimeType cString]);
return nil;
}
+
+
- (NSArray *) plugins{
return plugins;
}
diff --git a/WebCore/src/kwq/WKPluginView.h b/WebCore/src/kwq/WKPluginView.h
index cc97a98..25c7897 100644
--- a/WebCore/src/kwq/WKPluginView.h
+++ b/WebCore/src/kwq/WKPluginView.h
@@ -10,7 +10,6 @@
#include <qwidget.h>
#import <WKPlugin.h>
#include "npapi.h"
-#include <WCURLHandle.h>
typedef NPStream* NPS;
@@ -25,7 +24,7 @@ typedef NPStream* NPS;
-(void)stop;
@end
- at interface WKPluginView : NSQuickDrawView <WCURLHandleClient> {
+ at interface WKPluginView : NSQuickDrawView {
QWidget *widget;
WKPlugin *plugin;
WKPluginViewNullEventSender *eventSender;
@@ -42,8 +41,9 @@ typedef NPStream* NPS;
char **cAttributes, **cValues;
bool isFlipped, transferred, hidden;
- NSString *url, *mime;
+ NSString *url, *mime, *filename;
NSTrackingRectTag trackingTag;
+ NSFileHandle *file;
NPP_NewProcPtr NPP_New;
NPP_DestroyProcPtr NPP_Destroy;
@@ -95,3 +95,4 @@ typedef NPStream* NPS;
@end
+NSString* rootName(void);
diff --git a/WebCore/src/kwq/WKPluginView.mm b/WebCore/src/kwq/WKPluginView.mm
index a13fded..9d5428a 100644
--- a/WebCore/src/kwq/WKPluginView.mm
+++ b/WebCore/src/kwq/WKPluginView.mm
@@ -7,6 +7,8 @@
//
#import "WKPluginView.h"
+#include <WCURICacheData.h>
+#include <WCURICache.h>
#include <Carbon/Carbon.h>
#include "kwqdebug.h"
@@ -111,6 +113,8 @@
{
NPError npErr;
char cMime[200], cURL[800];
+ id <WCURICache> cache;
+ NSFileManager *fileManager;
//WindowRef windowRef;
//windowRef = [[self window] _windowRef]; // give the window a WindowRef
@@ -132,20 +136,23 @@
npErr = NPP_NewStream(instance, cMime, stream, FALSE, &transferMode);
KWQDebug("NPP_NewStream: %d\n", npErr);
+ cache = WCGetDefaultURICache();
if(transferMode == NP_NORMAL){
KWQDebug("Stream type: NP_NORMAL\n");
- //[cache requestWithString:url requestor:self userData:nil];
- [WCURLHandleCreate([NSURL URLWithString:url], self, nil) loadInBackground];
- }else if(transferMode == NP_ASFILEONLY){
- KWQDebug("Stream type: NP_ASFILEONLY not yet supported\n");
- }else if(transferMode == NP_ASFILE){
- KWQDebug("Stream type: NP_ASFILE not fully supported\n");
- [WCURLHandleCreate([NSURL URLWithString:url], self, nil) loadInBackground];
+ [cache requestWithString:url requestor:self userData:nil];
+ }else if(transferMode == NP_ASFILEONLY || transferMode == NP_ASFILE){
+ KWQDebug("Stream type: NP_ASFILEONLY or NP_ASFILE\n");
+ fileManager = [NSFileManager defaultManager];
+ filename = [NSString stringWithString:[@"/symroots" stringByAppendingPathComponent:[url lastPathComponent]]];
+ [fileManager createFileAtPath:filename contents:nil attributes:nil];
+ file = [NSFileHandle fileHandleForWritingAtPath:filename];
+ [file retain];
+ [filename retain];
+ [cache requestWithString:url requestor:self userData:nil];
}else if(transferMode == NP_SEEK){
KWQDebug("Stream type: NP_SEEK not yet supported\n");
}
transferred = TRUE;
-
}
[self sendUpdateEvent];
}
@@ -184,70 +191,42 @@
// cache methods
-- (void)WCURLHandleResourceDidBeginLoading:(id)sender userData:(void *)userData
-{
-}
-
-- (void)WCURLHandleResourceDidCancelLoading:(id)sender userData:(void *)userData
-{
-}
-
-- (void)WCURLHandleResourceDidFinishLoading:(id)sender userData:(void *)userData
-{
- NPError npErr;
-
- streamOffset = 0;
- if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
- NPP_StreamAsFile(instance, stream, NULL);
- }
- npErr = NPP_DestroyStream(instance, stream, NPRES_DONE);
- KWQDebug("NPP_DestroyStream: %d\n", npErr);
-}
-
-- (void)WCURLHandle:(id)sender resourceDataDidBecomeAvailable:(NSData *)data userData:(void *)userData
-{
- int32 bytes;
-
- bytes = NPP_WriteReady(instance, stream);
- KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
-
- bytes = NPP_Write(instance, stream, streamOffset, [data length], (void *)[data bytes]);
- KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
- streamOffset += [data length];
-}
-
-- (void)WCURLHandle:(id)sender resourceDidFailLoadingWithResult:(int)result userData:(void *)userData
-{
-}
-
-// FIXME: Remove old cache code
-#if 0
-(void)cacheDataAvailable:(NSNotification *)notification
{
id <WCURICacheData> data;
int32 bytes;
data = [notification object];
- bytes = NPP_WriteReady(instance, stream);
- KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
-
- bytes = NPP_Write(instance, stream, streamOffset, [data cacheDataSize], [data cacheData]);
- KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
- streamOffset += [data cacheDataSize];
+ if(transferMode != NP_ASFILEONLY){
+ bytes = NPP_WriteReady(instance, stream);
+ KWQDebug("NPP_WriteReady bytes=%d\n", (int)bytes);
+ bytes = NPP_Write(instance, stream, streamOffset, [data cacheDataSize], [data cacheData]);
+ KWQDebug("NPP_Write bytes=%d\n", (int)bytes);
+ streamOffset += [data cacheDataSize];
+ }
+ if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
+ if(file != nil){
+ [file writeData:[NSData dataWithBytes:[data cacheData] length:[data cacheDataSize]]];
+ }
+ }
}
-(void)cacheFinished:(NSNotification *)notification
{
NPError npErr;
+ char filenameC[400];
streamOffset = 0;
if(transferMode == NP_ASFILE || transferMode == NP_ASFILEONLY){
- NPP_StreamAsFile(instance, stream, NULL);
+ [file closeFile];
+ strcpy(filenameC, [rootName() cString]);
+ strcat(filenameC, ":symroots:"); //FIXME: This should be the user's cache directory or somewhere else
+ strcat(filenameC, [[url lastPathComponent] cString]);
+ NPP_StreamAsFile(instance, stream, filenameC);
}
npErr = NPP_DestroyStream(instance, stream, NPRES_DONE);
KWQDebug("NPP_DestroyStream: %d\n", npErr);
}
-#endif
// event methods
@@ -502,15 +481,31 @@
KWQDebug("forceRedraw\n");
}
-
-(void)dealloc
{
NPError npErr;
+ NSFileManager *fileManager;
- [eventSender stop];
+ [eventSender stop];
npErr = NPP_Destroy(instance, NULL);
KWQDebug("NPP_Destroy: %d\n", npErr);
+ fileManager = [NSFileManager defaultManager];
+ [fileManager removeFileAtPath:filename handler:nil];
[super dealloc];
}
@end
+
+NSString* rootName(void)
+{
+ NSString* rootName = nil;
+ FSRef rootRef;
+ if (FSPathMakeRef ((const UInt8 *) "/", & rootRef, NULL /*isDirectory*/) == noErr) {
+ HFSUniStr255 nameString;
+ if (FSGetCatalogInfo (&rootRef, kFSCatInfoNone, NULL /*catalogInfo*/, &nameString, NULL /*fsSpec*/, NULL /*parentRef*/) == noErr) {
+ rootName = [NSString stringWithCharacters:nameString.unicode length:nameString.length];
+ }
+ }
+ return rootName;
+}
+
diff --git a/WebCore/src/kwq/WKPluginWidget.mm b/WebCore/src/kwq/WKPluginWidget.mm
index 9b423d2..a61c317 100644
--- a/WebCore/src/kwq/WKPluginWidget.mm
+++ b/WebCore/src/kwq/WKPluginWidget.mm
@@ -46,8 +46,14 @@ WKPluginWidget::WKPluginWidget(QWidget *parent, const QString &url, const QStrin
[arguments setObject:[arg substringWithRange:r3] forKey:[arg substringToIndex:r1.location]];
}
plugin = [[WKPluginDatabase installedPlugins] getPluginForMimeType:QSTRING_TO_NSSTRING(serviceType)];
- if(plugin == nil)
+ if(plugin == nil){
+ plugin = [[WKPluginDatabase installedPlugins] getPluginForURL:QSTRING_TO_NSSTRING(url)];
+ }
+ if(plugin == nil){
+ //FIXME: Error dialog should be shown here
+ KWQDebug("Could not find plugin for mime: %s or URL: %s\n", serviceType.latin1(), url.latin1());
return;
+ }
[plugin load];
setView([[[WKPluginView alloc] initWithFrame:NSMakeRect(0,0,0,0) widget:this plugin:plugin url:QSTRING_TO_NSSTRING(url) mime:QSTRING_TO_NSSTRING(serviceType) arguments:arguments] autorelease]);
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list