2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 14:42:52 -08:00
|
|
|
|
|
|
|
#include "nsAndroidHistory.h"
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "Link.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using mozilla::dom::Link;
|
|
|
|
|
2012-07-09 13:20:12 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(nsAndroidHistory, IHistory, nsIRunnable)
|
2011-11-18 14:42:52 -08:00
|
|
|
|
|
|
|
nsAndroidHistory* nsAndroidHistory::sHistory = NULL;
|
|
|
|
|
|
|
|
/*static*/
|
|
|
|
nsAndroidHistory*
|
|
|
|
nsAndroidHistory::GetSingleton()
|
|
|
|
{
|
|
|
|
if (!sHistory) {
|
|
|
|
sHistory = new nsAndroidHistory();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(sHistory, nullptr);
|
2011-11-18 14:42:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(sHistory);
|
|
|
|
return sHistory;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAndroidHistory::nsAndroidHistory()
|
|
|
|
{
|
|
|
|
mListeners.Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
|
|
|
|
{
|
|
|
|
if (!aContent || !aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString uri;
|
2011-11-18 14:42:52 -08:00
|
|
|
nsresult rv = aURI->GetSpec(uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2012-03-22 21:18:59 -07:00
|
|
|
NS_ConvertUTF8toUTF16 uriString(uri);
|
2011-11-18 14:42:52 -08:00
|
|
|
|
|
|
|
nsTArray<Link*>* list = mListeners.Get(uriString);
|
|
|
|
if (! list) {
|
|
|
|
list = new nsTArray<Link*>();
|
|
|
|
mListeners.Put(uriString, list);
|
|
|
|
}
|
|
|
|
list->AppendElement(aContent);
|
|
|
|
|
|
|
|
AndroidBridge *bridge = AndroidBridge::Bridge();
|
|
|
|
if (bridge) {
|
|
|
|
bridge->CheckURIVisited(uriString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidHistory::UnregisterVisitedCallback(nsIURI *aURI, Link *aContent)
|
|
|
|
{
|
|
|
|
if (!aContent || !aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString uri;
|
2011-11-18 14:42:52 -08:00
|
|
|
nsresult rv = aURI->GetSpec(uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2012-03-22 21:18:59 -07:00
|
|
|
NS_ConvertUTF8toUTF16 uriString(uri);
|
2011-11-18 14:42:52 -08:00
|
|
|
|
|
|
|
nsTArray<Link*>* list = mListeners.Get(uriString);
|
|
|
|
if (! list)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
list->RemoveElement(aContent);
|
|
|
|
if (list->IsEmpty()) {
|
|
|
|
mListeners.Remove(uriString);
|
|
|
|
delete list;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, uint32_t aFlags)
|
2011-11-18 14:42:52 -08:00
|
|
|
{
|
|
|
|
if (!aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!(aFlags & VisitFlags::TOP_LEVEL))
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-10-24 09:04:44 -07:00
|
|
|
if (aFlags & VisitFlags::REDIRECT_SOURCE)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aFlags & VisitFlags::UNRECOVERABLE_ERROR)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-11-18 14:42:52 -08:00
|
|
|
AndroidBridge *bridge = AndroidBridge::Bridge();
|
|
|
|
if (bridge) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString uri;
|
2011-11-18 14:42:52 -08:00
|
|
|
nsresult rv = aURI->GetSpec(uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2012-03-22 21:18:59 -07:00
|
|
|
NS_ConvertUTF8toUTF16 uriString(uri);
|
2011-11-18 14:42:52 -08:00
|
|
|
bridge->MarkURIVisited(uriString);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
|
|
|
|
{
|
2013-02-18 09:27:30 -08:00
|
|
|
AndroidBridge *bridge = AndroidBridge::Bridge();
|
|
|
|
if (bridge) {
|
|
|
|
nsAutoCString uri;
|
|
|
|
nsresult rv = aURI->GetSpec(uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ConvertUTF8toUTF16 uriString(uri);
|
|
|
|
bridge->SetURITitle(uriString, aTitle);
|
|
|
|
}
|
2011-11-18 14:42:52 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-09 01:55:59 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidHistory::NotifyVisited(nsIURI *aURI)
|
2011-11-18 14:42:52 -08:00
|
|
|
{
|
2012-11-09 01:55:59 -08:00
|
|
|
if (aURI && sHistory) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
(void)aURI->GetSpec(spec);
|
|
|
|
sHistory->mPendingURIs.Push(NS_ConvertUTF8toUTF16(spec));
|
|
|
|
NS_DispatchToMainThread(sHistory);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2011-11-18 14:42:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidHistory::Run()
|
|
|
|
{
|
|
|
|
while (! mPendingURIs.IsEmpty()) {
|
|
|
|
nsString uriString = mPendingURIs.Pop();
|
|
|
|
nsTArray<Link*>* list = sHistory->mListeners.Get(uriString);
|
|
|
|
if (list) {
|
|
|
|
for (unsigned int i = 0; i < list->Length(); i++) {
|
|
|
|
list->ElementAt(i)->SetLinkState(eLinkState_Visited);
|
|
|
|
}
|
|
|
|
// as per the IHistory interface contract, remove the
|
|
|
|
// Link pointers once they have been notified
|
|
|
|
mListeners.Remove(uriString);
|
|
|
|
delete list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|