void CachedResourceLoader::setAutoLoadImages(bool enable) { if (enable == m_autoLoadImages) return; m_autoLoadImages = enable; if (!m_autoLoadImages) return; DocumentResourceMap::iterator end = m_documentResources.end(); for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != end; ++it) { CachedResource* resource = it->second.get(); if (resource->type() == CachedResource::ImageResource) { CachedImage* image = const_cast<CachedImage*>(static_cast<const CachedImage*>(resource)); #ifdef ANDROID_BLOCK_NETWORK_IMAGE if (shouldBlockNetworkImage(image->url())) continue; #endif image->setAutoLoadWasPreventedBySettings(false); if (image->stillNeedsLoad()) { image->setLoading(true); load(image, true); } } } }
CachedImage* CachedResourceLoader::requestImage(ResourceRequest& request) { if (Frame* f = frame()) { Settings* settings = f->settings(); if (!f->loader()->client()->allowImages(!settings || settings->areImagesEnabled())) return 0; if (f->loader()->pageDismissalEventBeingDispatched()) { KURL requestURL = request.url(); if (requestURL.isValid() && canRequest(CachedResource::ImageResource, requestURL)) PingLoader::loadImage(f, requestURL); return 0; } } CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, request, String())); if (resource) { #ifdef ANDROID_BLOCK_NETWORK_IMAGE resource->setAutoLoadWasPreventedBySettings(!autoLoadImages() || shouldBlockNetworkImage(request.url())); #else resource->setAutoLoadWasPreventedBySettings(!autoLoadImages()); #endif if (autoLoadImages() && resource->stillNeedsLoad()) { #ifdef ANDROID_BLOCK_NETWORK_IMAGE if (shouldBlockNetworkImage(request.url())) { return resource; } #endif resource->setLoading(true); load(resource, true); } } return resource; }
CachedImage* DocLoader::requestImage(const String& url) { CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); if (autoLoadImages() && resource && resource->stillNeedsLoad()) { resource->setLoading(true); cache()->loader()->load(this, resource, true); } return resource; }
CachedImage* DocLoader::requestImage(const String& url) { // <lab126> KINDLE_PRINT_MODULE(Kindle_Debug_Resources, "Image Request: %s\n", url.latin1().data()); // </lab126> CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); if (autoLoadImages() && resource && resource->stillNeedsLoad()) { resource->setLoading(true); cache()->loader()->load(this, resource, true); } return resource; }
void ImageLoader::updateFromElement() { // If we're not making renderers for the page, then don't load images. We don't want to slow // down the raw HTML parsing case by loading images we don't intend to display. Document* document = m_element->document(); if (!document->renderer()) return; AtomicString attr = m_element->getAttribute(m_element->imageSourceAttributeName()); if (attr == m_failedLoadURL) return; // Do not load any image if the 'src' attribute is missing or if it is // an empty string referring to a local file. The latter condition is // a quirk that preserves old behavior that Dashboard widgets // need (<rdar://problem/5994621>). CachedImage* newImage = 0; if (!(attr.isNull() || (attr.isEmpty() && document->baseURI().isLocalFile()))) { if (m_loadManually) { document->docLoader()->setAutoLoadImages(false); newImage = new CachedImage(sourceURI(attr)); newImage->setLoading(true); newImage->setDocLoader(document->docLoader()); document->docLoader()->m_documentResources.set(newImage->url(), newImage); } else newImage = document->docLoader()->requestImage(sourceURI(attr)); // If we do not have an image here, it means that a cross-site // violation occurred. m_failedLoadURL = !newImage ? attr : AtomicString(); } CachedImage* oldImage = m_image.get(); if (newImage != oldImage) { setLoadingImage(newImage); if (newImage) { newImage->addClient(this); if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER)) dispatchPendingBeforeLoadEvent(); else beforeLoadEventSender().dispatchEventSoon(this); } if (oldImage) oldImage->removeClient(this); } if (RenderObject* renderer = m_element->renderer()) { if (!renderer->isImage()) return; toRenderImage(renderer)->resetAnimation(); } }
CachedImage* DocLoader::requestImage(const String& url) { if (Frame* f = frame()) { Settings* settings = f->settings(); if (!f->loader()->client()->allowImages(!settings || settings->areImagesEnabled())) return 0; } CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); if (autoLoadImages() && resource && resource->stillNeedsLoad()) { resource->setLoading(true); cache()->loader()->load(this, resource, true); } return resource; }
void HTMLImageLoader::updateFromElement() { // If we're not making renderers for the page, then don't load images. We don't want to slow // down the raw HTML parsing case by loading images we don't intend to display. Element* elem = element(); Document* doc = elem->document(); if (!doc->renderer()) return; AtomicString attr = elem->getAttribute(elem->imageSourceAttributeName()); // Do not load any image if the 'src' attribute is missing or if it is // an empty string referring to a local file. The latter condition is // a quirk that preserves old behavior that Dashboard widgets // need (<rdar://problem/5994621>). CachedImage *newImage = 0; if (!(attr.isNull() || attr.isEmpty() && doc->baseURI().isLocalFile())) { if (m_loadManually) { doc->docLoader()->setAutoLoadImages(false); newImage = new CachedImage(parseURL(attr)); newImage->setLoading(true); newImage->setDocLoader(doc->docLoader()); doc->docLoader()->m_docResources.set(newImage->url(), newImage); } else newImage = doc->docLoader()->requestImage(parseURL(attr)); } CachedImage *oldImage = m_image; if (newImage != oldImage) { #ifdef INSTRUMENT_LAYOUT_SCHEDULING if (!doc->ownerElement() && newImage) OWB_PRINTF("Image requested at %d\n", doc->elapsedTime()); #endif setLoadingImage(newImage); if (newImage) newImage->addClient(this); if (oldImage) oldImage->removeClient(this); } if (RenderObject* renderer = elem->renderer()) if (renderer->isImage()) static_cast<RenderImage*>(renderer)->resetAnimation(); }
CachedImage* DocLoader::requestImage(const String& url) { if (Frame* f = frame()) { Settings* settings = f->settings(); if (!f->loader()->client()->allowImages(!settings || settings->areImagesEnabled())) return 0; } CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); if (autoLoadImages() && resource && resource->stillNeedsLoad()) { #ifdef ANDROID_BLOCK_NETWORK_IMAGE if (shouldBlockNetworkImage(url)) { return resource; } #endif resource->setLoading(true); cache()->loader()->load(this, resource, true); } return resource; }
void HTMLImageLoader::updateFromElement() { // If we're not making renderers for the page, then don't load images. We don't want to slow // down the raw HTML parsing case by loading images we don't intend to display. Element* elem = element(); Document* doc = elem->document(); if (!doc->renderer()) return; AtomicString attr = elem->getAttribute(elem->hasLocalName(objectTag) ? dataAttr : srcAttr); // Treat a lack of src or empty string for src as no image at all. CachedImage *newImage = 0; if (!attr.isEmpty()) { if (m_loadManually) { doc->docLoader()->setAutoLoadImages(false); newImage = new CachedImage(doc->docLoader(), parseURL(attr), false /* not for cache */); newImage->setLoading(true); newImage->setDocLoader(doc->docLoader()); doc->docLoader()->m_docResources.set(newImage->url(), newImage); } else newImage = doc->docLoader()->requestImage(parseURL(attr)); } CachedImage *oldImage = m_image; if (newImage != oldImage) { #ifdef INSTRUMENT_LAYOUT_SCHEDULING if (!doc->ownerElement() && newImage) printf("Image requested at %d\n", doc->elapsedTime()); #endif setLoadingImage(newImage); if (newImage) newImage->ref(this); if (oldImage) oldImage->deref(this); } if (RenderObject* renderer = elem->renderer()) if (renderer->isImage()) static_cast<RenderImage*>(renderer)->resetAnimation(); }
CachedImage* CachedResourceLoader::requestImage(const String& url) { if (Frame* f = frame()) { Settings* settings = f->settings(); if (!f->loader()->client()->allowImages(!settings || settings->areImagesEnabled())) return 0; if (f->loader()->pageDismissalEventBeingDispatched()) { KURL completeURL = m_document->completeURL(url); if (completeURL.isValid() && canRequest(CachedResource::ImageResource, completeURL)) PingLoader::loadImage(f, completeURL); return 0; } } CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); if (autoLoadImages() && resource && resource->stillNeedsLoad()) { resource->setLoading(true); load(resource, true); } return resource; }
void CachedResourceLoader::setBlockNetworkImage(bool block) { if (block == m_blockNetworkImage) return; m_blockNetworkImage = block; if (!m_autoLoadImages || m_blockNetworkImage) return; DocumentResourceMap::iterator end = m_documentResources.end(); for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != end; ++it) { CachedResource* resource = it->second.get(); if (resource->type() == CachedResource::ImageResource) { CachedImage* image = const_cast<CachedImage*>(static_cast<const CachedImage*>(resource)); image->setAutoLoadWasPreventedBySettings(false); if (image->stillNeedsLoad()) { image->setLoading(true); load(image, true); } } } }
void ImageLoader::updateFromElement() { // If we're not making renderers for the page, then don't load images. We don't want to slow // down the raw HTML parsing case by loading images we don't intend to display. Document* document = m_element->document(); if (!document->renderer()) return; AtomicString attr = m_element->getAttribute(m_element->imageSourceAttributeName()); if (attr == m_failedLoadURL) return; // Do not load any image if the 'src' attribute is missing or if it is // an empty string. CachedImage* newImage = 0; if (!attr.isNull() && !stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) { ResourceRequest request = ResourceRequest(document->completeURL(sourceURI(attr))); String crossOriginMode = m_element->fastGetAttribute(HTMLNames::crossoriginAttr); if (!crossOriginMode.isNull()) { StoredCredentials allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials; updateRequestForAccessControl(request, document->securityOrigin(), allowCredentials); } if (m_loadManually) { bool autoLoadOtherImages = document->cachedResourceLoader()->autoLoadImages(); document->cachedResourceLoader()->setAutoLoadImages(false); newImage = new CachedImage(request); newImage->setLoading(true); newImage->setOwningCachedResourceLoader(document->cachedResourceLoader()); document->cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage); document->cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages); } else newImage = document->cachedResourceLoader()->requestImage(request); // If we do not have an image here, it means that a cross-site // violation occurred. m_failedLoadURL = !newImage ? attr : AtomicString(); } else if (!attr.isNull()) // Fire an error event if the url is empty. m_element->dispatchEvent(Event::create(eventNames().errorEvent, false, false)); CachedImage* oldImage = m_image.get(); if (newImage != oldImage) { if (!m_firedBeforeLoad) beforeLoadEventSender().cancelEvent(this); if (!m_firedLoad) loadEventSender().cancelEvent(this); m_image = newImage; m_firedBeforeLoad = !newImage; m_firedLoad = !newImage; m_imageComplete = !newImage; if (newImage) { if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER)) dispatchPendingBeforeLoadEvent(); else beforeLoadEventSender().dispatchEventSoon(this); // If newImage is cached, addClient() will result in the load event // being queued to fire. Ensure this happens after beforeload is // dispatched. newImage->addClient(this); } if (oldImage) oldImage->removeClient(this); } if (RenderImageResource* imageResource = renderImageResource()) imageResource->resetAnimation(); }
void ImageLoader::updateFromElement() { // If we're not making renderers for the page, then don't load images. We don't want to slow // down the raw HTML parsing case by loading images we don't intend to display. Document* document = m_element->document(); if (!document->renderer()) return; AtomicString attr = m_element->getAttribute(m_element->imageSourceAttributeName()); if (attr == m_failedLoadURL) return; // Do not load any image if the 'src' attribute is missing or if it is // an empty string referring to a local file. The latter condition is // a quirk that preserves old behavior that Dashboard widgets // need (<rdar://problem/5994621>). CachedImage* newImage = 0; // CAPPFIX_WEB_IMG_SRC_NULL #if 1 if (!attr.isNull() && !stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) { #else if (!(attr.isNull() || (attr.isEmpty() && document->baseURI().isLocalFile()))) { #endif ResourceRequest request = ResourceRequest(document->completeURL(sourceURI(attr))); String crossOriginMode = m_element->fastGetAttribute(HTMLNames::crossoriginAttr); if (!crossOriginMode.isNull()) { bool allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials"); updateRequestForAccessControl(request, document->securityOrigin(), allowCredentials); } if (m_loadManually) { bool autoLoadOtherImages = document->cachedResourceLoader()->autoLoadImages(); document->cachedResourceLoader()->setAutoLoadImages(false); newImage = new CachedImage(request); newImage->setLoading(true); newImage->setOwningCachedResourceLoader(document->cachedResourceLoader()); document->cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage); document->cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages); } else newImage = document->cachedResourceLoader()->requestImage(request); // If we do not have an image here, it means that a cross-site // violation occurred. m_failedLoadURL = !newImage ? attr : AtomicString(); // CAPPFIX_WEB_IMG_SRC_NULL #if 1 } else if (!attr.isNull()) // Fire an error event if the url is empty. m_element->dispatchEvent(Event::create(eventNames().errorEvent, false, false)); #else } #endif CachedImage* oldImage = m_image.get(); if (newImage != oldImage) { if (!m_firedBeforeLoad) beforeLoadEventSender().cancelEvent(this); if (!m_firedLoad) loadEventSender().cancelEvent(this); m_image = newImage; m_firedBeforeLoad = !newImage; m_firedLoad = !newImage; m_imageComplete = !newImage; if (newImage) { newImage->addClient(this); if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER)) dispatchPendingBeforeLoadEvent(); else beforeLoadEventSender().dispatchEventSoon(this); } if (oldImage) oldImage->removeClient(this); } if (RenderImageResource* imageResource = renderImageResource()) imageResource->resetAnimation(); }