Bug 912981 - Make parser aware of view-source srcdoc status. r=hsivonen

This commit is contained in:
James Kitchener 2013-09-10 13:40:50 -04:00
parent 1b2b3a4929
commit 28cc0bfd16
4 changed files with 25 additions and 44 deletions

View File

@ -12,7 +12,7 @@
#include "nsHtml5TreeBuilder.h"
#include "nsHtml5AtomTable.h"
#include "nsHtml5DependentUTF16Buffer.h"
#include "nsIInputStreamChannel.h"
#include "nsNetUtil.h"
NS_INTERFACE_TABLE_HEAD(nsHtml5Parser)
NS_INTERFACE_TABLE2(nsHtml5Parser, nsIParser, nsISupportsWeakReference)
@ -218,7 +218,13 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
mExecutor->SetParser(this);
mTreeBuilder->setScriptingEnabled(mExecutor->IsScriptEnabled());
mTreeBuilder->setIsSrcdocDocument(IsSrcdocDocument());
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
isSrcdoc = NS_IsSrcdocChannel(channel);
}
mTreeBuilder->setIsSrcdocDocument(isSrcdoc);
mTokenizer->start();
mExecutor->Start();
@ -682,7 +688,13 @@ nsHtml5Parser::Initialize(nsIDocument* aDoc,
void
nsHtml5Parser::StartTokenizer(bool aScriptingEnabled) {
mTreeBuilder->setIsSrcdocDocument(IsSrcdocDocument());
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
nsresult rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
isSrcdoc = NS_IsSrcdocChannel(channel);
}
mTreeBuilder->setIsSrcdocDocument(isSrcdoc);
mTreeBuilder->SetPreventScriptExecution(!aScriptingEnabled);
mTreeBuilder->setScriptingEnabled(aScriptingEnabled);
@ -708,20 +720,3 @@ nsHtml5Parser::ContinueAfterFailedCharsetSwitch()
mStreamParser->ContinueAfterFailedCharsetSwitch();
}
bool
nsHtml5Parser::IsSrcdocDocument()
{
nsresult rv;
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIInputStreamChannel> isr = do_QueryInterface(channel);
if (isr) {
isr->GetIsSrcdocChannel(&isSrcdoc);
}
}
return isSrcdoc;
}

View File

@ -258,8 +258,6 @@ class nsHtml5Parser : public nsIParser,
*/
void ParseUntilBlocked();
bool IsSrcdocDocument();
private:
// State variables

View File

@ -26,9 +26,9 @@
#include "nsINestedURI.h"
#include "nsCharsetSource.h"
#include "nsIWyciwygChannel.h"
#include "nsIInputStreamChannel.h"
#include "nsIThreadRetargetableRequest.h"
#include "nsPrintfCString.h"
#include "nsNetUtil.h"
#include "mozilla/dom/EncodingUtils.h"
@ -877,7 +877,14 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
bool scriptingEnabled = mMode == LOAD_AS_DATA ?
false : mExecutor->IsScriptEnabled();
mOwner->StartTokenizer(scriptingEnabled);
mTreeBuilder->setIsSrcdocDocument(IsSrcdocDocument());
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
nsresult rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
isSrcdoc = NS_IsSrcdocChannel(channel);
}
mTreeBuilder->setIsSrcdocDocument(isSrcdoc);
mTreeBuilder->setScriptingEnabled(scriptingEnabled);
mTreeBuilder->SetPreventScriptExecution(!((mMode == NORMAL) &&
scriptingEnabled));
@ -913,7 +920,7 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
NS_ASSERTION(!mLastBuffer, "How come we have the last buffer set?");
mFirstBuffer = mLastBuffer = newBuf;
nsresult rv = NS_OK;
rv = NS_OK;
// The line below means that the encoding can end up being wrong if
// a view-source URL is loaded without having the encoding hint from a
@ -1672,20 +1679,3 @@ nsHtml5StreamParser::MarkAsBroken()
NS_WARNING("failed to dispatch executor flush event");
}
}
bool
nsHtml5StreamParser::IsSrcdocDocument()
{
nsresult rv;
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIInputStreamChannel> isr = do_QueryInterface(channel);
if (isr) {
isr->GetIsSrcdocChannel(&isSrcdoc);
}
}
return isSrcdoc;
}

View File

@ -202,8 +202,6 @@ class nsHtml5StreamParser : public nsIStreamListener,
*/
void SetViewSourceTitle(nsIURI* aURL);
bool IsSrcdocDocument();
private:
#ifdef DEBUG