Chromium Code Reviews| 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 |
| 11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
| 12 | 12 |
| 13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 Library General Public License for more details. | 16 Library General Public License for more details. |
| 17 | 17 |
| 18 You should have received a copy of the GNU Library General Public License | 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 | 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, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
| 22 | 22 |
| 23 This class provides all functionality needed for loading images, style sheet s and html | 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. | 24 pages from the web. It has a memory cache for these objects. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/fetch/ScriptResource.h" | 28 #include "core/fetch/ScriptResource.h" |
| 29 | 29 |
| 30 #include "core/fetch/ResourceClientWalker.h" | |
| 30 #include "platform/MIMETypeRegistry.h" | 31 #include "platform/MIMETypeRegistry.h" |
| 31 #include "platform/SharedBuffer.h" | 32 #include "platform/SharedBuffer.h" |
| 32 #include "platform/network/HTTPParsers.h" | 33 #include "platform/network/HTTPParsers.h" |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 ScriptResource::ScriptResource(const ResourceRequest& resourceRequest, const Str ing& charset) | 37 ScriptResource::ScriptResource(const ResourceRequest& resourceRequest, const Str ing& charset) |
| 37 : TextResource(resourceRequest, Script, "application/javascript", charset) | 38 : TextResource(resourceRequest, Script, "application/javascript", charset) |
| 38 { | 39 { |
| 39 DEFINE_STATIC_LOCAL(const AtomicString, acceptScript, ("*/*", AtomicString:: ConstructFromLiteral)); | 40 DEFINE_STATIC_LOCAL(const AtomicString, acceptScript, ("*/*", AtomicString:: ConstructFromLiteral)); |
| 40 | 41 |
| 41 // It's javascript we want. | 42 // It's javascript we want. |
| 42 // But some websites think their scripts are <some wrong mimetype here> | 43 // But some websites think their scripts are <some wrong mimetype here> |
| 43 // and refuse to serve them if we only accept application/x-javascript. | 44 // and refuse to serve them if we only accept application/x-javascript. |
| 44 setAccept(acceptScript); | 45 setAccept(acceptScript); |
| 45 } | 46 } |
| 46 | 47 |
| 47 ScriptResource::~ScriptResource() | 48 ScriptResource::~ScriptResource() |
| 48 { | 49 { |
| 49 } | 50 } |
| 50 | 51 |
| 52 void ScriptResource::didAddClient(ResourceClient* c) | |
|
haraken
2014/08/17 16:05:28
Nit: c => client
marja
2014/08/20 11:45:56
Done.
| |
| 53 { | |
| 54 ASSERT(c->resourceClientType() == ScriptResourceClient::expectedType()); | |
| 55 Resource::didAddClient(c); | |
| 56 } | |
| 57 | |
| 58 void ScriptResource::appendData(const char* data, int length) | |
| 59 { | |
| 60 Resource::appendData(data, length); | |
| 61 ResourceClientWalker<ScriptResourceClient> w(m_clients); | |
|
haraken
2014/08/17 16:05:28
Nit: w => walker
marja
2014/08/20 11:45:56
Done.
| |
| 62 while (ScriptResourceClient* c = w.next()) { | |
|
haraken
2014/08/17 16:05:28
Nit: c => client
marja
2014/08/20 11:45:56
Done.
| |
| 63 c->notifyAppendData(this); | |
| 64 } | |
| 65 } | |
| 66 | |
| 51 AtomicString ScriptResource::mimeType() const | 67 AtomicString ScriptResource::mimeType() const |
| 52 { | 68 { |
| 53 return extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type ")).lower(); | 69 return extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type ")).lower(); |
| 54 } | 70 } |
| 55 | 71 |
| 56 const String& ScriptResource::script() | 72 const String& ScriptResource::script() |
| 57 { | 73 { |
| 58 ASSERT(!isPurgeable()); | 74 ASSERT(!isPurgeable()); |
| 59 ASSERT(isLoaded()); | 75 ASSERT(isLoaded()); |
| 60 | 76 |
| 61 if (!m_script && m_data) { | 77 if (!m_script && m_data) { |
| 62 String script = decodedText(); | 78 String script = decodedText(); |
| 63 m_data.clear(); | 79 m_data.clear(); |
| 64 // We lie a it here and claim that script counts as encoded data (even t hough it's really decoded data). | 80 // We lie a it here and claim that script counts as encoded data (even t hough it's really decoded data). |
| 65 // That's because the MemoryCache thinks that it can clear out decoded d ata by calling destroyDecodedData(), | 81 // That's because the MemoryCache thinks that it can clear out decoded d ata by calling destroyDecodedData(), |
| 66 // but we can't destroy script in destroyDecodedData because that's our only copy of the data! | 82 // but we can't destroy script in destroyDecodedData because that's our only copy of the data! |
| 67 setEncodedSize(script.sizeInBytes()); | 83 setEncodedSize(script.sizeInBytes()); |
| 68 m_script = AtomicString(script); | 84 m_script = AtomicString(script); |
| 69 } | 85 } |
| 70 | 86 |
| 71 return m_script.string(); | 87 return m_script.string(); |
| 72 } | 88 } |
| 73 | 89 |
| 74 bool ScriptResource::mimeTypeAllowedByNosniff() const | 90 bool ScriptResource::mimeTypeAllowedByNosniff() const |
| 75 { | 91 { |
| 76 return parseContentTypeOptionsHeader(m_response.httpHeaderField("X-Content-T ype-Options")) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJava ScriptMIMEType(mimeType()); | 92 return parseContentTypeOptionsHeader(m_response.httpHeaderField("X-Content-T ype-Options")) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJava ScriptMIMEType(mimeType()); |
| 77 } | 93 } |
| 78 | 94 |
| 79 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |