2009-09-18 13:21:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#ifndef nsHtml5StreamParser_h
|
|
|
|
#define nsHtml5StreamParser_h
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsICharsetDetectionObserver.h"
|
|
|
|
#include "nsHtml5MetaScanner.h"
|
2017-04-27 13:27:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsHtml5TreeOpExecutor.h"
|
2011-09-28 16:45:17 +04:00
|
|
|
#include "nsHtml5OwningUTF16Buffer.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsIInputStream.h"
|
2009-09-21 17:18:20 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-11-20 04:19:57 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2009-09-21 17:18:20 +04:00
|
|
|
#include "nsHtml5AtomTable.h"
|
2009-10-12 17:08:04 +04:00
|
|
|
#include "nsHtml5Speculation.h"
|
2017-06-08 02:23:29 +03:00
|
|
|
#include "nsISerialEventTarget.h"
|
2009-11-17 11:52:30 +03:00
|
|
|
#include "nsITimer.h"
|
2010-01-12 16:15:10 +03:00
|
|
|
#include "nsICharsetDetector.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
class nsHtml5Parser;
|
|
|
|
|
|
|
|
#define NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE 1024
|
2010-02-26 12:18:38 +03:00
|
|
|
#define NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE 1024
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
enum eParserMode {
|
|
|
|
/**
|
|
|
|
* Parse a document normally as HTML.
|
|
|
|
*/
|
|
|
|
NORMAL,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View document as HTML source.
|
|
|
|
*/
|
|
|
|
VIEW_SOURCE_HTML,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View document as XML source
|
|
|
|
*/
|
|
|
|
VIEW_SOURCE_XML,
|
|
|
|
|
2011-11-30 21:44:31 +04:00
|
|
|
/**
|
|
|
|
* View document as plain text source
|
|
|
|
*/
|
|
|
|
VIEW_SOURCE_PLAIN,
|
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
/**
|
|
|
|
* View document as plain text
|
|
|
|
*/
|
2011-11-16 11:38:51 +04:00
|
|
|
PLAIN_TEXT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load as data (XHR)
|
|
|
|
*/
|
|
|
|
LOAD_AS_DATA
|
2010-07-30 14:15:38 +04:00
|
|
|
};
|
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
enum eBomState {
|
|
|
|
/**
|
|
|
|
* BOM sniffing hasn't started.
|
|
|
|
*/
|
|
|
|
BOM_SNIFFING_NOT_STARTED = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing is ongoing, and the first byte of an UTF-16LE BOM has been
|
|
|
|
* seen.
|
|
|
|
*/
|
|
|
|
SEEN_UTF_16_LE_FIRST_BYTE = 1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing is ongoing, and the first byte of an UTF-16BE BOM has been
|
|
|
|
* seen.
|
|
|
|
*/
|
|
|
|
SEEN_UTF_16_BE_FIRST_BYTE = 2,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing is ongoing, and the first byte of an UTF-8 BOM has been
|
|
|
|
* seen.
|
|
|
|
*/
|
|
|
|
SEEN_UTF_8_FIRST_BYTE = 3,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing is ongoing, and the first and second bytes of an UTF-8 BOM
|
|
|
|
* have been seen.
|
|
|
|
*/
|
|
|
|
SEEN_UTF_8_SECOND_BYTE = 4,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing was started but is now over for whatever reason.
|
|
|
|
*/
|
|
|
|
BOM_SNIFFING_OVER = 5
|
|
|
|
};
|
|
|
|
|
2009-09-21 17:18:20 +04:00
|
|
|
enum eHtml5StreamState {
|
|
|
|
STREAM_NOT_STARTED = 0,
|
|
|
|
STREAM_BEING_READ = 1,
|
|
|
|
STREAM_ENDED = 2
|
|
|
|
};
|
|
|
|
|
2017-06-25 19:30:13 +03:00
|
|
|
class nsHtml5StreamParser : public nsICharsetDetectionObserver {
|
2009-09-25 21:11:02 +04:00
|
|
|
|
|
|
|
friend class nsHtml5RequestStopper;
|
|
|
|
friend class nsHtml5DataAvailable;
|
2009-10-12 17:08:04 +04:00
|
|
|
friend class nsHtml5StreamParserContinuation;
|
2010-04-16 14:52:06 +04:00
|
|
|
friend class nsHtml5TimerKungFu;
|
2009-09-25 21:11:02 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHtml5StreamParser,
|
|
|
|
nsICharsetDetectionObserver)
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
static void InitializeStatics();
|
2009-11-17 11:52:30 +03:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
|
|
|
|
nsHtml5Parser* aOwner,
|
|
|
|
eParserMode aMode);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
// Methods that nsHtml5StreamListener calls
|
|
|
|
nsresult CheckListenerChain();
|
2014-04-16 09:41:39 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
nsresult OnStartRequest(nsIRequest* aRequest, nsISupports* aContext);
|
2014-04-16 09:41:39 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
nsresult OnDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStream,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aLength);
|
2014-04-16 09:41:39 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
nsresult OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult status);
|
2017-05-15 15:54:54 +03:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
// nsICharsetDetectionObserver
|
|
|
|
/**
|
2009-09-18 13:21:47 +04:00
|
|
|
* Chardet calls this to report the detection result
|
|
|
|
*/
|
2017-05-24 11:35:33 +03:00
|
|
|
NS_IMETHOD Notify(const char* aCharset, nsDetectionConfident aConf) override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
// EncodingDeclarationHandler
|
|
|
|
// https://hg.mozilla.org/projects/htmlparser/file/tip/src/nu/validator/htmlparser/common/EncodingDeclarationHandler.java
|
|
|
|
/**
|
2009-09-18 13:21:47 +04:00
|
|
|
* Tree builder uses this to report a late <meta charset>
|
|
|
|
*/
|
2017-05-24 11:35:33 +03:00
|
|
|
bool internalEncodingDeclaration(nsHtml5String aEncoding);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
// Not from an external interface
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-05-24 11:35:33 +03:00
|
|
|
/**
|
2009-09-18 13:21:47 +04:00
|
|
|
* Call this method once you've created a parser, and want to instruct it
|
|
|
|
* about what charset to load
|
|
|
|
*
|
2017-06-25 19:30:13 +03:00
|
|
|
* @param aCharset the charset of a document
|
2009-09-18 13:21:47 +04:00
|
|
|
* @param aCharsetSource the source of the charset
|
|
|
|
*/
|
2017-06-25 19:30:13 +03:00
|
|
|
inline void SetDocumentCharset(const nsACString& aCharset, int32_t aSource) {
|
2017-05-24 11:35:33 +03:00
|
|
|
NS_PRECONDITION(mStreamState == STREAM_NOT_STARTED,
|
|
|
|
"SetDocumentCharset called too late.");
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2017-06-25 19:30:13 +03:00
|
|
|
mCharset = aCharset;
|
2017-05-24 11:35:33 +03:00
|
|
|
mCharsetSource = aSource;
|
2009-09-18 13:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetObserver(nsIRequestObserver* aObserver) {
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2009-09-18 13:21:47 +04:00
|
|
|
mObserver = aObserver;
|
|
|
|
}
|
2009-10-12 17:08:04 +04:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
nsresult GetChannel(nsIChannel** aChannel);
|
|
|
|
|
2009-09-21 17:18:20 +04:00
|
|
|
/**
|
|
|
|
* The owner parser must call this after script execution
|
|
|
|
* when no scripts are executing and the document.written
|
|
|
|
* buffer has been exhausted.
|
|
|
|
*/
|
|
|
|
void ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
|
|
|
|
nsHtml5TreeBuilder* aTreeBuilder,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aLastWasCR);
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2009-10-21 16:12:50 +04:00
|
|
|
/**
|
2010-04-16 14:52:06 +04:00
|
|
|
* Continues the stream parser if the charset switch failed.
|
2009-10-21 16:12:50 +04:00
|
|
|
*/
|
|
|
|
void ContinueAfterFailedCharsetSwitch();
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
void Terminate()
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
mozilla::MutexAutoLock autoLock(mTerminatedMutex);
|
2011-10-17 18:59:28 +04:00
|
|
|
mTerminated = true;
|
2009-09-18 13:21:47 +04:00
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2010-04-16 14:52:06 +04:00
|
|
|
void DropTimer();
|
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
/**
|
2017-06-25 19:30:13 +03:00
|
|
|
* Sets mCharset and mCharsetSource appropriately for the XML View Source
|
2011-11-03 18:31:27 +04:00
|
|
|
* case if aEncoding names a supported rough ASCII superset and sets
|
2017-06-25 19:30:13 +03:00
|
|
|
* the mCharset and mCharsetSource to the UTF-8 default otherwise.
|
2011-11-01 15:33:11 +04:00
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
void SetEncodingFromExpat(const char16_t* aEncoding);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2011-11-30 21:44:31 +04:00
|
|
|
/**
|
|
|
|
* Sets the URL for View Source title in case this parser ends up being
|
|
|
|
* used for View Source. If aURL is a view-source: URL, takes the inner
|
|
|
|
* URL. data: URLs are shown with an ellipsis instead of the actual data.
|
|
|
|
*/
|
|
|
|
void SetViewSourceTitle(nsIURI* aURL);
|
|
|
|
|
2009-09-21 17:18:20 +04:00
|
|
|
private:
|
2014-06-27 22:41:03 +04:00
|
|
|
virtual ~nsHtml5StreamParser();
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2009-09-25 21:11:02 +04:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsParserThread() {
|
2017-06-08 02:23:29 +03:00
|
|
|
return mEventTarget->IsOnCurrentThread();
|
2009-09-25 21:11:02 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-05 18:44:37 +03:00
|
|
|
void MarkAsBroken(nsresult aRv);
|
2011-09-28 16:45:17 +04:00
|
|
|
|
2010-04-16 14:52:06 +04:00
|
|
|
/**
|
|
|
|
* Marks the stream parser as interrupted. If you ever add calls to this
|
|
|
|
* method, be sure to review Uninterrupt usage very, very carefully to
|
|
|
|
* avoid having a previous in-flight runnable cancel your Interrupt()
|
|
|
|
* call on the other thread too soon.
|
|
|
|
*/
|
2014-03-05 23:38:50 +04:00
|
|
|
void Interrupt()
|
|
|
|
{
|
2009-10-12 17:08:04 +04:00
|
|
|
mozilla::MutexAutoLock autoLock(mTerminatedMutex);
|
2011-10-17 18:59:28 +04:00
|
|
|
mInterrupted = true;
|
2009-10-12 17:08:04 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
void Uninterrupt()
|
|
|
|
{
|
2010-04-16 14:52:06 +04:00
|
|
|
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
2009-10-12 17:08:04 +04:00
|
|
|
mTokenizerMutex.AssertCurrentThreadOwns();
|
|
|
|
// Not acquiring mTerminatedMutex because mTokenizerMutex is already
|
|
|
|
// held at this point and is already stronger.
|
2011-10-17 18:59:28 +04:00
|
|
|
mInterrupted = false;
|
2009-10-12 17:08:04 +04:00
|
|
|
}
|
|
|
|
|
2010-04-16 14:52:06 +04:00
|
|
|
/**
|
|
|
|
* Flushes the tree ops from the tree builder and disarms the flush
|
|
|
|
* timer.
|
|
|
|
*/
|
|
|
|
void FlushTreeOpsAndDisarmTimer();
|
|
|
|
|
2009-10-12 17:08:04 +04:00
|
|
|
void ParseAvailableData();
|
2016-08-12 10:36:22 +03:00
|
|
|
|
2009-09-25 21:11:02 +04:00
|
|
|
void DoStopRequest();
|
2016-08-12 10:36:22 +03:00
|
|
|
|
2013-07-09 05:45:26 +04:00
|
|
|
void DoDataAvailable(const uint8_t* aBuffer, uint32_t aLength);
|
|
|
|
|
2016-08-12 10:36:22 +03:00
|
|
|
static nsresult CopySegmentsToParser(nsIInputStream *aInStream,
|
|
|
|
void *aClosure,
|
|
|
|
const char *aFromSegment,
|
|
|
|
uint32_t aToOffset,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t *aWriteCount);
|
2009-09-25 21:11:02 +04:00
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
bool IsTerminatedOrInterrupted()
|
|
|
|
{
|
2009-10-12 17:08:04 +04:00
|
|
|
mozilla::MutexAutoLock autoLock(mTerminatedMutex);
|
|
|
|
return mTerminated || mInterrupted;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
bool IsTerminated()
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
mozilla::MutexAutoLock autoLock(mTerminatedMutex);
|
2009-10-12 17:08:04 +04:00
|
|
|
return mTerminated;
|
2009-09-18 13:21:47 +04:00
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
/**
|
|
|
|
* True when there is a Unicode decoder already
|
|
|
|
*/
|
2014-03-05 23:38:50 +04:00
|
|
|
inline bool HasDecoder()
|
|
|
|
{
|
2009-09-18 13:21:47 +04:00
|
|
|
return !!mUnicodeDecoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push bytes from network when there is no Unicode decoder yet
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SniffStreamBytes(const uint8_t* aFromSegment,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aWriteCount);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Push bytes from network when there is a Unicode decoder already
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult WriteStreamBytes(const uint8_t* aFromSegment,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aWriteCount);
|
2011-02-16 09:40:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether every other byte in the sniffing buffer is zero.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
void SniffBOMlessUTF16BasicLatin(const uint8_t* aFromSegment,
|
|
|
|
uint32_t aCountToSniffingLimit);
|
2011-02-16 09:40:35 +03:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
/**
|
|
|
|
* <meta charset> scan failed. Try chardet if applicable. After this, the
|
|
|
|
* the parser will have some encoding even if a last resolt fallback.
|
|
|
|
*
|
|
|
|
* @param aFromSegment The current network buffer or null if the sniffing
|
|
|
|
* buffer is being flushed due to network stream ending.
|
|
|
|
* @param aCount The number of bytes in aFromSegment (ignored if
|
|
|
|
* aFromSegment is null)
|
|
|
|
* @param aWriteCount Return value for how many bytes got read from the
|
|
|
|
* buffer.
|
|
|
|
* @param aCountToSniffingLimit The number of unfilled slots in
|
|
|
|
* mSniffingBuffer
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult FinalizeSniffing(const uint8_t* aFromSegment,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aWriteCount,
|
|
|
|
uint32_t aCountToSniffingLimit);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the Unicode decoder and write the sniffing buffer into it
|
|
|
|
* followed by the current network buffer.
|
|
|
|
*
|
|
|
|
* @param aFromSegment The current network buffer or null if the sniffing
|
|
|
|
* buffer is being flushed due to network stream ending.
|
|
|
|
* @param aCount The number of bytes in aFromSegment (ignored if
|
|
|
|
* aFromSegment is null)
|
|
|
|
* @param aWriteCount Return value for how many bytes got read from the
|
|
|
|
* buffer.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const uint8_t* aFromSegment,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aWriteCount);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Unicode decoder, mark the BOM as the source and
|
|
|
|
* drop the sniffer.
|
|
|
|
*
|
2013-11-12 12:45:22 +04:00
|
|
|
* @param aDecoderCharsetName The name for the decoder's charset
|
2009-09-18 13:21:47 +04:00
|
|
|
* (UTF-16BE, UTF-16LE or UTF-8; the BOM has
|
|
|
|
* been swallowed)
|
|
|
|
*/
|
2017-06-25 19:30:13 +03:00
|
|
|
nsresult SetupDecodingFromBom(const char* aDecoderCharsetName);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
/**
|
|
|
|
* Become confident or resolve and encoding name to its preferred form.
|
|
|
|
* @param aEncoding the value of an internal encoding decl. Acts as an
|
|
|
|
* out param, too, when the method returns true.
|
|
|
|
* @return true if the parser needs to start using the new value of
|
|
|
|
* aEncoding and false if the parser became confident or if
|
|
|
|
* the encoding name did not specify a usable encoding
|
|
|
|
*/
|
2017-06-25 19:30:13 +03:00
|
|
|
bool PreferredForInternalEncodingDecl(nsACString& aEncoding);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
/**
|
|
|
|
* Callback for mFlushTimer.
|
|
|
|
*/
|
|
|
|
static void TimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parser thread entry point for (maybe) flushing the ops and posting
|
|
|
|
* a flush runnable back on the main thread.
|
|
|
|
*/
|
|
|
|
void TimerFlush();
|
|
|
|
|
2015-04-14 02:36:33 +03:00
|
|
|
/**
|
|
|
|
* Called when speculation fails.
|
|
|
|
*/
|
|
|
|
void MaybeDisableFutureSpeculation()
|
|
|
|
{
|
|
|
|
mSpeculationFailureCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to check whether we're getting too many speculation failures and
|
|
|
|
* should just stop trying. The 100 is picked pretty randomly to be not too
|
|
|
|
* small (so most pages are not affected) but small enough that we don't end
|
|
|
|
* up with failed speculations over and over in pathological cases.
|
|
|
|
*/
|
|
|
|
bool IsSpeculationEnabled()
|
|
|
|
{
|
|
|
|
return mSpeculationFailureCount < 100;
|
|
|
|
}
|
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
nsCOMPtr<nsIRequest> mRequest;
|
|
|
|
nsCOMPtr<nsIRequestObserver> mObserver;
|
|
|
|
|
2011-11-30 21:44:31 +04:00
|
|
|
/**
|
|
|
|
* The document title to use if this turns out to be a View Source parser.
|
|
|
|
*/
|
|
|
|
nsCString mViewSourceTitle;
|
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
/**
|
|
|
|
* The Unicode decoder
|
|
|
|
*/
|
2017-04-27 13:27:03 +03:00
|
|
|
mozilla::UniquePtr<mozilla::Decoder> mUnicodeDecoder;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The buffer for sniffing the character encoding
|
|
|
|
*/
|
2015-11-20 04:19:57 +03:00
|
|
|
mozilla::UniquePtr<uint8_t[]> mSniffingBuffer;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of meaningful bytes in mSniffingBuffer
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSniffingLength;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BOM sniffing state
|
|
|
|
*/
|
|
|
|
eBomState mBomState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <meta> prescan implementation
|
|
|
|
*/
|
|
|
|
nsAutoPtr<nsHtml5MetaScanner> mMetaScanner;
|
|
|
|
|
|
|
|
// encoding-related stuff
|
|
|
|
/**
|
|
|
|
* The source (confidence) of the character encoding in use
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mCharsetSource;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The character encoding in use
|
|
|
|
*/
|
2017-06-25 19:30:13 +03:00
|
|
|
nsCString mCharset;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2009-09-21 17:18:20 +04:00
|
|
|
/**
|
|
|
|
* Whether reparse is forbidden
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mReparseForbidden;
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
// Portable parser objects
|
|
|
|
/**
|
|
|
|
* The first buffer in the pending UTF-16 buffer queue
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHtml5OwningUTF16Buffer> mFirstBuffer;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The last buffer in the pending UTF-16 buffer queue
|
|
|
|
*/
|
2011-09-28 16:45:17 +04:00
|
|
|
nsHtml5OwningUTF16Buffer* mLastBuffer; // weak ref; always points to
|
2009-09-18 13:21:47 +04:00
|
|
|
// a buffer of the size NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The tree operation executor
|
|
|
|
*/
|
|
|
|
nsHtml5TreeOpExecutor* mExecutor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The HTML5 tree builder
|
|
|
|
*/
|
2009-09-21 17:18:20 +04:00
|
|
|
nsAutoPtr<nsHtml5TreeBuilder> mTreeBuilder;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The HTML5 tokenizer
|
|
|
|
*/
|
2009-09-21 17:18:20 +04:00
|
|
|
nsAutoPtr<nsHtml5Tokenizer> mTokenizer;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2009-09-21 17:18:20 +04:00
|
|
|
/**
|
|
|
|
* Makes sure the main thread can't mess the tokenizer state while it's
|
2009-10-12 17:08:04 +04:00
|
|
|
* tokenizing. This mutex also protects the current speculation.
|
2009-09-21 17:18:20 +04:00
|
|
|
*/
|
|
|
|
mozilla::Mutex mTokenizerMutex;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
2009-09-21 17:18:20 +04:00
|
|
|
* The scoped atom table
|
2009-09-18 13:21:47 +04:00
|
|
|
*/
|
2009-09-21 17:18:20 +04:00
|
|
|
nsHtml5AtomTable mAtomTable;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
2009-09-21 17:18:20 +04:00
|
|
|
* The owner parser.
|
2009-09-18 13:21:47 +04:00
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHtml5Parser> mOwner;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
2009-09-21 17:18:20 +04:00
|
|
|
* Whether the last character tokenized was a carriage return (for CRLF)
|
2009-09-18 13:21:47 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLastWasCR;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
2009-09-21 17:18:20 +04:00
|
|
|
* For tracking stream life cycle
|
|
|
|
*/
|
|
|
|
eHtml5StreamState mStreamState;
|
|
|
|
|
|
|
|
/**
|
2009-10-12 17:08:04 +04:00
|
|
|
* Whether we are speculating.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSpeculating;
|
2009-10-12 17:08:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the tokenizer has reached EOF. (Reset when stream rewinded.)
|
2009-09-18 13:21:47 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAtEOF;
|
2009-10-12 17:08:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The speculations. The mutex protects the nsTArray itself.
|
|
|
|
* To access the queue of current speculation, mTokenizerMutex must be
|
|
|
|
* obtained.
|
|
|
|
* The current speculation is the last element
|
|
|
|
*/
|
|
|
|
nsTArray<nsAutoPtr<nsHtml5Speculation> > mSpeculations;
|
|
|
|
mozilla::Mutex mSpeculationMutex;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2015-04-14 02:36:33 +03:00
|
|
|
/**
|
|
|
|
* Number of times speculation has failed for this parser.
|
|
|
|
*/
|
|
|
|
uint32_t mSpeculationFailureCount;
|
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
/**
|
2009-09-21 17:18:20 +04:00
|
|
|
* True to terminate early; protected by mTerminatedMutex
|
2009-09-18 13:21:47 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTerminated;
|
|
|
|
bool mInterrupted;
|
2009-09-21 17:18:20 +04:00
|
|
|
mozilla::Mutex mTerminatedMutex;
|
2009-09-25 21:11:02 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The thread this stream parser runs on.
|
|
|
|
*/
|
2017-06-08 02:23:29 +03:00
|
|
|
nsCOMPtr<nsISerialEventTarget> mEventTarget;
|
2009-09-25 21:11:02 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> mExecutorFlusher;
|
2009-10-12 17:08:04 +04:00
|
|
|
|
2010-02-26 12:18:38 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mLoadFlusher;
|
|
|
|
|
2010-01-12 16:15:10 +03:00
|
|
|
/**
|
|
|
|
* The chardet instance if chardet is enabled.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsICharsetDetector> mChardet;
|
|
|
|
|
2011-02-11 13:33:32 +03:00
|
|
|
/**
|
|
|
|
* If false, don't push data to chardet.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFeedChardet;
|
2011-02-11 13:33:32 +03:00
|
|
|
|
2012-03-24 15:34:42 +04:00
|
|
|
/**
|
|
|
|
* Whether the initial charset source was kCharsetFromParentFrame
|
|
|
|
*/
|
|
|
|
bool mInitialEncodingWasFromParentFrame;
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
/**
|
|
|
|
* Timer for flushing tree ops once in a while when not speculating.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsITimer> mFlushTimer;
|
|
|
|
|
2017-01-26 09:45:31 +03:00
|
|
|
/**
|
|
|
|
* Mutex for protecting access to mFlushTimer (but not for the two
|
|
|
|
* mFlushTimerFoo booleans below).
|
|
|
|
*/
|
|
|
|
mozilla::Mutex mFlushTimerMutex;
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
/**
|
2010-04-16 14:52:06 +04:00
|
|
|
* Keeps track whether mFlushTimer has been armed. Unfortunately,
|
|
|
|
* nsITimer doesn't enable querying this from the timer itself.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFlushTimerArmed;
|
2010-04-16 14:52:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* False initially and true after the timer has fired at least once.
|
2009-11-17 11:52:30 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFlushTimerEverFired;
|
2009-11-17 11:52:30 +03:00
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
/**
|
|
|
|
* Whether the parser is doing a normal parse, view source or plain text.
|
|
|
|
*/
|
|
|
|
eParserMode mMode;
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
/**
|
2010-04-16 14:52:06 +04:00
|
|
|
* The pref html5.flushtimer.initialdelay: Time in milliseconds between
|
|
|
|
* the time a network buffer is seen and the timer firing when the
|
|
|
|
* timer hasn't fired previously in this parse.
|
2009-11-17 11:52:30 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t sTimerInitialDelay;
|
2009-11-17 11:52:30 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-16 14:52:06 +04:00
|
|
|
* The pref html5.flushtimer.subsequentdelay: Time in milliseconds between
|
|
|
|
* the time a network buffer is seen and the timer firing when the
|
|
|
|
* timer has already fired previously in this parse.
|
2009-11-17 11:52:30 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t sTimerSubsequentDelay;
|
2009-09-18 13:21:47 +04:00
|
|
|
};
|
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#endif // nsHtml5StreamParser_h
|