michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIConsoleService.h" michael@0: #include "nsIScriptError.h" michael@0: michael@0: #ifndef __FUNCTION__ michael@0: #define __FUNCTION__ __func__ michael@0: #endif michael@0: michael@0: // Call a method on each observer in a category cache, then call the same michael@0: // method on the observer array. michael@0: #define NOTIFY_OBSERVERS(canFire, cache, array, type, method) \ michael@0: PR_BEGIN_MACRO \ michael@0: if (canFire) { \ michael@0: nsCOMArray entries; \ michael@0: cache.GetEntries(entries); \ michael@0: for (int32_t idx = 0; idx < entries.Count(); ++idx) \ michael@0: entries[idx]->method; \ michael@0: ENUMERATE_WEAKARRAY(array, type, method) \ michael@0: } \ michael@0: PR_END_MACRO; michael@0: michael@0: #define PLACES_FACTORY_SINGLETON_IMPLEMENTATION(_className, _sInstance) \ michael@0: _className * _className::_sInstance = nullptr; \ michael@0: \ michael@0: already_AddRefed<_className> \ michael@0: _className::GetSingleton() \ michael@0: { \ michael@0: if (_sInstance) { \ michael@0: nsRefPtr<_className> ret = _sInstance; \ michael@0: return ret.forget(); \ michael@0: } \ michael@0: _sInstance = new _className(); \ michael@0: nsRefPtr<_className> ret = _sInstance; \ michael@0: if (NS_FAILED(_sInstance->Init())) { \ michael@0: /* Null out ret before _sInstance so the destructor doesn't assert */ \ michael@0: ret = nullptr; \ michael@0: _sInstance = nullptr; \ michael@0: return nullptr; \ michael@0: } \ michael@0: return ret.forget(); \ michael@0: } michael@0: michael@0: #define PLACES_WARN_DEPRECATED() \ michael@0: PR_BEGIN_MACRO \ michael@0: nsCString msg = NS_LITERAL_CSTRING(__FUNCTION__); \ michael@0: msg.AppendLiteral(" is deprecated and will be removed in the next version.");\ michael@0: NS_WARNING(msg.get()); \ michael@0: nsCOMPtr cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);\ michael@0: if (cs) { \ michael@0: nsCOMPtr e = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); \ michael@0: if (e && NS_SUCCEEDED(e->Init(NS_ConvertUTF8toUTF16(msg), EmptyString(), \ michael@0: EmptyString(), 0, 0, \ michael@0: nsIScriptError::errorFlag, "Places"))) { \ michael@0: cs->LogMessage(e); \ michael@0: } \ michael@0: } \ michael@0: PR_END_MACRO