Clean up of Session History apis. Corresponding changes to the users of SH. r=mcafee. No bug #.

This commit is contained in:
radha%netscape.com 1999-10-22 20:48:07 +00:00
Родитель 7957d17185
Коммит 9cf9ffe640
7 изменённых файлов: 85 добавлений и 111 удалений

Просмотреть файл

@ -3678,7 +3678,6 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
const PRUnichar * title=nsnull;
PRInt32 curIndex=0;
nsresult rv;
nsAutoString newURL;
/* Get current history index and url for it */
rv = mSHist->GetCurrentIndex(&curIndex);
@ -3686,8 +3685,6 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
/* Get the url that netlib passed us */
char* spec;
aURL->GetSpec(&spec);
newURL = (spec);
nsCRT::free(spec);
//Get the title from webshell
rv = GetTitle(&title);
@ -3697,8 +3694,9 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
nsString titleStr(title);
mSHist->SetTitleForIndex(curIndex, title);
// Replace the top most history entry with the new url
mSHist->SetURLForIndex(curIndex, newURL.GetUnicode());
mSHist->SetURLForIndex(curIndex, spec);
}
nsCRT::free(spec);
return NS_OK;

Просмотреть файл

@ -3678,7 +3678,6 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
const PRUnichar * title=nsnull;
PRInt32 curIndex=0;
nsresult rv;
nsAutoString newURL;
/* Get current history index and url for it */
rv = mSHist->GetCurrentIndex(&curIndex);
@ -3686,8 +3685,6 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
/* Get the url that netlib passed us */
char* spec;
aURL->GetSpec(&spec);
newURL = (spec);
nsCRT::free(spec);
//Get the title from webshell
rv = GetTitle(&title);
@ -3697,8 +3694,9 @@ nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
nsString titleStr(title);
mSHist->SetTitleForIndex(curIndex, title);
// Replace the top most history entry with the new url
mSHist->SetURLForIndex(curIndex, newURL.GetUnicode());
mSHist->SetURLForIndex(curIndex, spec);
}
nsCRT::free(spec);
return NS_OK;

Просмотреть файл

@ -19,7 +19,7 @@
#ifndef nsAppShellCIDs_h__
#define nsAppShellCIDs_h__
#include "nsIFactory.h"
// 43147b80-8a39-11d2-9938-0080c7cb1080
#define NS_APPSHELL_SERVICE_CID \
@ -37,5 +37,10 @@
{ 0xa6852d40, 0xcd6f, 0x11d2, \
{0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} }
#define NS_SESSIONHISTORY_CID \
{ 0x68e73d52, 0x12eb, 0x11d3, { 0xbd, 0xc0, 0x00, 0x50, 0x04, 0x0a, 0x9b, 0x44 } }
extern nsresult NS_NewSessionHistoryFactory(nsIFactory** aResult);
#endif /* nsAppShellCIDs_h__ */

Просмотреть файл

@ -24,9 +24,6 @@
%{C++
#include "nscore.h"
class nsIWebShell;
#define NS_SESSIONHISTORY_CID \
{ 0x68e73d52, 0x12eb, 0x11d3, { 0xbd, 0xc0, 0x00, 0x50, 0x04, 0x0a, 0x9b, 0x44 } }
#define NS_ISESSIONHISTORY_PROGID "component://netscape/appshell/component/browser/sessionhistory"
%}
@ -38,37 +35,37 @@ interface nsISessionHistory: nsISupports
/**
* Go forward in history
*/
[noscript] void goForward(in nsIWebShell aPrevPage);
[noscript] void goForward(in nsIWebShell aContainer);
/**
* Go Back in History
*/
[noscript] void goBack(in nsIWebShell aPrevPage);
[noscript] void goBack(in nsIWebShell aContainer);
/**
* Reload the current history entry
*/
[noscript] void reload(in nsIWebShell aPrevPage, in nsLoadFlags aReloadFlags);
[noscript] void reload(in nsIWebShell aContainer, in nsLoadFlags aReloadFlags);
/**
* Can I go forward in History
*/
boolean canForward();
boolean canGoForward();
/**
* Can I go back in History
*/
boolean canBack();
boolean canGoBack();
/**
* Add a new URL to the History List
*/
[noscript] void add(in nsIWebShell aWebShell);
[noscript] void add(in nsIWebShell aContainer);
/**
* Goto to a particular point in history
*/
[noscript] void Goto(in long aHistoryIndex, in nsIWebShell prev, in boolean aIsReloading);
[noscript] void goto(in long aHistoryIndex, in nsIWebShell aContainer, in boolean aIsReloading);
/**
* Get the length of the History list
@ -95,18 +92,18 @@ interface nsISessionHistory: nsISupports
/**
* Get the URL of the index
*/
wstring getURLForIndex(in long aIndex);
string getURLForIndex(in long aIndex);
/**
* Set the URL of the index
*/
void setURLForIndex(in long aIndex, in wstring aURL);
void setURLForIndex(in long aIndex, in string aURL);
/**
* Get the title of the index
*/
wstring GetTitleForIndex(in long aIndex);
wstring getTitleForIndex(in long aIndex);
/**
* Set the Title of the index
@ -121,22 +118,13 @@ interface nsISessionHistory: nsISupports
/**
* Set the History state of the index
*/
void SetHistoryObjectForIndex(in long aIndex, in nsISupports aState);
/**
* Clear all history load flags
*/
void ClearLoadingFlags();
void setHistoryObjectForIndex(in long aIndex, in nsISupports aState);
/**
* Reconcile history status with the actual page load status
*/
[noscript] void UpdateStatus(in nsIWebShell aWebShell, in long aStatus);
[noscript] void updateStatus(in nsIWebShell aContainer, in long aStatus);
const unsigned long LOAD_HISTORY = 10;
};
%{C++
extern nsresult NS_NewSessionHistoryFactory(nsIFactory** aResult);
%}

Просмотреть файл

@ -64,7 +64,7 @@ NSRegisterSelf(nsISupports* serviceMgr, const char *path)
nsComponentManager::RegisterComponent(kProtocolHelperCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kXPConnectFactoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kNetSupportDialogCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kSessionHistoryCID, NULL, NS_ISESSIONHISTORY_PROGID, path, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kSessionHistoryCID, "sessionhistory", NS_ISESSIONHISTORY_PROGID, path, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kWindowMediatorCID,
"window-mediator", NS_RDF_DATASOURCE_PROGID_PREFIX "window-mediator",

Просмотреть файл

@ -19,7 +19,7 @@
#include "nsISessionHistory.h"
#include "nsAppShellCIDs.h"
#include "nsVoidArray.h"
#include "nsIWebShell.h"
#include "prmem.h"
@ -49,7 +49,7 @@ class nsHistoryEntry;
static nsHistoryEntry * GenerateTree(nsIWebShell * aWebShell,nsHistoryEntry *aparent, nsISessionHistory * aSHist);
#define APP_DEBUG 0
#define APP_DEBUG 1
class nsHistoryEntry
{
@ -97,12 +97,12 @@ public:
/**
* Get the URL of the page
*/
nsresult GetURL(PRUnichar ** aURL);
nsresult GetURL(char ** aURL);
/**
* Set the URL of the page
*/
nsresult SetURL(const PRUnichar * aURL);
nsresult SetURL(const char * aURL);
/**
* Get the webshell of the page
@ -233,16 +233,16 @@ nsHistoryEntry::DestroyChildren() {
nsresult
nsHistoryEntry::GetURL(PRUnichar** aURL)
nsHistoryEntry::GetURL(char** aURL)
{
//GetURlForIndex error checks aURL
if (mURL)
*aURL= mURL->ToNewUnicode();
*aURL= mURL->ToNewCString();
return NS_OK;
}
nsresult
nsHistoryEntry::SetURL(const PRUnichar* aURL)
nsHistoryEntry::SetURL(const char* aURL)
{
if (mURL)
@ -388,7 +388,9 @@ nsHistoryEntry::Create(nsIWebShell * aWebShell, nsHistoryEntry * aParent, nsISes
nsAutoString urlstr(url);
// save the webshell's URL in the history entry
SetURL(url);
char * urlcstr = urlstr.ToNewCString();
SetURL(urlcstr);
Recycle(urlcstr);
//Save the webshell id
SetWebShell(aWebShell);
@ -484,7 +486,7 @@ nsHistoryEntry::Load(nsIWebShell * aPrevEntry, PRBool aIsReload) {
PRBool result = PR_FALSE;
nsAutoString cSURL, pSURL;
const PRUnichar * pURL=nsnull;
PRUnichar * cURL=nsnull;
char * cURL=nsnull;
cur = this;
prev = aPrevEntry;
@ -531,7 +533,10 @@ nsHistoryEntry::Load(nsIWebShell * aPrevEntry, PRBool aIsReload) {
nsLoadType loadType = (nsLoadType)nsIChannel::LOAD_NORMAL;
if (!aIsReload)
loadType = (nsLoadType) nsISessionHistory::LOAD_HISTORY;
prev->LoadURL(cURL, nsnull, PR_FALSE, loadType, 0, historyObject);
PRUnichar * uniURL = cSURL.ToNewUnicode();
prev->LoadURL(uniURL, nsnull, PR_FALSE, loadType, 0, historyObject);
Recycle(uniURL);
if (aIsReload && (pcount > 0)) {
/* If this is a reload, on a page with frames, you want to return
* true so that consecutive calls by the frame children in to
@ -546,7 +551,10 @@ nsHistoryEntry::Load(nsIWebShell * aPrevEntry, PRBool aIsReload) {
return PR_TRUE;
}
else if (!isInSHist && isLoadingDoc) {
prev->SetURL(cURL);
PRUnichar * uniURL = cSURL.ToNewUnicode();
prev->SetURL(uniURL);
Recycle(uniURL);
if (APP_DEBUG) printf("Changing URL to %s in webshell\n", cSURL.ToNewCString());
Recycle(cURL);
@ -607,7 +615,7 @@ nsHistoryEntry::Compare(nsIWebShell * aPrevEntry, PRBool aIsReload) {
nsIWebShell *prev=nsnull;
PRBool result = PR_FALSE;
const PRUnichar * pURL=nsnull;
PRUnichar * cURL=nsnull;
char * cURL=nsnull;
nsAutoString cSURL, pSURL;
cur = this;
@ -842,6 +850,7 @@ nsSessionHistory::Add(nsIWebShell * aWebShell)
mHistoryEntries.AppendElement((void *)hEntry);
mHistoryLength++;
mHistoryCurrentIndex++;
if (APP_DEBUG) printf("nsSessionHistory::Add CurrentIndex = %d, HistoryLength = %d \n", mHistoryCurrentIndex, mHistoryLength);
return NS_OK;
} // (!mParent)
@ -980,16 +989,8 @@ nsSessionHistory::Add(nsIWebShell * aWebShell)
}
NS_IMETHODIMP
nsSessionHistory::ClearLoadingFlags()
{
mIsLoadingDoc = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSessionHistory::UpdateStatus(nsIWebShell * aWebShell, PRInt32 aStatus) {
if (!aWebShell)
return NS_ERROR_NULL_POINTER;
@ -1102,10 +1103,9 @@ nsSessionHistory::Goto(PRInt32 aGotoIndex, nsIWebShell * prev, PRBool aIsReload)
mHistoryEntryInLoad = hCurrentEntry;
//Load the page
PRUnichar * url;
char * url;
hCurrentEntry->GetURL(&url);
nsAutoString urlString(url);
if (APP_DEBUG) printf("nsSessionHistory::Goto, Trying to load URL %s\n", urlString.ToNewCString());
if (APP_DEBUG && url) printf("nsSessionHistory::Goto, Trying to load URL %s\n", url);
Recycle (url);
mHistoryCurrentIndex = aGotoIndex;
@ -1179,7 +1179,7 @@ nsSessionHistory::GetLoadingFlag(PRBool *aFlag)
NS_IMETHODIMP
nsSessionHistory::CanForward(PRBool * aResult)
nsSessionHistory::CanGoForward(PRBool * aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
@ -1193,7 +1193,7 @@ nsSessionHistory::CanForward(PRBool * aResult)
}
NS_IMETHODIMP
nsSessionHistory::CanBack(PRBool * aResult)
nsSessionHistory::CanGoBack(PRBool * aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
@ -1229,7 +1229,7 @@ nsSessionHistory::GetCurrentIndex(PRInt32 * aResult)
NS_IMETHODIMP
nsSessionHistory::GetURLForIndex(PRInt32 aIndex, PRUnichar** aURL)
nsSessionHistory::GetURLForIndex(PRInt32 aIndex, char** aURL)
{
nsHistoryEntry * hist=nsnull;
@ -1251,7 +1251,7 @@ nsSessionHistory::GetURLForIndex(PRInt32 aIndex, PRUnichar** aURL)
}
NS_IMETHODIMP
nsSessionHistory::SetURLForIndex(PRInt32 aIndex, const PRUnichar* aURL)
nsSessionHistory::SetURLForIndex(PRInt32 aIndex, const char* aURL)
{
nsHistoryEntry * hist=nsnull;
@ -1313,7 +1313,7 @@ nsSessionHistory::GetHistoryObjectForIndex(PRInt32 aIndex, nsISupports** aState)
if (aIndex < 0 || aIndex >= mHistoryLength)
{
if (APP_DEBUG) printf("nsSessionHistory::GetURLForIndex Returning error in GetURL for Index\n");
if (APP_DEBUG) printf("nsSessionHistory::GetHistoryObjectForIndex Returning error \n");
return NS_ERROR_FAILURE;
}
@ -1345,7 +1345,6 @@ nsSessionHistory::SetHistoryObjectForIndex(PRInt32 aIndex, nsISupports* aState)
}
NS_EXPORT nsresult NS_NewSessionHistory(nsISessionHistory** aResult)
{
if (nsnull == aResult) {
@ -1448,3 +1447,4 @@ NS_NewSessionHistoryFactory(nsIFactory** aFactory)
*aFactory = inst;
return rv;
}

Просмотреть файл

@ -127,7 +127,6 @@ static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
static NS_DEFINE_IID(kIGlobalHistoryIID, NS_IGLOBALHISTORY_IID);
static NS_DEFINE_IID(kISessionHistoryIID, NS_ISESSIONHISTORY_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
#ifdef DEBUG
@ -246,9 +245,10 @@ nsBrowserAppCore::Init()
nsresult rv = NS_OK;
// Create session history.
rv = nsComponentManager::CreateInstance(kCSessionHistoryCID,
nsnull,
kISessionHistoryIID,
nsISessionHistory::GetIID(),
(void **)&mSHistory );
if ( NS_SUCCEEDED( rv ) ) {
@ -257,6 +257,7 @@ nsBrowserAppCore::Init()
BeginObserving();
}
return rv;
}
@ -333,9 +334,7 @@ nsBrowserAppCore::Stop()
mContentAreaWebShell->Stop();
if (mIsLoadingHistory) {
mIsLoadingHistory = PR_FALSE;
if (mSHistory)
mSHistory->ClearLoadingFlags();
SetLoadingFlag(PR_FALSE);
}
nsAutoString v( "false" );
// XXX: The throbber should be turned off when the OnStopDocumentLoad
@ -417,13 +416,14 @@ nsBrowserAppCore::BackButtonPopup()
i = indix-SHISTORY_POPUP_LIST;
for (PRInt32 j=indix-1;j>=i;j--) {
PRUnichar * url=nsnull, *title=nsnull;
PRUnichar *title=nsnull;
char * url=nsnull;
mSHistory->GetURLForIndex(j, &url);
nsAutoString histURL(url);
mSHistory->GetTitleForIndex(j, &title);
nsAutoString histTitle(title);
rv = CreateMenuItem(menu, j, url);
rv = CreateMenuItem(menu, j, title);
if (!NS_SUCCEEDED(rv))
printf("nsBrowserAppCore:;BackButtonpopup ERROR while creating menu item\n");
Recycle(title);
@ -580,13 +580,13 @@ nsBrowserAppCore::ForwardButtonPopup()
i = length;
for (PRInt32 j=indix+1;j<i;j++) {
PRUnichar * url=nsnull, *title=nsnull;
PRUnichar *title=nsnull;
char * url=nsnull;
mSHistory->GetURLForIndex(j, &url);
nsAutoString histURL(url);
mSHistory->GetTitleForIndex(j, &title);
nsAutoString histTitle(title);
rv = CreateMenuItem(menu, j, url);
rv = CreateMenuItem(menu, j, title);
if (!NS_SUCCEEDED(rv))
printf("nsBrowserAppCore::ForwardbuttonPopup, Error while creating history menu items\n");
Recycle(title);
@ -709,7 +709,8 @@ nsBrowserAppCore::UpdateGoMenu()
i = length-SHISTORY_POPUP_LIST;
for (PRInt32 j=length-1;j>=i;j--) {
PRUnichar * url=nsnull, *title=nsnull;
PRUnichar *title=nsnull;
char * url=nsnull;
mSHistory->GetURLForIndex(j, &url);
nsAutoString histURL(url);
@ -977,10 +978,7 @@ nsBrowserAppCore::LoadUrl(const PRUnichar *aUrl)
nsresult rv = NS_OK;
if (mIsLoadingHistory) {
mIsLoadingHistory = PR_FALSE;
if (mSHistory) {
mSHistory->ClearLoadingFlags();
}
SetLoadingFlag(PR_FALSE);
}
/* Ask nsWebShell to load the URl */
if ( mIsViewSource ) {
@ -1476,12 +1474,12 @@ nsBrowserAppCore::OnStartDocumentLoad(nsIDocumentLoader* aLoader, nsIURI* aURL,
PRBool result=PR_TRUE;
// Check with sessionHistory if you can go forward
CanForward(&result);
CanGoForward(&result);
setAttribute(mWebShell, "canGoForward", "disabled", (result == PR_TRUE) ? "" : "true");
// Check with sessionHistory if you can go back
CanBack(&result);
CanGoBack(&result);
setAttribute(mWebShell, "canGoBack", "disabled", (result == PR_TRUE) ? "" : "true");
@ -1571,9 +1569,7 @@ nsBrowserAppCore::OnEndDocumentLoad(nsIDocumentLoader* aLoader, nsIChannel* chan
mSHistory->UpdateStatus(webshell, (PRInt32) aStatus);
}
if (mIsLoadingHistory) {
if (mSHistory)
mSHistory->ClearLoadingFlags();
mIsLoadingHistory=PR_FALSE;
SetLoadingFlag(PR_FALSE);
}
/* If this is a frame, don't do any of the Global History
@ -1809,9 +1805,7 @@ NS_IMETHODIMP
nsBrowserAppCore::GoBack(nsIWebShell * aPrev)
{
if (mIsLoadingHistory) {
mIsLoadingHistory = PR_FALSE;
if (mSHistory)
mSHistory->ClearLoadingFlags();
SetLoadingFlag(PR_FALSE);
}
mIsLoadingHistory = PR_TRUE;
if (mSHistory) {
@ -1825,9 +1819,7 @@ NS_IMETHODIMP
nsBrowserAppCore::GoForward(nsIWebShell * aPrev)
{
if (mIsLoadingHistory) {
mIsLoadingHistory = PR_FALSE;
if (mSHistory)
mSHistory->ClearLoadingFlags();
SetLoadingFlag(PR_FALSE);
}
mIsLoadingHistory = PR_TRUE;
if (mSHistory) {
@ -1845,9 +1837,7 @@ nsBrowserAppCore::Reload(nsIWebShell * aPrev, nsLoadFlags aType)
#endif // NECKO
{
if (mIsLoadingHistory) {
mIsLoadingHistory = PR_FALSE;
if (mSHistory)
mSHistory->ClearLoadingFlags();
SetLoadingFlag(PR_FALSE);
}
mIsLoadingHistory = PR_TRUE;
if (mSHistory) {
@ -1879,16 +1869,11 @@ nsBrowserAppCore::Goto(PRInt32 aGotoIndex, nsIWebShell * aPrev, PRBool aIsReload
return rv;
}
NS_IMETHODIMP
nsBrowserInstance::ClearLoadingFlags()
{
mIsLoadingHistory = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::SetLoadingFlag(PRBool aFlag)
{
mIsLoadingHistory = aFlag;
if (mSHistory)
mSHistory->SetLoadingFlag(aFlag);
return NS_OK;
@ -1918,21 +1903,21 @@ nsBrowserAppCore::GetLoadingFlag(PRBool *aFlag)
NS_IMETHODIMP
nsBrowserAppCore::CanForward(PRBool * aResult)
nsBrowserAppCore::CanGoForward(PRBool * aResult)
{
if (mSHistory) {
mSHistory->CanForward(aResult);
mSHistory->CanGoForward(aResult);
}
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::CanBack(PRBool * aResult)
nsBrowserAppCore::CanGoBack(PRBool * aResult)
{
if (mSHistory)
mSHistory->CanBack(aResult);
mSHistory->CanGoBack(aResult);
return NS_OK;
}
@ -1957,7 +1942,7 @@ nsBrowserAppCore::GetCurrentIndex(PRInt32 * aResult)
}
NS_IMETHODIMP
nsBrowserAppCore::GetURLForIndex(PRInt32 aIndex, PRUnichar** aURL)
nsBrowserAppCore::GetURLForIndex(PRInt32 aIndex, char** aURL)
{
if (mSHistory)
return mSHistory->GetURLForIndex(aIndex, aURL);
@ -1965,7 +1950,7 @@ nsBrowserAppCore::GetURLForIndex(PRInt32 aIndex, PRUnichar** aURL)
}
NS_IMETHODIMP
nsBrowserAppCore::SetURLForIndex(PRInt32 aIndex, const PRUnichar* aURL)
nsBrowserAppCore::SetURLForIndex(PRInt32 aIndex, const char* aURL)
{
if (mSHistory)
mSHistory->SetURLForIndex(aIndex, aURL);