| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptStreamer.h" | 5 #include "bindings/core/v8/ScriptStreamer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptStreamerThread.h" | 7 #include "bindings/core/v8/ScriptStreamerThread.h" |
| 8 #include "bindings/core/v8/V8ScriptRunner.h" | 8 #include "bindings/core/v8/V8ScriptRunner.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // So when resetting the bookmark, we have to adjust the lead position | 368 // So when resetting the bookmark, we have to adjust the lead position |
| 369 // to account for the BOM (which happens implicitly in the regular | 369 // to account for the BOM (which happens implicitly in the regular |
| 370 // streaming case). | 370 // streaming case). |
| 371 // We store this separately, to avoid having to guard all | 371 // We store this separately, to avoid having to guard all |
| 372 // m_queueLeadPosition references with a mutex. | 372 // m_queueLeadPosition references with a mutex. |
| 373 size_t m_lengthOfBOM; // Used by both threads; guarded by m_mutex. | 373 size_t m_lengthOfBOM; // Used by both threads; guarded by m_mutex. |
| 374 | 374 |
| 375 OwnPtr<WebTaskRunner> m_loadingTaskRunner; | 375 OwnPtr<WebTaskRunner> m_loadingTaskRunner; |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 size_t ScriptStreamer::kSmallScriptThreshold = 30 * 1024; | 378 size_t ScriptStreamer::s_smallScriptThreshold = 30 * 1024; |
| 379 | 379 |
| 380 void ScriptStreamer::startStreaming(PendingScript* script, Type scriptType, Sett
ings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunner) | 380 void ScriptStreamer::startStreaming(PendingScript* script, Type scriptType, Sett
ings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunner) |
| 381 { | 381 { |
| 382 // We don't yet know whether the script will really be streamed. E.g., | 382 // We don't yet know whether the script will really be streamed. E.g., |
| 383 // suppressing streaming for short scripts is done later. Record only the | 383 // suppressing streaming for short scripts is done later. Record only the |
| 384 // sure negative cases here. | 384 // sure negative cases here. |
| 385 bool startedStreaming = startStreamingInternal(script, scriptType, settings,
scriptState, loadingTaskRunner); | 385 bool startedStreaming = startStreamingInternal(script, scriptType, settings,
scriptState, loadingTaskRunner); |
| 386 if (!startedStreaming) | 386 if (!startedStreaming) |
| 387 Platform::current()->histogramEnumeration(startedStreamingHistogramName(
scriptType), 0, 2); | 387 Platform::current()->histogramEnumeration(startedStreamingHistogramName(
scriptType), 0, 2); |
| 388 } | 388 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 MutexLocker locker(m_mutex); | 463 MutexLocker locker(m_mutex); |
| 464 if (m_streamingSuppressed) | 464 if (m_streamingSuppressed) |
| 465 return; | 465 return; |
| 466 } | 466 } |
| 467 size_t lengthOfBOM = 0; | 467 size_t lengthOfBOM = 0; |
| 468 if (!m_haveEnoughDataForStreaming) { | 468 if (!m_haveEnoughDataForStreaming) { |
| 469 // Even if the first data chunk is small, the script can still be big | 469 // Even if the first data chunk is small, the script can still be big |
| 470 // enough - wait until the next data chunk comes before deciding whether | 470 // enough - wait until the next data chunk comes before deciding whether |
| 471 // to start the streaming. | 471 // to start the streaming. |
| 472 ASSERT(resource->resourceBuffer()); | 472 ASSERT(resource->resourceBuffer()); |
| 473 if (resource->resourceBuffer()->size() < kSmallScriptThreshold) | 473 if (resource->resourceBuffer()->size() < s_smallScriptThreshold) |
| 474 return; | 474 return; |
| 475 m_haveEnoughDataForStreaming = true; | 475 m_haveEnoughDataForStreaming = true; |
| 476 | 476 |
| 477 // Encoding should be detected only when we have some data. It's | 477 // Encoding should be detected only when we have some data. It's |
| 478 // possible that resource->encoding() returns a different encoding | 478 // possible that resource->encoding() returns a different encoding |
| 479 // before the loading has started and after we got some data. In | 479 // before the loading has started and after we got some data. In |
| 480 // addition, check for byte order marks. Note that checking the byte | 480 // addition, check for byte order marks. Note that checking the byte |
| 481 // order mark might change the encoding. We cannot decode the full text | 481 // order mark might change the encoding. We cannot decode the full text |
| 482 // here, because it might contain incomplete UTF-8 characters. Also note | 482 // here, because it might contain incomplete UTF-8 characters. Also note |
| 483 // that have at least kSmallScriptThreshold worth of data, which is more | 483 // that have at least s_smallScriptThreshold worth of data, which is mor
e |
| 484 // than enough for detecting a BOM. | 484 // than enough for detecting a BOM. |
| 485 const char* data = 0; | 485 const char* data = 0; |
| 486 size_t length = resource->resourceBuffer()->getSomeData(data, static_cas
t<size_t>(0)); | 486 size_t length = resource->resourceBuffer()->getSomeData(data, static_cas
t<size_t>(0)); |
| 487 | 487 |
| 488 OwnPtr<TextResourceDecoder> decoder(TextResourceDecoder::create("applica
tion/javascript", resource->encoding())); | 488 OwnPtr<TextResourceDecoder> decoder(TextResourceDecoder::create("applica
tion/javascript", resource->encoding())); |
| 489 lengthOfBOM = decoder->checkForBOM(data, length); | 489 lengthOfBOM = decoder->checkForBOM(data, length); |
| 490 | 490 |
| 491 // Maybe the encoding changed because we saw the BOM; get the encoding | 491 // Maybe the encoding changed because we saw the BOM; get the encoding |
| 492 // from the decoder. | 492 // from the decoder. |
| 493 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) { | 493 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 668 |
| 669 // The Resource might go out of scope if the script is no longer | 669 // The Resource might go out of scope if the script is no longer |
| 670 // needed. This makes PendingScript notify the ScriptStreamer when it is | 670 // needed. This makes PendingScript notify the ScriptStreamer when it is |
| 671 // destroyed. | 671 // destroyed. |
| 672 script->setStreamer(ScriptStreamer::create(resource, scriptType, scriptState
, compileOption, loadingTaskRunner)); | 672 script->setStreamer(ScriptStreamer::create(resource, scriptType, scriptState
, compileOption, loadingTaskRunner)); |
| 673 | 673 |
| 674 return true; | 674 return true; |
| 675 } | 675 } |
| 676 | 676 |
| 677 } // namespace blink | 677 } // namespace blink |
| OLD | NEW |