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

📄 webdatasource.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
        addedImageTypes = YES;    }        return repTypes;}- (void)_replaceSelectionWithArchive:(WebArchive *)archive selectReplacement:(BOOL)selectReplacement{    DOMDocumentFragment *fragment = [self _documentFragmentWithArchive:archive];    if (fragment)        [[self webFrame] _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:NO matchStyle:NO];}// FIXME: There are few reasons why this method and many of its related methods can't be pushed entirely into WebCore in the future.- (DOMDocumentFragment *)_documentFragmentWithArchive:(WebArchive *)archive{    ASSERT(archive);    WebResource *mainResource = [archive mainResource];    if (mainResource) {        NSString *MIMEType = [mainResource MIMEType];        if ([WebView canShowMIMETypeAsHTML:MIMEType]) {            NSString *markupString = [[NSString alloc] initWithData:[mainResource data] encoding:NSUTF8StringEncoding];            // FIXME: seems poor form to do this as a side effect of getting a document fragment            if (DocumentLoader* loader = [self _documentLoader])                loader->addAllArchiveResources([archive _coreLegacyWebArchive]);            DOMDocumentFragment *fragment = [[self webFrame] _documentFragmentWithMarkupString:markupString baseURLString:[[mainResource URL] _web_originalDataAsString]];            [markupString release];            return fragment;        } else if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType)) {            return [self _documentFragmentWithImageResource:mainResource];                    }    }    return nil;}- (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource{    DOMElement *imageElement = [self _imageElementWithImageResource:resource];    if (!imageElement)        return 0;    DOMDocumentFragment *fragment = [[[self webFrame] DOMDocument] createDocumentFragment];    [fragment appendChild:imageElement];    return fragment;}- (DOMElement *)_imageElementWithImageResource:(WebResource *)resource{    if (!resource)        return 0;        [self addSubresource:resource];        DOMElement *imageElement = [[[self webFrame] DOMDocument] createElement:@"img"];        // FIXME: calling _web_originalDataAsString on a file URL returns an absolute path. Workaround this.    NSURL *URL = [resource URL];    [imageElement setAttribute:@"src" value:[URL isFileURL] ? [URL absoluteString] : [URL _web_originalDataAsString]];        return imageElement;}// May return nil if not initialized with a URL.- (NSURL *)_URL{    const KURL& url = _private->loader->url();    if (url.isEmpty())        return nil;    return url;}- (WebView *)_webView{    return [[self webFrame] webView];}- (BOOL)_isDocumentHTML{    NSString *MIMEType = [self _responseMIMEType];    return [WebView canShowMIMETypeAsHTML:MIMEType];}-(void)_makeRepresentation{    Class repClass = [[self class] _representationClassForMIMEType:[self _responseMIMEType]];        // Check if the data source was already bound?    if (![[self representation] isKindOfClass:repClass]) {        id newRep = repClass != nil ? [[repClass alloc] init] : nil;        [self _setRepresentation:(id <WebDocumentRepresentation>)newRep];        [newRep release];    }        [_private->representation setDataSource:self];}- (DocumentLoader*)_documentLoader{    return _private->loader;}- (id)_initWithDocumentLoader:(PassRefPtr<WebDocumentLoaderMac>)loader{    self = [super init];    if (!self)        return nil;        _private = [[WebDataSourcePrivate alloc] init];        _private->loader = loader.releaseRef();            LOG(Loading, "creating datasource for %@", static_cast<NSURL *>(_private->loader->request().url()));        ++WebDataSourceCount;        return self;    }@end@implementation WebDataSource- (id)initWithRequest:(NSURLRequest *)request{    return [self _initWithDocumentLoader:WebDocumentLoaderMac::create(request, SubstituteData())];}- (void)dealloc{    --WebDataSourceCount;        [_private release];        [super dealloc];}- (void)finalize{    --WebDataSourceCount;    [super finalize];}- (NSData *)data{    RefPtr<SharedBuffer> mainResourceData = _private->loader->mainResourceData();    if (!mainResourceData)        return nil;    return [mainResourceData->createNSData() autorelease];}- (id <WebDocumentRepresentation>)representation{    return _private->representation;}- (WebFrame *)webFrame{    FrameLoader* frameLoader = _private->loader->frameLoader();    if (!frameLoader)        return nil;    return static_cast<WebFrameLoaderClient*>(frameLoader->client())->webFrame();}- (NSURLRequest *)initialRequest{    return _private->loader->originalRequest().nsURLRequest();}- (NSMutableURLRequest *)request{    FrameLoader* frameLoader = _private->loader->frameLoader();    if (!frameLoader || !frameLoader->frameHasLoaded())        return nil;    // FIXME: this cast is dubious    return (NSMutableURLRequest *)_private->loader->request().nsURLRequest();}- (NSURLResponse *)response{    return _private->loader->response().nsURLResponse();}- (NSString *)textEncodingName{    NSString *textEncodingName = _private->loader->overrideEncoding();    if (!textEncodingName)        textEncodingName = [[self response] textEncodingName];    return textEncodingName;}- (BOOL)isLoading{    return _private->loader->isLoadingInAPISense();}// Returns nil or the page title.- (NSString *)pageTitle{    return [[self representation] title];}- (NSURL *)unreachableURL{    const KURL& unreachableURL = _private->loader->unreachableURL();    if (unreachableURL.isEmpty())        return nil;    return unreachableURL;}- (WebArchive *)webArchive{    // it makes no sense to grab a WebArchive from an uncommitted document.    if (!_private->loader->isCommitted())        return nil;            return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core([self webFrame]))] autorelease];}- (WebResource *)mainResource{    RefPtr<ArchiveResource> coreResource = _private->loader->mainResource();    return [[[WebResource alloc] _initWithCoreResource:coreResource.release()] autorelease];}- (NSArray *)subresources{    Vector<PassRefPtr<ArchiveResource> > coreSubresources;    _private->loader->getSubresources(coreSubresources);    NSMutableArray *subresources = [[NSMutableArray alloc] initWithCapacity:coreSubresources.size()];    for (unsigned i = 0; i < coreSubresources.size(); ++i) {        WebResource *resource = [[WebResource alloc] _initWithCoreResource:coreSubresources[i]];        if (resource) {            [subresources addObject:resource];            [resource release];        }    }    return [subresources autorelease];}- (WebResource *)subresourceForURL:(NSURL *)URL{    RefPtr<ArchiveResource> subresource = _private->loader->subresource(URL);        return subresource ? [[[WebResource alloc] _initWithCoreResource:subresource.get()] autorelease] : nil;}- (void)addSubresource:(WebResource *)subresource{        _private->loader->addArchiveResource([subresource _coreResource]);}@end

⌨️ 快捷键说明

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