| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 m_haveEnoughDataForStreaming = true; | 491 m_haveEnoughDataForStreaming = true; |
| 492 | 492 |
| 493 // Encoding should be detected only when we have some data. It's | 493 // Encoding should be detected only when we have some data. It's |
| 494 // possible that resource->encoding() returns a different encoding | 494 // possible that resource->encoding() returns a different encoding |
| 495 // before the loading has started and after we got some data. In | 495 // before the loading has started and after we got some data. In |
| 496 // addition, check for byte order marks. Note that checking the byte | 496 // addition, check for byte order marks. Note that checking the byte |
| 497 // order mark might change the encoding. We cannot decode the full text | 497 // order mark might change the encoding. We cannot decode the full text |
| 498 // here, because it might contain incomplete UTF-8 characters. Also note | 498 // here, because it might contain incomplete UTF-8 characters. Also note |
| 499 // that have at least s_smallScriptThreshold worth of data, which is mor
e | 499 // that have at least s_smallScriptThreshold worth of data, which is mor
e |
| 500 // than enough for detecting a BOM. | 500 // than enough for detecting a BOM. |
| 501 const char* data = 0; | 501 constexpr size_t maximumLengthOfBOM = 4; |
| 502 size_t length = resource->resourceBuffer()->getSomeData(data, static_cas
t<size_t>(0)); | 502 char maybeBOM[maximumLengthOfBOM] = {}; |
| 503 if (!resource->resourceBuffer()->getPartAsBytes(maybeBOM, static_cast<si
ze_t>(0), maximumLengthOfBOM)) { |
| 504 NOTREACHED(); |
| 505 return; |
| 506 } |
| 503 | 507 |
| 504 std::unique_ptr<TextResourceDecoder> decoder(TextResourceDecoder::create
("application/javascript", resource->encoding())); | 508 std::unique_ptr<TextResourceDecoder> decoder(TextResourceDecoder::create
("application/javascript", resource->encoding())); |
| 505 lengthOfBOM = decoder->checkForBOM(data, length); | 509 lengthOfBOM = decoder->checkForBOM(maybeBOM, maximumLengthOfBOM); |
| 506 | 510 |
| 507 // Maybe the encoding changed because we saw the BOM; get the encoding | 511 // Maybe the encoding changed because we saw the BOM; get the encoding |
| 508 // from the decoder. | 512 // from the decoder. |
| 509 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) { | 513 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) { |
| 510 suppressStreaming(); | 514 suppressStreaming(); |
| 511 recordNotStreamingReasonHistogram(m_scriptType, EncodingNotSupported
); | 515 recordNotStreamingReasonHistogram(m_scriptType, EncodingNotSupported
); |
| 512 recordStartedStreamingHistogram(m_scriptType, 0); | 516 recordStartedStreamingHistogram(m_scriptType, 0); |
| 513 return; | 517 return; |
| 514 } | 518 } |
| 515 if (ScriptStreamerThread::shared()->isRunningTask()) { | 519 if (ScriptStreamerThread::shared()->isRunningTask()) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 677 |
| 674 // The Resource might go out of scope if the script is no longer | 678 // The Resource might go out of scope if the script is no longer |
| 675 // needed. This makes PendingScript notify the ScriptStreamer when it is | 679 // needed. This makes PendingScript notify the ScriptStreamer when it is |
| 676 // destroyed. | 680 // destroyed. |
| 677 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState,
compileOption, loadingTaskRunner)); | 681 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState,
compileOption, loadingTaskRunner)); |
| 678 | 682 |
| 679 return true; | 683 return true; |
| 680 } | 684 } |
| 681 | 685 |
| 682 } // namespace blink | 686 } // namespace blink |
| OLD | NEW |