Bug 739033 - Allow external View Source editor code live dangerously. r=smaug.

This commit is contained in:
Henri Sivonen 2012-03-27 09:27:45 +03:00
parent 10f76a2526
commit 943497857a
3 changed files with 31 additions and 1 deletions

View File

@ -74,6 +74,7 @@ nsHtml5Module::InitializeStatics()
nsHtml5TreeBuilder::initializeStatics();
nsHtml5UTF16Buffer::initializeStatics();
nsHtml5StreamParser::InitializeStatics();
nsHtml5TreeOpExecutor::InitializeStatics();
#ifdef DEBUG
sNsHtml5ModuleInitialized = true;
#endif

View File

@ -61,6 +61,7 @@
#include "mozilla/Util.h" // DebugOnly
#include "sampler.h"
#include "nsIScriptError.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
@ -121,7 +122,8 @@ nsHtml5TreeOpExecutor::WillParse()
NS_IMETHODIMP
nsHtml5TreeOpExecutor::WillBuildModel(nsDTDMode aDTDMode)
{
if (mDocShell && !GetDocument()->GetScriptGlobalObject()) {
if (mDocShell && !GetDocument()->GetScriptGlobalObject() &&
!IsExternalViewSource()) {
// Not loading as data but script global object not ready
return MarkAsBroken(NS_ERROR_DOM_INVALID_STATE_ERR);
}
@ -969,6 +971,27 @@ nsHtml5TreeOpExecutor::GetViewSourceBaseURI()
return mViewSourceBaseURI;
}
//static
void
nsHtml5TreeOpExecutor::InitializeStatics()
{
mozilla::Preferences::AddBoolVarCache(&sExternalViewSource,
"view_source.editor.external");
}
bool
nsHtml5TreeOpExecutor::IsExternalViewSource()
{
if (!sExternalViewSource) {
return false;
}
bool isViewSource = false;
if (mDocumentURI) {
mDocumentURI->SchemeIs("view-source", &isViewSource);
}
return isViewSource;
}
// Speculative loading
already_AddRefed<nsIURI>
@ -1060,3 +1083,4 @@ PRUint32 nsHtml5TreeOpExecutor::sAppendBatchExaminations = 0;
PRUint32 nsHtml5TreeOpExecutor::sLongestTimeOffTheEventLoop = 0;
PRUint32 nsHtml5TreeOpExecutor::sTimesFlushLoopInterrupted = 0;
#endif
bool nsHtml5TreeOpExecutor::sExternalViewSource = false;

View File

@ -85,6 +85,7 @@ class nsHtml5TreeOpExecutor : public nsContentSink,
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHtml5TreeOpExecutor, nsContentSink)
private:
static bool sExternalViewSource;
#ifdef DEBUG_NS_HTML5_TREE_OP_EXECUTOR_FLUSH
static PRUint32 sAppendBatchMaxSize;
static PRUint32 sAppendBatchSlotsExamined;
@ -446,9 +447,13 @@ class nsHtml5TreeOpExecutor : public nsContentSink,
void SetSpeculationBase(const nsAString& aURL);
static void InitializeStatics();
private:
nsHtml5Parser* GetParser();
bool IsExternalViewSource();
/**
* Get a nsIURI for an nsString if the URL hasn't been preloaded yet.
*/