Commit aeea2bcf authored by eseidel's avatar eseidel
Browse files

Bug #: 5037

Submitted by: eseidel
Reviewed by: mjs
	Moved MIME type support from a hard coded list
        (in two places) to single lists in the corresponding
        *Representation classes.  Also moved the list of types
        supported by WebCore (WebHTMLRepresentation) into WebCore.
        http://bugzilla.opendarwin.org/show_bug.cgi?id=5037

        * WebView.subproj/WebDataSource.m:
        (addTypesFromClass): new inline function
        (+[WebDataSource _repTypesAllowImageTypeOmission:]):
        * WebView.subproj/WebFrameView.m:
        (addTypesFromClass): new inline function
        (+[WebFrameView _viewTypesAllowImageTypeOmission:]):
        * WebView.subproj/WebHTMLRepresentation.h:
        * WebView.subproj/WebHTMLRepresentation.m:
        (+[WebHTMLRepresentation supportedMIMETypes]):
        * WebView.subproj/WebHTMLView.m:
        (+[WebHTMLView supportedMIMETypes]):
        * WebView.subproj/WebHTMLViewPrivate.h:
        * WebView.subproj/WebImageRepresentation.h:
        * WebView.subproj/WebImageRepresentation.m:
        (+[WebImageRepresentation supportedMIMETypes]):
        * WebView.subproj/WebImageView.h:
        * WebView.subproj/WebImageView.m:
        (+[WebImageView supportedMIMETypes]):
        * WebView.subproj/WebPDFRepresentation.h:
        * WebView.subproj/WebPDFRepresentation.m:
        (+[WebPDFRepresentation supportedMIMETypes]):
        * WebView.subproj/WebPDFView.h:
        * WebView.subproj/WebPDFView.m:
        (+[WebPDFView supportedMIMETypes]):
        * WebView.subproj/WebTextRepresentation.h:
        * WebView.subproj/WebTextRepresentation.m:
        (+[WebTextRepresentation supportedMIMETypes]):
        * WebView.subproj/WebTextView.h:
        * WebView.subproj/WebTextView.m:
        (+[WebTextView supportedMIMETypes]):
        * WebView.subproj/WebView.m:
        (+[WebView _viewClass:andRepresentationClass:forMIMEType:]):
        (+[WebView MIMETypesShownAsHTML]): updated to match style
        (+[WebView setMIMETypesShownAsHTML:]): ditto


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@10575 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 536d03b6
2005-09-20 Eric Seidel <eseidel@apple.com>
Reviewed by mjs.
Moved MIME type support from a hard coded list
(in two places) to single lists in the corresponding
*Representation classes. Also moved the list of types
supported by WebCore (WebHTMLRepresentation) into WebCore.
http://bugzilla.opendarwin.org/show_bug.cgi?id=5037
* WebView.subproj/WebDataSource.m:
(addTypesFromClass): new inline function
(+[WebDataSource _repTypesAllowImageTypeOmission:]):
* WebView.subproj/WebFrameView.m:
(addTypesFromClass): new inline function
(+[WebFrameView _viewTypesAllowImageTypeOmission:]):
* WebView.subproj/WebHTMLRepresentation.h:
* WebView.subproj/WebHTMLRepresentation.m:
(+[WebHTMLRepresentation supportedMIMETypes]):
* WebView.subproj/WebHTMLView.m:
(+[WebHTMLView supportedMIMETypes]):
* WebView.subproj/WebHTMLViewPrivate.h:
* WebView.subproj/WebImageRepresentation.h:
* WebView.subproj/WebImageRepresentation.m:
(+[WebImageRepresentation supportedMIMETypes]):
* WebView.subproj/WebImageView.h:
* WebView.subproj/WebImageView.m:
(+[WebImageView supportedMIMETypes]):
* WebView.subproj/WebPDFRepresentation.h:
* WebView.subproj/WebPDFRepresentation.m:
(+[WebPDFRepresentation supportedMIMETypes]):
* WebView.subproj/WebPDFView.h:
* WebView.subproj/WebPDFView.m:
(+[WebPDFView supportedMIMETypes]):
* WebView.subproj/WebTextRepresentation.h:
* WebView.subproj/WebTextRepresentation.m:
(+[WebTextRepresentation supportedMIMETypes]):
* WebView.subproj/WebTextView.h:
* WebView.subproj/WebTextView.m:
(+[WebTextView supportedMIMETypes]):
* WebView.subproj/WebView.m:
(+[WebView _viewClass:andRepresentationClass:forMIMEType:]):
(+[WebView MIMETypesShownAsHTML]): updated to match style
(+[WebView setMIMETypesShownAsHTML:]): ditto
2005-09-16 John Sullivan <sullivan@apple.com>
 
* WebView.subproj/WebImageView.m:
......@@ -651,43 +651,36 @@ - (void)_clearErrors
_private->mainDocumentError = nil;
}
static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class class, NSArray *supportTypes)
{
NSEnumerator *enumerator = [supportTypes objectEnumerator];
ASSERT(enumerator != nil);
NSString *mime = nil;
while ((mime = [enumerator nextObject]) != nil) {
// Don't clobber previously-registered classes.
if ([allTypes objectForKey:mime] == nil)
[allTypes setObject:class forKey:mime];
}
}
+ (NSMutableDictionary *)_repTypesAllowImageTypeOmission:(BOOL)allowImageTypeOmission
{
static NSMutableDictionary *repTypes = nil;
static BOOL addedImageTypes;
static BOOL addedImageTypes = NO;
if (!repTypes) {
repTypes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[WebHTMLRepresentation class], @"text/html",
[WebHTMLRepresentation class], @"text/xml",
[WebHTMLRepresentation class], @"text/xsl",
[WebHTMLRepresentation class], @"application/xml",
[WebHTMLRepresentation class], @"application/xhtml+xml",
[WebHTMLRepresentation class], @"application/rss+xml",
[WebHTMLRepresentation class], @"application/atom+xml",
[WebHTMLRepresentation class], @"application/x-webarchive",
[WebHTMLRepresentation class], @"multipart/x-mixed-replace",
[WebTextRepresentation class], @"text/",
[WebTextRepresentation class], @"application/x-javascript",
nil];
repTypes = [[NSMutableDictionary alloc] init];
addTypesFromClass(repTypes, [WebHTMLRepresentation class], [WebHTMLRepresentation supportedMIMETypes]);
addTypesFromClass(repTypes, [WebTextRepresentation class], [WebTextRepresentation supportedMIMETypes]);
// Since this is a "secret default" we don't both registering it.
BOOL omitPDFSupport = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
if (!omitPDFSupport) {
[repTypes setObject:[WebPDFRepresentation class] forKey:@"text/pdf"];
[repTypes setObject:[WebPDFRepresentation class] forKey:@"application/pdf"];
}
BOOL omitPDFSupport = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
if (!omitPDFSupport)
addTypesFromClass(repTypes, [WebPDFRepresentation class], [WebPDFRepresentation supportedMIMETypes]);
}
if (!addedImageTypes && !allowImageTypeOmission) {
NSEnumerator *enumerator = [[WebImageView supportedImageMIMETypes] objectEnumerator];
NSString *mime;
while ((mime = [enumerator nextObject]) != nil) {
// Don't clobber previously-registered rep classes.
if ([repTypes objectForKey:mime] == nil) {
[repTypes setObject:[WebImageRepresentation class] forKey:mime];
}
}
addTypesFromClass(repTypes, [WebImageRepresentation class], [WebImageRepresentation supportedMIMETypes]);
addedImageTypes = YES;
}
......
......@@ -238,45 +238,36 @@ - (float)_verticalPageScrollDistance
return (height < overlap) ? height / 2 : height - overlap;
}
static NSMutableDictionary *viewTypes;
static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class class, NSArray *supportTypes)
{
NSEnumerator *enumerator = [supportTypes objectEnumerator];
ASSERT(enumerator != nil);
NSString *mime = nil;
while ((mime = [enumerator nextObject]) != nil) {
// Don't clobber previously-registered classes.
if ([allTypes objectForKey:mime] == nil)
[allTypes setObject:class forKey:mime];
}
}
+ (NSMutableDictionary *)_viewTypesAllowImageTypeOmission:(BOOL)allowImageTypeOmission
{
static BOOL addedImageTypes;
static NSMutableDictionary *viewTypes = nil;
static BOOL addedImageTypes = NO;
if (!viewTypes) {
viewTypes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[WebHTMLView class], @"text/html",
[WebHTMLView class], @"text/xml",
[WebHTMLView class], @"text/xsl",
[WebHTMLView class], @"application/xml",
[WebHTMLView class], @"application/xhtml+xml",
[WebHTMLView class], @"application/rss+xml",
[WebHTMLView class], @"application/atom+xml",
[WebHTMLView class], @"application/x-webarchive",
[WebHTMLView class], @"multipart/x-mixed-replace",
[WebTextView class], @"text/",
[WebTextView class], @"application/x-javascript",
nil];
viewTypes = [[NSMutableDictionary alloc] init];
addTypesFromClass(viewTypes, [WebHTMLView class], [WebHTMLView supportedMIMETypes]);
addTypesFromClass(viewTypes, [WebTextView class], [WebTextView supportedMIMETypes]);
// Since this is a "secret default" we don't both registering it.
BOOL omitPDFSupport = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
if (!omitPDFSupport) {
[viewTypes setObject:[WebPDFView class] forKey:@"text/pdf"];
[viewTypes setObject:[WebPDFView class] forKey:@"application/pdf"];
}
BOOL omitPDFSupport = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
if (!omitPDFSupport)
addTypesFromClass(viewTypes, [WebPDFView class], [WebPDFView supportedMIMETypes]);
}
if (!addedImageTypes && !allowImageTypeOmission) {
NSEnumerator *enumerator = [[WebImageView supportedImageMIMETypes] objectEnumerator];
ASSERT(enumerator != nil);
NSString *mime;
while ((mime = [enumerator nextObject]) != nil) {
// Don't clobber previously-registered view classes.
if ([viewTypes objectForKey:mime] == nil) {
[viewTypes setObject:[WebImageView class] forKey:mime];
}
}
addTypesFromClass(viewTypes, [WebImageView class], [WebImageView supportedMIMETypes]);
addedImageTypes = YES;
}
......
......@@ -48,6 +48,8 @@
WebHTMLRepresentationPrivate *_private;
}
+ (NSArray *)supportedMIMETypes;
- (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset;
- (DOMElement *)elementWithName:(NSString *)name inForm:(DOMElement *)form;
......
......@@ -64,6 +64,11 @@ - (void)dealloc
@implementation WebHTMLRepresentation
+ (NSArray *)supportedMIMETypes
{
return [WebCoreBridge supportedMIMETypes];
}
- init
{
self = [super init];
......
......@@ -644,6 +644,11 @@ - (void)_reset
[WebImageRenderer stopAnimationsInView:self];
}
+ (NSArray *)supportedMIMETypes
{
return [WebHTMLRepresentation supportedMIMETypes];
}
+ (void)_postFlagsChangedEvent:(NSEvent *)flagsChangedEvent
{
NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved
......
......@@ -39,6 +39,7 @@
@interface WebHTMLView (WebPrivate)
- (void)_reset;
+ (NSArray *)supportedMIMETypes;
// Modifier (flagsChanged) tracking SPI
+ (void)_postFlagsChangedEvent:(NSEvent *)flagsChangedEvent;
......
......@@ -40,6 +40,7 @@
WebImageRenderer *image;
BOOL doneLoading;
}
+ (NSArray *)supportedMIMETypes;
- (WebImageRenderer *)image;
- (NSString *)filename;
- (WebArchive *)archive;
......
......@@ -41,6 +41,17 @@
@implementation WebImageRepresentation
+ (NSArray *)supportedMIMETypes
{
static NSMutableArray *imageMIMETypes = nil;
if (imageMIMETypes == nil) {
imageMIMETypes = [[[WebImageRendererFactory sharedFactory] supportedMIMETypes] mutableCopy];
[imageMIMETypes removeObject:@"application/pdf"];
[imageMIMETypes removeObject:@"application/postscript"];
}
return imageMIMETypes;
}
- (void)dealloc
{
[image release];
......
......@@ -38,5 +38,5 @@
NSEvent *mouseDownEvent;
unsigned int dragSourceActionMask;
}
+ (NSArray *)supportedImageMIMETypes;
+ (NSArray *)supportedMIMETypes;
@end
......@@ -51,15 +51,9 @@ + (void)initialize
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObject:NSTIFFPboardType] returnTypes:nil];
}
+ (NSArray *)supportedImageMIMETypes
+ (NSArray *)supportedMIMETypes
{
static NSMutableArray *imageMIMETypes = nil;
if (imageMIMETypes == nil) {
imageMIMETypes = [[[WebImageRendererFactory sharedFactory] supportedMIMETypes] mutableCopy];
[imageMIMETypes removeObject:@"application/pdf"];
[imageMIMETypes removeObject:@"application/postscript"];
}
return imageMIMETypes;
return [WebImageRepresentation supportedMIMETypes];
}
- (id)initWithFrame:(NSRect)frame
......
......@@ -31,4 +31,5 @@
@protocol WebDocumentRepresentation;
@interface WebPDFRepresentation : NSObject <WebDocumentRepresentation>
+ (NSArray *)supportedMIMETypes;
@end
......@@ -38,6 +38,14 @@
@implementation WebPDFRepresentation
+ (NSArray *)supportedMIMETypes
{
return [NSArray arrayWithObjects:
@"text/pdf",
@"application/pdf",
nil];
}
+ (Class)PDFDocumentClass
{
static Class PDFDocumentClass = nil;
......
......@@ -45,6 +45,7 @@
PDFView *PDFSubviewProxy;
}
+ (NSArray *)supportedMIMETypes;
+ (NSBundle *)PDFKitBundle;
- (PDFView *)PDFSubview;
......
......@@ -42,6 +42,7 @@
#import <WebKit/WebView.h>
#import <WebKit/WebViewPrivate.h>
#import <WebKit/WebPreferencesPrivate.h>
#import <WebKit/WebPDFRepresentation.h>
#import <WebKitSystemInterface.h>
#import <PDFKit/PDFKit.h>
......@@ -94,6 +95,11 @@ + (Class)PDFViewClass
return PDFViewClass;
}
+ (NSArray *)supportedMIMETypes
{
return [WebPDFRepresentation supportedMIMETypes];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
......
......@@ -35,4 +35,5 @@
NSString *RTFSource;
BOOL hasRTFSource;
}
+ (NSArray *)supportedMIMETypes;
@end
......@@ -38,6 +38,14 @@
@implementation WebTextRepresentation
+ (NSArray *)supportedMIMETypes
{
return [NSArray arrayWithObjects:
@"text/",
@"application/x-javascript",
nil];
}
- (void)dealloc
{
[RTFSource release];
......
......@@ -36,6 +36,7 @@
float _textSizeMultiplier;
}
+ (NSArray *)supportedMIMETypes;
+ (NSArray *)unsupportedTextMIMETypes;
- (void)setFixedWidthFont;
......
......@@ -42,6 +42,7 @@
#import <WebKit/WebPreferences.h>
#import <WebKit/WebTextRendererFactory.h>
#import <WebKit/WebViewPrivate.h>
#import <WebKit/WebTextRepresentation.h>
#import <Foundation/NSURLResponse.h>
......@@ -58,6 +59,11 @@ @interface WebTextView (TextSizing) <_WebDocumentTextSizing>
@implementation WebTextView
+ (NSArray *)supportedMIMETypes
{
return [WebTextRepresentation supportedMIMETypes];
}
+ (NSArray *)unsupportedTextMIMETypes
{
return [NSArray arrayWithObjects:
......
......@@ -369,30 +369,19 @@ + (NSArray *)_supportedFileExtensions
+ (BOOL)_viewClass:(Class *)vClass andRepresentationClass:(Class *)rClass forMIMEType:(NSString *)MIMEType;
{
MIMEType = [MIMEType lowercaseString];
Class viewClass;
Class repClass;
// Simple optimization that avoids loading the plug-in DB and image types for the HTML case.
if ([self canShowMIMETypeAsHTML:MIMEType]) {
viewClass = [[WebFrameView _viewTypesAllowImageTypeOmission:YES] _webkit_objectForMIMEType:MIMEType];
repClass = [[WebDataSource _repTypesAllowImageTypeOmission:YES] _webkit_objectForMIMEType:MIMEType];
if (viewClass && repClass) {
if (vClass) {
*vClass = viewClass;
}
if (rClass) {
*rClass = repClass;
}
return YES;
}
Class viewClass = [[WebFrameView _viewTypesAllowImageTypeOmission:YES] _webkit_objectForMIMEType:MIMEType];
Class repClass = [[WebDataSource _repTypesAllowImageTypeOmission:YES] _webkit_objectForMIMEType:MIMEType];
if (!viewClass || !repClass) {
// Our optimization to avoid loading the plug-in DB and image types for the HTML case failed.
// Load the plug-in DB allowing plug-ins to install types.
[WebPluginDatabase installedPlugins];
// Load the image types and get the view class and rep class. This should be the fullest picture of all handled types.
viewClass = [[WebFrameView _viewTypesAllowImageTypeOmission:NO] _webkit_objectForMIMEType:MIMEType];
repClass = [[WebDataSource _repTypesAllowImageTypeOmission:NO] _webkit_objectForMIMEType:MIMEType];
}
// Load the plug-in DB allowing plug-ins to install types.
[WebPluginDatabase installedPlugins];
// Load the image types and get the view class and rep class. This should be the fullest picture of all handled types.
viewClass = [[WebFrameView _viewTypesAllowImageTypeOmission:NO] _webkit_objectForMIMEType:MIMEType];
repClass = [[WebDataSource _repTypesAllowImageTypeOmission:NO] _webkit_objectForMIMEType:MIMEType];
if (viewClass && repClass) {
// Special-case WebTextView for text types that shouldn't be shown.
if (viewClass == [WebTextView class] &&
......@@ -400,12 +389,10 @@ + (BOOL)_viewClass:(Class *)vClass andRepresentationClass:(Class *)rClass forMIM
[[WebTextView unsupportedTextMIMETypes] containsObject:MIMEType]) {
return NO;
}
if (vClass) {
if (vClass)
*vClass = viewClass;
}
if (rClass) {
if (rClass)
*rClass = repClass;
}
return YES;
}
......@@ -1488,9 +1475,8 @@ + (NSArray *)MIMETypesShownAsHTML
NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
while ((key = [enumerator nextObject])) {
if ([viewTypes objectForKey:key] == [WebHTMLView class]) {
if ([viewTypes objectForKey:key] == [WebHTMLView class])
[array addObject:key];
}
}
return array;
......@@ -1498,15 +1484,12 @@ + (NSArray *)MIMETypesShownAsHTML
+ (void)setMIMETypesShownAsHTML:(NSArray *)MIMETypes
{
NSEnumerator *enumerator;
id key;
NSMutableDictionary *viewTypes = [WebFrameView _viewTypesAllowImageTypeOmission:YES];
enumerator = [viewTypes keyEnumerator];
NSEnumerator *enumerator = [viewTypes keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
if ([viewTypes objectForKey:key] == [WebHTMLView class]) {
if ([viewTypes objectForKey:key] == [WebHTMLView class])
[WebView _unregisterViewClassAndRepresentationClassForMIMEType:key];
}
}
int i, count = [MIMETypes count];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment