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"
|
2013-08-17 15:50:18 -07:00
|
|
|
#include "jsapi.h"
|
2011-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// PlaceInfo
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
PlaceInfo::PlaceInfo(int64_t aId,
|
|
|
|
const nsCString& aGUID,
|
|
|
|
already_AddRefed<nsIURI> aURI,
|
|
|
|
const nsString& aTitle,
|
|
|
|
int64_t aFrecency)
|
|
|
|
: mId(aId)
|
|
|
|
, mGUID(aGUID)
|
|
|
|
, mURI(aURI)
|
|
|
|
, mTitle(aTitle)
|
|
|
|
, mFrecency(aFrecency)
|
|
|
|
, mVisitsAvailable(false)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mURI, "Must provide a non-null uri!");
|
|
|
|
}
|
|
|
|
|
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)
|
2013-06-19 00:18:38 -07:00
|
|
|
, mVisitsAvailable(true)
|
2011-01-14 14:38:34 -08:00
|
|
|
{
|
|
|
|
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,
|
2014-01-09 09:39:36 -08:00
|
|
|
JS::MutableHandle<JS::Value> _visits)
|
2011-01-14 14:38:34 -08:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
// If the visits data was not provided, return null rather
|
|
|
|
// than an empty array to distinguish this case from the case
|
|
|
|
// of a place without any visit.
|
|
|
|
if (!mVisitsAvailable) {
|
2014-01-09 09:39:36 -08:00
|
|
|
_visits.setNull();
|
2013-06-19 00:18:38 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:38:34 -08:00
|
|
|
// 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.
|
2013-10-10 13:38:05 -07:00
|
|
|
JS::Rooted<JSObject*> visits(aContext,
|
2014-02-12 02:50:46 -08:00
|
|
|
JS_NewArrayObject(aContext, 0));
|
2011-01-14 14:38:34 -08:00
|
|
|
NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2013-07-29 16:45:27 -07:00
|
|
|
JS::Rooted<JSObject*> global(aContext, JS::CurrentGlobalOrNull(aContext));
|
2011-01-14 14:38:34 -08:00
|
|
|
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);
|
|
|
|
|
2013-05-20 05:44:18 -07:00
|
|
|
JS::Rooted<JSObject*> jsobj(aContext, wrapper->GetJSObject());
|
|
|
|
NS_ENSURE_STATE(jsobj);
|
2011-01-14 14:38:34 -08:00
|
|
|
|
2014-01-25 01:31:17 -08:00
|
|
|
bool rc = JS_SetElement(aContext, visits, idx, jsobj);
|
2011-01-14 14:38:34 -08:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
_visits.setObject(*visits);
|
2011-01-14 14:38:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsISupports
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2011-01-14 14:38:34 -08:00
|
|
|
PlaceInfo
|
|
|
|
, mozIPlaceInfo
|
2011-01-20 10:33:19 -08:00
|
|
|
)
|
2011-01-14 14:38:34 -08:00
|
|
|
|
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|