diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc | 132 |
1 files changed, 13 insertions, 119 deletions
diff --git a/chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc b/chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc index 21f66864055..c68af5bc75e 100644 --- a/chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc +++ b/chromium/third_party/blink/renderer/core/loader/resource/script_resource.cc @@ -26,6 +26,8 @@ #include "third_party/blink/renderer/core/loader/resource/script_resource.h" +#include <utility> + #include "services/network/public/mojom/request_context_frame_type.mojom-blink.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/loader/subresource_integrity_helper.h" @@ -36,6 +38,7 @@ #include "third_party/blink/renderer/platform/loader/fetch/integrity_metadata.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_client_walker.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h" +#include "third_party/blink/renderer/platform/loader/fetch/script_cached_metadata_handler.h" #include "third_party/blink/renderer/platform/loader/fetch/text_resource_decoder_options.h" #include "third_party/blink/renderer/platform/loader/subresource_integrity.h" #include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h" @@ -67,109 +70,6 @@ bool IsRequestContextSupported(WebURLRequest::RequestContext request_context) { } // namespace -// SingleCachedMetadataHandlerImpl should be created when a response is -// received, and can be used independently from Resource. - It doesn't have any -// references to Resource. Necessary data are captured -// from Resource when the handler is created. -// - It is not affected by Resource's revalidation on MemoryCache. -// The validity of the handler is solely checked by |response_url_| and -// |response_time_| (not by Resource) by the browser process, and the cached -// metadata written to the handler is rejected if e.g. the disk cache entry -// has been updated and the handler refers to an older response. -class ScriptResource::SingleCachedMetadataHandlerImpl final - : public SingleCachedMetadataHandler { - public: - SingleCachedMetadataHandlerImpl(const WTF::TextEncoding&, - std::unique_ptr<CachedMetadataSender>); - ~SingleCachedMetadataHandlerImpl() override = default; - void Trace(blink::Visitor*) override; - void SetCachedMetadata(uint32_t, const char*, size_t, CacheType) override; - void ClearCachedMetadata(CacheType) override; - scoped_refptr<CachedMetadata> GetCachedMetadata(uint32_t) const override; - - // This returns the encoding at the time of ResponseReceived(). - // Therefore this does NOT reflect encoding detection from body contents, - // but the final encoding after the encoding detection can be determined - // uniquely from Encoding(), provided the body content is the same, - // as we can assume the encoding detection will results in the same final - // encoding. - // TODO(hiroshige): Make this semantics cleaner. - String Encoding() const override { return String(encoding_.GetName()); } - - bool IsServedFromCacheStorage() const override { - return sender_->IsServedFromCacheStorage(); - } - - // Sets the serialized metadata retrieved from the platform's cache. - void SetSerializedCachedMetadata(const char*, size_t); - - private: - void SendToPlatform(); - - scoped_refptr<CachedMetadata> cached_metadata_; - std::unique_ptr<CachedMetadataSender> sender_; - - const WTF::TextEncoding encoding_; -}; - -ScriptResource::SingleCachedMetadataHandlerImpl:: - SingleCachedMetadataHandlerImpl( - const WTF::TextEncoding& encoding, - std::unique_ptr<CachedMetadataSender> sender) - : sender_(std::move(sender)), encoding_(encoding) {} - -void ScriptResource::SingleCachedMetadataHandlerImpl::Trace( - blink::Visitor* visitor) { - CachedMetadataHandler::Trace(visitor); -} - -void ScriptResource::SingleCachedMetadataHandlerImpl::SetCachedMetadata( - uint32_t data_type_id, - const char* data, - size_t size, - CachedMetadataHandler::CacheType cache_type) { - // Currently, only one type of cached metadata per resource is supported. If - // the need arises for multiple types of metadata per resource this could be - // enhanced to store types of metadata in a map. - DCHECK(!cached_metadata_); - cached_metadata_ = CachedMetadata::Create(data_type_id, data, size); - if (cache_type == CachedMetadataHandler::kSendToPlatform) - SendToPlatform(); -} - -void ScriptResource::SingleCachedMetadataHandlerImpl::ClearCachedMetadata( - CachedMetadataHandler::CacheType cache_type) { - cached_metadata_ = nullptr; - if (cache_type == CachedMetadataHandler::kSendToPlatform) - SendToPlatform(); -} - -scoped_refptr<CachedMetadata> -ScriptResource::SingleCachedMetadataHandlerImpl::GetCachedMetadata( - uint32_t data_type_id) const { - if (!cached_metadata_ || cached_metadata_->DataTypeID() != data_type_id) - return nullptr; - return cached_metadata_; -} - -void ScriptResource::SingleCachedMetadataHandlerImpl:: - SetSerializedCachedMetadata(const char* data, size_t size) { - // We only expect to receive cached metadata from the platform once. If this - // triggers, it indicates an efficiency problem which is most likely - // unexpected in code designed to improve performance. - DCHECK(!cached_metadata_); - cached_metadata_ = CachedMetadata::CreateFromSerializedData(data, size); -} - -void ScriptResource::SingleCachedMetadataHandlerImpl::SendToPlatform() { - if (cached_metadata_) { - const Vector<char>& serialized_data = cached_metadata_->SerializedData(); - sender_->Send(serialized_data.data(), serialized_data.size()); - } else { - sender_->Send(nullptr, 0); - } -} - ScriptResource* ScriptResource::Fetch(FetchParameters& params, ResourceFetcher* fetcher, ResourceClient* client) { @@ -199,14 +99,14 @@ void ScriptResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail, dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); } -const MovableString& ScriptResource::SourceText() { +const ParkableString& ScriptResource::SourceText() { DCHECK(IsLoaded()); if (source_text_.IsNull() && Data()) { String source_text = DecodedText(); ClearData(); SetDecodedSize(source_text.CharactersSizeInBytes()); - source_text_ = MovableString(source_text.ReleaseImpl()); + source_text_ = ParkableString(source_text.ReleaseImpl()); } return source_text_; @@ -218,36 +118,30 @@ SingleCachedMetadataHandler* ScriptResource::CacheHandler() { CachedMetadataHandler* ScriptResource::CreateCachedMetadataHandler( std::unique_ptr<CachedMetadataSender> send_callback) { - return new SingleCachedMetadataHandlerImpl(Encoding(), - std::move(send_callback)); + return new ScriptCachedMetadataHandler(Encoding(), std::move(send_callback)); } void ScriptResource::SetSerializedCachedMetadata(const char* data, size_t size) { Resource::SetSerializedCachedMetadata(data, size); - SingleCachedMetadataHandlerImpl* cache_handler = - static_cast<SingleCachedMetadataHandlerImpl*>(Resource::CacheHandler()); + ScriptCachedMetadataHandler* cache_handler = + static_cast<ScriptCachedMetadataHandler*>(Resource::CacheHandler()); if (cache_handler) { cache_handler->SetSerializedCachedMetadata(data, size); } } void ScriptResource::DestroyDecodedDataForFailedRevalidation() { - source_text_ = MovableString(); + source_text_ = ParkableString(); SetDecodedSize(0); } -AccessControlStatus ScriptResource::CalculateAccessControlStatus( - const SecurityOrigin* security_origin) const { - if (GetResponse().WasFetchedViaServiceWorker()) { - if (GetCORSStatus() == CORSStatus::kServiceWorkerOpaque) - return kOpaqueResource; - return kSharableCrossOrigin; - } +AccessControlStatus ScriptResource::CalculateAccessControlStatus() const { + if (GetCORSStatus() == CORSStatus::kServiceWorkerOpaque) + return kOpaqueResource; - if (security_origin && PassesAccessControlCheck(*security_origin)) + if (IsSameOriginOrCORSSuccessful()) return kSharableCrossOrigin; - return kNotSharableCrossOrigin; } |