Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 Resource::didAddClient(c); | 83 Resource::didAddClient(c); |
| 84 if (m_didNotifyFirstData) | 84 if (m_didNotifyFirstData) |
| 85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); | 85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); |
| 86 | 86 |
| 87 // |c| might be removed in didAppendFirstData, so ensure it is still a | 87 // |c| might be removed in didAppendFirstData, so ensure it is still a |
| 88 // client. | 88 // client. |
| 89 if (hasClient(c) && !isLoading()) | 89 if (hasClient(c) && !isLoading()) |
| 90 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); |
| 91 } | 91 } |
| 92 | 92 |
| 93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const | 93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) |
| 94 { | 94 { |
| 95 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) | 95 if (!canUseSheet(mimeTypeCheck)) |
| 96 return String(); | 96 return String(); |
| 97 | 97 |
| 98 // Only cache decoded sheet text when loading is complete. | |
| 99 if (isLoading()) | |
| 100 return decodedText(); | |
| 101 | |
| 102 // Use cached decoded sheet text when available. | |
| 98 if (!m_decodedSheetText.isNull()) | 103 if (!m_decodedSheetText.isNull()) |
| 99 return m_decodedSheetText; | 104 return m_decodedSheetText; |
| 100 | 105 |
| 101 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory | 106 if (!data() || data()->isEmpty()) |
| 102 return decodedText(); | 107 return String(); |
| 108 | |
| 109 m_decodedSheetText = decodedText(); | |
| 110 clearData(); | |
| 111 return m_decodedSheetText; | |
|
hiroshige
2016/08/31 07:30:25
IIUC, the Lines 106--111 are executed only in shee
kouhei (in TOK)
2016/08/31 10:27:43
Done.
| |
| 103 } | 112 } |
| 104 | 113 |
| 105 void CSSStyleSheetResource::appendData(const char* data, size_t length) | 114 void CSSStyleSheetResource::appendData(const char* data, size_t length) |
| 106 { | 115 { |
| 107 Resource::appendData(data, length); | 116 Resource::appendData(data, length); |
| 108 if (m_didNotifyFirstData) | 117 if (m_didNotifyFirstData) |
| 109 return; | 118 return; |
| 110 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 119 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 111 while (StyleSheetResourceClient* c = w.next()) | 120 while (StyleSheetResourceClient* c = w.next()) |
| 112 c->didAppendFirstData(this); | 121 c->didAppendFirstData(this); |
| 113 m_didNotifyFirstData = true; | 122 m_didNotifyFirstData = true; |
| 114 } | 123 } |
| 115 | 124 |
| 116 void CSSStyleSheetResource::checkNotify() | 125 void CSSStyleSheetResource::checkNotify() |
| 117 { | 126 { |
| 118 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify() | 127 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify() |
| 119 if (data()) | 128 sheetText(); |
|
hiroshige
2016/08/31 07:30:25
I think we call sheetText() here to ensure |m_data
kouhei (in TOK)
2016/08/31 10:27:43
Done.
| |
| 120 m_decodedSheetText = decodedText(); | |
| 121 | 129 |
| 122 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 130 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 123 while (StyleSheetResourceClient* c = w.next()) | 131 while (StyleSheetResourceClient* c = w.next()) |
| 124 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this); | 132 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this); |
| 125 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate. | |
| 126 m_decodedSheetText = String(); | |
| 127 } | 133 } |
| 128 | 134 |
| 129 void CSSStyleSheetResource::destroyDecodedDataIfPossible() | 135 void CSSStyleSheetResource::destroyDecodedDataIfPossible() |
| 130 { | 136 { |
| 131 if (!m_parsedStyleSheetCache) | 137 if (!m_parsedStyleSheetCache) |
| 132 return; | 138 return; |
| 133 | 139 |
| 134 setParsedStyleSheetCache(nullptr); | 140 setParsedStyleSheetCache(nullptr); |
| 135 setDecodedSize(0); | 141 setDecodedSize(0); |
| 136 } | 142 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // This stylesheet resource did conflict with another resource and was | 188 // This stylesheet resource did conflict with another resource and was |
| 183 // not added to the cache. | 189 // not added to the cache. |
| 184 setParsedStyleSheetCache(nullptr); | 190 setParsedStyleSheetCache(nullptr); |
| 185 return; | 191 return; |
| 186 } | 192 } |
| 187 setParsedStyleSheetCache(sheet); | 193 setParsedStyleSheetCache(sheet); |
| 188 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 194 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 189 } | 195 } |
| 190 | 196 |
| 191 } // namespace blink | 197 } // namespace blink |
| OLD | NEW |