diff --git a/dom/base/CallState.h b/dom/base/CallState.h new file mode 100644 index 000000000000..e9c312dbe41f --- /dev/null +++ b/dom/base/CallState.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef mozilla_CallState_h +#define mozilla_CallState_h + +namespace mozilla { + +// An enum class to be used for returned value of callback functions. If Stop +// is returned from the callback function, caller stops calling further +// children. If Continue is returned then caller will keep calling further +// children. +enum class CallState { + Continue, + Stop, +}; + +} // namespace mozilla + +#endif // mozilla_CallSate_h diff --git a/dom/base/moz.build b/dom/base/moz.build index d1409e9c7feb..627b6a3e8fe1 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -121,6 +121,7 @@ if CONFIG['MOZ_WEBRTC']: ] EXPORTS.mozilla += [ + 'CallState.h', 'ContentIterator.h', 'CORSMode.h', 'FlushType.h', diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index f26abc9bc7d2..948dd3c3ca89 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -2262,8 +2262,7 @@ bool nsGlobalWindowInner::HasOpenerForInitialContentBrowser() { FORWARD_TO_OUTER(HasOpenerForInitialContentBrowser, (), false); } -nsGlobalWindowInner::CallState -nsGlobalWindowInner::ShouldReportForServiceWorkerScopeInternal( +CallState nsGlobalWindowInner::ShouldReportForServiceWorkerScopeInternal( const nsACString& aScope, bool* aResultOut) { MOZ_DIAGNOSTIC_ASSERT(aResultOut); @@ -5342,8 +5341,7 @@ void nsGlobalWindowInner::SyncStateFromParentWindow() { } template -nsGlobalWindowInner::CallState nsGlobalWindowInner::CallOnChildren( - Method aMethod, Args&... aArgs) { +CallState nsGlobalWindowInner::CallOnChildren(Method aMethod, Args&... aArgs) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(IsCurrentInnerWindow()); diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index e3e3dbc22479..1e62044cf942 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -40,6 +40,7 @@ #include "mozilla/dom/StorageEvent.h" #include "mozilla/dom/StorageEventBinding.h" #include "mozilla/dom/UnionTypes.h" +#include "mozilla/CallState.h" #include "mozilla/ErrorResult.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" @@ -1033,36 +1034,25 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, bool IsPopupSpamWindow(); private: - // A type that methods called by CallOnChildren can return. If Stop - // is returned then CallOnChildren will stop calling further children. - // If Continue is returned then CallOnChildren will keep calling further - // children. - enum class CallState { - Continue, - Stop, - }; - // Call the given method on the immediate children of this window. The // CallState returned by the last child method invocation is returned or // CallState::Continue if the method returns void. template - CallState CallOnChildren(Method aMethod, Args&... aArgs); + mozilla::CallState CallOnChildren(Method aMethod, Args&... aArgs); // Helper to convert a void returning child method into an implicit // CallState::Continue value. template - typename std::enable_if::value, - nsGlobalWindowInner::CallState>::type + typename std::enable_if::value, mozilla::CallState>::type CallChild(nsGlobalWindowInner* aWindow, Method aMethod, Args&... aArgs) { (aWindow->*aMethod)(aArgs...); - return nsGlobalWindowInner::CallState::Continue; + return mozilla::CallState::Continue; } // Helper that passes through the CallState value from a child method. template - typename std::enable_if< - std::is_same::value, - nsGlobalWindowInner::CallState>::type + typename std::enable_if::value, + mozilla::CallState>::type CallChild(nsGlobalWindowInner* aWindow, Method aMethod, Args&... aArgs) { return (aWindow->*aMethod)(aArgs...); } @@ -1070,8 +1060,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, void FreezeInternal(); void ThawInternal(); - CallState ShouldReportForServiceWorkerScopeInternal(const nsACString& aScope, - bool* aResultOut); + mozilla::CallState ShouldReportForServiceWorkerScopeInternal( + const nsACString& aScope, bool* aResultOut); public: // Timeout Functions