mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Changes related to history listener interface 65608 r=valeski sr=rpotts
This commit is contained in:
parent
9e8b0a29b7
commit
cce20c37bb
@ -1,4 +1,5 @@
|
|||||||
nsIShEntry.idl \
|
nsIShEntry.idl \
|
||||||
nsISHTransaction.idl \
|
nsISHTransaction.idl \
|
||||||
nsISHContainer.idl \
|
nsISHContainer.idl \
|
||||||
nsISHistory.idl
|
nsISHistory.idl \
|
||||||
|
nsISHistoryListener.idl
|
@ -32,6 +32,7 @@ XPIDLSRCS = nsISHEntry.idl \
|
|||||||
nsISHContainer.idl \
|
nsISHContainer.idl \
|
||||||
nsISHTransaction.idl \
|
nsISHTransaction.idl \
|
||||||
nsISHistory.idl \
|
nsISHistory.idl \
|
||||||
|
nsISHistoryListener.idl \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
@ -28,6 +28,7 @@ XPIDLSRCS = \
|
|||||||
.\nsISHContainer.idl \
|
.\nsISHContainer.idl \
|
||||||
.\nsISHTransaction.idl \
|
.\nsISHTransaction.idl \
|
||||||
.\nsISHistory.idl \
|
.\nsISHistory.idl \
|
||||||
|
.\nsISHistoryListener.idl \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
include <$(DEPTH)\config\rules.mak>
|
include <$(DEPTH)\config\rules.mak>
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#include "nsISHEntry.idl"
|
#include "nsISHEntry.idl"
|
||||||
#include "nsISHTransaction.idl"
|
#include "nsISHTransaction.idl"
|
||||||
#include "nsIDocShell.idl"
|
#include "nsIDocShell.idl"
|
||||||
|
#include "nsISHistoryListener.idl"
|
||||||
|
|
||||||
//interface nsIDocShell;
|
|
||||||
|
|
||||||
%{C++
|
%{C++
|
||||||
#define NS_SHISTORY_CID \
|
#define NS_SHISTORY_CID \
|
||||||
@ -40,10 +40,10 @@ interface nsISHistory: nsISupports
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Add a new Entry to the History List
|
* Add a new Entry to the History List
|
||||||
* @param aEntry - The entry to add
|
* @param aEntry - The entry to add
|
||||||
* @param aPersist - If true this specifies that the entry should persist
|
* @param aPersist - If true this specifies that the entry should persist
|
||||||
* in the list. If false, this means that when new entries are added
|
* in the list. If false, this means that when new entries are added
|
||||||
* this element will not appear in the session history list.
|
* this element will not appear in the session history list.
|
||||||
*/
|
*/
|
||||||
void addEntry(in nsISHEntry aEntry, in boolean aPersist);
|
void addEntry(in nsISHEntry aEntry, in boolean aPersist);
|
||||||
|
|
||||||
@ -92,4 +92,14 @@ interface nsISHistory: nsISupports
|
|||||||
*/
|
*/
|
||||||
void PurgeHistory(in long numEntries);
|
void PurgeHistory(in long numEntries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a Session History Listener to be notified on SHistory events
|
||||||
|
*/
|
||||||
|
void addSHistoryListener(in nsISHistoryListener aListener);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a previously registered Session History Listener
|
||||||
|
*/
|
||||||
|
void removeSHistoryListener(in nsISHistoryListener aListener);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -113,6 +113,16 @@ nsSHistory::AddEntry(nsISHEntry * aSHEntry, PRBool aPersist)
|
|||||||
nsCOMPtr<nsISHTransaction> txn(do_CreateInstance(NS_SHTRANSACTION_CONTRACTID));
|
nsCOMPtr<nsISHTransaction> txn(do_CreateInstance(NS_SHTRANSACTION_CONTRACTID));
|
||||||
NS_ENSURE_TRUE(txn, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(txn, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
// Notify any listener about the new addition
|
||||||
|
if (mListener) {
|
||||||
|
nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(mListener));
|
||||||
|
if (listener) {
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
aSHEntry->GetURI(getter_AddRefs(uri));
|
||||||
|
listener->OnHistoryNewEntry(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the ShEntry and parent for the transaction. setting the
|
// Set the ShEntry and parent for the transaction. setting the
|
||||||
// parent will properly set the parent child relationship
|
// parent will properly set the parent child relationship
|
||||||
txn->SetPersist(aPersist);
|
txn->SetPersist(aPersist);
|
||||||
@ -346,7 +356,21 @@ nsSHistory::PurgeHistory(PRInt32 aEntries)
|
|||||||
if (mLength <= 0 || aEntries <= 0)
|
if (mLength <= 0 || aEntries <= 0)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
PRInt32 cnt = 0;
|
PRBool purgeHistory = PR_TRUE;
|
||||||
|
// Notify the listener about the history purge
|
||||||
|
if (mListener) {
|
||||||
|
nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(mListener));
|
||||||
|
if (listener) {
|
||||||
|
listener->OnHistoryPurge(aEntries, &purgeHistory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!purgeHistory) {
|
||||||
|
// Listener asked us not to purge
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRInt32 cnt = 0;
|
||||||
while (cnt < aEntries) {
|
while (cnt < aEntries) {
|
||||||
nsCOMPtr<nsISHTransaction> txn = mListRoot;
|
nsCOMPtr<nsISHTransaction> txn = mListRoot;
|
||||||
nsCOMPtr<nsISHTransaction> nextTxn;
|
nsCOMPtr<nsISHTransaction> nextTxn;
|
||||||
@ -361,6 +385,29 @@ nsSHistory::PurgeHistory(PRInt32 aEntries)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsSHistory::AddSHistoryListener(nsISHistoryListener * aListener)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aListener);
|
||||||
|
|
||||||
|
// Check if the listener supports Weak Reference. This is a must.
|
||||||
|
// This listener functionality is used by embedders and we want to
|
||||||
|
// have the right ownership with who ever listens to SHistory
|
||||||
|
nsWeakPtr listener = getter_AddRefs(NS_GetWeakReference(aListener));
|
||||||
|
if (!listener) return NS_ERROR_FAILURE;
|
||||||
|
mListener = listener;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsSHistory::RemoveSHistoryListener(nsISHistoryListener * aListener)
|
||||||
|
{
|
||||||
|
mListener = nsnull;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
// nsSHistory: nsIWebNavigation
|
// nsSHistory: nsIWebNavigation
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
@ -405,7 +452,7 @@ nsSHistory::GoBack()
|
|||||||
GetCanGoBack(&canGoBack);
|
GetCanGoBack(&canGoBack);
|
||||||
if (!canGoBack) // Can't go back
|
if (!canGoBack) // Can't go back
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
return GotoIndex(mIndex-1);
|
return GotoIndex(mIndex-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -417,13 +464,14 @@ nsSHistory::GoForward()
|
|||||||
GetCanGoForward(&canGoForward);
|
GetCanGoForward(&canGoForward);
|
||||||
if (!canGoForward) // Can't go forward
|
if (!canGoForward) // Can't go forward
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
return GotoIndex(mIndex+1);
|
return GotoIndex(mIndex+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSHistory::Reload(PRUint32 aReloadFlags)
|
nsSHistory::Reload(PRUint32 aReloadFlags)
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
nsDocShellInfoLoadType loadType;
|
nsDocShellInfoLoadType loadType;
|
||||||
if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY &&
|
if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY &&
|
||||||
aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
|
aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
|
||||||
@ -442,7 +490,25 @@ nsSHistory::Reload(PRUint32 aReloadFlags)
|
|||||||
{
|
{
|
||||||
loadType = nsIDocShellLoadInfo::loadReloadNormal;
|
loadType = nsIDocShellLoadInfo::loadReloadNormal;
|
||||||
}
|
}
|
||||||
return LoadEntry(mIndex, PR_TRUE, loadType);
|
|
||||||
|
// Notify listeners
|
||||||
|
PRBool canNavigate = PR_TRUE;
|
||||||
|
if (mListener) {
|
||||||
|
nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(mListener));
|
||||||
|
// We are reloading. Send Reload notifications.
|
||||||
|
// nsDocShellLoadFlagType is not public, where as nsIWebNavigation
|
||||||
|
// is public. So send the reload notifications with the
|
||||||
|
// nsIWebNavigation flags.
|
||||||
|
if (listener) {
|
||||||
|
nsCOMPtr<nsIURI> currentURI;
|
||||||
|
rv = GetCurrentURI(getter_AddRefs(currentURI));
|
||||||
|
listener->OnHistoryReload(currentURI, aReloadFlags, &canNavigate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!canNavigate)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
return LoadEntry(mIndex, loadType);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -463,12 +529,15 @@ nsSHistory::GetDocument(nsIDOMDocument** aDocument)
|
|||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSHistory::GetCurrentURI(nsIURI** aCurrentURI)
|
nsSHistory::GetCurrentURI(nsIURI** aResultURI)
|
||||||
{
|
{
|
||||||
// Not implemented
|
NS_ENSURE_ARG_POINTER(aResultURI);
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
nsCOMPtr<nsISHEntry> currentEntry;
|
||||||
|
nsresult rv = GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(currentEntry));
|
||||||
|
if (NS_FAILED(rv) && !currentEntry) return rv;
|
||||||
|
return currentEntry->GetURI(aResultURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -496,11 +565,11 @@ nsSHistory::LoadURI(const PRUnichar* aURI, PRUint32 aLoadFlags)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSHistory::GotoIndex(PRInt32 aIndex)
|
nsSHistory::GotoIndex(PRInt32 aIndex)
|
||||||
{
|
{
|
||||||
return LoadEntry(aIndex, PR_FALSE, nsIDocShellLoadInfo::loadHistory);
|
return LoadEntry(aIndex, nsIDocShellLoadInfo::loadHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSHistory::LoadEntry(PRInt32 aIndex, PRBool aReloadFlag, long aLoadType)
|
nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDocShell> docShell;
|
nsCOMPtr<nsIDocShell> docShell;
|
||||||
nsCOMPtr<nsISHEntry> shEntry;
|
nsCOMPtr<nsISHEntry> shEntry;
|
||||||
@ -513,6 +582,35 @@ nsSHistory::LoadEntry(PRInt32 aIndex, PRBool aReloadFlag, long aLoadType)
|
|||||||
nsCOMPtr<nsISHEntry> nextEntry;
|
nsCOMPtr<nsISHEntry> nextEntry;
|
||||||
GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(nextEntry));
|
GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(nextEntry));
|
||||||
|
|
||||||
|
// Send appropriate listener notifications
|
||||||
|
PRBool canNavigate = PR_TRUE;
|
||||||
|
if(mListener) {
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
nextEntry->GetURI(getter_AddRefs(uri));
|
||||||
|
nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(mListener));
|
||||||
|
if (listener) {
|
||||||
|
if (mIndex+1 == oldIndex) {
|
||||||
|
// We are going back one entry. Send GoBack notifications
|
||||||
|
listener->OnHistoryGoBack(uri, &canNavigate);
|
||||||
|
}
|
||||||
|
else if (mIndex-1 == oldIndex) {
|
||||||
|
// We are going forward. Send GoForward notification
|
||||||
|
listener->OnHistoryGoForward(uri, &canNavigate);
|
||||||
|
}
|
||||||
|
else if (mIndex != oldIndex) {
|
||||||
|
// We are going somewhere else. This is not reload either
|
||||||
|
listener->OnHistoryGotoIndex(mIndex, uri, &canNavigate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canNavigate) {
|
||||||
|
// reset the index back to what it was, if the listener
|
||||||
|
// asked us not to proceed with the operation.
|
||||||
|
mIndex = oldIndex;
|
||||||
|
return NS_OK; // XXX Maybe I can return some other error code?
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> nexturi;
|
nsCOMPtr<nsIURI> nexturi;
|
||||||
PRInt32 pCount=0, nCount=0;
|
PRInt32 pCount=0, nCount=0;
|
||||||
nsCOMPtr<nsISHContainer> prevAsContainer(do_QueryInterface(prevEntry));
|
nsCOMPtr<nsISHContainer> prevAsContainer(do_QueryInterface(prevEntry));
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "nsISHistory.h"
|
#include "nsISHistory.h"
|
||||||
#include "nsISHTransaction.h"
|
#include "nsISHTransaction.h"
|
||||||
#include "nsIWebNavigation.h"
|
#include "nsIWebNavigation.h"
|
||||||
|
#include "nsIWeakReference.h"
|
||||||
|
|
||||||
class nsIDocShell;
|
class nsIDocShell;
|
||||||
|
|
||||||
@ -54,12 +55,14 @@ protected:
|
|||||||
NS_IMETHOD GetTransactionAtIndex(PRInt32 aIndex, nsISHTransaction ** aResult);
|
NS_IMETHOD GetTransactionAtIndex(PRInt32 aIndex, nsISHTransaction ** aResult);
|
||||||
PRBool CompareSHEntry(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell,
|
PRBool CompareSHEntry(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell,
|
||||||
nsIDocShell ** aResultDocShell, nsISHEntry ** aResultSHEntry);
|
nsIDocShell ** aResultDocShell, nsISHEntry ** aResultSHEntry);
|
||||||
NS_IMETHOD LoadEntry(PRInt32 aIndex, PRBool aReloadFlag, long aLoadType);
|
NS_IMETHOD LoadEntry(PRInt32 aIndex, long aLoadType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsCOMPtr<nsISHTransaction> mListRoot;
|
nsCOMPtr<nsISHTransaction> mListRoot;
|
||||||
PRInt32 mIndex;
|
PRInt32 mIndex;
|
||||||
PRInt32 mLength;
|
PRInt32 mLength;
|
||||||
|
// Session History listener
|
||||||
|
nsWeakPtr mListener;
|
||||||
// Weak reference. Do not refcount this.
|
// Weak reference. Do not refcount this.
|
||||||
nsIDocShell * mRootDocShell;
|
nsIDocShell * mRootDocShell;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user