OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | |
6 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
7 | |
8 This library is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU Library General Public | |
10 License as published by the Free Software Foundation; either | |
11 version 2 of the License, or (at your option) any later version. | |
12 | |
13 This library is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 Library General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Library General Public License | |
19 along with this library; see the file COPYING.LIB. If not, write to | |
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
21 Boston, MA 02110-1301, USA. | |
22 | |
23 This class provides all functionality needed for loading images, style sheet
s and html | |
24 pages from the web. It has a memory cache for these objects. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/fetch/ScriptResource.h" | |
29 | |
30 #include "core/fetch/FetchRequest.h" | |
31 #include "core/fetch/ResourceClientWalker.h" | |
32 #include "core/fetch/ResourceFetcher.h" | |
33 #include "platform/MIMETypeRegistry.h" | |
34 #include "platform/SharedBuffer.h" | |
35 #include "platform/network/HTTPParsers.h" | |
36 | |
37 namespace blink { | |
38 | |
39 ResourcePtr<ScriptResource> ScriptResource::fetch(FetchRequest& request, Resourc
eFetcher* fetcher) | |
40 { | |
41 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | |
42 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textScript); | |
43 return toScriptResource(fetcher->requestResource(request, ScriptResourceFact
ory())); | |
44 } | |
45 | |
46 ScriptResource::ScriptResource(const ResourceRequest& resourceRequest, const Str
ing& charset) | |
47 : TextResource(resourceRequest, Script, "application/javascript", charset) | |
48 { | |
49 DEFINE_STATIC_LOCAL(const AtomicString, acceptScript, ("*/*", AtomicString::
ConstructFromLiteral)); | |
50 | |
51 // It's javascript we want. | |
52 // But some websites think their scripts are <some wrong mimetype here> | |
53 // and refuse to serve them if we only accept application/x-javascript. | |
54 setAccept(acceptScript); | |
55 } | |
56 | |
57 ScriptResource::~ScriptResource() | |
58 { | |
59 } | |
60 | |
61 void ScriptResource::didAddClient(ResourceClient* client) | |
62 { | |
63 ASSERT(client->resourceClientType() == ScriptResourceClient::expectedType())
; | |
64 Resource::didAddClient(client); | |
65 } | |
66 | |
67 void ScriptResource::appendData(const char* data, unsigned length) | |
68 { | |
69 Resource::appendData(data, length); | |
70 ResourceClientWalker<ScriptResourceClient> walker(m_clients); | |
71 while (ScriptResourceClient* client = walker.next()) | |
72 client->notifyAppendData(this); | |
73 } | |
74 | |
75 AtomicString ScriptResource::mimeType() const | |
76 { | |
77 return extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type
")).lower(); | |
78 } | |
79 | |
80 const String& ScriptResource::script() | |
81 { | |
82 ASSERT(!isPurgeable()); | |
83 ASSERT(isLoaded()); | |
84 | |
85 if (!m_script && m_data) { | |
86 String script = decodedText(); | |
87 m_data.clear(); | |
88 // We lie a it here and claim that script counts as encoded data (even t
hough it's really decoded data). | |
89 // That's because the MemoryCache thinks that it can clear out decoded d
ata by calling destroyDecodedData(), | |
90 // but we can't destroy script in destroyDecodedData because that's our
only copy of the data! | |
91 setEncodedSize(script.sizeInBytes()); | |
92 m_script = AtomicString(script); | |
93 } | |
94 | |
95 return m_script.string(); | |
96 } | |
97 | |
98 bool ScriptResource::mimeTypeAllowedByNosniff() const | |
99 { | |
100 return parseContentTypeOptionsHeader(m_response.httpHeaderField("X-Content-T
ype-Options")) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJava
ScriptMIMEType(mimeType()); | |
101 } | |
102 | |
103 } // namespace blink | |
OLD | NEW |