⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webdatasource.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1.  Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer.  * 2.  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.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. */#import "WebDataSource.h"#import "WebArchive.h"#import "WebArchiveInternal.h"#import "WebDataSourceInternal.h"#import "WebDocument.h"#import "WebDocumentLoaderMac.h"#import "WebFrameInternal.h"#import "WebFrameLoadDelegate.h"#import "WebFrameLoaderClient.h"#import "WebHTMLRepresentation.h"#import "WebKitErrorsPrivate.h"#import "WebKitLogging.h"#import "WebKitStatisticsPrivate.h"#import "WebKitNSStringExtras.h"#import "WebNSURLExtras.h"#import "WebNSURLRequestExtras.h"#import "WebPDFRepresentation.h"#import "WebResourceInternal.h"#import "WebResourceLoadDelegate.h"#import "WebViewInternal.h"#import <WebCore/ApplicationCacheStorage.h>#import <WebCore/FrameLoader.h>#import <WebCore/KURL.h>#import <WebCore/LegacyWebArchive.h>#import <WebCore/MIMETypeRegistry.h>#import <WebCore/ResourceRequest.h>#import <WebCore/SharedBuffer.h>#import <WebCore/WebCoreObjCExtras.h>#import <WebCore/WebCoreURLResponse.h>#import <WebKit/DOMHTML.h>#import <WebKit/DOMPrivate.h>#import <runtime/InitializeThreading.h>#import <wtf/Assertions.h>using namespace WebCore;@interface WebDataSourcePrivate : NSObject {@public    WebDocumentLoaderMac* loader;       id <WebDocumentRepresentation> representation;        BOOL representationFinishedLoading;}@end@implementation WebDataSourcePrivate + (void)initialize{    JSC::initializeThreading();#ifndef BUILDING_ON_TIGER    WebCoreObjCFinalizeOnMainThread(self);#endif}- (void)dealloc{    if (WebCoreObjCScheduleDeallocateOnMainThread([WebDataSourcePrivate class], self))        return;    ASSERT(loader);    if (loader) {        ASSERT(!loader->isLoading());        loader->detachDataSource();        loader->deref();    }        [representation release];    [super dealloc];}- (void)finalize{    ASSERT_MAIN_THREAD();    ASSERT(loader);    if (loader) {        ASSERT(!loader->isLoading());        loader->detachDataSource();        loader->deref();    }    [super finalize];}@end@interface WebDataSource (WebFileInternal)@end@implementation WebDataSource (WebFileInternal)- (void)_setRepresentation:(id<WebDocumentRepresentation>)representation{    [_private->representation release];    _private->representation = [representation retain];    _private->representationFinishedLoading = NO;}static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCClass, 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:objCClass forKey:mime];    }}+ (Class)_representationClassForMIMEType:(NSString *)MIMEType{    Class repClass;    return [WebView _viewClass:nil andRepresentationClass:&repClass forMIMEType:MIMEType] ? repClass : nil;}@end@implementation WebDataSource (WebPrivate)- (NSError *)_mainDocumentError{    return _private->loader->mainDocumentError();}- (void)_addSubframeArchives:(NSArray *)subframeArchives{    // FIXME: This SPI is poor, poor design.  Can we come up with another solution for those who need it?    DocumentLoader* loader = [self _documentLoader];    ASSERT(loader);        NSEnumerator *enumerator = [subframeArchives objectEnumerator];    WebArchive *archive;    while ((archive = [enumerator nextObject]) != nil)        loader->addAllArchiveResources([archive _coreLegacyWebArchive]);}- (NSFileWrapper *)_fileWrapperForURL:(NSURL *)URL{    if ([URL isFileURL]) {        NSString *path = [[URL path] stringByResolvingSymlinksInPath];        return [[[NSFileWrapper alloc] initWithPath:path] autorelease];    }        WebResource *resource = [self subresourceForURL:URL];    if (resource)        return [resource _fileWrapperRepresentation];        NSCachedURLResponse *cachedResponse = [[self _webView] _cachedResponseForURL:URL];    if (cachedResponse) {        NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:[cachedResponse data]] autorelease];        [wrapper setPreferredFilename:[[cachedResponse response] suggestedFilename]];        return wrapper;    }        return nil;}- (NSString *)_responseMIMEType{    return [[self response] _webcore_MIMEType];}- (BOOL)_transferApplicationCache:(NSString*)destinationBundleIdentifier{    DocumentLoader* loader = [self _documentLoader];        if (!loader)        return NO;        ApplicationCache* cache = loader->applicationCache();    if (!cache)        return YES;        NSString *cacheDir = [NSString _webkit_localCacheDirectoryWithBundleIdentifier:destinationBundleIdentifier];        return ApplicationCacheStorage::storeCopyOfCache(cacheDir, cache);}@end@implementation WebDataSource (WebInternal)- (void)_finishedLoading{    _private->representationFinishedLoading = YES;    [[self representation] finishedLoadingWithDataSource:self];}- (void)_receivedData:(NSData *)data{    // protect self temporarily, as the bridge receivedData call could remove our last ref    RetainPtr<WebDataSource*> protect(self);        [[self representation] receivedData:data withDataSource:self];    [[[[self webFrame] frameView] documentView] dataSourceUpdated:self];}- (void)_setMainDocumentError:(NSError *)error{    if (!_private->representationFinishedLoading) {        _private->representationFinishedLoading = YES;        [[self representation] receivedError:error withDataSource:self];    }}- (void)_revertToProvisionalState{    [self _setRepresentation:nil];}+ (NSMutableDictionary *)_repTypesAllowImageTypeOmission:(BOOL)allowImageTypeOmission{    static NSMutableDictionary *repTypes = nil;    static BOOL addedImageTypes = NO;        if (!repTypes) {        repTypes = [[NSMutableDictionary alloc] init];        addTypesFromClass(repTypes, [WebHTMLRepresentation class], [WebHTMLRepresentation supportedNonImageMIMETypes]);                // Since this is a "secret default" we don't both registering it.        BOOL omitPDFSupport = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];        if (!omitPDFSupport)            addTypesFromClass(repTypes, [WebPDFRepresentation class], [WebPDFRepresentation supportedMIMETypes]);    }        if (!addedImageTypes && !allowImageTypeOmission) {        addTypesFromClass(repTypes, [WebHTMLRepresentation class], [WebHTMLRepresentation supportedImageMIMETypes]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -