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); | |
hiroshige
2016/07/26 09:57:10
|*c| must not be destructed during didAppendFirstD
haraken
2016/07/26 10:01:06
You won't need Persistent<StyleSheetResourceClient
| |
83 | 86 |
84 if (!isLoading()) | 87 if (!isLoading()) |
hiroshige
2016/07/26 09:57:10
|c| might be removed as client in didAppendFirstDa
Charlie Harrison
2016/07/26 16:31:52
Done.
| |
85 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(m_resourceRe quest.url(), m_response.url(), encoding(), this); | 88 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(m_resourceRe quest.url(), m_response.url(), encoding(), this); |
86 } | 89 } |
87 | 90 |
88 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const | 91 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const |
89 { | 92 { |
90 ASSERT(!isPurgeable()); | 93 ASSERT(!isPurgeable()); |
91 | 94 |
92 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck)) | 95 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck)) |
93 return String(); | 96 return String(); |
94 | 97 |
95 if (!m_decodedSheetText.isNull()) | 98 if (!m_decodedSheetText.isNull()) |
96 return m_decodedSheetText; | 99 return m_decodedSheetText; |
97 | 100 |
98 // 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 |
99 return decodedText(); | 102 return decodedText(); |
100 } | 103 } |
101 | 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 | |
102 void CSSStyleSheetResource::checkNotify() | 116 void CSSStyleSheetResource::checkNotify() |
103 { | 117 { |
104 // 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() |
105 if (m_data) | 119 if (m_data) |
106 m_decodedSheetText = decodedText(); | 120 m_decodedSheetText = decodedText(); |
107 | 121 |
108 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 122 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
109 while (StyleSheetResourceClient* c = w.next()) | 123 while (StyleSheetResourceClient* c = w.next()) |
110 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), encoding( ), this); | 124 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), encoding( ), this); |
111 // 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // This stylesheet resource did conflict with another resource and was | 187 // This stylesheet resource did conflict with another resource and was |
174 // not added to the cache. | 188 // not added to the cache. |
175 setParsedStyleSheetCache(nullptr); | 189 setParsedStyleSheetCache(nullptr); |
176 return; | 190 return; |
177 } | 191 } |
178 setParsedStyleSheetCache(sheet); | 192 setParsedStyleSheetCache(sheet); |
179 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 193 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
180 } | 194 } |
181 | 195 |
182 } // namespace blink | 196 } // namespace blink |
OLD | NEW |