toolkit/components/places/PlaceInfo.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "PlaceInfo.h"
     6 #include "VisitInfo.h"
     7 #include "nsIURI.h"
     8 #include "nsServiceManagerUtils.h"
     9 #include "nsIXPConnect.h"
    10 #include "mozilla/Services.h"
    11 #include "jsapi.h"
    13 namespace mozilla {
    14 namespace places {
    16 ////////////////////////////////////////////////////////////////////////////////
    17 //// PlaceInfo
    19 PlaceInfo::PlaceInfo(int64_t aId,
    20                      const nsCString& aGUID,
    21                      already_AddRefed<nsIURI> aURI,
    22                      const nsString& aTitle,
    23                      int64_t aFrecency)
    24 : mId(aId)
    25 , mGUID(aGUID)
    26 , mURI(aURI)
    27 , mTitle(aTitle)
    28 , mFrecency(aFrecency)
    29 , mVisitsAvailable(false)
    30 {
    31   NS_PRECONDITION(mURI, "Must provide a non-null uri!");
    32 }
    34 PlaceInfo::PlaceInfo(int64_t aId,
    35                      const nsCString& aGUID,
    36                      already_AddRefed<nsIURI> aURI,
    37                      const nsString& aTitle,
    38                      int64_t aFrecency,
    39                      const VisitsArray& aVisits)
    40 : mId(aId)
    41 , mGUID(aGUID)
    42 , mURI(aURI)
    43 , mTitle(aTitle)
    44 , mFrecency(aFrecency)
    45 , mVisits(aVisits)
    46 , mVisitsAvailable(true)
    47 {
    48   NS_PRECONDITION(mURI, "Must provide a non-null uri!");
    49 }
    51 ////////////////////////////////////////////////////////////////////////////////
    52 //// mozIPlaceInfo
    54 NS_IMETHODIMP
    55 PlaceInfo::GetPlaceId(int64_t* _placeId)
    56 {
    57   *_placeId = mId;
    58   return NS_OK;
    59 }
    61 NS_IMETHODIMP
    62 PlaceInfo::GetGuid(nsACString& _guid)
    63 {
    64   _guid = mGUID;
    65   return NS_OK;
    66 }
    68 NS_IMETHODIMP
    69 PlaceInfo::GetUri(nsIURI** _uri)
    70 {
    71   NS_ADDREF(*_uri = mURI);
    72   return NS_OK;
    73 }
    75 NS_IMETHODIMP
    76 PlaceInfo::GetTitle(nsAString& _title)
    77 {
    78   _title = mTitle;
    79   return NS_OK;
    80 }
    82 NS_IMETHODIMP
    83 PlaceInfo::GetFrecency(int64_t* _frecency)
    84 {
    85   *_frecency = mFrecency;
    86   return NS_OK;
    87 }
    89 NS_IMETHODIMP
    90 PlaceInfo::GetVisits(JSContext* aContext,
    91                      JS::MutableHandle<JS::Value> _visits)
    92 {
    93   // If the visits data was not provided, return null rather
    94   // than an empty array to distinguish this case from the case
    95   // of a place without any visit.
    96   if (!mVisitsAvailable) {
    97     _visits.setNull();
    98     return NS_OK;
    99   }
   101   // TODO bug 625913 when we use this in situations that have more than one
   102   // visit here, we will likely want to make this cache the value.
   103   JS::Rooted<JSObject*> visits(aContext,
   104                                JS_NewArrayObject(aContext, 0));
   105   NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);
   107   JS::Rooted<JSObject*> global(aContext, JS::CurrentGlobalOrNull(aContext));
   108   NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
   110   nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
   112   for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
   113     nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
   114     nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
   115                                   NS_GET_IID(mozIVisitInfo),
   116                                   getter_AddRefs(wrapper));
   117     NS_ENSURE_SUCCESS(rv, rv);
   119     JS::Rooted<JSObject*> jsobj(aContext, wrapper->GetJSObject());
   120     NS_ENSURE_STATE(jsobj);
   122     bool rc = JS_SetElement(aContext, visits, idx, jsobj);
   123     NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
   124   }
   126   _visits.setObject(*visits);
   127   return NS_OK;
   128 }
   130 ////////////////////////////////////////////////////////////////////////////////
   131 //// nsISupports
   133 NS_IMPL_ISUPPORTS(
   134   PlaceInfo
   135 , mozIPlaceInfo
   136 )
   138 } // namespace places
   139 } // namespace mozilla

mercurial