diff --git a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp index 03cd312bc34..16fb24adec0 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp @@ -77,7 +77,7 @@ static nsModuleComponentInfo gAppShellModuleInfo[] = }, { "CommandLine Service", NS_COMMANDLINE_SERVICE_CID, - NULL, + "@mozilla.org/appshell/commandLineService;1", nsCmdLineServiceConstructor, }, { "XPConnect Factory?", diff --git a/mozilla/xpfe/browser/public/nsIBrowserInstance.idl b/mozilla/xpfe/browser/public/nsIBrowserInstance.idl index 6de366e99db..8ac325fa2e0 100644 --- a/mozilla/xpfe/browser/public/nsIBrowserInstance.idl +++ b/mozilla/xpfe/browser/public/nsIBrowserInstance.idl @@ -33,11 +33,11 @@ interface nsIInputStream; interface nsIBrowserInstance : nsISupports { void loadUrl(in wstring url); - void loadInitialPage(); + boolean startPageCycler(); + attribute boolean cmdLineURLUsed; // Infrastructure. void init(); - void setContentWindow( in nsIDOMWindowInternal aWindow ); void getContentDocShell(out nsIDocShell aDocShell); void setWebShellWindow( in nsIDOMWindowInternal aWindow ); void SetDocumentCharset(in wstring charset); diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index e4cfe75c23e..c50c335773a 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -396,9 +396,10 @@ function Startup() } catch (e) { alert("Error creating browser instance"); window.close(); // Give up. + return; } - _content.appCore= appCore; + _content.appCore = appCore; // Initialize browser instance.. appCore.setWebShellWindow(window); @@ -410,29 +411,6 @@ function Startup() // set the offline/online mode setOfflineStatus(); - debug("Setting content window\n"); - appCore.setContentWindow(_content); - // Have browser app core load appropriate initial page. - - /* START OF UNNECESSARY CODE */ - /* sspitzer: I think this code is unnecessary, but I'll leave it until I prove it */ - var startpage; - try { - var handler = Components.classes["@mozilla.org/commandlinehandler/general-startup;1?type=browser"] - .getService(Components.interfaces.nsICmdLineHandler); - startpage = handler.defaultArgs; - } catch (ex) { - debug("failed, reason: " + ex + "\n"); - // we failed to get the start page, load this - startpage = "about:blank"; - } - - //debug("startpage = " + startpage + "\n"); - document.getElementById("args").setAttribute("value", startpage); - /* END OF UNNECESSARY CODE */ - - appCore.loadInitialPage(); - // Add a capturing event listener to the content area // (rjc note: not the entire window, otherwise we'll get sidebar pane loads too!) // so we'll be notified when onloads complete. @@ -464,19 +442,29 @@ function Startup() if (homePage) document.getElementById("home-button").setAttribute("tooltiptext", homePage); - // Check for window.arguments[0]. If present, go to that url. - if ("arguments" in window && window.arguments.length > 0) { + var startPage; - // See if load in progress (loading default page). - if (document.getElementById("navigator-throbber").getAttribute("busy") == "true") { - debug("Stopping load of default initial page\n"); - getWebNavigation().stop(); + if (!appCore.cmdLineURLUsed) { + // load appropriate initial page from commandline. + var isPageCycling = appCore.startPageCycler(); + + if (!isPageCycling) { + var cmdLineService = Components.classes["@mozilla.org/appshell/commandLineService;1"] + .getService(Components.interfaces.nsICmdLineService); + startPage = cmdLineService.URLToLoad; + appCore.cmdLineURLUsed = true; } - - debug("Loading page specified via openDialog\n"); - loadURI(window.arguments[0]); } + // Check for window.arguments[0]. If present, use that for startPage. + if (!startPage && "arguments" in window && window.arguments.length > 0) + startPage = window.arguments[0]; + + if (!startPage) + startPage = "about:blank"; + + loadURI(startPage); + initConsoleListener(); // Perform default browser checking. diff --git a/mozilla/xpfe/browser/resources/content/viewsource.js b/mozilla/xpfe/browser/resources/content/viewsource.js index 4ae86ff9e56..860ad37d5db 100644 --- a/mozilla/xpfe/browser/resources/content/viewsource.js +++ b/mozilla/xpfe/browser/resources/content/viewsource.js @@ -10,7 +10,7 @@ function onLoadViewSource() function viewSource(url) { if (!url) - return; // throw Components.results.NS_ERROR_FAILURE; + return false; // throw Components.results.NS_ERROR_FAILURE; try { createBrowserInstance(); if (appCore == null) { @@ -22,10 +22,6 @@ function viewSource(url) // Initialize browser instance.. appCore.setWebShellWindow(window); - if ( window._content ) { - dump("Setting content window\n"); - appCore.setContentWindow( window._content ); - } } catch(ex) { diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index 28aa6afb30b..e8e129faea0 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -171,10 +171,6 @@ static int APP_DEBUG = 0; // Set to 1 in debugger to turn on debugging. #define PREF_BROWSER_STARTUP_PAGE "browser.startup.page" #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage" -static nsresult -FindNamedXULElement(nsIDocShell * aShell, const char *aId, nsCOMPtr * aResult ); - - //***************************************************************************** //*** PageCycler: Object Management //***************************************************************************** @@ -236,8 +232,7 @@ public: NS_WITH_SERVICE(nsIObserverService, obsServ, NS_OBSERVERSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - nsString topic; topic.AssignWithConversion("EndDocumentLoad"); - rv = obsServ->AddObserver(this, topic.GetUnicode()); + rv = obsServ->AddObserver(this, NS_LITERAL_STRING("EndDocumentLoad").get()); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add self to observer service"); return rv; } @@ -325,8 +320,7 @@ public: } if (NS_FAILED(rv)) { - printf("######### PageCycler couldn't asynchronously load: %s\n", - NS_STATIC_CAST(const char*, NS_ConvertUCS2toUTF8(mLastRequest))); + printf("######### PageCycler couldn't asynchronously load: %s\n", NS_ConvertUCS2toUTF8(mLastRequest).get()); } } } @@ -346,8 +340,7 @@ public: // load the URL const PRUnichar* url = self->mLastRequest.GetUnicode(); - printf("########## PageCycler starting: %s\n", - NS_STATIC_CAST(const char*, NS_ConvertUCS2toUTF8(url))); + printf("########## PageCycler starting: %s\n", NS_ConvertUCS2toUTF8(url).get()); self->mAppCore->LoadUrl(url); @@ -431,6 +424,7 @@ void TimesUp(nsITimer *aTimer, void *aClosure) #endif //ENABLE_PAGE_CYCLER PRUint32 nsBrowserInstance::gRefCnt = 0; +PRBool nsBrowserInstance::sCmdLineURLUsed = PR_FALSE; int PR_CALLBACK ButtonShowHideCallback(const char* aPref, void* aClosure); static const char kShowToolbarElts[] = "browser.toolbars.showbutton"; @@ -440,13 +434,10 @@ static const char kShowToolbarElts[] = "browser.toolbars.showbutton"; nsBrowserInstance::nsBrowserInstance() : mIsClosed(PR_FALSE) { - mContentWindowWeak = nsnull; - mContentScriptContext = nsnull; mWebShellWin = nsnull; mDocShell = nsnull; mDOMWindow = nsnull; mContentAreaDocShellWeak = nsnull; - mContentAreaDocLoaderWeak = nsnull; NS_INIT_REFCNT(); gRefCnt++; if (gRefCnt == 1) { @@ -476,23 +467,78 @@ nsBrowserInstance::~nsBrowserInstance() void nsBrowserInstance::ReinitializeContentVariables() { - nsCOMPtr content; - mDOMWindow->Get_content(getter_AddRefs(content)); - SetContentWindow(content); + nsresult rv; + + nsCOMPtr contentWindow; + mDOMWindow->Get_content(getter_AddRefs(contentWindow)); + nsCOMPtr globalObj(do_QueryInterface(contentWindow)); + + if (globalObj) { + nsCOMPtr docShell; + globalObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr webShell(do_QueryInterface(docShell)); + + if (webShell) { + mContentAreaDocShellWeak = getter_AddRefs(NS_GetWeakReference(docShell)); // Weak reference + + // Add a WebProgressListener to receive start/stop document notifications + nsCOMPtr webProgress(do_GetInterface(docShell)); + webProgress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*, this)); + + nsCOMPtr sessionHistory; + if (mSessionHistory) { + /* There is already a Session History for this browser + * component. Maybe the theme changed and we got called + * to reinitialize the window, docloader, docshell etc... + * Use the existing session History + */ + sessionHistory = mSessionHistory; + } + else { + sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID, &rv); + mSessionHistory = sessionHistory; + if (!mSessionHistory) { + if (APP_DEBUG) printf("#### Error initialising Session History ####\n"); + } + } + + if (sessionHistory) { + nsCOMPtr webNav(do_QueryInterface(docShell)); + if (webNav) + webNav->SetSessionHistory(sessionHistory); + } + + nsCOMPtr dsHistory(do_QueryInterface(docShell)); + nsCOMPtr history(do_GetService(kCGlobalHistoryCID)); + if (dsHistory) + dsHistory->SetGlobalHistory(history); + + if (APP_DEBUG) { + nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsXPIDLString name; + docShellAsItem->GetName(getter_Copies(name)); + nsCAutoString str; + str.AssignWithConversion(name); + printf("Attaching to Content WebShell [%s]\n", str.get()); + } + + nsCOMPtr ubHistory = do_GetService(NS_URLBARHISTORY_CONTRACTID, &rv); + + if (ubHistory) + mUrlbarHistory = ubHistory; + } + } /* reinitialize the security module */ - nsresult rv; - nsCOMPtr security = - do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); + nsCOMPtr security = do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); if (NS_SUCCEEDED(rv) && security) { nsCOMPtr doc; rv = mDOMWindow->GetDocument(getter_AddRefs(doc)); if (NS_SUCCEEDED(rv) && doc) { nsCOMPtr button; - rv = doc->GetElementById(NS_LITERAL_STRING("security-button"), - getter_AddRefs(button)); + rv = doc->GetElementById(NS_LITERAL_STRING("security-button"), getter_AddRefs(button)); if (NS_SUCCEEDED(rv)) { - security->Init(content,button); + security->Init(contentWindow, button); } } } @@ -523,11 +569,9 @@ nsresult nsBrowserInstance::GetContentAreaDocShell(nsIDocShell** outDocShell) nsresult nsBrowserInstance::GetContentWindow(nsIDOMWindowInternal** outDOMWindow) { - nsCOMPtr domWindow(do_QueryReferent(mContentWindowWeak)); - if (!domWindow) - ReinitializeContentVariables(); - domWindow = do_QueryReferent(mContentWindowWeak); - NS_IF_ADDREF(*outDOMWindow = domWindow); + nsCOMPtr contentWindow; + mDOMWindow->Get_content(getter_AddRefs(contentWindow)); + NS_IF_ADDREF(*outDOMWindow = contentWindow); return NS_OK; } @@ -566,16 +610,6 @@ nsresult nsBrowserInstance::GetFocussedContentWindow(nsIDOMWindowInternal** outF } -nsresult nsBrowserInstance::GetContentAreaDocLoader(nsIDocumentLoader** outDocLoader) -{ - nsCOMPtr docLoader(do_QueryReferent(mContentAreaDocLoaderWeak)); - if (!docLoader) - ReinitializeContentVariables(); - docLoader = do_QueryReferent(mContentAreaDocLoaderWeak); - NS_IF_ADDREF(*outDocLoader = docLoader); - return NS_OK; -} - //***************************************************************************** // nsBrowserInstance: nsISupports //***************************************************************************** @@ -613,13 +647,30 @@ nsBrowserInstance::LoadUrl(const PRUnichar * urlToLoad) } NS_IMETHODIMP -nsBrowserInstance::LoadInitialPage(void) +nsBrowserInstance::SetCmdLineURLUsed(PRBool aCmdLineURLUsed) +{ + sCmdLineURLUsed = aCmdLineURLUsed; + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserInstance::GetCmdLineURLUsed(PRBool* aCmdLineURLUsed) +{ + NS_ASSERTION(aCmdLineURLUsed, "aCmdLineURLUsed can't be null"); + if (!aCmdLineURLUsed) + return NS_ERROR_NULL_POINTER; + + *aCmdLineURLUsed = sCmdLineURLUsed; + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserInstance::StartPageCycler(PRBool* aIsPageCycling) { - static PRBool cmdLineURLUsed = PR_FALSE; - char * urlstr = nsnull; nsresult rv; - if (!cmdLineURLUsed) { + *aIsPageCycling = PR_FALSE; + if (!sCmdLineURLUsed) { NS_WITH_SERVICE(nsICmdLineService, cmdLineArgs, kCmdLineServiceCID, &rv); if (NS_FAILED(rv)) { if (APP_DEBUG) fprintf(stderr, "Could not obtain CmdLine processing service\n"); @@ -629,9 +680,11 @@ nsBrowserInstance::LoadInitialPage(void) #ifdef ENABLE_PAGE_CYCLER // First, check if there's a URL file to load (for testing), and if there // is, process it instead of anything else. + nsAutoString urlstr; nsXPIDLCString file; rv = cmdLineArgs->GetCmdLineValue("-f", getter_Copies(file)); if (NS_SUCCEEDED(rv) && (const char*)file) { + // see if we have a timeout value corresponding to the url-file nsXPIDLCString timeoutVal; rv = cmdLineArgs->GetCmdLineValue("-ftimeout", getter_Copies(timeoutVal)); @@ -647,84 +700,21 @@ nsBrowserInstance::LoadInitialPage(void) rv = bb->Init(file); if (NS_FAILED(rv)) return rv; - nsAutoString str; - rv = bb->GetNextURL(str); - if (NS_SUCCEEDED(rv)) { - urlstr = str.ToNewCString(); - } + rv = bb->GetNextURL(urlstr); NS_RELEASE(bb); - } - else -#endif //ENABLE_PAGE_CYCLER - { - nsCOMPtr docShell; - GetContentAreaDocShell(getter_AddRefs(docShell)); - // Examine content URL. - if (docShell) { - nsCOMPtr uri; - nsCOMPtr webNav = do_QueryInterface(docShell); - rv = webNav->GetCurrentURI(getter_AddRefs(uri)); - nsXPIDLCString spec; - if (uri) - rv = uri->GetSpec(getter_Copies(spec)); - /* Check whether url is valid. Otherwise we compare with - * "about:blank" and there by return from here with out - * loading the command line url or default home page. - */ - if (NS_SUCCEEDED(rv) && nsCRT::strcasecmp(spec, "about:blank") != 0) { - // Something has already been loaded (probably via window.open), - // leave it be. - return NS_OK; - } - } - - // Get the URL to load - rv = cmdLineArgs->GetURLToLoad(&urlstr); + *aIsPageCycling = PR_TRUE; } - if (urlstr != nsnull) { + if (!urlstr.IsEmpty()) { // A url was provided. Load it - if (APP_DEBUG) printf("Got Command line URL to load %s\n", urlstr); - nsString url; url.AssignWithConversion( urlstr ); - nsMemory::Free(urlstr); urlstr = nsnull; - rv = LoadUrl( url.GetUnicode() ); - cmdLineURLUsed = PR_TRUE; + if (APP_DEBUG) printf("Got Command line URL to load %s\n", NS_ConvertUCS2toUTF8(urlstr).get()); + rv = LoadUrl( urlstr.GetUnicode() ); + sCmdLineURLUsed = PR_TRUE; return rv; } +#endif //ENABLE_PAGE_CYCLER } - - // No URL was provided in the command line. Load the default provided - // in the navigator.xul; - - // but first, abort if the window doesn't want a default page loaded - if (mWebShellWin) { - PRBool loadDefault; - mWebShellWin->ShouldLoadDefaultPage(&loadDefault); - if (!loadDefault) - return NS_OK; - } - - nsCOMPtr argsElement; - - rv = FindNamedXULElement(mDocShell, "args", address_of(argsElement)); - if (!argsElement) { - // Couldn't get the "args" element from the xul file. Load a blank page - if (APP_DEBUG) printf("Couldn't find args element\n"); - nsAutoString url; url.AssignWithConversion("about:blank"); - rv = LoadUrl( url.GetUnicode() ); - return rv; - } - - // Load the default page mentioned in the xul file. - nsString value; - argsElement->GetAttribute(NS_ConvertASCIItoUCS2("value"), value); - if (value.Length()) { - rv = LoadUrl(value.GetUnicode()); - return rv; - } - - if (APP_DEBUG) printf("Quitting LoadInitialPage\n"); return NS_OK; } @@ -743,92 +733,6 @@ nsBrowserInstance::Init() return rv; } -NS_IMETHODIMP -nsBrowserInstance::SetContentWindow(nsIDOMWindowInternal* aWin) -{ - NS_PRECONDITION(aWin != nsnull, "null ptr"); - if (! aWin) - return NS_ERROR_NULL_POINTER; - - mContentWindowWeak = getter_AddRefs(NS_GetWeakReference(aWin)); - - // NS_ADDREF(aWin); WE DO NOT OWN THIS - nsresult rv; - - // we do not own the script context, so don't addref it - nsCOMPtr globalObj(do_QueryInterface(aWin)); - if(!globalObj) - return NS_ERROR_FAILURE; - - nsCOMPtr scriptContext; - globalObj->GetContext(getter_AddRefs(scriptContext)); - mContentScriptContext = scriptContext; - - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr webShell(do_QueryInterface(docShell)); - if (webShell) { - mContentAreaDocShellWeak = getter_AddRefs(NS_GetWeakReference(docShell)); // Weak reference - - // Add a WebProgressListener to receive start/stop document notifications - nsCOMPtr webProgress(do_GetInterface(docShell)); - webProgress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*, this)); - - nsCOMPtr sessionHistory; - if (mSessionHistory) { - /* There is already a Session History for this browser - * component. Maybe the theme changed and we got called - * to reinitialize the window, docloader, docshell etc... - * Use the existing session History - */ - sessionHistory = mSessionHistory; - } - else { - sessionHistory = (do_CreateInstance(NS_SHISTORY_CONTRACTID, &rv)); - mSessionHistory = sessionHistory; - if (!mSessionHistory) { - if (APP_DEBUG) printf("#### Error initialising Session History ####\n"); - return NS_FAILED(rv) ? rv : NS_ERROR_OUT_OF_MEMORY; - } - } - - nsCOMPtr webNav(do_QueryInterface(docShell)); - if (webNav) - webNav->SetSessionHistory(sessionHistory); - - nsCOMPtr docShell; - GetContentAreaDocShell(getter_AddRefs(docShell)); - - nsCOMPtr dsHistory(do_QueryInterface(docShell)); - nsCOMPtr history(do_GetService(kCGlobalHistoryCID)); - if (dsHistory) - dsHistory->SetGlobalHistory(history); - - // Cache the Document Loader for the content area webshell. This is a - // weak reference that is *not* reference counted... - nsCOMPtr docLoader; - - webShell->GetDocumentLoader(*getter_AddRefs(docLoader)); - mContentAreaDocLoaderWeak = getter_AddRefs(NS_GetWeakReference(docLoader.get())); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - nsXPIDLString name; - docShellAsItem->GetName(getter_Copies(name)); - nsCAutoString str; - str.AssignWithConversion(name); - - if (APP_DEBUG) { - printf("Attaching to Content WebShell [%s]\n", (const char *)str); - } - nsCOMPtr ubHistory = do_GetService(NS_URLBARHISTORY_CONTRACTID, &rv); - - NS_ENSURE_TRUE(ubHistory, NS_ERROR_FAILURE); - mUrlbarHistory = ubHistory; - } - - return NS_OK; -} - NS_IMETHODIMP nsBrowserInstance::GetContentDocShell(nsIDocShell** aDocShell) { @@ -859,8 +763,8 @@ nsBrowserInstance::GetUrlbarHistory(nsIUrlbarHistory** aUrlbarHistory) NS_IMETHODIMP nsBrowserInstance::SetWebShellWindow(nsIDOMWindowInternal* aWin) { - NS_ENSURE_ARG(aWin); - mDOMWindow = aWin; + NS_ENSURE_ARG(aWin); + mDOMWindow = aWin; nsCOMPtr globalObj( do_QueryInterface(aWin) ); if (!globalObj) { @@ -875,28 +779,27 @@ nsBrowserInstance::SetWebShellWindow(nsIDOMWindowInternal* aWin) // inform our top level webshell that we are its parent URI content listener... docShell->SetParentURIContentListener(this); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - nsXPIDLString name; - docShellAsItem->GetName(getter_Copies(name)); - nsCAutoString str; - str.AssignWithConversion(name); - if (APP_DEBUG) { - printf("Attaching to WebShellWindow[%s]\n", (const char *)str); + nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsXPIDLString name; + docShellAsItem->GetName(getter_Copies(name)); + nsCAutoString str; + str.AssignWithConversion(name); + printf("Attaching to WebShellWindow[%s]\n", str.get()); } nsCOMPtr webShell(do_QueryInterface(docShell)); nsCOMPtr webShellContainer; webShell->GetContainer(*getter_AddRefs(webShellContainer)); - if (nsnull != webShellContainer) - { + if (webShellContainer) { nsCOMPtr webShellWin; if (NS_OK == webShellContainer->QueryInterface(NS_GET_IID(nsIWebShellWindow), getter_AddRefs(webShellWin))) - { mWebShellWin = webShellWin; // WE DO NOT OWN THIS - } } } + + ReinitializeContentVariables(); + return NS_OK; } @@ -1195,15 +1098,10 @@ nsresult nsBrowserInstance::StartDocumentLoad(nsIDOMWindow *aDOMWindow, NS_WITH_SERVICE(nsIObserverService, observer, NS_OBSERVERSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - nsAutoString kStartDocumentLoad; - kStartDocumentLoad.AssignWithConversion("StartDocumentLoad"); + rv = observer->Notify(contentWindow, NS_LITERAL_STRING("StartDocumentLoad").get(), urlStr.GetUnicode()); - rv = observer->Notify(contentWindow, - kStartDocumentLoad.GetUnicode(), - urlStr.GetUnicode()); - - // XXX Ignore rv for now. They are using nsIEnumerator instead of - // nsISimpleEnumerator. + // XXX Ignore rv for now. They are using nsIEnumerator instead of + // nsISimpleEnumerator. return NS_OK; } @@ -1234,7 +1132,6 @@ nsresult nsBrowserInstance::EndDocumentLoad(nsIDOMWindow *aDOMWindow, (const char *)urlCString, PR_IntervalToMilliseconds(diff) / 1000.0); #endif - // // If this document notification is for a frame then ignore it... // @@ -1249,20 +1146,34 @@ nsresult nsBrowserInstance::EndDocumentLoad(nsIDOMWindow *aDOMWindow, } } + nsCOMPtr contentWindow; + rv = GetContentWindow(getter_AddRefs(contentWindow)); + if (NS_FAILED(rv)) return rv; + // // XXX: The DocLoader should never be busy at this point!! // -#if 1 - nsCOMPtr docLoader; - GetContentAreaDocLoader(getter_AddRefs(docLoader)); - - if (docLoader) { - PRBool isBusy = PR_FALSE; +#ifdef DEBUG + nsCOMPtr globalObj(do_QueryInterface(contentWindow)); - docLoader->IsBusy(&isBusy); - if (isBusy) { - NS_ASSERTION(0, "The DocLoader is still busy... There is a bug in End Document notifications\n"); - return NS_OK; + if (globalObj) { + nsCOMPtr docShell; + globalObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr webShell(do_QueryInterface(docShell)); + + if (webShell) { + nsCOMPtr docLoader; + webShell->GetDocumentLoader(*getter_AddRefs(docLoader)); + + if (docLoader) { + PRBool isBusy = PR_FALSE; + docLoader->IsBusy(&isBusy); + + if (isBusy) { + NS_ASSERTION(0, "The DocLoader is still busy... There is a bug in End Document notifications\n"); + return NS_OK; + } + } } } #endif @@ -1270,24 +1181,15 @@ nsresult nsBrowserInstance::EndDocumentLoad(nsIDOMWindow *aDOMWindow, /* If this is a frame, don't do any of the Global History * & observer thingy */ - nsAutoString urlStr; - nsAutoString notifyString; - nsCOMPtr contentWindow; - - urlStr.AssignWithConversion(urlCString); - notifyString.AssignWithConversion( NS_SUCCEEDED(aStatus) ? "EndDocumentLoad" - : "FailDocumentLoad" ); - // Notify observers that a document load has started in the - // content window. - rv = GetContentWindow(getter_AddRefs(contentWindow)); - if (NS_FAILED(rv)) return rv; - NS_WITH_SERVICE(nsIObserverService, observer, NS_OBSERVERSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + // Notify observers that a document load has started in the + // content window. rv = observer->Notify(contentWindow, - notifyString.GetUnicode(), - urlStr.GetUnicode()); + NS_SUCCEEDED(aStatus) ? NS_LITERAL_STRING("EndDocumentLoad").get() + : NS_LITERAL_STRING("FailDocumentLoad").get(), + NS_ConvertASCIItoUCS2(urlCString).get()); // XXX Ignore rv for now. They are using nsIEnumerator instead of // nsISimpleEnumerator. @@ -1297,17 +1199,20 @@ nsresult nsBrowserInstance::EndDocumentLoad(nsIDOMWindow *aDOMWindow, if (NS_SUCCEEDED(aStatus)) { // Remember post data for http channels. nsCOMPtr httpChannel(do_QueryInterface(aChannel)); - if (httpChannel) { + if (httpChannel) httpChannel->GetUploadStream(getter_AddRefs(postData)); - } - fprintf(stdout, "Document %s loaded successfully\n", - (const char*)urlCString); + } + +#ifdef DEBUG + if (NS_SUCCEEDED(aStatus)) { + fprintf(stdout, "Document %s loaded successfully\n", urlCString.get()); fflush(stdout); } else { - fprintf(stdout, "Error loading URL %s: %0x \n", - (const char*)urlCString, aStatus); + fprintf(stdout, "Error loading URL %s: %0x \n", urlCString.get(), aStatus); fflush(stdout); } +#endif + SetPostData(postData); return NS_OK; @@ -1577,8 +1482,7 @@ nsBrowserInstance::EnsureXULBrowserWindow() NS_ENSURE_TRUE(piDOMWindow, NS_ERROR_FAILURE); nsCOMPtr xpConnectObj; - nsAutoString xulBrowserWinId; xulBrowserWinId.AssignWithConversion("XULBrowserWindow"); - piDOMWindow->GetObjectProperty(xulBrowserWinId.GetUnicode(), getter_AddRefs(xpConnectObj)); + piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("XULBrowserWindow").get(), getter_AddRefs(xpConnectObj)); mXULBrowserWindow = do_QueryInterface(xpConnectObj); if(mXULBrowserWindow) @@ -1587,53 +1491,6 @@ nsBrowserInstance::EnsureXULBrowserWindow() return NS_ERROR_FAILURE; } -static nsresult -FindNamedXULElement(nsIDocShell * aShell, - const char *aId, - nsCOMPtr * aResult ) { - nsresult rv = NS_OK; - - nsCOMPtr cv; - rv = aShell ? aShell->GetContentViewer(getter_AddRefs(cv)) - : NS_ERROR_NULL_POINTER; - if ( cv ) { - // Up-cast. - nsCOMPtr docv(do_QueryInterface(cv)); - if ( docv ) { - // Get the document from the doc viewer. - nsCOMPtr doc; - rv = docv->GetDocument(*getter_AddRefs(doc)); - if ( doc ) { - // Up-cast. - - nsCOMPtr xulDoc( do_QueryInterface(doc) ); - if ( xulDoc ) { - // Find specified element. - nsCOMPtr elem; - - rv = xulDoc->GetElementById( NS_ConvertASCIItoUCS2(aId), getter_AddRefs(elem) ); - if ( elem ) { - *aResult = elem; - } else { - if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv); - } - } else { - if (APP_DEBUG) printf("Upcast to nsIDOMXULDocument failed\n"); - } - - } else { - if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv); - } - } else { - if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n"); - } - } else { - if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv); - } - return rv; -} - - //////////////////////////////////////////////////////////////////////// // browserCntHandler is a content handler component that registers // the browse as the preferred content handler for various content @@ -1703,91 +1560,88 @@ NS_IMETHODIMP nsBrowserContentHandler::GetChromeUrlForTask(char **aChromeUrlForT return NS_OK; } -NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs) -{ - if (!aDefaultArgs) return NS_ERROR_FAILURE; +NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs) +{ + if (!aDefaultArgs) + return NS_ERROR_NULL_POINTER; - nsString args; + nsresult rv; + static PRBool timebombChecked = PR_FALSE; + nsAutoString args; - nsresult rv; - nsXPIDLString url; - static PRBool timebombChecked = PR_FALSE; + if (!timebombChecked) { + // timebomb check + timebombChecked = PR_TRUE; - if (timebombChecked == PR_FALSE) - { - // timebomb check - timebombChecked = PR_TRUE; - - PRBool expired; - NS_WITH_SERVICE(nsITimeBomb, timeBomb, kTimeBombCID, &rv); - if ( NS_FAILED(rv) ) return rv; + PRBool expired; + nsCOMPtr timeBomb(do_GetService(kTimeBombCID, &rv)); + if (NS_FAILED(rv)) return rv; - rv = timeBomb->Init(); - if ( NS_FAILED(rv) ) return rv; + rv = timeBomb->Init(); + if (NS_FAILED(rv)) return rv; - rv = timeBomb->CheckWithUI(&expired); - if ( NS_FAILED(rv) ) return rv; + rv = timeBomb->CheckWithUI(&expired); + if (NS_FAILED(rv)) return rv; - if ( expired ) - { - char* urlString; - rv = timeBomb->GetTimebombURL(&urlString); - if ( NS_FAILED(rv) ) return rv; + if (expired) { + nsXPIDLCString urlString; + rv = timeBomb->GetTimebombURL(getter_Copies(urlString)); + if (NS_FAILED(rv)) return rv; - *aDefaultArgs = nsXPIDLString::Copy(url); - nsMemory::Free(urlString); - return rv; - } + args.AssignWithConversion(urlString); } + } - /* the default, in case we fail somewhere */ - args.AssignWithConversion("about:blank"); - + if (args.IsEmpty()) { nsCOMPtr prefs(do_GetService(kCPrefServiceCID)); if (!prefs) return NS_ERROR_FAILURE; - nsCOMPtr history(do_GetService(kCGlobalHistoryCID)); - PRBool override = PR_FALSE; rv = prefs->GetBoolPref(PREF_HOMEPAGE_OVERRIDE, &override); if (NS_SUCCEEDED(rv) && override) { - rv = prefs->GetLocalizedUnicharPref(PREF_HOMEPAGE_OVERRIDE_URL, getter_Copies(url)); - if (NS_SUCCEEDED(rv) && (const PRUnichar *)url) { - rv = prefs->SetBoolPref(PREF_HOMEPAGE_OVERRIDE, PR_FALSE); - } + nsXPIDLString url; + rv = prefs->GetLocalizedUnicharPref(PREF_HOMEPAGE_OVERRIDE_URL, getter_Copies(url)); + if (NS_SUCCEEDED(rv) && (const PRUnichar *)url) { + rv = prefs->SetBoolPref(PREF_HOMEPAGE_OVERRIDE, PR_FALSE); + args = url; + } } - - nsAutoString tmp(url); - if (!url || !tmp.Length()) { - PRInt32 choice = 0; - rv = prefs->GetIntPref(PREF_BROWSER_STARTUP_PAGE, &choice); - if (NS_SUCCEEDED(rv)) { - switch (choice) { - case 1: - rv = prefs->GetLocalizedUnicharPref(PREF_BROWSER_STARTUP_HOMEPAGE, getter_Copies(url)); - tmp = url; - break; - case 2: - if (history) { - nsXPIDLCString curl; - rv = history->GetLastPageVisited(getter_Copies(curl)); - tmp = NS_ConvertUTF8toUCS2((const char *)curl); - } - break; - case 0: - default: - args.AssignWithConversion("about:blank"); - break; + + if (args.IsEmpty()) { + PRInt32 choice = 0; + rv = prefs->GetIntPref(PREF_BROWSER_STARTUP_PAGE, &choice); + if (NS_SUCCEEDED(rv)) { + switch (choice) { + case 1: { + nsXPIDLString url; + rv = prefs->GetLocalizedUnicharPref(PREF_BROWSER_STARTUP_HOMEPAGE, getter_Copies(url)); + args = url; + break; + } + case 2: { + nsCOMPtr history(do_GetService(kCGlobalHistoryCID)); + if (history) { + nsXPIDLCString curl; + rv = history->GetLastPageVisited(getter_Copies(curl)); + args.AssignWithConversion(curl); } + break; + } + case 0: + default: + // fall through to about:blank below + break; } - } + } - if (NS_SUCCEEDED(rv) && tmp.Length()) { - args = tmp; + // the default, in case we fail somewhere + if (args.IsEmpty()) + args.Assign(NS_LITERAL_STRING("about:blank")); } + } - *aDefaultArgs = args.ToNewUnicode(); - return NS_OK; + *aDefaultArgs = args.ToNewUnicode(); + return NS_OK; } NS_IMETHODIMP nsBrowserContentHandler::HandleContent(const char * aContentType, diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.h b/mozilla/xpfe/browser/src/nsBrowserInstance.h index c873171cefb..b08d93bb052 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.h +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.h @@ -89,7 +89,6 @@ class nsBrowserInstance : public nsIBrowserInstance, nsresult GetContentAreaDocShell(nsIDocShell** outDocShell); nsresult GetContentWindow(nsIDOMWindowInternal** outContentWindow); - nsresult GetContentAreaDocLoader(nsIDocumentLoader** outDocLoader); nsresult GetFocussedContentWindow(nsIDOMWindowInternal** outFocussedWindow); @@ -108,16 +107,14 @@ class nsBrowserInstance : public nsIBrowserInstance, nsresult aResult); PRBool mIsClosed; + static PRBool sCmdLineURLUsed; nsCOMPtr mXULBrowserWindow; #ifdef SH_IN_FRAMES nsCOMPtr mSessionHistory; #endif - nsIScriptContext *mContentScriptContext; // weak reference - nsWeakPtr mContentWindowWeak; nsWeakPtr mContentAreaDocShellWeak; - nsWeakPtr mContentAreaDocLoaderWeak; nsIWebShellWindow *mWebShellWin; // weak reference nsIDocShell * mDocShell; // weak reference