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

Side by Side Diff: third_party/WebKit/Source/core/loader/resource/ScriptResource.cpp

Issue 2724673002: [WIP] Introduce ScriptResourceData
Patch Set: Fix 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) 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 16 matching lines...) Expand all
27 #include "core/loader/resource/ScriptResource.h" 27 #include "core/loader/resource/ScriptResource.h"
28 28
29 #include "platform/SharedBuffer.h" 29 #include "platform/SharedBuffer.h"
30 #include "platform/instrumentation/tracing/web_memory_allocator_dump.h" 30 #include "platform/instrumentation/tracing/web_memory_allocator_dump.h"
31 #include "platform/instrumentation/tracing/web_process_memory_dump.h" 31 #include "platform/instrumentation/tracing/web_process_memory_dump.h"
32 #include "platform/loader/fetch/CrossOriginAccessControl.h" 32 #include "platform/loader/fetch/CrossOriginAccessControl.h"
33 #include "platform/loader/fetch/FetchParameters.h" 33 #include "platform/loader/fetch/FetchParameters.h"
34 #include "platform/loader/fetch/IntegrityMetadata.h" 34 #include "platform/loader/fetch/IntegrityMetadata.h"
35 #include "platform/loader/fetch/ResourceClientWalker.h" 35 #include "platform/loader/fetch/ResourceClientWalker.h"
36 #include "platform/loader/fetch/ResourceFetcher.h" 36 #include "platform/loader/fetch/ResourceFetcher.h"
37 #include "platform/network/mime/MIMETypeRegistry.h"
38 37
39 namespace blink { 38 namespace blink {
40 39
41 ScriptResource* ScriptResource::Fetch(FetchParameters& params, 40 ScriptResource* ScriptResource::Fetch(FetchParameters& params,
42 ResourceFetcher* fetcher) { 41 ResourceFetcher* fetcher) {
43 DCHECK_EQ(params.GetResourceRequest().GetFrameType(), 42 DCHECK_EQ(params.GetResourceRequest().GetFrameType(),
44 WebURLRequest::kFrameTypeNone); 43 WebURLRequest::kFrameTypeNone);
45 params.SetRequestContext(WebURLRequest::kRequestContextScript); 44 params.SetRequestContext(WebURLRequest::kRequestContextScript);
46 ScriptResource* resource = ToScriptResource( 45 ScriptResource* resource = ToScriptResource(
47 fetcher->RequestResource(params, ScriptResourceFactory())); 46 fetcher->RequestResource(params, ScriptResourceFactory()));
(...skipping 23 matching lines...) Expand all
71 ResourceClientWalker<ScriptResourceClient> walker(Clients()); 70 ResourceClientWalker<ScriptResourceClient> walker(Clients());
72 while (ScriptResourceClient* client = walker.Next()) 71 while (ScriptResourceClient* client = walker.Next())
73 client->NotifyAppendData(this); 72 client->NotifyAppendData(this);
74 } 73 }
75 74
76 void ScriptResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail, 75 void ScriptResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail,
77 WebProcessMemoryDump* memory_dump) const { 76 WebProcessMemoryDump* memory_dump) const {
78 Resource::OnMemoryDump(level_of_detail, memory_dump); 77 Resource::OnMemoryDump(level_of_detail, memory_dump);
79 const String name = GetMemoryDumpName() + "/decoded_script"; 78 const String name = GetMemoryDumpName() + "/decoded_script";
80 auto dump = memory_dump->CreateMemoryAllocatorDump(name); 79 auto dump = memory_dump->CreateMemoryAllocatorDump(name);
81 dump->AddScalar("size", "bytes", source_text_.CharactersSizeInBytes()); 80 dump->AddScalar("size", "bytes", DecodedSize());
82 memory_dump->AddSuballocation( 81 memory_dump->AddSuballocation(
83 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); 82 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
84 } 83 }
85 84
86 const String& ScriptResource::SourceText() { 85 const ScriptResourceData* ScriptResource::ResourceData() {
87 DCHECK(IsLoaded()); 86 DCHECK(IsLoaded());
87 if (script_data_)
88 return script_data_;
88 89
89 if (source_text_.IsNull() && Data()) { 90 AtomicString atomic_source_text;
91 if (Data()) {
90 String source_text = DecodedText(); 92 String source_text = DecodedText();
91 ClearData(); 93 ClearData();
92 SetDecodedSize(source_text.CharactersSizeInBytes()); 94 SetDecodedSize(source_text.CharactersSizeInBytes());
93 source_text_ = AtomicString(source_text); 95 atomic_source_text = AtomicString(source_text);
94 } 96 }
95 97
96 return source_text_; 98 script_data_ = new ScriptResourceData(Url(), GetResponse(), ErrorOccurred(),
99 atomic_source_text, CacheHandler(),
100 GetStoredCredentials());
101
102 return script_data_;
97 } 103 }
98 104
99 void ScriptResource::DestroyDecodedDataForFailedRevalidation() { 105 void ScriptResource::DestroyDecodedDataForFailedRevalidation() {
100 source_text_ = AtomicString(); 106 script_data_ = nullptr;
101 } 107 }
102 108
103 // static 109 DEFINE_TRACE(ScriptResource) {
104 bool ScriptResource::MimeTypeAllowedByNosniff( 110 visitor->Trace(script_data_);
105 const ResourceResponse& response) { 111 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(
114 const SecurityOrigin* security_origin) const {
115 if (GetResponse().WasFetchedViaServiceWorker()) {
116 if (GetResponse().ServiceWorkerResponseType() ==
117 kWebServiceWorkerResponseTypeOpaque) {
118 return kOpaqueResource;
119 }
120
121 return kSharableCrossOrigin;
122 }
123
124 if (CrossOriginAccessControl::CheckAccess(
125 GetResponse(), GetStoredCredentials(), security_origin) ==
126 CrossOriginAccessControl::kAccessAllowed) {
127 return kSharableCrossOrigin;
128 }
129
130 return kNotSharableCrossOrigin;
131 } 112 }
132 113
133 } // namespace blink 114 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698