Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 setScriptResource(nullptr); | 59 setScriptResource(nullptr); |
| 60 m_startingPosition = TextPosition::belowRangePosition(); | 60 m_startingPosition = TextPosition::belowRangePosition(); |
| 61 m_integrityFailure = false; | 61 m_integrityFailure = false; |
| 62 m_parserBlockingLoadStartTime = 0; | 62 m_parserBlockingLoadStartTime = 0; |
| 63 if (m_streamer) | 63 if (m_streamer) |
| 64 m_streamer->cancel(); | 64 m_streamer->cancel(); |
| 65 m_streamer = nullptr; | 65 m_streamer = nullptr; |
| 66 m_element = nullptr; | 66 m_element = nullptr; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PendingScript::watchForLoad(ScriptResourceClient* client) { | 69 void PendingScript::watchForLoad(PendingScriptClient* client) { |
| 70 DCHECK(!m_watchingForLoad); | 70 DCHECK(!m_watchingForLoad); |
| 71 // addClient() will call streamingFinished() if the load is complete. Callers | 71 // addClient() will call streamingFinished() if the load is complete. Callers |
| 72 // who do not expect to be re-entered from this call should not call | 72 // who do not expect to be re-entered from this call should not call |
| 73 // watchForLoad for a PendingScript which isReady. We also need to set | 73 // watchForLoad for a PendingScript which isReady. We also need to set |
| 74 // m_watchingForLoad early, since addClient() can result in calling | 74 // m_watchingForLoad early, since addClient() can result in calling |
| 75 // notifyFinished and further stopWatchingForLoad(). | 75 // notifyFinished and further stopWatchingForLoad(). |
| 76 m_watchingForLoad = true; | 76 m_watchingForLoad = true; |
| 77 m_client = client; | 77 m_client = client; |
| 78 if (!m_streamer) | 78 if (isReady()) |
| 79 resource()->addClient(client); | 79 m_client->pendingScriptFinished(this); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void PendingScript::stopWatchingForLoad() { | 82 void PendingScript::stopWatchingForLoad() { |
| 83 if (!m_watchingForLoad) | 83 if (!m_watchingForLoad) |
| 84 return; | 84 return; |
| 85 DCHECK(resource()); | 85 DCHECK(resource()); |
| 86 if (!m_streamer) | |
| 87 resource()->removeClient(m_client); | |
| 88 m_client = nullptr; | 86 m_client = nullptr; |
| 89 m_watchingForLoad = false; | 87 m_watchingForLoad = false; |
| 90 } | 88 } |
| 91 | 89 |
| 92 void PendingScript::streamingFinished() { | 90 void PendingScript::streamingFinished() { |
| 93 DCHECK(resource()); | 91 DCHECK(resource()); |
| 94 if (m_client) | 92 if (m_client) |
| 95 m_client->notifyFinished(resource()); | 93 m_client->pendingScriptFinished(this); |
|
kouhei (in TOK)
2016/12/12 01:37:05
Wow. Thanks for this change. Old code abusing Scri
| |
| 96 } | 94 } |
| 97 | 95 |
| 98 void PendingScript::setElement(Element* element) { | 96 void PendingScript::setElement(Element* element) { |
| 99 m_element = element; | 97 m_element = element; |
| 100 } | 98 } |
| 101 | 99 |
| 102 void PendingScript::setScriptResource(ScriptResource* resource) { | 100 void PendingScript::setScriptResource(ScriptResource* resource) { |
| 103 setResource(resource); | 101 setResource(resource); |
| 104 } | 102 } |
| 105 | 103 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 scriptResource->integrityMetadata(), *m_element, | 155 scriptResource->integrityMetadata(), *m_element, |
| 158 resource->resourceBuffer()->data(), | 156 resource->resourceBuffer()->data(), |
| 159 resource->resourceBuffer()->size(), resource->url(), *resource); | 157 resource->resourceBuffer()->size(), resource->url(), *resource); |
| 160 scriptResource->setIntegrityDisposition( | 158 scriptResource->setIntegrityDisposition( |
| 161 m_integrityFailure ? ResourceIntegrityDisposition::Failed | 159 m_integrityFailure ? ResourceIntegrityDisposition::Failed |
| 162 : ResourceIntegrityDisposition::Passed); | 160 : ResourceIntegrityDisposition::Passed); |
| 163 } | 161 } |
| 164 } | 162 } |
| 165 } | 163 } |
| 166 | 164 |
| 165 // If script streaming is in use, the client will be notified in | |
| 166 // streamingFinished. | |
| 167 if (m_streamer) | 167 if (m_streamer) |
| 168 m_streamer->notifyFinished(resource); | 168 m_streamer->notifyFinished(resource); |
| 169 else if (m_client) | |
| 170 m_client->pendingScriptFinished(this); | |
| 169 } | 171 } |
| 170 | 172 |
| 171 void PendingScript::notifyAppendData(ScriptResource* resource) { | 173 void PendingScript::notifyAppendData(ScriptResource* resource) { |
| 172 if (m_streamer) | 174 if (m_streamer) |
| 173 m_streamer->notifyAppendData(resource); | 175 m_streamer->notifyAppendData(resource); |
| 174 } | 176 } |
| 175 | 177 |
| 176 DEFINE_TRACE(PendingScript) { | 178 DEFINE_TRACE(PendingScript) { |
| 177 visitor->trace(m_element); | 179 visitor->trace(m_element); |
| 178 visitor->trace(m_streamer); | 180 visitor->trace(m_streamer); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 void PendingScript::onMemoryStateChange(MemoryState state) { | 222 void PendingScript::onMemoryStateChange(MemoryState state) { |
| 221 if (state != MemoryState::SUSPENDED) | 223 if (state != MemoryState::SUSPENDED) |
| 222 return; | 224 return; |
| 223 if (!m_streamer) | 225 if (!m_streamer) |
| 224 return; | 226 return; |
| 225 m_streamer->cancel(); | 227 m_streamer->cancel(); |
| 226 m_streamer = nullptr; | 228 m_streamer = nullptr; |
| 227 } | 229 } |
| 228 | 230 |
| 229 } // namespace blink | 231 } // namespace blink |
| OLD | NEW |