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

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: Split CL 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return; 490 return;
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.
kouhei (in TOK) 2016/08/15 07:43:49 Let's update this comment too.
kouhei (in TOK) 2016/08/15 08:19:14 Discussed offline, let me retract this.
peria 2016/08/15 08:28:38 Acknowledged.
501 const char* data = 0; 501 char maybeBOM[length] = {};
502 size_t length = resource->resourceBuffer()->getSomeData(data, static_cas t<size_t>(0)); 502 if (!resource->resourceBuffer()->getPartAsBytes(maybeBOM, static_cast<si ze_t>(0), length)) {
503 NOTREACHED();
504 return;
505 }
503 506
504 std::unique_ptr<TextResourceDecoder> decoder(TextResourceDecoder::create ("application/javascript", resource->encoding())); 507 std::unique_ptr<TextResourceDecoder> decoder(TextResourceDecoder::create ("application/javascript", resource->encoding()));
505 lengthOfBOM = decoder->checkForBOM(data, length); 508 lengthOfBOM = decoder->checkForBOM(maybeBOM, length);
506 509
507 // Maybe the encoding changed because we saw the BOM; get the encoding 510 // Maybe the encoding changed because we saw the BOM; get the encoding
508 // from the decoder. 511 // from the decoder.
509 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) { 512 if (!convertEncoding(decoder->encoding().name(), &m_encoding)) {
510 suppressStreaming(); 513 suppressStreaming();
511 recordNotStreamingReasonHistogram(m_scriptType, EncodingNotSupported ); 514 recordNotStreamingReasonHistogram(m_scriptType, EncodingNotSupported );
512 recordStartedStreamingHistogram(m_scriptType, 0); 515 recordStartedStreamingHistogram(m_scriptType, 0);
513 return; 516 return;
514 } 517 }
515 if (ScriptStreamerThread::shared()->isRunningTask()) { 518 if (ScriptStreamerThread::shared()->isRunningTask()) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 676
674 // The Resource might go out of scope if the script is no longer 677 // The Resource might go out of scope if the script is no longer
675 // needed. This makes PendingScript notify the ScriptStreamer when it is 678 // needed. This makes PendingScript notify the ScriptStreamer when it is
676 // destroyed. 679 // destroyed.
677 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState, compileOption, loadingTaskRunner)); 680 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState, compileOption, loadingTaskRunner));
678 681
679 return true; 682 return true;
680 } 683 }
681 684
682 } // namespace blink 685 } // 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