Bug 739033 - Allow external View Source editor code live dangerously. r=smaug.
authorHenri Sivonen <hsivonen@iki.fi>
Tue, 27 Mar 2012 09:27:45 +0300
changeset 90366 2f205fdb13a759e3d6e458aadca207be03f03517
parent 90365 dbaa6772917204c862f0b9a89d549e59186f41bb
child 90367 902b81504db99ac788fa635fa1dd252cc44a3e6b
push id7629
push userhsivonen@iki.fi
push dateTue, 27 Mar 2012 06:28:44 +0000
treeherdermozilla-inbound@902b81504db9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs739033
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739033 - Allow external View Source editor code live dangerously. r=smaug.
parser/html/nsHtml5Module.cpp
parser/html/nsHtml5TreeOpExecutor.cpp
parser/html/nsHtml5TreeOpExecutor.h
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -69,16 +69,17 @@ nsHtml5Module::InitializeStatics()
   nsHtml5HtmlAttributes::initializeStatics();
   nsHtml5NamedCharacters::initializeStatics();
   nsHtml5Portability::initializeStatics();
   nsHtml5StackNode::initializeStatics();
   nsHtml5Tokenizer::initializeStatics();
   nsHtml5TreeBuilder::initializeStatics();
   nsHtml5UTF16Buffer::initializeStatics();
   nsHtml5StreamParser::InitializeStatics();
+  nsHtml5TreeOpExecutor::InitializeStatics();
 #ifdef DEBUG
   sNsHtml5ModuleInitialized = true;
 #endif
 }
 
 // static
 void
 nsHtml5Module::ReleaseStatics()
--- a/parser/html/nsHtml5TreeOpExecutor.cpp
+++ b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -56,16 +56,17 @@
 #include "nsHtml5Parser.h"
 #include "nsHtml5Tokenizer.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5StreamParser.h"
 #include "mozilla/css/Loader.h"
 #include "mozilla/Util.h" // DebugOnly
 #include "sampler.h"
 #include "nsIScriptError.h"
+#include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHtml5TreeOpExecutor)
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHtml5TreeOpExecutor)
   NS_INTERFACE_TABLE_INHERITED1(nsHtml5TreeOpExecutor, 
                                 nsIContentSink)
@@ -116,17 +117,18 @@ nsHtml5TreeOpExecutor::WillParse()
 {
   NS_NOTREACHED("No one should call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 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);
   }
   mDocument->AddObserver(this);
   WillBuildModelImpl();
   GetDocument()->BeginLoad();
   return NS_OK;
 }
@@ -964,16 +966,37 @@ nsHtml5TreeOpExecutor::GetViewSourceBase
       // Fail gracefully if the base URL isn't a view-source: URL.
       // Not sure if this can ever happen.
       mViewSourceBaseURI = orig;
     }
   }
   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>
 nsHtml5TreeOpExecutor::ConvertIfNotPreloadedYet(const nsAString& aURL)
 {
   if (aURL.IsEmpty()) {
     return nsnull;
   }
@@ -1055,8 +1078,9 @@ nsHtml5TreeOpExecutor::SetSpeculationBas
 
 #ifdef DEBUG_NS_HTML5_TREE_OP_EXECUTOR_FLUSH
 PRUint32 nsHtml5TreeOpExecutor::sAppendBatchMaxSize = 0;
 PRUint32 nsHtml5TreeOpExecutor::sAppendBatchSlotsExamined = 0;
 PRUint32 nsHtml5TreeOpExecutor::sAppendBatchExaminations = 0;
 PRUint32 nsHtml5TreeOpExecutor::sLongestTimeOffTheEventLoop = 0;
 PRUint32 nsHtml5TreeOpExecutor::sTimesFlushLoopInterrupted = 0;
 #endif
+bool nsHtml5TreeOpExecutor::sExternalViewSource = false;
--- a/parser/html/nsHtml5TreeOpExecutor.h
+++ b/parser/html/nsHtml5TreeOpExecutor.h
@@ -80,16 +80,17 @@ class nsHtml5TreeOpExecutor : public nsC
   friend class nsHtml5FlushLoopGuard;
 
   public:
     NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
     NS_DECL_ISUPPORTS_INHERITED
     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;
     static PRUint32    sAppendBatchExaminations;
     static PRUint32    sLongestTimeOffTheEventLoop;
     static PRUint32    sTimesFlushLoopInterrupted;
 #endif
 
@@ -441,19 +442,23 @@ class nsHtml5TreeOpExecutor : public nsC
                        const nsAString& aCrossOrigin);
 
     void PreloadStyle(const nsAString& aURL, const nsAString& aCharset);
 
     void PreloadImage(const nsAString& aURL, const nsAString& aCrossOrigin);
 
     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.
      */
     already_AddRefed<nsIURI> ConvertIfNotPreloadedYet(const nsAString& aURL);
 
 };
 
 #endif // nsHtml5TreeOpExecutor_h__