diff options
Diffstat (limited to 'WebCore/loader')
-rw-r--r-- | WebCore/loader/CachedScript.cpp | 6 | ||||
-rw-r--r-- | WebCore/loader/CachedScript.h | 1 | ||||
-rw-r--r-- | WebCore/loader/DocumentLoader.cpp | 2 | ||||
-rw-r--r-- | WebCore/loader/DocumentWriter.cpp | 49 | ||||
-rw-r--r-- | WebCore/loader/DocumentWriter.h | 4 | ||||
-rw-r--r-- | WebCore/loader/FTPDirectoryDocument.cpp | 17 | ||||
-rw-r--r-- | WebCore/loader/FrameLoader.cpp | 2 | ||||
-rw-r--r-- | WebCore/loader/ImageDocument.cpp | 8 | ||||
-rw-r--r-- | WebCore/loader/MediaDocument.cpp | 11 | ||||
-rw-r--r-- | WebCore/loader/PluginDocument.cpp | 32 | ||||
-rw-r--r-- | WebCore/loader/SinkDocument.cpp | 16 | ||||
-rw-r--r-- | WebCore/loader/SubresourceLoader.cpp | 2 | ||||
-rw-r--r-- | WebCore/loader/TextDocument.cpp | 34 |
13 files changed, 98 insertions, 86 deletions
diff --git a/WebCore/loader/CachedScript.cpp b/WebCore/loader/CachedScript.cpp index 466a5e9..c96427c 100644 --- a/WebCore/loader/CachedScript.cpp +++ b/WebCore/loader/CachedScript.cpp @@ -37,6 +37,7 @@ namespace WebCore { CachedScript::CachedScript(const String& url, const String& charset) : CachedResource(url, Script) + , m_scriptHasBOMs(SourceCouldHaveBOMs) , m_decoder(TextResourceDecoder::create("application/javascript", charset)) , m_decodedDataDeletionTimer(this, &CachedScript::decodedDataDeletionTimerFired) { @@ -78,6 +79,11 @@ const String& CachedScript::script() if (!m_script && m_data) { m_script = m_decoder->decode(m_data->data(), encodedSize()); m_script += m_decoder->flush(); + if (m_scriptHasBOMs != SourceHasNoBOMs && m_script.length()) { + bool hasBOMs = false; + m_script = String(m_script.impl()->copyStringWithoutBOMs(m_scriptHasBOMs == SourceHasBOMs, hasBOMs)); + m_scriptHasBOMs = hasBOMs ? SourceHasBOMs : SourceHasNoBOMs; + } setDecodedSize(m_script.length() * sizeof(UChar)); } diff --git a/WebCore/loader/CachedScript.h b/WebCore/loader/CachedScript.h index 13afa89..2374409 100644 --- a/WebCore/loader/CachedScript.h +++ b/WebCore/loader/CachedScript.h @@ -59,6 +59,7 @@ namespace WebCore { void decodedDataDeletionTimerFired(Timer<CachedScript>*); String m_script; + enum { SourceHasNoBOMs, SourceCouldHaveBOMs, SourceHasBOMs } m_scriptHasBOMs; RefPtr<TextResourceDecoder> m_decoder; Timer<CachedScript> m_decodedDataDeletionTimer; }; diff --git a/WebCore/loader/DocumentLoader.cpp b/WebCore/loader/DocumentLoader.cpp index 990c48a..fcc1826 100644 --- a/WebCore/loader/DocumentLoader.cpp +++ b/WebCore/loader/DocumentLoader.cpp @@ -39,6 +39,7 @@ #include "CachedPage.h" #include "DocLoader.h" #include "Document.h" +#include "DocumentParser.h" #include "Event.h" #include "Frame.h" #include "FrameLoader.h" @@ -50,7 +51,6 @@ #include "PlatformString.h" #include "Settings.h" #include "SharedBuffer.h" -#include "XMLDocumentParser.h" #include <wtf/Assertions.h> #include <wtf/unicode/Unicode.h> diff --git a/WebCore/loader/DocumentWriter.cpp b/WebCore/loader/DocumentWriter.cpp index 2ea1afd..d99f340 100644 --- a/WebCore/loader/DocumentWriter.cpp +++ b/WebCore/loader/DocumentWriter.cpp @@ -38,12 +38,14 @@ #include "FrameView.h" #include "PlaceholderDocument.h" #include "PluginDocument.h" +#include "RawDataDocumentParser.h" +#include "ScriptableDocumentParser.h" #include "SecurityOrigin.h" #include "SegmentedString.h" #include "Settings.h" #include "SinkDocument.h" #include "TextResourceDecoder.h" -#include "DocumentParser.h" + namespace WebCore { @@ -73,10 +75,10 @@ void DocumentWriter::replaceDocument(const String& source) m_frame->document()->setParseMode(Document::Strict); } - // FIXME: If we wanted to support the <img src='javascript:'imagedata'> - // case then we would need to call addData(char*, int) instead. + // FIXME: This should call DocumentParser::appendBytes instead of append + // to support RawDataDocumentParsers. if (DocumentParser* parser = m_frame->document()->parser()) - parser->write(source, true); + parser->append(source); } end(); @@ -143,21 +145,8 @@ void DocumentWriter::begin(const KURL& url, bool dispatch, SecurityOrigin* origi m_frame->view()->setContentsSize(IntSize()); } -void DocumentWriter::addData(const char* str, int len, bool flush) +TextResourceDecoder* DocumentWriter::createDecoderIfNeeded() { - if (len == 0 && !flush) - return; - - if (len == -1) - len = strlen(str); - - DocumentParser* parser = m_frame->document()->parser(); - if (parser && parser->wantsRawData()) { - if (len > 0) - parser->writeRawData(str, len); - return; - } - if (!m_decoder) { if (Settings* settings = m_frame->settings()) { m_decoder = TextResourceDecoder::create(m_mimeType, @@ -187,24 +176,28 @@ void DocumentWriter::addData(const char* str, int len, bool flush) } m_frame->document()->setDecoder(m_decoder.get()); } + return m_decoder.get(); +} - String decoded = m_decoder->decode(str, len); - if (flush) - decoded += m_decoder->flush(); - if (decoded.isEmpty()) - return; - +void DocumentWriter::reportDataRecieved() +{ + ASSERT(m_decoder); if (!m_receivedData) { m_receivedData = true; if (m_decoder->encoding().usesVisualOrdering()) m_frame->document()->setVisuallyOrdered(); m_frame->document()->recalcStyle(Node::Force); } +} - if (parser) { - ASSERT(!parser->wantsRawData()); - parser->write(decoded, true); - } +void DocumentWriter::addData(const char* str, int len, bool flush) +{ + if (len == -1) + len = strlen(str); + + DocumentParser* parser = m_frame->document()->parser(); + if (parser) + parser->appendBytes(this, str, len, flush); } void DocumentWriter::end() diff --git a/WebCore/loader/DocumentWriter.h b/WebCore/loader/DocumentWriter.h index 6644093..b1007ef 100644 --- a/WebCore/loader/DocumentWriter.h +++ b/WebCore/loader/DocumentWriter.h @@ -67,6 +67,10 @@ public: void setDecoder(TextResourceDecoder*); + // Exposed for DoucmentParser::appendBytes + TextResourceDecoder* createDecoderIfNeeded(); + void reportDataRecieved(); + private: PassRefPtr<Document> createDocument(const KURL&); diff --git a/WebCore/loader/FTPDirectoryDocument.cpp b/WebCore/loader/FTPDirectoryDocument.cpp index 2a19fa3..9315e45 100644 --- a/WebCore/loader/FTPDirectoryDocument.cpp +++ b/WebCore/loader/FTPDirectoryDocument.cpp @@ -52,7 +52,7 @@ class FTPDirectoryDocumentParser : public LegacyHTMLDocumentParser { public: FTPDirectoryDocumentParser(HTMLDocument*); - virtual void write(const SegmentedString&, bool appendData); + virtual void append(const SegmentedString&); virtual void finish(); virtual bool isWaitingForScripts() const { return false; } @@ -100,7 +100,7 @@ FTPDirectoryDocumentParser::FTPDirectoryDocumentParser(HTMLDocument* document) , m_size(254) , m_buffer(static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size))) , m_dest(m_buffer) -{ +{ } void FTPDirectoryDocumentParser::appendEntry(const String& filename, const String& size, const String& date, bool isDirectory) @@ -301,11 +301,8 @@ bool FTPDirectoryDocumentParser::loadDocumentTemplate() LOG_ERROR("Could not load templateData"); return false; } - - // Tokenize the template as an HTML document synchronously - setForceSynchronous(true); - LegacyHTMLDocumentParser::write(String(templateDocumentData->data(), templateDocumentData->size()), true); - setForceSynchronous(false); + + LegacyHTMLDocumentParser::insert(String(templateDocumentData->data(), templateDocumentData->size())); RefPtr<Element> tableElement = document()->getElementById("ftpDirectoryTable"); if (!tableElement) @@ -354,8 +351,8 @@ void FTPDirectoryDocumentParser::createBasicDocument() bodyElement->appendChild(m_tableElement, ec); } -void FTPDirectoryDocumentParser::write(const SegmentedString& s, bool /*appendData*/) -{ +void FTPDirectoryDocumentParser::append(const SegmentedString& source) +{ // Make sure we have the table element to append to by loading the template set in the pref, or // creating a very basic document with the appropriate table if (!m_tableElement) { @@ -367,7 +364,7 @@ void FTPDirectoryDocumentParser::write(const SegmentedString& s, bool /*appendDa bool foundNewLine = false; m_dest = m_buffer; - SegmentedString str = s; + SegmentedString str = source; while (!str.isEmpty()) { UChar c = *str; diff --git a/WebCore/loader/FrameLoader.cpp b/WebCore/loader/FrameLoader.cpp index 1fbf2ee..540e0f7 100644 --- a/WebCore/loader/FrameLoader.cpp +++ b/WebCore/loader/FrameLoader.cpp @@ -3438,7 +3438,7 @@ KURL FrameLoader::originalRequestURL() const String FrameLoader::referrer() const { - return documentLoader()->request().httpReferrer(); + return m_documentLoader ? m_documentLoader->request().httpReferrer() : ""; } void FrameLoader::dispatchDocumentElementAvailable() diff --git a/WebCore/loader/ImageDocument.cpp b/WebCore/loader/ImageDocument.cpp index 49f54e2..b1e33f4 100644 --- a/WebCore/loader/ImageDocument.cpp +++ b/WebCore/loader/ImageDocument.cpp @@ -84,7 +84,7 @@ public: } private: - virtual bool writeRawData(const char* data, int len); + virtual void appendBytes(DocumentWriter*, const char*, int, bool); virtual void finish(); }; @@ -118,19 +118,17 @@ static float pageZoomFactor(Document* document) return view ? view->pageZoomFactor() : 1; } -bool ImageDocumentParser::writeRawData(const char*, int) +void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool) { Frame* frame = document()->frame(); Settings* settings = frame->settings(); if (!frame->loader()->client()->allowImages(!settings || settings->areImagesEnabled())) - return false; + return; CachedImage* cachedImage = document()->cachedImage(); cachedImage->data(frame->loader()->documentLoader()->mainResourceData(), false); document()->imageChanged(); - - return false; } void ImageDocumentParser::finish() diff --git a/WebCore/loader/MediaDocument.cpp b/WebCore/loader/MediaDocument.cpp index 97ca783..97e1775 100644 --- a/WebCore/loader/MediaDocument.cpp +++ b/WebCore/loader/MediaDocument.cpp @@ -54,7 +54,7 @@ public: } private: - virtual bool writeRawData(const char* data, int len); + virtual void appendBytes(DocumentWriter*, const char*, int, bool); void createDocumentStructure(); @@ -90,16 +90,15 @@ void MediaDocumentParser::createDocumentStructure() frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false); } - -bool MediaDocumentParser::writeRawData(const char*, int) + +void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool) { ASSERT(!m_mediaElement); if (m_mediaElement) - return false; - + return; + createDocumentStructure(); finish(); - return false; } MediaDocument::MediaDocument(Frame* frame, const KURL& url) diff --git a/WebCore/loader/PluginDocument.cpp b/WebCore/loader/PluginDocument.cpp index 12ab746..cca6894 100644 --- a/WebCore/loader/PluginDocument.cpp +++ b/WebCore/loader/PluginDocument.cpp @@ -52,7 +52,7 @@ public: static Widget* pluginWidgetFromDocument(Document*); private: - virtual bool writeRawData(const char* data, int len); + virtual void appendBytes(DocumentWriter*, const char*, int, bool); void createDocumentStructure(); @@ -98,30 +98,30 @@ void PluginDocumentParser::createDocumentStructure() body->appendChild(embedElement, ec); } - -bool PluginDocumentParser::writeRawData(const char*, int) + +void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool) { ASSERT(!m_embedElement); if (m_embedElement) - return false; - + return; + createDocumentStructure(); - if (Frame* frame = document()->frame()) { - Settings* settings = frame->settings(); - if (settings && frame->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin)) { - document()->updateLayout(); + Frame* frame = document()->frame(); + if (!frame) + return; + Settings* settings = frame->settings(); + if (!settings || !frame->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin)) + return; - if (RenderWidget* renderer = toRenderWidget(m_embedElement->renderer())) { - frame->loader()->client()->redirectDataToPlugin(renderer->widget()); - frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false); - } + document()->updateLayout(); - finish(); - } + if (RenderWidget* renderer = toRenderWidget(m_embedElement->renderer())) { + frame->loader()->client()->redirectDataToPlugin(renderer->widget()); + frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false); } - return false; + finish(); } PluginDocument::PluginDocument(Frame* frame, const KURL& url) diff --git a/WebCore/loader/SinkDocument.cpp b/WebCore/loader/SinkDocument.cpp index e149981..fb0ab94 100644 --- a/WebCore/loader/SinkDocument.cpp +++ b/WebCore/loader/SinkDocument.cpp @@ -30,6 +30,18 @@ namespace WebCore { +class SinkDocumentParser : public RawDataDocumentParser { +public: + SinkDocumentParser(SinkDocument* document) + : RawDataDocumentParser(document) + { + } + +private: + // Ignore all data. + virtual void appendBytes(DocumentWriter*, const char*, int, bool) { } +}; + SinkDocument::SinkDocument(Frame* frame, const KURL& url) : HTMLDocument(frame, url) { @@ -38,9 +50,7 @@ SinkDocument::SinkDocument(Frame* frame, const KURL& url) DocumentParser* SinkDocument::createParser() { - // The basic RawDataDocumentParser does nothing with the data - // which is sufficient for our purposes here. - return new RawDataDocumentParser(this); + return new SinkDocumentParser(this); } } // namespace WebCore diff --git a/WebCore/loader/SubresourceLoader.cpp b/WebCore/loader/SubresourceLoader.cpp index d37bb1c..9c2959b 100644 --- a/WebCore/loader/SubresourceLoader.cpp +++ b/WebCore/loader/SubresourceLoader.cpp @@ -66,7 +66,7 @@ PassRefPtr<SubresourceLoader> SubresourceLoader::create(Frame* frame, Subresourc return 0; FrameLoader* fl = frame->loader(); - if (securityCheck == DoSecurityCheck && (fl->state() == FrameStateProvisional || fl->activeDocumentLoader()->isStopping())) + if (securityCheck == DoSecurityCheck && (fl->state() == FrameStateProvisional || !fl->activeDocumentLoader() || fl->activeDocumentLoader()->isStopping())) return 0; ResourceRequest newRequest = request; diff --git a/WebCore/loader/TextDocument.cpp b/WebCore/loader/TextDocument.cpp index 3360aca..6b53084 100644 --- a/WebCore/loader/TextDocument.cpp +++ b/WebCore/loader/TextDocument.cpp @@ -25,12 +25,12 @@ #include "config.h" #include "TextDocument.h" +#include "DecodedDataDocumentParser.h" #include "Element.h" #include "HTMLNames.h" #include "HTMLViewSourceDocument.h" #include "SegmentedString.h" #include "Text.h" -#include "XMLDocumentParser.h" using namespace std; @@ -38,18 +38,20 @@ namespace WebCore { using namespace HTMLNames; -class TextDocumentParser : public DocumentParser { +// FIXME: TextDocumentParser could just be an HTMLDocumentParser +// which started the Tokenizer in the PlainText state. +class TextDocumentParser : public DecodedDataDocumentParser { public: TextDocumentParser(Document*); virtual ~TextDocumentParser(); TextDocumentParser(HTMLViewSourceDocument*); private: - virtual void write(const SegmentedString&, bool appendData); + virtual void insert(const SegmentedString&); + virtual void append(const SegmentedString&); virtual void finish(); virtual bool finishWasCalled(); - virtual bool isWaitingForScripts() const; - + inline void checkBuffer(int len = 10) { if ((m_dest - m_buffer) > m_size - len) { @@ -62,6 +64,7 @@ private: } } +private: Element* m_preElement; bool m_skipLF; @@ -72,7 +75,7 @@ private: }; TextDocumentParser::TextDocumentParser(Document* document) - : DocumentParser(document) + : DecodedDataDocumentParser(document) , m_preElement(0) , m_skipLF(false) { @@ -83,7 +86,7 @@ TextDocumentParser::TextDocumentParser(Document* document) } TextDocumentParser::TextDocumentParser(HTMLViewSourceDocument* document) - : DocumentParser(document, true) + : DecodedDataDocumentParser(document, true) , m_preElement(0) , m_skipLF(false) { @@ -99,7 +102,12 @@ TextDocumentParser::~TextDocumentParser() ASSERT(!m_buffer); } -void TextDocumentParser::write(const SegmentedString& s, bool) +void TextDocumentParser::insert(const SegmentedString&) +{ + ASSERT_NOT_REACHED(); +} + +void TextDocumentParser::append(const SegmentedString& s) { ExceptionCode ec; @@ -162,12 +170,14 @@ void TextDocumentParser::write(const SegmentedString& s, bool) void TextDocumentParser::finish() { if (!m_preElement) - write(SegmentedString(), true); // Create document structure for an empty text document. + append(SegmentedString()); // Create document structure for an empty text document. m_preElement = 0; fastFree(m_buffer); m_buffer = 0; m_dest = 0; + // FIXME: Should this call finishParsing even if m_parserStopped is true? + // See equivalent implementation in RawDataDocumentParser. document()->finishedParsing(); } @@ -178,12 +188,6 @@ bool TextDocumentParser::finishWasCalled() return false; } -bool TextDocumentParser::isWaitingForScripts() const -{ - // A text document is never waiting for scripts - return false; -} - TextDocument::TextDocument(Frame* frame, const KURL& url) : HTMLDocument(frame, url) { |