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