| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/loader/SubresourceIntegrityHelper.h" | 30 #include "core/loader/SubresourceIntegrityHelper.h" |
| 31 #include "platform/SharedBuffer.h" | 31 #include "platform/SharedBuffer.h" |
| 32 #include "platform/instrumentation/tracing/web_memory_allocator_dump.h" | 32 #include "platform/instrumentation/tracing/web_memory_allocator_dump.h" |
| 33 #include "platform/instrumentation/tracing/web_process_memory_dump.h" | 33 #include "platform/instrumentation/tracing/web_process_memory_dump.h" |
| 34 #include "platform/loader/SubresourceIntegrity.h" | 34 #include "platform/loader/SubresourceIntegrity.h" |
| 35 #include "platform/loader/fetch/FetchParameters.h" | 35 #include "platform/loader/fetch/FetchParameters.h" |
| 36 #include "platform/loader/fetch/IntegrityMetadata.h" | 36 #include "platform/loader/fetch/IntegrityMetadata.h" |
| 37 #include "platform/loader/fetch/ResourceClientWalker.h" | 37 #include "platform/loader/fetch/ResourceClientWalker.h" |
| 38 #include "platform/loader/fetch/ResourceFetcher.h" | 38 #include "platform/loader/fetch/ResourceFetcher.h" |
| 39 #include "platform/loader/fetch/TextResourceDecoderOptions.h" | |
| 40 #include "platform/network/mime/MIMETypeRegistry.h" | |
| 41 | 39 |
| 42 namespace blink { | 40 namespace blink { |
| 43 | 41 |
| 44 ScriptResource* ScriptResource::Fetch(FetchParameters& params, | 42 ScriptResource* ScriptResource::Fetch(FetchParameters& params, |
| 45 ResourceFetcher* fetcher) { | 43 ResourceFetcher* fetcher) { |
| 46 DCHECK_EQ(params.GetResourceRequest().GetFrameType(), | 44 DCHECK_EQ(params.GetResourceRequest().GetFrameType(), |
| 47 WebURLRequest::kFrameTypeNone); | 45 WebURLRequest::kFrameTypeNone); |
| 48 params.SetRequestContext(WebURLRequest::kRequestContextScript); | 46 params.SetRequestContext(WebURLRequest::kRequestContextScript); |
| 49 ScriptResource* resource = ToScriptResource( | 47 ScriptResource* resource = ToScriptResource( |
| 50 fetcher->RequestResource(params, ScriptResourceFactory())); | 48 fetcher->RequestResource(params, ScriptResourceFactory())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 ResourceClientWalker<ScriptResourceClient> walker(Clients()); | 69 ResourceClientWalker<ScriptResourceClient> walker(Clients()); |
| 72 while (ScriptResourceClient* client = walker.Next()) | 70 while (ScriptResourceClient* client = walker.Next()) |
| 73 client->NotifyAppendData(this); | 71 client->NotifyAppendData(this); |
| 74 } | 72 } |
| 75 | 73 |
| 76 void ScriptResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail, | 74 void ScriptResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail, |
| 77 WebProcessMemoryDump* memory_dump) const { | 75 WebProcessMemoryDump* memory_dump) const { |
| 78 Resource::OnMemoryDump(level_of_detail, memory_dump); | 76 Resource::OnMemoryDump(level_of_detail, memory_dump); |
| 79 const String name = GetMemoryDumpName() + "/decoded_script"; | 77 const String name = GetMemoryDumpName() + "/decoded_script"; |
| 80 auto dump = memory_dump->CreateMemoryAllocatorDump(name); | 78 auto dump = memory_dump->CreateMemoryAllocatorDump(name); |
| 81 dump->AddScalar("size", "bytes", source_text_.CharactersSizeInBytes()); | 79 dump->AddScalar("size", "bytes", DecodedSize()); |
| 82 memory_dump->AddSuballocation( | 80 memory_dump->AddSuballocation( |
| 83 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); | 81 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); |
| 84 } | 82 } |
| 85 | 83 |
| 86 const String& ScriptResource::SourceText() { | 84 const ScriptResourceData* ScriptResource::ResourceData() { |
| 87 DCHECK(IsLoaded()); | 85 DCHECK(IsLoaded()); |
| 86 if (script_data_) |
| 87 return script_data_; |
| 88 | 88 |
| 89 if (source_text_.IsNull() && Data()) { | 89 AtomicString atomic_source_text; |
| 90 if (Data()) { |
| 90 String source_text = DecodedText(); | 91 String source_text = DecodedText(); |
| 91 ClearData(); | 92 ClearData(); |
| 92 SetDecodedSize(source_text.CharactersSizeInBytes()); | 93 SetDecodedSize(source_text.CharactersSizeInBytes()); |
| 93 source_text_ = AtomicString(source_text); | 94 atomic_source_text = AtomicString(source_text); |
| 94 } | 95 } |
| 95 | 96 |
| 96 return source_text_; | 97 script_data_ = new ScriptResourceData( |
| 98 Url(), ResourceRequest().GetFetchCredentialsMode(), GetResponse(), |
| 99 ErrorOccurred(), atomic_source_text, CacheHandler(), GetCORSStatus()); |
| 100 |
| 101 return script_data_; |
| 97 } | 102 } |
| 98 | 103 |
| 99 void ScriptResource::DestroyDecodedDataForFailedRevalidation() { | 104 void ScriptResource::DestroyDecodedDataForFailedRevalidation() { |
| 100 source_text_ = AtomicString(); | 105 script_data_ = nullptr; |
| 101 } | 106 } |
| 102 | 107 |
| 103 // static | 108 DEFINE_TRACE(ScriptResource) { |
| 104 bool ScriptResource::MimeTypeAllowedByNosniff( | 109 visitor->Trace(script_data_); |
| 105 const ResourceResponse& response) { | 110 TextResource::Trace(visitor); |
| 106 return ParseContentTypeOptionsHeader( | |
| 107 response.HttpHeaderField(HTTPNames::X_Content_Type_Options)) != | |
| 108 kContentTypeOptionsNosniff || | |
| 109 MIMETypeRegistry::IsSupportedJavaScriptMIMEType( | |
| 110 response.HttpContentType()); | |
| 111 } | |
| 112 | |
| 113 AccessControlStatus ScriptResource::CalculateAccessControlStatus() const { | |
| 114 if (GetCORSStatus() == CORSStatus::kServiceWorkerOpaque) | |
| 115 return kOpaqueResource; | |
| 116 | |
| 117 if (IsSameOriginOrCORSSuccessful()) | |
| 118 return kSharableCrossOrigin; | |
| 119 | |
| 120 return kNotSharableCrossOrigin; | |
| 121 } | 111 } |
| 122 | 112 |
| 123 } // namespace blink | 113 } // namespace blink |
| OLD | NEW |