[storage] Fix dependency
[abstract.git] / view / aaSessionHistory.cpp
blob4a5c3c52467df71055d0b864ff4137d6ac1dee14
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 "xpcom-config.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 "nsISHistoryInternal.h"
32 #include "nsIWebNavigation.h"
34 /* Project includes */
35 #include "aaIPageView.h"
36 #include "aaSessionHistory.h"
38 aaSessionHistory::aaSessionHistory()
39 :mChoosing(PR_FALSE)
41 mSH = do_CreateInstance(NS_SHISTORY_CONTRACTID);
42 if (!mSH)
43 return;
44 mSHI = do_QueryInterface(mSH);
45 if (!mSHI)
46 return;
47 mWN = do_QueryInterface(mSH);
48 if (!mWN)
49 return;
50 mSession = do_CreateInstance("@aasii.org/storage/session;1");
53 aaSessionHistory::~aaSessionHistory()
57 NS_IMPL_ISUPPORTS5_CI(aaSessionHistory,
58 nsISHistory,
59 nsISHistoryInternal,
60 nsIWebNavigation,
61 aaISHistory,
62 aaISession)
64 /* nsISHistoryInternal */
65 NS_IMETHODIMP
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);
71 if (mChoosing)
72 mChoosing = PR_FALSE;
73 return mSHI->AddEntry(pageView, aPersist);
76 NS_IMETHODIMP
77 aaSessionHistory::GetRootTransaction(nsISHTransaction * *aRootTransaction)
79 return mSHI->GetRootTransaction(aRootTransaction);
82 NS_IMETHODIMP
83 aaSessionHistory::GetRootDocShell(nsIDocShell * *aRootDocShell)
85 return mSHI->GetRootDocShell( aRootDocShell );
87 NS_IMETHODIMP
88 aaSessionHistory::SetRootDocShell(nsIDocShell * aRootDocShell)
90 return mSHI->SetRootDocShell( aRootDocShell );
93 NS_IMETHODIMP
94 aaSessionHistory::UpdateIndex()
96 return mSHI->UpdateIndex();
99 NS_IMETHODIMP
100 aaSessionHistory::ReplaceEntry(PRInt32 aIndex, nsISHEntry *aReplaceEntry)
102 return mSHI->ReplaceEntry(aIndex, aReplaceEntry);
105 NS_IMETHODIMP
106 aaSessionHistory::GetListener(nsISHistoryListener * *aListener)
108 return mSHI->GetListener(aListener);
111 NS_IMETHODIMP
112 aaSessionHistory::EvictContentViewers(PRInt32 previousIndex, PRInt32 index)
114 return mSHI->EvictContentViewers(previousIndex, index);
117 NS_IMETHODIMP
118 aaSessionHistory::EvictExpiredContentViewerForEntry(nsISHEntry *aEntry)
120 return mSHI->EvictExpiredContentViewerForEntry(aEntry);
123 /* aaISHistory */
124 NS_IMETHODIMP
125 aaSessionHistory::GetChoosing(PRBool *aChoosing)
127 nsresult rv;
128 nsCOMPtr<aaIPageView> pv1 = getter_AddRefs( getDestination(0, rv) );
129 NS_ENSURE_TRUE(pv1, rv);
131 return pv1->GetChoosing(aChoosing);
134 NS_IMETHODIMP
135 aaSessionHistory::BeginQuery()
137 if ( mChoosing )
138 return NS_ERROR_ALREADY_INITIALIZED;
139 mChoosing = PR_TRUE;
140 return NS_OK;
143 NS_IMETHODIMP
144 aaSessionHistory::GetQueryBuffer(nsISupports * *aQueryBuffer)
146 nsresult rv;
147 nsCOMPtr<aaIPageView> pv1 = getter_AddRefs( getDestination(0, rv) );
148 NS_ENSURE_TRUE(pv1, rv);
150 return pv1->GetQueryChoice(aQueryBuffer);
153 NS_IMETHODIMP
154 aaSessionHistory::GetChoice(nsISupports * *aChoice)
156 nsresult rv;
157 nsCOMPtr<aaIPageView> pv0 = getter_AddRefs( getDestination(-1, rv) );
158 NS_ENSURE_TRUE(pv0, rv);
160 return pv0->GetQueryChoice(aChoice);
162 NS_IMETHODIMP
163 aaSessionHistory::SetChoice(nsISupports * aChoice)
165 nsresult rv;
166 nsCOMPtr<aaIPageView> pv0 = getter_AddRefs( getDestination(-1, rv) );
167 NS_ENSURE_TRUE(pv0, rv);
169 return pv0->SetQueryChoice(aChoice);
172 /* Private methods */
173 aaIPageView *
174 aaSessionHistory::getDestination(PRInt32 offset, nsresult &rv)
176 PRInt32 index;
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);
184 aaIPageView *pv0;
185 rv = CallQueryInterface(he0, &pv0);
186 return pv0;