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

📄 loader.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            const String& lastModified = resourceToRevalidate->response().httpHeaderField("Last-Modified");            const String& eTag = resourceToRevalidate->response().httpHeaderField("ETag");            if (!lastModified.isEmpty() || !eTag.isEmpty()) {                ASSERT(docLoader->cachePolicy() != CachePolicyReload);                if (docLoader->cachePolicy() == CachePolicyRevalidate)                    resourceRequest.setHTTPHeaderField("Cache-Control", "max-age=0");                if (!lastModified.isEmpty())                    resourceRequest.setHTTPHeaderField("If-Modified-Since", lastModified);                if (!eTag.isEmpty())                    resourceRequest.setHTTPHeaderField("If-None-Match", eTag);            }        }        RefPtr<SubresourceLoader> loader = SubresourceLoader::create(docLoader->doc()->frame(),                                                                     this, resourceRequest, request->shouldSkipCanLoadCheck(), request->sendResourceLoadCallbacks());        if (loader) {            m_requestsLoading.add(loader.release(), request);            request->cachedResource()->setRequestedFromNetworkingLayer();#if REQUEST_DEBUG            printf("HOST %s COUNT %d LOADING %s\n", resourceRequest.url().host().latin1().data(), m_requestsLoading.size(), request->cachedResource()->url().latin1().data());#endif        } else {                        docLoader->decrementRequestCount();            docLoader->setLoadInProgress(true);            request->cachedResource()->error();            docLoader->setLoadInProgress(false);            delete request;        }    }}void Loader::Host::didFinishLoading(SubresourceLoader* loader){    RequestMap::iterator i = m_requestsLoading.find(loader);    if (i == m_requestsLoading.end())        return;        ProcessingResource processingResource(this);    Request* request = i->second;    m_requestsLoading.remove(i);    DocLoader* docLoader = request->docLoader();    // Prevent the document from being destroyed before we are done with    // the docLoader that it will delete when the document gets deleted.    DocPtr<Document> protector(docLoader->doc());    if (!request->isMultipart())        docLoader->decrementRequestCount();    CachedResource* resource = request->cachedResource();    ASSERT(!resource->resourceToRevalidate());    // If we got a 4xx response, we're pretending to have received a network    // error, so we can't send the successful data() and finish() callbacks.    if (!resource->errorOccurred()) {        docLoader->setLoadInProgress(true);        resource->data(loader->resourceData(), true);        resource->finish();    }    delete request;    docLoader->setLoadInProgress(false);        docLoader->checkForPendingPreloads();#if REQUEST_DEBUG    KURL u(resource->url());    printf("HOST %s COUNT %d RECEIVED %s\n", u.host().latin1().data(), m_requestsLoading.size(), resource->url().latin1().data());#endif    servePendingRequests();}void Loader::Host::didFail(SubresourceLoader* loader, const ResourceError&){    didFail(loader);}void Loader::Host::didFail(SubresourceLoader* loader, bool cancelled){    loader->clearClient();    RequestMap::iterator i = m_requestsLoading.find(loader);    if (i == m_requestsLoading.end())        return;    ProcessingResource processingResource(this);        Request* request = i->second;    m_requestsLoading.remove(i);    DocLoader* docLoader = request->docLoader();    // Prevent the document from being destroyed before we are done with    // the docLoader that it will delete when the document gets deleted.    DocPtr<Document> protector(docLoader->doc());    if (!request->isMultipart())        docLoader->decrementRequestCount();    CachedResource* resource = request->cachedResource();        if (resource->resourceToRevalidate())        cache()->revalidationFailed(resource);    if (!cancelled) {        docLoader->setLoadInProgress(true);        resource->error();    }        docLoader->setLoadInProgress(false);    if (cancelled || !resource->isPreloaded())        cache()->remove(resource);        delete request;        docLoader->checkForPendingPreloads();    servePendingRequests();}void Loader::Host::didReceiveResponse(SubresourceLoader* loader, const ResourceResponse& response){    Request* request = m_requestsLoading.get(loader);        // FIXME: This is a workaround for <rdar://problem/5236843>    // If a load starts while the frame is still in the provisional state     // (this can be the case when loading the user style sheet), committing the load then causes all    // requests to be removed from the m_requestsLoading map. This means that request might be null here.    // In that case we just return early.     // ASSERT(request);    if (!request)        return;        CachedResource* resource = request->cachedResource();        if (resource->isCacheValidator()) {        if (response.httpStatusCode() == 304) {            // 304 Not modified / Use local copy            m_requestsLoading.remove(loader);            loader->clearClient();            request->docLoader()->decrementRequestCount();            // Existing resource is ok, just use it updating the expiration time.            cache()->revalidationSucceeded(resource, response);                        if (request->docLoader()->frame())                request->docLoader()->frame()->loader()->checkCompleted();            delete request;            servePendingRequests();            return;        }         // Did not get 304 response, continue as a regular resource load.        cache()->revalidationFailed(resource);    }    resource->setResponse(response);    String encoding = response.textEncodingName();    if (!encoding.isNull())        resource->setEncoding(encoding);        if (request->isMultipart()) {        ASSERT(resource->isImage());        static_cast<CachedImage*>(resource)->clear();        if (request->docLoader()->frame())            request->docLoader()->frame()->loader()->checkCompleted();    } else if (response.isMultipart()) {        request->setIsMultipart(true);                // We don't count multiParts in a DocLoader's request count        request->docLoader()->decrementRequestCount();        // If we get a multipart response, we must have a handle        ASSERT(loader->handle());        if (!resource->isImage())            loader->handle()->cancel();    }}void Loader::Host::didReceiveData(SubresourceLoader* loader, const char* data, int size){    Request* request = m_requestsLoading.get(loader);    if (!request)        return;    CachedResource* resource = request->cachedResource();        ASSERT(!resource->isCacheValidator());        if (resource->errorOccurred())        return;        ProcessingResource processingResource(this);        if (resource->response().httpStatusCode() / 100 == 4) {        // Treat a 4xx response like a network error.        resource->error();        return;    }    // Set the data.    if (request->isMultipart()) {        // The loader delivers the data in a multipart section all at once, send eof.        // The resource data will change as the next part is loaded, so we need to make a copy.        RefPtr<SharedBuffer> copiedData = SharedBuffer::create(data, size);        resource->data(copiedData.release(), true);    } else if (request->isIncremental())        resource->data(loader->resourceData(), false);}    void Loader::Host::cancelPendingRequests(RequestQueue& requestsPending, DocLoader* docLoader){    RequestQueue remaining;    RequestQueue::iterator end = requestsPending.end();    for (RequestQueue::iterator it = requestsPending.begin(); it != end; ++it) {        Request* request = *it;        if (request->docLoader() == docLoader) {            cache()->remove(request->cachedResource());            delete request;            docLoader->decrementRequestCount();        } else            remaining.append(request);    }    requestsPending.swap(remaining);}void Loader::Host::cancelRequests(DocLoader* docLoader){    for (unsigned p = 0; p <= High; p++)        cancelPendingRequests(m_requestsPending[p], docLoader);    Vector<SubresourceLoader*, 256> loadersToCancel;    RequestMap::iterator end = m_requestsLoading.end();    for (RequestMap::iterator i = m_requestsLoading.begin(); i != end; ++i) {        Request* r = i->second;        if (r->docLoader() == docLoader)            loadersToCancel.append(i->first.get());    }    for (unsigned i = 0; i < loadersToCancel.size(); ++i) {        SubresourceLoader* loader = loadersToCancel[i];        didFail(loader, true);    }}} //namespace WebCore

⌨️ 快捷键说明

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