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 <abstract/aacore.h>
25 #include "nsISHistory.h"
26 #include "nsComponentManagerUtils.h"
28 #include "nsIClassInfoImpl.h"
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()
43 mSH
= do_CreateInstance(NS_SHISTORY_CONTRACTID
);
46 mSHI
= do_QueryInterface(mSH
);
49 mWN
= do_QueryInterface(mSH
);
52 mSession
= do_CreateInstance("@aasii.org/storage/session;1");
55 aaSessionHistory::~aaSessionHistory()
59 NS_IMPL_ISUPPORTS5_CI(aaSessionHistory
,
66 /* nsISHistoryInternal */
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
);
75 return mSHI
->AddEntry(pageView
, aPersist
);
79 aaSessionHistory::GetRootTransaction(nsISHTransaction
* *aRootTransaction
)
81 return mSHI
->GetRootTransaction(aRootTransaction
);
85 aaSessionHistory::GetRootDocShell(nsIDocShell
* *aRootDocShell
)
87 return mSHI
->GetRootDocShell( aRootDocShell
);
90 aaSessionHistory::SetRootDocShell(nsIDocShell
* aRootDocShell
)
92 return mSHI
->SetRootDocShell( aRootDocShell
);
96 aaSessionHistory::UpdateIndex()
98 return mSHI
->UpdateIndex();
102 aaSessionHistory::ReplaceEntry(PRInt32 aIndex
, nsISHEntry
*aReplaceEntry
)
104 return mSHI
->ReplaceEntry(aIndex
, aReplaceEntry
);
108 aaSessionHistory::GetListener(nsISHistoryListener
* *aListener
)
110 return mSHI
->GetListener(aListener
);
114 aaSessionHistory::EvictContentViewers(PRInt32 previousIndex
, PRInt32 index
)
116 return mSHI
->EvictContentViewers(previousIndex
, index
);
120 aaSessionHistory::EvictExpiredContentViewerForEntry(nsISHEntry
*aEntry
)
122 return mSHI
->EvictExpiredContentViewerForEntry(aEntry
);
127 aaSessionHistory::GetChoosing(PRBool
*aChoosing
)
130 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
131 NS_ENSURE_TRUE(pv1
, rv
);
133 return pv1
->GetChoosing(aChoosing
);
137 aaSessionHistory::BeginQuery()
140 return NS_ERROR_ALREADY_INITIALIZED
;
146 aaSessionHistory::GetQueryBuffer(nsISupports
* *aQueryBuffer
)
149 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
150 NS_ENSURE_TRUE(pv1
, rv
);
152 return pv1
->GetQueryChoice(aQueryBuffer
);
156 aaSessionHistory::GetChoice(nsISupports
* *aChoice
)
159 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
160 NS_ENSURE_TRUE(pv0
, rv
);
162 return pv0
->GetQueryChoice(aChoice
);
165 aaSessionHistory::SetChoice(nsISupports
* aChoice
)
168 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
169 NS_ENSURE_TRUE(pv0
, rv
);
171 return pv0
->SetQueryChoice(aChoice
);
174 /* Private methods */
176 aaSessionHistory::getDestination(PRInt32 offset
, nsresult
&rv
)
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
);
187 rv
= CallQueryInterface(he0
, &pv0
);