diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 846b3cc8fab..43cd06ba25f 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -173,6 +173,12 @@ static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, // Number of documents currently loading static PRInt32 gNumberOfDocumentsLoading = 0; +// Global count of existing docshells. +static PRInt32 gDocShellCount = 0; + +// Global reference to the URI fixup service. +nsIURIFixup *nsDocShell::sURIFixup = 0; + // Hint for native dispatch of plevents on how long to delay after // all documents have loaded in milliseconds before favoring normal // native event dispatch priorites over performance @@ -233,12 +239,6 @@ nsDocShellFocusController nsDocShellFocusController::mDocShellFocusControllerSin //***************************************************************************** nsDocShell::nsDocShell(): - mContentListener(nsnull), - mMarginWidth(0), - mMarginHeight(0), - mItemType(typeContent), - mCurrentScrollbarPref(-1, -1), - mDefaultScrollbarPref(-1, -1), mAllowSubframes(PR_TRUE), mAllowPlugins(PR_TRUE), mAllowJavascript(PR_TRUE), @@ -249,8 +249,6 @@ nsDocShell::nsDocShell(): mCreatingDocument(PR_FALSE), mUseErrorPages(PR_FALSE), mAllowAuth(PR_TRUE), - mAppType(nsIDocShell::APP_TYPE_UNKNOWN), - mBusyFlags(BUSY_FLAGS_NONE), mFiredUnloadEvent(PR_FALSE), mEODForCurrentDocument(PR_FALSE), mURIResultedInDocument(PR_FALSE), @@ -260,11 +258,27 @@ nsDocShell::nsDocShell(): mValidateOrigin(PR_FALSE), mIsExecutingOnLoadHandler(PR_FALSE), mIsPrintingOrPP(PR_FALSE), + mAppType(nsIDocShell::APP_TYPE_UNKNOWN), + mChildOffset(0), + mBusyFlags(BUSY_FLAGS_NONE), + mMarginWidth(0), + mMarginHeight(0), + mItemType(typeContent), + mContentListener(nsnull), + mCurrentScrollbarPref(-1, -1), + mDefaultScrollbarPref(-1, -1), mEditorData(nsnull), mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull) { + if (gDocShellCount++ == 0) { + NS_ASSERTION(sURIFixup == nsnull, + "Huh, sURIFixup not null in first nsDocShell ctor!"); + + CallGetService(NS_URIFIXUP_CONTRACTID, &sURIFixup); + } + #ifdef PR_LOGGING if (! gDocShellLog) gDocShellLog = PR_NewLogModule("nsDocShell"); @@ -278,6 +292,10 @@ nsDocShell::~nsDocShell() dsfc->ClosingDown(this); } Destroy(); + + if (--gDocShellCount == 0) { + NS_IF_RELEASE(sURIFixup); + } } NS_IMETHODIMP @@ -2469,23 +2487,19 @@ nsDocShell::LoadURI(const PRUnichar * aURI, nsCOMPtr uri; nsresult rv = NS_OK; // Create the fixup object if necessary - if (!mURIFixup) { - mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID); - if (!mURIFixup) { - // No fixup service so try and create a URI and see what happens - nsAutoString uriString(aURI); - // Cleanup the empty spaces that might be on each end. - uriString.Trim(" "); - // Eliminate embedded newlines, which single-line text fields now allow: - uriString.StripChars("\r\n"); - NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE); + if (!sURIFixup) { + // No fixup service so try and create a URI and see what happens + nsAutoString uriString(aURI); + // Cleanup the empty spaces that might be on each end. + uriString.Trim(" "); + // Eliminate embedded newlines, which single-line text fields now allow: + uriString.StripChars("\r\n"); + NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE); - rv = NS_NewURI(getter_AddRefs(uri), uriString); - } - } - if (mURIFixup) { + rv = NS_NewURI(getter_AddRefs(uri), uriString); + } else { // Call the fixup object - rv = mURIFixup->CreateFixupURI(NS_ConvertUCS2toUTF8(aURI), + rv = sURIFixup->CreateFixupURI(NS_ConvertUCS2toUTF8(aURI), nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP, getter_AddRefs(uri)); } @@ -7048,19 +7062,16 @@ nsDocShell::InterfaceRequestorProxy::GetInterface(const nsIID & aIID, void **aSi nsresult nsDocShell::SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer) { - nsCOMPtr baseURI; - nsCOMPtr document; - nsresult rv = NS_OK; - if (!aContentViewer) return NS_ERROR_FAILURE; - // Create the fixup object if necessary - if (!mURIFixup) - mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID, &rv); + nsCOMPtr baseURI; + nsCOMPtr document; + nsresult rv = NS_ERROR_NOT_AVAILABLE; - if (mURIFixup) - rv = mURIFixup->CreateExposableURI(mCurrentURI, getter_AddRefs(baseURI)); + if (sURIFixup) + rv = sURIFixup->CreateExposableURI(mCurrentURI, + getter_AddRefs(baseURI)); // Get the current document and set the base uri if (baseURI) { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 4a8d68314a5..b7fd65137e6 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -326,6 +326,59 @@ protected: nsIChannel * aChannel, nsresult aResult); protected: + PRPackedBool mAllowSubframes; + PRPackedBool mAllowPlugins; + PRPackedBool mAllowJavascript; + PRPackedBool mAllowMetaRedirects; + PRPackedBool mAllowImages; + PRPackedBool mFocusDocFirst; + PRPackedBool mHasFocus; + PRPackedBool mCreatingDocument; // (should be) debugging only + PRPackedBool mUseErrorPages; + PRPackedBool mAllowAuth; + + PRPackedBool mFiredUnloadEvent; + + // this flag is for bug #21358. a docshell may load many urls + // which don't result in new documents being created (i.e. a new + // content viewer) we want to make sure we don't call a on load + // event more than once for a given content viewer. + PRPackedBool mEODForCurrentDocument; + PRPackedBool mURIResultedInDocument; + + PRPackedBool mIsBeingDestroyed; + + // used to keep track of whether user click links should be handle + // by us or immediately kicked out to an external + // application. mscott: eventually i'm going to try to fold this + // up into the uriloader where it belongs but i haven't figured + // out how to do that yet. + PRPackedBool mUseExternalProtocolHandler; + + // Disallow popping up new windows with target= + PRPackedBool mDisallowPopupWindows; + + // Validate window targets to prevent frameset spoofing + PRPackedBool mValidateOrigin; + + PRPackedBool mIsExecutingOnLoadHandler; + + // Indicates that a DocShell in this "docshell tree" is printing + PRPackedBool mIsPrintingOrPP; + + PRUint32 mAppType; + + // Offset in the parent's child list. + PRInt32 mChildOffset; + + PRUint32 mBusyFlags; + + PRInt32 mMarginWidth; + PRInt32 mMarginHeight; + PRInt32 mItemType; + + PRUint32 mLoadType; + nsString mName; nsString mTitle; nsVoidArray mChildren; @@ -345,30 +398,9 @@ protected: nsCOMPtr mSessionHistory; nsCOMPtr mGlobalHistory; nsCOMPtr mLoadCookie; // the load cookie associated with the window context. - nsCOMPtr mURIFixup; nsCOMPtr mFind; - PRInt32 mMarginWidth; - PRInt32 mMarginHeight; - PRInt32 mItemType; nsPoint mCurrentScrollbarPref; // this document only nsPoint mDefaultScrollbarPref; // persistent across doc loads - PRUint32 mLoadType; - - PRBool mAllowSubframes; - PRPackedBool mAllowPlugins; - PRPackedBool mAllowJavascript; - PRPackedBool mAllowMetaRedirects; - PRPackedBool mAllowImages; - PRPackedBool mFocusDocFirst; - PRPackedBool mHasFocus; - PRPackedBool mCreatingDocument; // (should be) debugging only - PRPackedBool mUseErrorPages; - PRPackedBool mAllowAuth; - - PRUint32 mAppType; - PRInt32 mChildOffset; // Offset in the parent's child list. - PRUint32 mBusyFlags; - // Reference to the SHEntry for this docshell until the page is destroyed. // Somebody give me better name nsCOMPtr mOSHE; @@ -376,34 +408,6 @@ protected: // Somebody give me better name nsCOMPtr mLSHE; - PRPackedBool mFiredUnloadEvent; - - // this flag is for bug #21358. a docshell may load many urls - // which don't result in new documents being created (i.e. a new content viewer) - // we want to make sure we don't call a on load event more than once for a given - // content viewer. - PRPackedBool mEODForCurrentDocument; - PRPackedBool mURIResultedInDocument; - - PRPackedBool mIsBeingDestroyed; - - // used to keep track of whether user click links should be handle by us - // or immediately kicked out to an external application. mscott: eventually - // i'm going to try to fold this up into the uriloader where it belongs but i haven't - // figured out how to do that yet. - PRPackedBool mUseExternalProtocolHandler; - - // Disallow popping up new windows with target= - PRPackedBool mDisallowPopupWindows; - - // Validate window targets to prevent frameset spoofing - PRPackedBool mValidateOrigin; - - PRPackedBool mIsExecutingOnLoadHandler; - - // Indicates that a DocShell in this "docshell tree" is printing - PRPackedBool mIsPrintingOrPP; - // Editor stuff nsDocShellEditorData* mEditorData; // editor data, if any @@ -418,6 +422,8 @@ protected: nsIDocShellTreeOwner * mTreeOwner; // Weak Reference nsIChromeEventHandler * mChromeEventHandler; //Weak Reference + static nsIURIFixup *sURIFixup; + public: class InterfaceRequestorProxy : public nsIInterfaceRequestor { diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 86669f519b9..7d05132dd61 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -773,13 +773,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, return NS_OK; } - // Create the fixup object if necessary - if (!mURIFixup) - { - mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID); - } - - if (mURIFixup) + if (sURIFixup) { // // Try and make an alternative URI from the old one @@ -870,7 +864,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, if (doCreateAlternate) { newURI = nsnull; - mURIFixup->CreateFixupURI(oldSpec, + sURIFixup->CreateFixupURI(oldSpec, nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI, getter_AddRefs(newURI)); } }