| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe
etResourceFactory())); | 44 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe
etResourceFactory())); |
| 45 } | 45 } |
| 46 | 46 |
| 47 CSSStyleSheetResource* CSSStyleSheetResource::createForTest(const ResourceReques
t& request, const String& charset) | 47 CSSStyleSheetResource* CSSStyleSheetResource::createForTest(const ResourceReques
t& request, const String& charset) |
| 48 { | 48 { |
| 49 return new CSSStyleSheetResource(request, ResourceLoaderOptions(), charset); | 49 return new CSSStyleSheetResource(request, ResourceLoaderOptions(), charset); |
| 50 } | 50 } |
| 51 | 51 |
| 52 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ
est, const ResourceLoaderOptions& options, const String& charset) | 52 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ
est, const ResourceLoaderOptions& options, const String& charset) |
| 53 : StyleSheetResource(resourceRequest, CSSStyleSheet, options, "text/css", ch
arset) | 53 : StyleSheetResource(resourceRequest, CSSStyleSheet, options, "text/css", ch
arset) |
| 54 , m_didNotifyFirstData(false) |
| 54 { | 55 { |
| 55 } | 56 } |
| 56 | 57 |
| 57 CSSStyleSheetResource::~CSSStyleSheetResource() | 58 CSSStyleSheetResource::~CSSStyleSheetResource() |
| 58 { | 59 { |
| 59 } | 60 } |
| 60 | 61 |
| 61 void CSSStyleSheetResource::setParsedStyleSheetCache(StyleSheetContents* newShee
t) | 62 void CSSStyleSheetResource::setParsedStyleSheetCache(StyleSheetContents* newShee
t) |
| 62 { | 63 { |
| 63 if (m_parsedStyleSheetCache) | 64 if (m_parsedStyleSheetCache) |
| 64 m_parsedStyleSheetCache->clearReferencedFromResource(); | 65 m_parsedStyleSheetCache->clearReferencedFromResource(); |
| 65 m_parsedStyleSheetCache = newSheet; | 66 m_parsedStyleSheetCache = newSheet; |
| 66 if (m_parsedStyleSheetCache) | 67 if (m_parsedStyleSheetCache) |
| 67 m_parsedStyleSheetCache->setReferencedFromResource(this); | 68 m_parsedStyleSheetCache->setReferencedFromResource(this); |
| 68 } | 69 } |
| 69 | 70 |
| 70 DEFINE_TRACE(CSSStyleSheetResource) | 71 DEFINE_TRACE(CSSStyleSheetResource) |
| 71 { | 72 { |
| 72 visitor->trace(m_parsedStyleSheetCache); | 73 visitor->trace(m_parsedStyleSheetCache); |
| 73 StyleSheetResource::trace(visitor); | 74 StyleSheetResource::trace(visitor); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void CSSStyleSheetResource::didAddClient(ResourceClient* c) | 77 void CSSStyleSheetResource::didAddClient(ResourceClient* c) |
| 77 { | 78 { |
| 78 ASSERT(StyleSheetResourceClient::isExpectedType(c)); | 79 ASSERT(StyleSheetResourceClient::isExpectedType(c)); |
| 79 // Resource::didAddClient() must be before setCSSStyleSheet(), | 80 // Resource::didAddClient() must be before setCSSStyleSheet(), |
| 80 // because setCSSStyleSheet() may cause scripts to be executed, which could
destroy 'c' if it is an instance of HTMLLinkElement. | 81 // because setCSSStyleSheet() may cause scripts to be executed, which could
destroy 'c' if it is an instance of HTMLLinkElement. |
| 81 // see the comment of HTMLLinkElement::setCSSStyleSheet. | 82 // see the comment of HTMLLinkElement::setCSSStyleSheet. |
| 82 Resource::didAddClient(c); | 83 Resource::didAddClient(c); |
| 84 if (m_didNotifyFirstData) |
| 85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); |
| 83 | 86 |
| 84 if (!isLoading()) | 87 // |c| might be removed in didAppendFirstData, so ensure it is still a |
| 88 // client. |
| 89 if (hasClient(c) && !isLoading()) |
| 85 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ
est().url(), response().url(), encoding(), this); | 90 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ
est().url(), response().url(), encoding(), this); |
| 86 } | 91 } |
| 87 | 92 |
| 88 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const | 93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const |
| 89 { | 94 { |
| 90 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) | 95 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) |
| 91 return String(); | 96 return String(); |
| 92 | 97 |
| 93 if (!m_decodedSheetText.isNull()) | 98 if (!m_decodedSheetText.isNull()) |
| 94 return m_decodedSheetText; | 99 return m_decodedSheetText; |
| 95 | 100 |
| 96 // Don't cache the decoded text, regenerating is cheap and it can use quite
a bit of memory | 101 // Don't cache the decoded text, regenerating is cheap and it can use quite
a bit of memory |
| 97 return decodedText(); | 102 return decodedText(); |
| 98 } | 103 } |
| 99 | 104 |
| 105 void CSSStyleSheetResource::appendData(const char* data, size_t length) |
| 106 { |
| 107 Resource::appendData(data, length); |
| 108 if (m_didNotifyFirstData) |
| 109 return; |
| 110 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 111 while (StyleSheetResourceClient* c = w.next()) |
| 112 c->didAppendFirstData(this); |
| 113 m_didNotifyFirstData = true; |
| 114 } |
| 115 |
| 100 void CSSStyleSheetResource::checkNotify() | 116 void CSSStyleSheetResource::checkNotify() |
| 101 { | 117 { |
| 102 // Decode the data to find out the encoding and keep the sheet text around d
uring checkNotify() | 118 // Decode the data to find out the encoding and keep the sheet text around d
uring checkNotify() |
| 103 if (data()) | 119 if (data()) |
| 104 m_decodedSheetText = decodedText(); | 120 m_decodedSheetText = decodedText(); |
| 105 | 121 |
| 106 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 122 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 107 while (StyleSheetResourceClient* c = w.next()) | 123 while (StyleSheetResourceClient* c = w.next()) |
| 108 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(
), this); | 124 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(
), this); |
| 109 // Clear the decoded text as it is unlikely to be needed immediately again a
nd is cheap to regenerate. | 125 // Clear the decoded text as it is unlikely to be needed immediately again a
nd is cheap to regenerate. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // This stylesheet resource did conflict with another resource and was | 182 // This stylesheet resource did conflict with another resource and was |
| 167 // not added to the cache. | 183 // not added to the cache. |
| 168 setParsedStyleSheetCache(nullptr); | 184 setParsedStyleSheetCache(nullptr); |
| 169 return; | 185 return; |
| 170 } | 186 } |
| 171 setParsedStyleSheetCache(sheet); | 187 setParsedStyleSheetCache(sheet); |
| 172 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 188 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 173 } | 189 } |
| 174 | 190 |
| 175 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |