1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsISHistory.h"
26 #include "nsComponentManagerUtils.h"
28 #include "nsIClassInfoImpl.h"
31 #include "nsISHistoryInternal.h"
32 #include "nsIWebNavigation.h"
34 /* Project includes */
35 #include "aaIPageView.h"
36 #include "aaSessionHistory.h"
38 aaSessionHistory::aaSessionHistory()
41 mSH
= do_CreateInstance(NS_SHISTORY_CONTRACTID
);
44 mSHI
= do_QueryInterface(mSH
);
47 mWN
= do_QueryInterface(mSH
);
50 mSession
= do_CreateInstance("@aasii.org/storage/session;1");
53 aaSessionHistory::~aaSessionHistory()
57 NS_IMPL_ISUPPORTS5_CI(aaSessionHistory
,
64 /* nsISHistoryInternal */
66 aaSessionHistory::AddEntry(nsISHEntry
*aEntry
, PRBool aPersist
)
68 nsCOMPtr
<aaIPageView
> pageView( do_CreateInstance(
69 "@aasii.org/view/page-view;1", aEntry
));
70 pageView
->SetChoosing(mChoosing
);
73 return mSHI
->AddEntry(pageView
, aPersist
);
77 aaSessionHistory::GetRootTransaction(nsISHTransaction
* *aRootTransaction
)
79 return mSHI
->GetRootTransaction(aRootTransaction
);
83 aaSessionHistory::GetRootDocShell(nsIDocShell
* *aRootDocShell
)
85 return mSHI
->GetRootDocShell( aRootDocShell
);
88 aaSessionHistory::SetRootDocShell(nsIDocShell
* aRootDocShell
)
90 return mSHI
->SetRootDocShell( aRootDocShell
);
94 aaSessionHistory::UpdateIndex()
96 return mSHI
->UpdateIndex();
100 aaSessionHistory::ReplaceEntry(PRInt32 aIndex
, nsISHEntry
*aReplaceEntry
)
102 return mSHI
->ReplaceEntry(aIndex
, aReplaceEntry
);
106 aaSessionHistory::GetListener(nsISHistoryListener
* *aListener
)
108 return mSHI
->GetListener(aListener
);
112 aaSessionHistory::EvictContentViewers(PRInt32 previousIndex
, PRInt32 index
)
114 return mSHI
->EvictContentViewers(previousIndex
, index
);
118 aaSessionHistory::EvictExpiredContentViewerForEntry(nsISHEntry
*aEntry
)
120 return mSHI
->EvictExpiredContentViewerForEntry(aEntry
);
125 aaSessionHistory::GetChoosing(PRBool
*aChoosing
)
128 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
129 NS_ENSURE_TRUE(pv1
, rv
);
131 return pv1
->GetChoosing(aChoosing
);
135 aaSessionHistory::BeginQuery()
138 return NS_ERROR_ALREADY_INITIALIZED
;
144 aaSessionHistory::GetQueryBuffer(nsISupports
* *aQueryBuffer
)
147 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
148 NS_ENSURE_TRUE(pv1
, rv
);
150 return pv1
->GetQueryChoice(aQueryBuffer
);
154 aaSessionHistory::GetChoice(nsISupports
* *aChoice
)
157 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
158 NS_ENSURE_TRUE(pv0
, rv
);
160 return pv0
->GetQueryChoice(aChoice
);
163 aaSessionHistory::SetChoice(nsISupports
* aChoice
)
166 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
167 NS_ENSURE_TRUE(pv0
, rv
);
169 return pv0
->SetQueryChoice(aChoice
);
172 /* Private methods */
174 aaSessionHistory::getDestination(PRInt32 offset
, nsresult
&rv
)
177 rv
= mSH
->GetIndex(&index
);
178 NS_ENSURE_SUCCESS(rv
, nsnull
);
180 nsCOMPtr
<nsIHistoryEntry
> he0
;
181 rv
= mSH
->GetEntryAtIndex(index
+ offset
, PR_FALSE
, getter_AddRefs( he0
));
182 NS_ENSURE_SUCCESS(rv
, nsnull
);
185 rv
= CallQueryInterface(he0
, &pv0
);