toolkit/components/places/nsPlacesMacros.h

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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsIConsoleService.h"
     7 #include "nsIScriptError.h"
     9 #ifndef __FUNCTION__
    10 #define __FUNCTION__ __func__
    11 #endif
    13 // Call a method on each observer in a category cache, then call the same
    14 // method on the observer array.
    15 #define NOTIFY_OBSERVERS(canFire, cache, array, type, method)                  \
    16   PR_BEGIN_MACRO                                                               \
    17   if (canFire) {                                                               \
    18     nsCOMArray<type> entries;                                                  \
    19     cache.GetEntries(entries);                                                 \
    20     for (int32_t idx = 0; idx < entries.Count(); ++idx)                        \
    21         entries[idx]->method;                                                  \
    22     ENUMERATE_WEAKARRAY(array, type, method)                                   \
    23   }                                                                            \
    24   PR_END_MACRO;
    26 #define PLACES_FACTORY_SINGLETON_IMPLEMENTATION(_className, _sInstance)        \
    27   _className * _className::_sInstance = nullptr;                                \
    28                                                                                \
    29   already_AddRefed<_className>                                                 \
    30   _className::GetSingleton()                                                   \
    31   {                                                                            \
    32     if (_sInstance) {                                                          \
    33       nsRefPtr<_className> ret = _sInstance;                                   \
    34       return ret.forget();                                                     \
    35     }                                                                          \
    36     _sInstance = new _className();                                             \
    37     nsRefPtr<_className> ret = _sInstance;                                     \
    38     if (NS_FAILED(_sInstance->Init())) {                                       \
    39       /* Null out ret before _sInstance so the destructor doesn't assert */    \
    40       ret = nullptr;                                                           \
    41       _sInstance = nullptr;                                                    \
    42       return nullptr;                                                          \
    43     }                                                                          \
    44     return ret.forget();                                                       \
    45   }
    47 #define PLACES_WARN_DEPRECATED()                                               \
    48   PR_BEGIN_MACRO                                                               \
    49   nsCString msg = NS_LITERAL_CSTRING(__FUNCTION__);                            \
    50   msg.AppendLiteral(" is deprecated and will be removed in the next version.");\
    51   NS_WARNING(msg.get());                                                       \
    52   nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);\
    53   if (cs) {                                                                    \
    54     nsCOMPtr<nsIScriptError> e = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); \
    55     if (e && NS_SUCCEEDED(e->Init(NS_ConvertUTF8toUTF16(msg), EmptyString(),   \
    56                                   EmptyString(), 0, 0,                         \
    57                                   nsIScriptError::errorFlag, "Places"))) {     \
    58       cs->LogMessage(e);                                                       \
    59     }                                                                          \
    60   }                                                                            \
    61   PR_END_MACRO

mercurial