[xpunit] Restore tests (bug #114)
[abstract.git] / view / aaSessionHistory.cpp
blob6381bee6d684d137e67e8b5e41334c8529a0bf03
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: */
3 /*
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 <abstract/aacore.h>
24 #include "nsCOMPtr.h"
25 #include "nsISHistory.h"
26 #include "nsComponentManagerUtils.h"
27 #include "nsMemory.h"
28 #include "nsIClassInfoImpl.h"
30 /* Unfrozen API */
31 #include "unstable/nsISHistoryInternal.h"
32 #include "unstable/nsIWebNavigation.h"
34 /* Project includes */
35 #include <abstract/storage/aaISession.h>
36 #include <abstract/view/aaISHistory.h>
37 #include <abstract/view/aaIPageView.h>
38 #include "aaSessionHistory.h"
40 aaSessionHistory::aaSessionHistory()
41 :mChoosing(PR_FALSE)
43 mSH = do_CreateInstance(NS_SHISTORY_CONTRACTID);
44 if (!mSH)
45 return;
46 mSHI = do_QueryInterface(mSH);
47 if (!mSHI)
48 return;
49 mWN = do_QueryInterface(mSH);
50 if (!mWN)
51 return;
52 mSession = do_CreateInstance("@aasii.org/storage/session;1");
55 aaSessionHistory::~aaSessionHistory()
59 NS_IMPL_ISUPPORTS5_CI(aaSessionHistory,
60 nsISHistory,
61 nsISHistoryInternal,
62 nsIWebNavigation,
63 aaISHistory,
64 aaISession)
66 /* nsISHistoryInternal */
67 NS_IMETHODIMP
68 aaSessionHistory::AddEntry(nsISHEntry *aEntry, PRBool aPersist)
70 nsCOMPtr<aaIPageView> pageView( do_CreateInstance(
71 "@aasii.org/view/page-view;1", aEntry));
72 pageView->SetChoosing(mChoosing);
73 if (mChoosing)
74 mChoosing = PR_FALSE;
75 return mSHI->AddEntry(pageView, aPersist);
78 NS_IMETHODIMP
79 aaSessionHistory::GetRootTransaction(nsISHTransaction * *aRootTransaction)
81 return mSHI->GetRootTransaction(aRootTransaction);
84 NS_IMETHODIMP
85 aaSessionHistory::GetRootDocShell(nsIDocShell * *aRootDocShell)
87 return mSHI->GetRootDocShell( aRootDocShell );
89 NS_IMETHODIMP
90 aaSessionHistory::SetRootDocShell(nsIDocShell * aRootDocShell)
92 return mSHI->SetRootDocShell( aRootDocShell );
95 NS_IMETHODIMP
96 aaSessionHistory::UpdateIndex()
98 return mSHI->UpdateIndex();
101 NS_IMETHODIMP
102 aaSessionHistory::ReplaceEntry(PRInt32 aIndex, nsISHEntry *aReplaceEntry)
104 return mSHI->ReplaceEntry(aIndex, aReplaceEntry);
107 NS_IMETHODIMP
108 aaSessionHistory::GetListener(nsISHistoryListener * *aListener)
110 return mSHI->GetListener(aListener);
113 NS_IMETHODIMP
114 aaSessionHistory::EvictContentViewers(PRInt32 previousIndex, PRInt32 index)
116 return mSHI->EvictContentViewers(previousIndex, index);
119 NS_IMETHODIMP
120 aaSessionHistory::EvictExpiredContentViewerForEntry(nsISHEntry *aEntry)
122 return mSHI->EvictExpiredContentViewerForEntry(aEntry);
125 /* aaISHistory */
126 NS_IMETHODIMP
127 aaSessionHistory::GetChoosing(PRBool *aChoosing)
129 nsresult rv;
130 nsCOMPtr<aaIPageView> pv1 = getter_AddRefs( getDestination(0, rv) );
131 NS_ENSURE_TRUE(pv1, rv);
133 return pv1->GetChoosing(aChoosing);
136 NS_IMETHODIMP
137 aaSessionHistory::BeginQuery()
139 if ( mChoosing )
140 return NS_ERROR_ALREADY_INITIALIZED;
141 mChoosing = PR_TRUE;
142 return NS_OK;
145 NS_IMETHODIMP
146 aaSessionHistory::GetQueryBuffer(nsISupports * *aQueryBuffer)
148 nsresult rv;
149 nsCOMPtr<aaIPageView> pv1 = getter_AddRefs( getDestination(0, rv) );
150 NS_ENSURE_TRUE(pv1, rv);
152 return pv1->GetQueryChoice(aQueryBuffer);
155 NS_IMETHODIMP
156 aaSessionHistory::GetChoice(nsISupports * *aChoice)
158 nsresult rv;
159 nsCOMPtr<aaIPageView> pv0 = getter_AddRefs( getDestination(-1, rv) );
160 NS_ENSURE_TRUE(pv0, rv);
162 return pv0->GetQueryChoice(aChoice);
164 NS_IMETHODIMP
165 aaSessionHistory::SetChoice(nsISupports * aChoice)
167 nsresult rv;
168 nsCOMPtr<aaIPageView> pv0 = getter_AddRefs( getDestination(-1, rv) );
169 NS_ENSURE_TRUE(pv0, rv);
171 return pv0->SetQueryChoice(aChoice);
174 /* Private methods */
175 aaIPageView *
176 aaSessionHistory::getDestination(PRInt32 offset, nsresult &rv)
178 PRInt32 index;
179 rv = mSH->GetIndex(&index);
180 NS_ENSURE_SUCCESS(rv, nsnull);
182 nsCOMPtr<nsIHistoryEntry> he0;
183 rv = mSH->GetEntryAtIndex(index + offset, PR_FALSE, getter_AddRefs( he0 ));
184 NS_ENSURE_SUCCESS(rv, nsnull);
186 aaIPageView *pv0;
187 rv = CallQueryInterface(he0, &pv0);
188 return pv0;