Exemplo n.º 1
0
StringView CachedScript::script()
{
    if (!m_data)
        return { };

    if (m_decodingState == NeverDecoded
        && TextEncoding(encoding()).isByteBasedEncoding()
        && m_data->size()
        && charactersAreAllASCII(reinterpret_cast<const LChar*>(m_data->data()), m_data->size())) {

        m_decodingState = DataAndDecodedStringHaveSameBytes;

        // If the encoded and decoded data are the same, there is no decoded data cost!
        setDecodedSize(0);
        m_decodedDataDeletionTimer.stop();

        m_scriptHash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const LChar*>(m_data->data()), m_data->size());
    }

    if (m_decodingState == DataAndDecodedStringHaveSameBytes)
        return { reinterpret_cast<const LChar*>(m_data->data()), m_data->size() };

    if (!m_script) {
        m_script = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
        m_scriptHash = m_script.impl()->hash();
        m_decodingState = DataAndDecodedStringHaveDifferentBytes;
        setDecodedSize(m_script.sizeInBytes());
    }

    m_decodedDataDeletionTimer.restart();
    return m_script;
}
Exemplo n.º 2
0
void CachedResource::setBodyDataFrom(const CachedResource& resource)
{
    m_data = resource.m_data;
    m_response = resource.m_response;
    setDecodedSize(resource.decodedSize());
    setEncodedSize(resource.encodedSize());
}
Exemplo n.º 3
0
void CachedCSSStyleSheet::saveParsedStyleSheet(PassRefPtr<StyleSheetInternal> sheet)
{
    ASSERT(sheet && sheet->isCacheable());
    m_parsedStyleSheetCache = sheet;

    setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
}
Exemplo n.º 4
0
const String& CachedScript::script()
{
    ASSERT(!isPurgeable());

    if (!m_script && m_data) {
        m_script = m_decoder->decode(m_data->data(), encodedSize());
        m_script.append(m_decoder->flush());
#if ENABLE(MEMORY_OUT_HANDLING)
        // If we fail to decode the script (because of lack of memory)
        // and return an empty string the Lexer will barf.  It
        // assumes that the data ptr is not going to be null.
        if (encodedSize() > 0 && m_script.length() == 0)
            m_script = " ";
#endif
        setDecodedSize(m_script.sizeInBytes());
    }
#if !ENABLE(MEMORY_OUT_HANDLING)
    // If memory out handling is enabled, don't delete the decoded data.
    // JS parser assumes that if a script has been decoded once we'll always
    // be able to decode it.
    m_decodedDataDeletionTimer.startOneShot(0);
#endif

    return m_script;
}
Exemplo n.º 5
0
void CachedImage::decodedSizeChanged(const Image* image, int delta)
{
    if (image != m_image)
        return;
    
    setDecodedSize(decodedSize() + delta);
}
void CachedScript::destroyDecodedData()
{
    m_script = String();
    setDecodedSize(0);
    if (isSafeToMakePurgeable())
        makePurgeable(true);
}
Exemplo n.º 7
0
void CachedScript::destroyDecodedData()
{
    m_script = String();
    setDecodedSize(0);
    if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable())
        makePurgeable(true);
}
Exemplo n.º 8
0
void ImageResource::decodedSizeChanged(const blink::Image* image, int delta)
{
    if (!image || image != m_image)
        return;

    setDecodedSize(decodedSize() + delta);
}
Exemplo n.º 9
0
void CachedImage::decodedSizeChanged(const Image* image, long long delta)
{
    if (!image || image != m_image)
        return;

    ASSERT(delta >= 0 || decodedSize() + delta >= 0);
    setDecodedSize(static_cast<unsigned>(decodedSize() + delta));
}
Exemplo n.º 10
0
void CachedImage::destroyDecodedData()
{
    bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmapImage());
    if (canDeleteImage && !isLoading() && !hasClients()) {
        m_image = nullptr;
        setDecodedSize(0);
    } else if (m_image && !errorOccurred())
        m_image->destroyDecodedData();
}
Exemplo n.º 11
0
void ImageResource::destroyDecodedDataIfPossible()
{
    if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m_image->isBitmapImage()))) {
        m_image = nullptr;
        setDecodedSize(0);
    } else if (m_image && !errorOccurred()) {
        m_image->destroyDecodedData(true);
    }
}
Exemplo n.º 12
0
const String& CachedScript::script()
{
    if (!m_script && m_data) {
        m_script = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
        setDecodedSize(m_script.sizeInBytes());
    }
    m_decodedDataDeletionTimer.restart();
    return m_script;
}
Exemplo n.º 13
0
void CachedCSSStyleSheet::destroyDecodedData()
{
    if (!m_parsedStyleSheetCache)
        return;

    m_parsedStyleSheetCache->removedFromMemoryCache();
    m_parsedStyleSheetCache.clear();

    setDecodedSize(0);
}
Exemplo n.º 14
0
bool JPEGImageDecoder::setSize(unsigned width, unsigned height)
{
    if (!ImageDecoder::setSize(width, height))
        return false;

    if (!desiredScaleNumerator())
        return setFailed();

    setDecodedSize(width, height);
    return true;
}
Exemplo n.º 15
0
void CachedCSSStyleSheet::saveParsedStyleSheet(PassRefPtr<StyleSheetContents> sheet)
{
    ASSERT(sheet && sheet->isCacheable());

    if (m_parsedStyleSheetCache)
        m_parsedStyleSheetCache->removedFromMemoryCache();
    m_parsedStyleSheetCache = sheet;
    m_parsedStyleSheetCache->addedToMemoryCache();

    setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
}
Exemplo n.º 16
0
const String& ScriptResource::script() {
  DCHECK(isLoaded());

  if (m_script.isNull() && data()) {
    String script = decodedText();
    clearData();
    setDecodedSize(script.charactersSizeInBytes());
    m_script = AtomicString(script);
  }

  return m_script;
}
Exemplo n.º 17
0
void CachedImage::destroyDecodedData()
{
    bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmapImage());
    if (isSafeToMakePurgeable() && canDeleteImage && !m_loading) {
        // Image refs the data buffer so we should not make it purgeable while the image is alive. 
        // Invoking addClient() will reconstruct the image object.
        m_image = 0;
        setDecodedSize(0);
        makePurgeable(true);
    } else if (m_image && !m_errorOccurred)
        m_image->destroyDecodedData();
}
Exemplo n.º 18
0
const String& CachedScript::script()
{
    ASSERT(!isPurgeable());

    if (!m_script && m_data) {
        m_script = m_decoder->decode(m_data->data(), encodedSize());
        m_script += m_decoder->flush();
        setDecodedSize(m_script.length() * sizeof(UChar));
    }
    m_decodedDataDeletionTimer.startOneShot(0);
    return m_script;
}
Exemplo n.º 19
0
const String& CachedScript::script()
{
    ASSERT(!isPurgeable());

    if (!m_script && m_data) {
        m_script = m_decoder->decode(m_data->data(), encodedSize());
        m_script.append(m_decoder->flush());
        setDecodedSize(m_script.sizeInBytes());
    }
    m_decodedDataDeletionTimer.startOneShot(0);

    return m_script;
}
Exemplo n.º 20
0
void CachedCSSStyleSheet::destroyDecodedData()
{
    if (!m_parsedStyleSheetCache)
        return;

    m_parsedStyleSheetCache->removedFromMemoryCache();
    m_parsedStyleSheetCache.clear();

    setDecodedSize(0);

    if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable())
        makePurgeable(true);
}
Exemplo n.º 21
0
void CachedCSSStyleSheet::destroyDecodedData()
{
    if (!m_parsedStyleSheetCache)
        return;

    m_parsedStyleSheetCache->removedFromMemoryCache();
    m_parsedStyleSheetCache.clear();

    setDecodedSize(0);

    if (isSafeToMakePurgeable())
        makePurgeable(true);
}
Exemplo n.º 22
0
void CachedScript::destroyDecodedData()
{
    m_script = String();
    unsigned extraSize = 0;
#if USE(JSC)
    if (m_sourceProviderCache && m_clients.isEmpty())
        m_sourceProviderCache->clear();

    extraSize = m_sourceProviderCache ? m_sourceProviderCache->byteSize() : 0;
#endif
    setDecodedSize(extraSize);
    if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable())
        makePurgeable(true);
}
Exemplo n.º 23
0
StringView CachedScript::script()
{
    if (!m_script && m_data) {
        if (m_ASCIIOptimizationState == Unknown
            && encodingMayBeAllASCII(encoding())
            && m_data->size()
            && charactersAreAllASCII(reinterpret_cast<const LChar*>(m_data->data()), m_data->size())) {

            m_script = StringImpl::createWithoutCopying(reinterpret_cast<const LChar*>(m_data->data()), m_data->size());
            m_ASCIIOptimizationState = DataAndDecodedStringHaveSameBytes;

            // If the encoded and decoded data are the same, there is no decoded data cost!
            setDecodedSize(0);
            m_decodedDataDeletionTimer.stop();
            return m_script;
        }
        m_script = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
        m_ASCIIOptimizationState = DataAndDecodedStringHaveDifferentBytes;
        setDecodedSize(m_script.sizeInBytes());
    }
    if (m_ASCIIOptimizationState == DataAndDecodedStringHaveDifferentBytes)
        m_decodedDataDeletionTimer.restart();
    return m_script;
}
Exemplo n.º 24
0
PassRefPtr<StyleSheetInternal> CachedCSSStyleSheet::restoreParsedStyleSheet(const CSSParserContext& context)
{
    if (!m_parsedStyleSheetCache)
        return 0;
    // Cached parsed stylesheet has mutated, kick it out.
    if (!m_parsedStyleSheetCache->isCacheable()) {
        m_parsedStyleSheetCache.clear();
        setDecodedSize(0);
        return 0;
    }
    // Contexts must be identical so we know we would get the same exact result if we parsed again.
    if (m_parsedStyleSheetCache->parserContext() != context)
        return 0;

    didAccessDecodedData(currentTime());
    // FIXME: Implement copy-on-write to avoid copying when not necessary.
    return m_parsedStyleSheetCache->copy();
}
Exemplo n.º 25
0
 void destroyDecodedDataIfPossible() override { setDecodedSize(0); }
 virtual void destroyDecodedData()
 {
     setDecodedSize(0);
 }
Exemplo n.º 27
0
void CachedScript::sourceProviderCacheSizeChanged(int delta)
{
    setDecodedSize(decodedSize() + delta);
}
Exemplo n.º 28
0
 virtual void appendData(const char* data, size_t len) {
   Resource::appendData(data, len);
   setDecodedSize(this->size());
 }
Exemplo n.º 29
0
void CSSStyleSheetResource::updateDecodedSize() {
    size_t decodedSize = m_decodedSheetText.charactersSizeInBytes();
    if (m_parsedStyleSheetCache)
        decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes();
    setDecodedSize(decodedSize);
}
Exemplo n.º 30
0
void CachedScript::destroyDecodedData()
{
    m_script = String();
    setDecodedSize(0);
}