Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp

Issue 2245003002: [Binding] Load 4 bytes to detect BOM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 const size_t length = 4;
502 size_t length = resource->resourceBuffer()->getSomeData(data, static_cas t<size_t>(0)); 502 char maybeBom[length + 1] = {};
tzik 2016/08/15 06:02:22 nit: s/Bom/BOM/ for consistency? nit: Do we need "
peria 2016/08/15 07:02:03 Done: BOM, +1 I put "= {}" just in case to clear m
503 if (!resource->resourceBuffer()->getAsBytes(maybeBom, length)) {
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, length);
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698