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,2008 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 "nsAutoPtr.h"
26 #include "nsIIOService.h"
27 #include "nsISHistory.h"
29 #include "nsIComponentManager.h"
30 #include "nsComponentManagerUtils.h"
32 #include "nsStringAPI.h"
33 #include "nsIClassInfoImpl.h"
34 #include "nsIServiceManager.h"
37 #include "nsIDocShell.h"
38 #include "nsISHistoryInternal.h"
39 #include "nsITreeView.h"
40 #include "nsIWebNavigation.h"
42 /* Project includes */
43 #include "aaIPageView.h"
44 #include "aaLoadGroup.h"
45 #include "aaSessionHistory.h"
47 aaSessionHistory::aaSessionHistory()
50 mSH
= do_CreateInstance(NS_SHISTORY_CONTRACTID
);
53 mSHI
= do_QueryInterface(mSH
);
56 mWN
= do_QueryInterface(mSH
);
61 aaSessionHistory::~aaSessionHistory()
65 NS_IMPL_ISUPPORTS5_CI(aaSessionHistory
,
72 /* nsISHistoryInternal */
74 aaSessionHistory::AddEntry(nsISHEntry
*aEntry
, PRBool aPersist
)
76 nsCOMPtr
<aaIPageView
> pageView( do_CreateInstance(
77 "@aasii.org/view/page-view;1", aEntry
));
78 pageView
->SetChoosing(mChoosing
);
81 return mSHI
->AddEntry(pageView
, aPersist
);
85 aaSessionHistory::GetRootTransaction(nsISHTransaction
* *aRootTransaction
)
87 return mSHI
->GetRootTransaction(aRootTransaction
);
91 aaSessionHistory::GetRootDocShell(nsIDocShell
* *aRootDocShell
)
93 return mSHI
->GetRootDocShell( aRootDocShell
);
96 aaSessionHistory::SetRootDocShell(nsIDocShell
* aRootDocShell
)
98 return mSHI
->SetRootDocShell( aRootDocShell
);
102 aaSessionHistory::UpdateIndex()
104 return mSHI
->UpdateIndex();
108 aaSessionHistory::ReplaceEntry(PRInt32 aIndex
, nsISHEntry
*aReplaceEntry
)
110 if (!aReplaceEntry
->GetIID().Equals(NS_GET_IID(aaIPageView
))) {
111 nsCOMPtr
<aaIPageView
> pageView(do_CreateInstance("@aasii.org/view/page-view;1", aReplaceEntry
));
112 pageView
->SetChoosing(mChoosing
);
113 return mSHI
->ReplaceEntry(aIndex
, pageView
);
115 return mSHI
->ReplaceEntry(aIndex
, aReplaceEntry
);
119 aaSessionHistory::GetListener(nsISHistoryListener
* *aListener
)
121 return mSHI
->GetListener(aListener
);
125 aaSessionHistory::EvictContentViewers(PRInt32 previousIndex
, PRInt32 index
)
127 return mSHI
->EvictContentViewers(previousIndex
, index
);
131 aaSessionHistory::EvictExpiredContentViewerForEntry(nsISHEntry
*aEntry
)
133 return mSHI
->EvictExpiredContentViewerForEntry(aEntry
);
137 aaSessionHistory::EvictAllContentViewers()
139 return mSHI
->EvictAllContentViewers();
142 /* nsIWebNavigation */
144 aaSessionHistory::LoadURI(const PRUnichar
*aURI
, PRUint32 aLoadFlags
,
145 nsIURI
*aReferrer
, nsIInputStream
*aPostData
, nsIInputStream
*aHeaders
)
148 nsIDocShell
*docShell
;
149 rv
= mSHI
->GetRootDocShell(&docShell
);
150 NS_ENSURE_SUCCESS(rv
, rv
);
152 nsRefPtr
<aaLoadGroup
> loader
= new aaLoadGroup(docShell
);
153 rv
= loader
->Init(aURI
, aLoadFlags
, aReferrer
, aPostData
, aHeaders
);
154 NS_ENSURE_SUCCESS(rv
, rv
);
161 aaSessionHistory::GetChoosing(PRBool
*aChoosing
)
164 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
165 NS_ENSURE_TRUE(pv1
, rv
);
167 return pv1
->GetChoosing(aChoosing
);
171 aaSessionHistory::BeginQuery()
174 return NS_ERROR_ALREADY_INITIALIZED
;
180 aaSessionHistory::SetFile(nsIFile
*file
)
190 aaSessionHistory::GetQueryBuffer(nsISupports
* *aQueryBuffer
)
193 nsCOMPtr
<aaIPageView
> pv1
= getter_AddRefs( getDestination(0, rv
) );
194 NS_ENSURE_TRUE(pv1
, rv
);
196 return pv1
->GetQueryChoice(aQueryBuffer
);
200 aaSessionHistory::GetChoice(nsISupports
* *aChoice
)
203 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
204 NS_ENSURE_TRUE(pv0
, rv
);
206 return pv0
->GetQueryChoice(aChoice
);
209 aaSessionHistory::SetChoice(nsISupports
* aChoice
)
212 nsCOMPtr
<aaIPageView
> pv0
= getter_AddRefs( getDestination(-1, rv
) );
213 NS_ENSURE_TRUE(pv0
, rv
);
215 return pv0
->SetQueryChoice(aChoice
);
219 aaSessionHistory::CreateTreeView(const char *aContract
, nsITreeView
* *_retval
)
221 NS_ENSURE_ARG_POINTER(_retval
);
222 nsCOMPtr
<nsIComponentManager
> compMgr
;
223 nsresult rv
= NS_GetComponentManager(getter_AddRefs(compMgr
));
225 rv
= compMgr
->CreateInstanceByContractID(aContract
, get_mSession(),
226 NS_GET_IID(nsITreeView
), (void **) _retval
);
231 /* Private methods */
233 aaSessionHistory::getDestination(PRInt32 offset
, nsresult
&rv
)
236 rv
= mSH
->GetIndex(&index
);
237 NS_ENSURE_SUCCESS(rv
, nsnull
);
239 nsCOMPtr
<nsIHistoryEntry
> he0
;
240 rv
= mSH
->GetEntryAtIndex(index
+ offset
, PR_FALSE
, getter_AddRefs( he0
));
241 NS_ENSURE_SUCCESS(rv
, nsnull
);
244 rv
= CallQueryInterface(he0
, &pv0
);
249 aaSessionHistory::get_mSession()
253 mSession
= do_CreateInstance("@aasii.org/storage/session;1", mFile
, &rv
);
254 NS_ENSURE_SUCCESS(rv
, nsnull
);