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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2842923002: Support Inline module script (Closed)
Patch Set: Rebase Created 3 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (!IsScriptForEventSupported()) 313 if (!IsScriptForEventSupported())
314 return false; 314 return false;
315 315
316 // 14. is handled below. 316 // 14. is handled below.
317 317
318 // 15. "Let CORS setting be the current state of the element's 318 // 15. "Let CORS setting be the current state of the element's
319 // crossorigin content attribute." 319 // crossorigin content attribute."
320 CrossOriginAttributeValue cross_origin = 320 CrossOriginAttributeValue cross_origin =
321 GetCrossOriginAttributeValue(element_->CrossOriginAttributeValue()); 321 GetCrossOriginAttributeValue(element_->CrossOriginAttributeValue());
322 322
323 // 16. is handled below. 323 // 16. "Let module script credentials mode be determined by switching
324 // on CORS setting:"
325 WebURLRequest::FetchCredentialsMode credentials_mode =
326 WebURLRequest::kFetchCredentialsModeOmit;
327 switch (cross_origin) {
328 case kCrossOriginAttributeNotSet:
329 credentials_mode = WebURLRequest::kFetchCredentialsModeOmit;
330 break;
331 case kCrossOriginAttributeAnonymous:
332 credentials_mode = WebURLRequest::kFetchCredentialsModeSameOrigin;
333 break;
334 case kCrossOriginAttributeUseCredentials:
335 credentials_mode = WebURLRequest::kFetchCredentialsModeInclude;
336 break;
337 }
324 338
325 // 17. "If the script element has a nonce attribute, 339 // 17. "If the script element has a nonce attribute,
326 // then let cryptographic nonce be that attribute's value. 340 // then let cryptographic nonce be that attribute's value.
327 // Otherwise, let cryptographic nonce be the empty string." 341 // Otherwise, let cryptographic nonce be the empty string."
328 String nonce; 342 String nonce;
329 if (element_->IsNonceableElement()) 343 if (element_->IsNonceableElement())
330 nonce = element_->nonce(); 344 nonce = element_->nonce();
331 345
332 // 18. is handled below. 346 // 18. is handled below.
333 347
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // or if getting an encoding failed, let encoding 396 // or if getting an encoding failed, let encoding
383 // be the same as the encoding of the script element's node 397 // be the same as the encoding of the script element's node
384 // document." 398 // document."
385 // TODO(hiroshige): Should we handle failure in getting an encoding? 399 // TODO(hiroshige): Should we handle failure in getting an encoding?
386 String encoding; 400 String encoding;
387 if (!element_->CharsetAttributeValue().IsEmpty()) 401 if (!element_->CharsetAttributeValue().IsEmpty())
388 encoding = element_->CharsetAttributeValue(); 402 encoding = element_->CharsetAttributeValue();
389 else 403 else
390 encoding = element_document.characterSet(); 404 encoding = element_document.characterSet();
391 405
392 // Step 16 is skipped because "module script credentials" is not used
393 // for classic scripts.
394
395 // 18. "If the script element has an integrity attribute, 406 // 18. "If the script element has an integrity attribute,
396 // then let integrity metadata be that attribute's value. 407 // then let integrity metadata be that attribute's value.
397 // Otherwise, let integrity metadata be the empty string." 408 // Otherwise, let integrity metadata be the empty string."
398 String integrity_attr = element_->IntegrityAttributeValue(); 409 String integrity_attr = element_->IntegrityAttributeValue();
399 IntegrityMetadataSet integrity_metadata; 410 IntegrityMetadataSet integrity_metadata;
400 if (!integrity_attr.IsEmpty()) { 411 if (!integrity_attr.IsEmpty()) {
401 SubresourceIntegrity::ParseIntegrityAttribute( 412 SubresourceIntegrity::ParseIntegrityAttribute(
402 integrity_attr, integrity_metadata, &element_document); 413 integrity_attr, integrity_metadata, &element_document);
403 } 414 }
404 415
405 if (!FetchClassicScript(url, element_document.Fetcher(), nonce, 416 if (!FetchClassicScript(url, element_document.Fetcher(), nonce,
406 integrity_metadata, parser_state, cross_origin, 417 integrity_metadata, parser_state, cross_origin,
407 element_document.GetSecurityOrigin(), encoding)) { 418 element_document.GetSecurityOrigin(), encoding)) {
408 // TODO(hiroshige): Make this asynchronous. Currently we fire the error 419 // TODO(hiroshige): Make this asynchronous. Currently we fire the error
409 // event synchronously to keep the existing behavior. 420 // event synchronously to keep the existing behavior.
410 DispatchErrorEvent(); 421 DispatchErrorEvent();
411 return false; 422 return false;
412 } 423 }
413 424
414 DCHECK(resource_); 425 DCHECK(resource_);
415 DCHECK(!module_tree_client_); 426 DCHECK(!module_tree_client_);
416 } else { 427 } else {
417 // - "module": 428 // - "module":
418 429
419 // Steps 14 and 18 are skipped because they are not used in module 430 // Steps 14 and 18 are skipped because they are not used in module
420 // scripts. 431 // scripts.
421 432
422 // 16. "Let module script credentials mode be determined by switching
423 // on CORS setting:"
424 WebURLRequest::FetchCredentialsMode credentials_mode =
425 WebURLRequest::kFetchCredentialsModeOmit;
426 switch (cross_origin) {
427 case kCrossOriginAttributeNotSet:
428 credentials_mode = WebURLRequest::kFetchCredentialsModeOmit;
429 break;
430 case kCrossOriginAttributeAnonymous:
431 credentials_mode = WebURLRequest::kFetchCredentialsModeSameOrigin;
432 break;
433 case kCrossOriginAttributeUseCredentials:
434 credentials_mode = WebURLRequest::kFetchCredentialsModeInclude;
435 break;
436 }
437
438 DCHECK(RuntimeEnabledFeatures::moduleScriptsEnabled()); 433 DCHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
439 Modulator* modulator = Modulator::From( 434 Modulator* modulator = Modulator::From(
440 ToScriptStateForMainWorld(element_document.GetFrame())); 435 ToScriptStateForMainWorld(element_document.GetFrame()));
441 FetchModuleScriptTree(url, modulator, nonce, parser_state, 436 FetchModuleScriptTree(url, modulator, nonce, parser_state,
442 credentials_mode); 437 credentials_mode);
443 438
444 DCHECK(!resource_); 439 DCHECK(!resource_);
445 DCHECK(module_tree_client_); 440 DCHECK(module_tree_client_);
446 } 441 }
447 442
(...skipping 26 matching lines...) Expand all
474 // TODO(hiroshige): Make them merged or consistent. 469 // TODO(hiroshige): Make them merged or consistent.
475 470
476 // 22.2. "Switch on the script's type:" 471 // 22.2. "Switch on the script's type:"
477 switch (GetScriptType()) { 472 switch (GetScriptType()) {
478 // - "classic": 473 // - "classic":
479 case ScriptType::kClassic: 474 case ScriptType::kClassic:
480 // TODO(hiroshige): Clarify how Step 22.2 is implemented for "classic". 475 // TODO(hiroshige): Clarify how Step 22.2 is implemented for "classic".
481 break; 476 break;
482 477
483 // - "module": 478 // - "module":
484 case ScriptType::kModule: 479 case ScriptType::kModule: {
485 // TODO(hiroshige): Implement inline module scripts. 480 // 1. Let base URL be the script element's node document's document
486 element_document.AddConsoleMessage(ConsoleMessage::Create( 481 // base URL.
487 kJSMessageSource, kErrorMessageLevel, 482 KURL base_url = element_document.BaseURL();
488 "Inline module script is not yet supported", 483
489 SourceLocation::Create(element_document.Url().GetString(), 484 // 2. Let script be the result of creating a module script using
490 script_start_position.line_.OneBasedInt(), 485 // source text, settings, base URL, cryptographic nonce, parser state,
491 script_start_position.column_.OneBasedInt(), 486 // and module script credentials mode.
492 nullptr))); 487 Modulator* modulator = Modulator::From(
493 return false; 488 ToScriptStateForMainWorld(element_document.GetFrame()));
489 ModuleScript* module_script = ModuleScript::Create(
490 ScriptContent(), modulator, base_url, nonce, parser_state,
491 credentials_mode, kSharableCrossOrigin);
492
493 // 3. If this returns null, set the script's script to null and abort
494 // these substeps; the script is ready.
495 if (!module_script)
496 return false;
497
498 // 4. Fetch the descendants of script (using an empty ancestor list).
499 // When this asynchronously completes, set the script's script to
500 // the result. At that time, the script is ready.
501 DCHECK(!module_tree_client_);
502 module_tree_client_ = ModulePendingScriptTreeClient::Create();
503 modulator->FetchDescendantsForInlineScript(module_script,
504 module_tree_client_);
505 break;
506 }
494 } 507 }
495 } 508 }
496 509
497 // [Intervention] 510 // [Intervention]
498 // Since the asynchronous, low priority fetch for doc.written blocked 511 // Since the asynchronous, low priority fetch for doc.written blocked
499 // script is not for execution, return early from here. Watch for its 512 // script is not for execution, return early from here. Watch for its
500 // completion to be able to remove it from the memory cache. 513 // completion to be able to remove it from the memory cache.
501 if (GetScriptType() == ScriptType::kClassic && 514 if (GetScriptType() == ScriptType::kClassic &&
502 document_write_intervention_ == 515 document_write_intervention_ ==
503 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) { 516 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 // then abort these steps at this point. The script is not executed. 985 // then abort these steps at this point. The script is not executed.
973 return DeprecatedEqualIgnoringCase(event_attribute, "onload") || 986 return DeprecatedEqualIgnoringCase(event_attribute, "onload") ||
974 DeprecatedEqualIgnoringCase(event_attribute, "onload()"); 987 DeprecatedEqualIgnoringCase(event_attribute, "onload()");
975 } 988 }
976 989
977 String ScriptLoader::ScriptContent() const { 990 String ScriptLoader::ScriptContent() const {
978 return element_->TextFromChildren(); 991 return element_->TextFromChildren();
979 } 992 }
980 993
981 } // namespace blink 994 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698