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-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
#include "PlaceInfo.h"
|
|
|
|
#include "VisitInfo.h"
|
|
|
|
#include "nsIURI.h"
|
2011-01-20 12:23:48 -08:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIXPConnect.h"
|
2011-01-28 09:15:37 -08:00
|
|
|
#include "mozilla/Services.h"
|
2011-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// PlaceInfo
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
PlaceInfo::PlaceInfo(int64_t aId,
|
2011-01-14 14:38:34 -08:00
|
|
|
const nsCString& aGUID,
|
|
|
|
already_AddRefed<nsIURI> aURI,
|
|
|
|
const nsString& aTitle,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aFrecency,
|
2011-01-14 14:38:34 -08:00
|
|
|
const VisitsArray& aVisits)
|
|
|
|
: mId(aId)
|
|
|
|
, mGUID(aGUID)
|
|
|
|
, mURI(aURI)
|
|
|
|
, mTitle(aTitle)
|
|
|
|
, mFrecency(aFrecency)
|
|
|
|
, mVisits(aVisits)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mURI, "Must provide a non-null uri!");
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// mozIPlaceInfo
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
PlaceInfo::GetPlaceId(int64_t* _placeId)
|
2011-01-14 14:38:34 -08:00
|
|
|
{
|
|
|
|
*_placeId = mId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PlaceInfo::GetGuid(nsACString& _guid)
|
|
|
|
{
|
|
|
|
_guid = mGUID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PlaceInfo::GetUri(nsIURI** _uri)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*_uri = mURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PlaceInfo::GetTitle(nsAString& _title)
|
|
|
|
{
|
|
|
|
_title = mTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
PlaceInfo::GetFrecency(int64_t* _frecency)
|
2011-01-14 14:38:34 -08:00
|
|
|
{
|
|
|
|
*_frecency = mFrecency;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PlaceInfo::GetVisits(JSContext* aContext,
|
|
|
|
jsval* _visits)
|
|
|
|
{
|
|
|
|
// TODO bug 625913 when we use this in situations that have more than one
|
|
|
|
// visit here, we will likely want to make this cache the value.
|
|
|
|
JSObject* visits = JS_NewArrayObject(aContext, 0, NULL);
|
|
|
|
NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
JSObject* global = JS_GetGlobalForScopeChain(aContext);
|
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-01-28 09:15:37 -08:00
|
|
|
nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
|
2011-01-20 12:23:48 -08:00
|
|
|
|
2011-01-14 14:38:34 -08:00
|
|
|
for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
|
2011-01-20 12:23:48 -08:00
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
|
2011-01-28 09:15:37 -08:00
|
|
|
nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
|
|
|
|
NS_GET_IID(mozIVisitInfo),
|
|
|
|
getter_AddRefs(wrapper));
|
2011-01-20 12:23:48 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
JSObject* jsobj;
|
|
|
|
rv = wrapper->GetJSObject(&jsobj);
|
2011-01-14 14:38:34 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-20 12:23:48 -08:00
|
|
|
jsval wrappedVisit = OBJECT_TO_JSVAL(jsobj);
|
2011-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
JSBool rc = JS_SetElement(aContext, visits, idx, &wrappedVisit);
|
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
*_visits = OBJECT_TO_JSVAL(visits);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsISupports
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(
|
|
|
|
PlaceInfo
|
|
|
|
, mozIPlaceInfo
|
2011-01-20 10:33:19 -08:00
|
|
|
)
|
2011-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|