From 4585cb0becf84b40a7797968e50f171da50cf0ca Mon Sep 17 00:00:00 2001 From: "rbs%maths.uq.edu.au" Date: Wed, 2 May 2001 04:53:38 +0000 Subject: [PATCH] Fix bug 76567 (load viewsource.css on demand rather than at startup). Patch mostly by bzbarsky@mit.edu r=harishd,brendan sr=jst git-svn-id: svn://10.0.0.236/trunk@93619 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/html/style/src/nsCSSLoader.cpp | 55 +++++++++---------- mozilla/layout/build/nsLayoutDLF.cpp | 30 ---------- mozilla/layout/build/nsLayoutModule.cpp | 2 - mozilla/layout/build/nsLayoutModule.h | 2 - mozilla/layout/html/document/src/ua.css | 1 - mozilla/layout/style/nsCSSLoader.cpp | 55 +++++++++---------- mozilla/layout/style/ua.css | 1 - 7 files changed, 52 insertions(+), 94 deletions(-) diff --git a/mozilla/content/html/style/src/nsCSSLoader.cpp b/mozilla/content/html/style/src/nsCSSLoader.cpp index 89e996c7a56..9dcc39f730f 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.cpp +++ b/mozilla/content/html/style/src/nsCSSLoader.cpp @@ -737,31 +737,19 @@ CSSLoaderImpl::Cleanup(URLKey& aKey, SheetLoadData* aLoadData) #ifdef INCLUDE_XUL static PRBool IsChromeURI(nsIURI* aURI) { - nsresult rv; - nsXPIDLCString protocol; - rv = aURI->GetScheme(getter_Copies(protocol)); - if (NS_SUCCEEDED(rv)) { - if (PL_strcmp(protocol, "chrome") == 0) { - return PR_TRUE; - } - } - - return PR_FALSE; + NS_ASSERTION(aURI, "bad caller"); + PRBool isChrome = PR_FALSE; + aURI->SchemeIs("chrome", &isChrome); + return isChrome; } #endif static PRBool IsFileURI(nsIURI* aURI) { - nsresult rv; - nsXPIDLCString protocol; - rv = aURI->GetScheme(getter_Copies(protocol)); - if (NS_SUCCEEDED(rv)) { - if (PL_strcmp(protocol, "file") == 0) { - return PR_TRUE; - } - } - - return PR_FALSE; + NS_ASSERTION(aURI, "bad caller"); + PRBool isFile = PR_FALSE; + aURI->SchemeIs("file", &isFile); + return isFile; } nsresult @@ -1313,15 +1301,24 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement, } //-- Make sure this page is allowed to load this URL - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - nsIURI* docURI; - rv = mDocument->GetBaseURL(docURI); - if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; - rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); - NS_IF_RELEASE(docURI); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + // If we are doing view-source, no need to check... + PRBool isForViewSource = PR_FALSE; + if (aParserToUnblock) { + nsAutoString command; + aParserToUnblock->GetCommand(command); + isForViewSource = command.Equals(NS_LITERAL_STRING("view-source")); + } + if (!isForViewSource) { + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + nsIURI* docURI; + rv = mDocument->GetBaseURL(docURI); + if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; + rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); + NS_IF_RELEASE(docURI); + if (NS_FAILED(rv)) return rv; + } // XXX need to add code to cancel any pending sheets for element nsresult result = NS_ERROR_NULL_POINTER; diff --git a/mozilla/layout/build/nsLayoutDLF.cpp b/mozilla/layout/build/nsLayoutDLF.cpp index b3357a84363..b91ea8691f0 100644 --- a/mozilla/layout/build/nsLayoutDLF.cpp +++ b/mozilla/layout/build/nsLayoutDLF.cpp @@ -48,8 +48,6 @@ static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); // URL for the "user agent" style sheet #define UA_CSS_URL "resource:/res/ua.css" -// URL for the "view source" style sheet -#define VIEW_SOURCE_CSS_URL "resource:/res/viewsource.css" // Factory code for creating variations on html documents @@ -211,20 +209,6 @@ nsLayoutDLF::CreateInstance(const char *aCommand, PRBool complete; rv = cssLoader->LoadAgentSheet(uri, nsLayoutModule::gUAStyleSheet, complete, nsnull); - if (NS_SUCCEEDED(rv)) { - // also cache the view source stylesheet - if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), VIEW_SOURCE_CSS_URL))) { - PRBool bHasSheet = PR_FALSE; - nsLayoutModule::gUAStyleSheet-> - ContainsStyleSheet(uri, - bHasSheet, - &nsLayoutModule::gViewSourceStyleSheet); - // assert if we found a stylesheet but it's nsnull -- should not happen - NS_ASSERTION(!bHasSheet || nsLayoutModule::gViewSourceStyleSheet, - "gViewSourceStyleSheet must be set: ContainsStyleSheet is hosed"); - - } - } } } if (NS_FAILED(rv)) { @@ -280,20 +264,6 @@ nsLayoutDLF::CreateInstance(const char *aCommand, else aContentType=gXMLTypes[0]; #endif - - if (nsLayoutModule::gViewSourceStyleSheet) { -#ifdef DEBUG - printf( "Enabling View Source StyleSheet\n"); -#endif - nsLayoutModule::gViewSourceStyleSheet->SetEnabled(PR_TRUE); - } - } else { - if (nsLayoutModule::gViewSourceStyleSheet) { -#ifdef DEBUG - printf( "Disabling View Source StyleSheet\n"); -#endif - nsLayoutModule::gViewSourceStyleSheet->SetEnabled(PR_FALSE); - } } // Try html diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index fd09fbf0ae2..496d1c8eece 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -174,7 +174,6 @@ LayoutScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext) nsIScriptNameSetRegistry* nsLayoutModule::gRegistry; nsICSSStyleSheet* nsLayoutModule::gUAStyleSheet = nsnull; -nsIStyleSheet* nsLayoutModule::gViewSourceStyleSheet = nsnull; nsLayoutModule::nsLayoutModule() : mInitialized(PR_FALSE) @@ -280,7 +279,6 @@ nsLayoutModule::Shutdown() NS_IF_RELEASE(gRegistry); NS_IF_RELEASE(gUAStyleSheet); - NS_IF_RELEASE(gViewSourceStyleSheet); } NS_IMETHODIMP diff --git a/mozilla/layout/build/nsLayoutModule.h b/mozilla/layout/build/nsLayoutModule.h index 6a6d6829730..d73d38e7071 100644 --- a/mozilla/layout/build/nsLayoutModule.h +++ b/mozilla/layout/build/nsLayoutModule.h @@ -25,7 +25,6 @@ #include "nslayout.h" #include "nsIModule.h" -class nsIStyleSheet; class nsICSSStyleSheet; class nsIScriptNameSetRegistry; @@ -59,7 +58,6 @@ protected: public: static nsICSSStyleSheet* gUAStyleSheet; - static nsIStyleSheet* gViewSourceStyleSheet; }; //---------------------------------------------------------------------- diff --git a/mozilla/layout/html/document/src/ua.css b/mozilla/layout/html/document/src/ua.css index e2aa9de47a9..3b0c7cb555e 100644 --- a/mozilla/layout/html/document/src/ua.css +++ b/mozilla/layout/html/document/src/ua.css @@ -22,7 +22,6 @@ @import url(resource:/res/html.css); @import url(chrome://global/content/xul.css); @import url(resource:/res/quirk.css); -@import url(resource:/res/viewsource.css); parsererror { display: block; diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index 89e996c7a56..9dcc39f730f 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -737,31 +737,19 @@ CSSLoaderImpl::Cleanup(URLKey& aKey, SheetLoadData* aLoadData) #ifdef INCLUDE_XUL static PRBool IsChromeURI(nsIURI* aURI) { - nsresult rv; - nsXPIDLCString protocol; - rv = aURI->GetScheme(getter_Copies(protocol)); - if (NS_SUCCEEDED(rv)) { - if (PL_strcmp(protocol, "chrome") == 0) { - return PR_TRUE; - } - } - - return PR_FALSE; + NS_ASSERTION(aURI, "bad caller"); + PRBool isChrome = PR_FALSE; + aURI->SchemeIs("chrome", &isChrome); + return isChrome; } #endif static PRBool IsFileURI(nsIURI* aURI) { - nsresult rv; - nsXPIDLCString protocol; - rv = aURI->GetScheme(getter_Copies(protocol)); - if (NS_SUCCEEDED(rv)) { - if (PL_strcmp(protocol, "file") == 0) { - return PR_TRUE; - } - } - - return PR_FALSE; + NS_ASSERTION(aURI, "bad caller"); + PRBool isFile = PR_FALSE; + aURI->SchemeIs("file", &isFile); + return isFile; } nsresult @@ -1313,15 +1301,24 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement, } //-- Make sure this page is allowed to load this URL - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - nsIURI* docURI; - rv = mDocument->GetBaseURL(docURI); - if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; - rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); - NS_IF_RELEASE(docURI); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + // If we are doing view-source, no need to check... + PRBool isForViewSource = PR_FALSE; + if (aParserToUnblock) { + nsAutoString command; + aParserToUnblock->GetCommand(command); + isForViewSource = command.Equals(NS_LITERAL_STRING("view-source")); + } + if (!isForViewSource) { + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + nsIURI* docURI; + rv = mDocument->GetBaseURL(docURI); + if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; + rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); + NS_IF_RELEASE(docURI); + if (NS_FAILED(rv)) return rv; + } // XXX need to add code to cancel any pending sheets for element nsresult result = NS_ERROR_NULL_POINTER; diff --git a/mozilla/layout/style/ua.css b/mozilla/layout/style/ua.css index e2aa9de47a9..3b0c7cb555e 100644 --- a/mozilla/layout/style/ua.css +++ b/mozilla/layout/style/ua.css @@ -22,7 +22,6 @@ @import url(resource:/res/html.css); @import url(chrome://global/content/xul.css); @import url(resource:/res/quirk.css); -@import url(resource:/res/viewsource.css); parsererror { display: block;