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 ASSERT(!isPurgeable()); | 95 ASSERT(!isPurgeable()); |
91 | 96 |
92 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck)) | 97 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck)) |
93 return String(); | 98 return String(); |
94 | 99 |
95 if (!m_decodedSheetText.isNull()) | 100 if (!m_decodedSheetText.isNull()) |
96 return m_decodedSheetText; | 101 return m_decodedSheetText; |
97 | 102 |
98 // Don't cache the decoded text, regenerating is cheap and it can use quite
a bit of memory | 103 // Don't cache the decoded text, regenerating is cheap and it can use quite
a bit of memory |
99 return decodedText(); | 104 return decodedText(); |
100 } | 105 } |
101 | 106 |
| 107 void CSSStyleSheetResource::appendData(const char* data, size_t length) |
| 108 { |
| 109 Resource::appendData(data, length); |
| 110 if (m_didNotifyFirstData) |
| 111 return; |
| 112 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 113 while (StyleSheetResourceClient* c = w.next()) |
| 114 c->didAppendFirstData(this); |
| 115 m_didNotifyFirstData = true; |
| 116 } |
| 117 |
102 void CSSStyleSheetResource::checkNotify() | 118 void CSSStyleSheetResource::checkNotify() |
103 { | 119 { |
104 // Decode the data to find out the encoding and keep the sheet text around d
uring checkNotify() | 120 // Decode the data to find out the encoding and keep the sheet text around d
uring checkNotify() |
105 if (m_data) | 121 if (m_data) |
106 m_decodedSheetText = decodedText(); | 122 m_decodedSheetText = decodedText(); |
107 | 123 |
108 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 124 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
109 while (StyleSheetResourceClient* c = w.next()) | 125 while (StyleSheetResourceClient* c = w.next()) |
110 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(
), this); | 126 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(
), this); |
111 // Clear the decoded text as it is unlikely to be needed immediately again a
nd is cheap to regenerate. | 127 // Clear the decoded text as it is unlikely to be needed immediately again a
nd is cheap to regenerate. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // This stylesheet resource did conflict with another resource and was | 189 // This stylesheet resource did conflict with another resource and was |
174 // not added to the cache. | 190 // not added to the cache. |
175 setParsedStyleSheetCache(nullptr); | 191 setParsedStyleSheetCache(nullptr); |
176 return; | 192 return; |
177 } | 193 } |
178 setParsedStyleSheetCache(sheet); | 194 setParsedStyleSheetCache(sheet); |
179 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 195 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
180 } | 196 } |
181 | 197 |
182 } // namespace blink | 198 } // namespace blink |
OLD | NEW |