From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/ipc/AppProcessChecker.cpp | 95 + dom/ipc/AppProcessChecker.h | 160 + dom/ipc/Blob.cpp | 4793 ++++++++++++++++++ dom/ipc/BlobChild.h | 246 + dom/ipc/BlobParent.h | 260 + dom/ipc/BlobTypes.ipdlh | 21 + dom/ipc/CPOWManagerGetter.h | 27 + dom/ipc/ColorPickerParent.cpp | 87 + dom/ipc/ColorPickerParent.h | 61 + dom/ipc/ContentBridgeChild.cpp | 206 + dom/ipc/ContentBridgeChild.h | 102 + dom/ipc/ContentBridgeParent.cpp | 221 + dom/ipc/ContentBridgeParent.h | 154 + dom/ipc/ContentChild.cpp | 3310 +++++++++++++ dom/ipc/ContentChild.h | 702 +++ dom/ipc/ContentParent.cpp | 5185 ++++++++++++++++++++ dom/ipc/ContentParent.h | 1197 +++++ dom/ipc/ContentProcess.cpp | 162 + dom/ipc/ContentProcess.h | 65 + dom/ipc/ContentProcessManager.cpp | 372 ++ dom/ipc/ContentProcessManager.h | 166 + dom/ipc/CrashReporterChild.cpp | 42 + dom/ipc/CrashReporterChild.h | 32 + dom/ipc/CrashReporterParent.cpp | 146 + dom/ipc/CrashReporterParent.h | 306 ++ dom/ipc/DOMTypes.ipdlh | 181 + dom/ipc/DatePickerParent.cpp | 87 + dom/ipc/DatePickerParent.h | 61 + dom/ipc/FilePickerParent.cpp | 306 ++ dom/ipc/FilePickerParent.h | 110 + dom/ipc/IdType.h | 73 + dom/ipc/PBlob.ipdl | 57 + dom/ipc/PBlobStream.ipdl | 22 + dom/ipc/PBrowser.ipdl | 928 ++++ dom/ipc/PBrowserOrId.ipdlh | 21 + dom/ipc/PColorPicker.ipdl | 27 + dom/ipc/PContent.ipdl | 1063 ++++ dom/ipc/PContentBridge.ipdl | 69 + dom/ipc/PContentPermission.ipdlh | 20 + dom/ipc/PContentPermissionRequest.ipdl | 28 + dom/ipc/PCrashReporter.ipdl | 31 + dom/ipc/PCycleCollectWithLogs.ipdl | 22 + dom/ipc/PDatePicker.ipdl | 27 + dom/ipc/PDocumentRenderer.ipdl | 25 + dom/ipc/PFilePicker.ipdl | 46 + dom/ipc/PMemoryReportRequest.ipdl | 29 + dom/ipc/PPluginWidget.ipdl | 61 + dom/ipc/PProcessHangMonitor.ipdl | 47 + dom/ipc/PScreenManager.ipdl | 62 + dom/ipc/PTabContext.ipdlh | 84 + dom/ipc/PermissionMessageUtils.cpp | 69 + dom/ipc/PermissionMessageUtils.h | 52 + dom/ipc/PreallocatedProcessManager.cpp | 252 + dom/ipc/PreallocatedProcessManager.h | 88 + dom/ipc/ProcessHangMonitor.cpp | 1278 +++++ dom/ipc/ProcessHangMonitor.h | 82 + dom/ipc/ProcessHangMonitorIPC.h | 34 + dom/ipc/ProcessPriorityManager.cpp | 1454 ++++++ dom/ipc/ProcessPriorityManager.h | 84 + dom/ipc/ScreenManagerParent.cpp | 229 + dom/ipc/ScreenManagerParent.h | 56 + dom/ipc/ServiceWorkerConfiguration.ipdlh | 18 + dom/ipc/StructuredCloneData.cpp | 133 + dom/ipc/StructuredCloneData.h | 160 + dom/ipc/TabChild.cpp | 3371 +++++++++++++ dom/ipc/TabChild.h | 818 +++ dom/ipc/TabContext.cpp | 434 ++ dom/ipc/TabContext.h | 337 ++ dom/ipc/TabMessageUtils.cpp | 30 + dom/ipc/TabMessageUtils.h | 117 + dom/ipc/TabParent.cpp | 3306 +++++++++++++ dom/ipc/TabParent.h | 813 +++ dom/ipc/extensions.js | 17 + dom/ipc/jar.mn | 13 + dom/ipc/manifestMessages.js | 108 + dom/ipc/moz.build | 179 + dom/ipc/nsIContentChild.cpp | 159 + dom/ipc/nsIContentChild.h | 118 + dom/ipc/nsIContentParent.cpp | 328 ++ dom/ipc/nsIContentParent.h | 145 + dom/ipc/nsIHangReport.idl | 66 + dom/ipc/nsIRemoteBlob.h | 45 + dom/ipc/preload.js | 130 + dom/ipc/remote-test.js | 54 + dom/ipc/test.xul | 274 ++ dom/ipc/tests/blob_verify.sjs | 20 + dom/ipc/tests/browser.ini | 6 + dom/ipc/tests/browser_domainPolicy.js | 240 + dom/ipc/tests/chrome.ini | 8 + dom/ipc/tests/file_bug1086684.html | 16 + dom/ipc/tests/file_disableScript.html | 11 + dom/ipc/tests/file_domainPolicy_base.html | 8 + dom/ipc/tests/mochitest.ini | 22 + dom/ipc/tests/process_error.xul | 58 + dom/ipc/tests/process_error_contentscript.js | 7 + dom/ipc/tests/test_CrashService_crash.html | 95 + .../tests/test_blob_sliced_from_child_process.html | 185 + .../test_blob_sliced_from_parent_process.html | 213 + dom/ipc/tests/test_bug1086684.html | 107 + dom/ipc/tests/test_child_docshell.html | 86 + dom/ipc/tests/test_cpow_cookies.html | 90 + dom/ipc/tests/test_process_error.xul | 22 + dom/ipc/tests/test_temporaryfile_stream.html | 80 + 103 files changed, 37730 insertions(+) create mode 100644 dom/ipc/AppProcessChecker.cpp create mode 100644 dom/ipc/AppProcessChecker.h create mode 100644 dom/ipc/Blob.cpp create mode 100644 dom/ipc/BlobChild.h create mode 100644 dom/ipc/BlobParent.h create mode 100644 dom/ipc/BlobTypes.ipdlh create mode 100644 dom/ipc/CPOWManagerGetter.h create mode 100644 dom/ipc/ColorPickerParent.cpp create mode 100644 dom/ipc/ColorPickerParent.h create mode 100644 dom/ipc/ContentBridgeChild.cpp create mode 100644 dom/ipc/ContentBridgeChild.h create mode 100644 dom/ipc/ContentBridgeParent.cpp create mode 100644 dom/ipc/ContentBridgeParent.h create mode 100644 dom/ipc/ContentChild.cpp create mode 100644 dom/ipc/ContentChild.h create mode 100644 dom/ipc/ContentParent.cpp create mode 100644 dom/ipc/ContentParent.h create mode 100644 dom/ipc/ContentProcess.cpp create mode 100644 dom/ipc/ContentProcess.h create mode 100644 dom/ipc/ContentProcessManager.cpp create mode 100644 dom/ipc/ContentProcessManager.h create mode 100644 dom/ipc/CrashReporterChild.cpp create mode 100644 dom/ipc/CrashReporterChild.h create mode 100644 dom/ipc/CrashReporterParent.cpp create mode 100644 dom/ipc/CrashReporterParent.h create mode 100644 dom/ipc/DOMTypes.ipdlh create mode 100644 dom/ipc/DatePickerParent.cpp create mode 100644 dom/ipc/DatePickerParent.h create mode 100644 dom/ipc/FilePickerParent.cpp create mode 100644 dom/ipc/FilePickerParent.h create mode 100644 dom/ipc/IdType.h create mode 100644 dom/ipc/PBlob.ipdl create mode 100644 dom/ipc/PBlobStream.ipdl create mode 100644 dom/ipc/PBrowser.ipdl create mode 100644 dom/ipc/PBrowserOrId.ipdlh create mode 100644 dom/ipc/PColorPicker.ipdl create mode 100644 dom/ipc/PContent.ipdl create mode 100644 dom/ipc/PContentBridge.ipdl create mode 100644 dom/ipc/PContentPermission.ipdlh create mode 100644 dom/ipc/PContentPermissionRequest.ipdl create mode 100644 dom/ipc/PCrashReporter.ipdl create mode 100644 dom/ipc/PCycleCollectWithLogs.ipdl create mode 100644 dom/ipc/PDatePicker.ipdl create mode 100644 dom/ipc/PDocumentRenderer.ipdl create mode 100644 dom/ipc/PFilePicker.ipdl create mode 100644 dom/ipc/PMemoryReportRequest.ipdl create mode 100644 dom/ipc/PPluginWidget.ipdl create mode 100644 dom/ipc/PProcessHangMonitor.ipdl create mode 100644 dom/ipc/PScreenManager.ipdl create mode 100644 dom/ipc/PTabContext.ipdlh create mode 100644 dom/ipc/PermissionMessageUtils.cpp create mode 100644 dom/ipc/PermissionMessageUtils.h create mode 100644 dom/ipc/PreallocatedProcessManager.cpp create mode 100644 dom/ipc/PreallocatedProcessManager.h create mode 100644 dom/ipc/ProcessHangMonitor.cpp create mode 100644 dom/ipc/ProcessHangMonitor.h create mode 100644 dom/ipc/ProcessHangMonitorIPC.h create mode 100644 dom/ipc/ProcessPriorityManager.cpp create mode 100644 dom/ipc/ProcessPriorityManager.h create mode 100644 dom/ipc/ScreenManagerParent.cpp create mode 100644 dom/ipc/ScreenManagerParent.h create mode 100644 dom/ipc/ServiceWorkerConfiguration.ipdlh create mode 100644 dom/ipc/StructuredCloneData.cpp create mode 100644 dom/ipc/StructuredCloneData.h create mode 100644 dom/ipc/TabChild.cpp create mode 100644 dom/ipc/TabChild.h create mode 100644 dom/ipc/TabContext.cpp create mode 100644 dom/ipc/TabContext.h create mode 100644 dom/ipc/TabMessageUtils.cpp create mode 100644 dom/ipc/TabMessageUtils.h create mode 100644 dom/ipc/TabParent.cpp create mode 100644 dom/ipc/TabParent.h create mode 100644 dom/ipc/extensions.js create mode 100644 dom/ipc/jar.mn create mode 100644 dom/ipc/manifestMessages.js create mode 100644 dom/ipc/moz.build create mode 100644 dom/ipc/nsIContentChild.cpp create mode 100644 dom/ipc/nsIContentChild.h create mode 100644 dom/ipc/nsIContentParent.cpp create mode 100644 dom/ipc/nsIContentParent.h create mode 100644 dom/ipc/nsIHangReport.idl create mode 100644 dom/ipc/nsIRemoteBlob.h create mode 100644 dom/ipc/preload.js create mode 100644 dom/ipc/remote-test.js create mode 100644 dom/ipc/test.xul create mode 100644 dom/ipc/tests/blob_verify.sjs create mode 100644 dom/ipc/tests/browser.ini create mode 100644 dom/ipc/tests/browser_domainPolicy.js create mode 100644 dom/ipc/tests/chrome.ini create mode 100644 dom/ipc/tests/file_bug1086684.html create mode 100644 dom/ipc/tests/file_disableScript.html create mode 100644 dom/ipc/tests/file_domainPolicy_base.html create mode 100644 dom/ipc/tests/mochitest.ini create mode 100644 dom/ipc/tests/process_error.xul create mode 100644 dom/ipc/tests/process_error_contentscript.js create mode 100644 dom/ipc/tests/test_CrashService_crash.html create mode 100644 dom/ipc/tests/test_blob_sliced_from_child_process.html create mode 100644 dom/ipc/tests/test_blob_sliced_from_parent_process.html create mode 100644 dom/ipc/tests/test_bug1086684.html create mode 100644 dom/ipc/tests/test_child_docshell.html create mode 100644 dom/ipc/tests/test_cpow_cookies.html create mode 100644 dom/ipc/tests/test_process_error.xul create mode 100644 dom/ipc/tests/test_temporaryfile_stream.html (limited to 'dom/ipc') diff --git a/dom/ipc/AppProcessChecker.cpp b/dom/ipc/AppProcessChecker.cpp new file mode 100644 index 000000000..fa91c94ff --- /dev/null +++ b/dom/ipc/AppProcessChecker.cpp @@ -0,0 +1,95 @@ +/* -*- 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/. */ + +#include "AppProcessChecker.h" +#include "nsIPermissionManager.h" + +namespace mozilla { +namespace dom { +class PContentParent; +} // namespace dom +} // namespace mozilla + +class nsIPrincipal; + +namespace mozilla { + +#if DEBUG + #define LOG(...) printf_stderr(__VA_ARGS__) +#else + #define LOG(...) +#endif + +bool +AssertAppProcess(mozilla::dom::PBrowserParent* aActor, + AssertAppProcessType aType, + const char* aCapability) +{ + return true; +} + +bool +AssertAppStatus(mozilla::dom::PBrowserParent* aActor, + unsigned short aStatus) +{ + return true; +} + +bool +AssertAppProcess(const mozilla::dom::TabContext& aContext, + AssertAppProcessType aType, + const char* aCapability) +{ + return true; +} + +bool +AssertAppStatus(const mozilla::dom::TabContext& aContext, + unsigned short aStatus) +{ + return true; +} + + +bool +AssertAppProcess(mozilla::dom::PContentParent* aActor, + AssertAppProcessType aType, + const char* aCapability) +{ + return true; +} + +bool +AssertAppStatus(mozilla::dom::PContentParent* aActor, + unsigned short aStatus) +{ + return true; +} + +bool +AssertAppProcess(mozilla::hal_sandbox::PHalParent* aActor, + AssertAppProcessType aType, + const char* aCapability) +{ + return true; +} + +bool +AssertAppPrincipal(mozilla::dom::PContentParent* aActor, + nsIPrincipal* aPrincipal) +{ + return true; +} + +uint32_t +CheckPermission(mozilla::dom::PContentParent* aActor, + nsIPrincipal* aPrincipal, + const char* aPermission) +{ + return nsIPermissionManager::ALLOW_ACTION; +} + +} // namespace mozilla diff --git a/dom/ipc/AppProcessChecker.h b/dom/ipc/AppProcessChecker.h new file mode 100644 index 000000000..e5e7a90ba --- /dev/null +++ b/dom/ipc/AppProcessChecker.h @@ -0,0 +1,160 @@ +/* -*- 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_AppProcessChecker_h +#define mozilla_AppProcessChecker_h + +#include + +class nsIPrincipal; + +namespace mozilla { + +namespace dom { +class TabContext; +class PBrowserParent; +class PContentParent; +} // namespace dom + +namespace hal_sandbox { +class PHalParent; +} // namespace hal_sandbox + +enum AssertAppProcessType { + ASSERT_APP_PROCESS_PERMISSION, + ASSERT_APP_PROCESS_MANIFEST_URL, + ASSERT_APP_HAS_PERMISSION +}; + +/** + * Return true if the specified browser has the specified capability. + * If this returns false, the browser didn't have the capability and + * will be killed. + */ +bool +AssertAppProcess(mozilla::dom::PBrowserParent* aActor, + AssertAppProcessType aType, + const char* aCapability); + +/** + * Return true if the specified app has the specified status. + * If this returns false, the browser will be killed. + */ +bool +AssertAppStatus(mozilla::dom::PBrowserParent* aActor, + unsigned short aStatus); + +/** + * Return true if the specified browser has the specified capability. + * If this returns false, the browser didn't have the capability and + * will be killed. + */ +bool +AssertAppProcess(const mozilla::dom::TabContext& aContext, + AssertAppProcessType aType, + const char* aCapability); + +/** + * Return true if the specified app has the specified status. + * If this returns false, the browser will be killed. + */ +bool +AssertAppStatus(const mozilla::dom::TabContext& aContext, + unsigned short aStatus); + +/** + * Return true if any of the PBrowsers loaded in this content process + * has the specified capability. If this returns false, the process + * didn't have the capability and will be killed. + */ +bool +AssertAppProcess(mozilla::dom::PContentParent* aActor, + AssertAppProcessType aType, + const char* aCapability); + +/** + * Return true if any of the PBrowsers loaded in this content process + * has an app with the specified status. If this returns false, the process + * didn't have the status and will be killed. + */ +bool +AssertAppStatus(mozilla::dom::PContentParent* aActor, + unsigned short aStatus); + +bool +AssertAppProcess(mozilla::hal_sandbox::PHalParent* aActor, + AssertAppProcessType aType, + const char* aCapability); + +// NB: when adding capability checks for other IPDL actors, please add +// them to this file and have them delegate to the two functions above +// as appropriate. For example, +// +// bool AppProcessHasCapability(PNeckoParent* aActor, AssertAppProcessType aType) { +// return AssertAppProcess(aActor->Manager(), aType); +// } + +bool +AssertAppPrincipal(mozilla::dom::PContentParent* aParent, + nsIPrincipal* aPrincipal); + +/** + * Check if the specified principal is valid, and return the saved permission + * value for permission `aPermission' on that principal. + * See nsIPermissionManager.idl for possible return values. + * + * nsIPermissionManager::UNKNOWN_ACTION is retuned if the principal is invalid. + */ +uint32_t +CheckPermission(mozilla::dom::PContentParent* aParent, + nsIPrincipal* aPrincipal, const char* aPermission); + +/** + * Inline function for asserting the process's permission. + */ +template +inline bool +AssertAppProcessPermission(T* aActor, + const char* aPermission) { + return AssertAppProcess(aActor, + ASSERT_APP_PROCESS_PERMISSION, + aPermission); +} + +/** + * Inline function for asserting the process's manifest URL. + */ +template +inline bool +AssertAppProcessManifestURL(T* aActor, + const char* aManifestURL) { + return AssertAppProcess(aActor, + ASSERT_APP_PROCESS_MANIFEST_URL, + aManifestURL); +} + +/** + * Inline function for asserting the process's manifest URL. + */ +template +inline bool +AssertAppHasPermission(T* aActor, + const char* aPermission) { + return AssertAppProcess(aActor, + ASSERT_APP_HAS_PERMISSION, + aPermission); +} + +template +inline bool +AssertAppHasStatus(T* aActor, + unsigned short aStatus) { + return AssertAppStatus(aActor, aStatus); +} + +} // namespace mozilla + +#endif // mozilla_AppProcessChecker_h diff --git a/dom/ipc/Blob.cpp b/dom/ipc/Blob.cpp new file mode 100644 index 000000000..95d2e0513 --- /dev/null +++ b/dom/ipc/Blob.cpp @@ -0,0 +1,4793 @@ +/* -*- 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/. */ + +#include "BlobChild.h" +#include "BlobParent.h" + +#include "BackgroundParent.h" +#include "ContentChild.h" +#include "ContentParent.h" +#include "FileDescriptorSetChild.h" +#include "jsapi.h" +#include "mozilla/Assertions.h" +#include "mozilla/ClearOnShutdown.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/Monitor.h" +#include "mozilla/Mutex.h" +#include "mozilla/Unused.h" +#include "mozilla/dom/File.h" +#include "mozilla/dom/nsIContentParent.h" +#include "mozilla/dom/nsIContentChild.h" +#include "mozilla/dom/PBlobStreamChild.h" +#include "mozilla/dom/PBlobStreamParent.h" +#include "mozilla/dom/indexedDB/FileSnapshot.h" +#include "mozilla/dom/IndexedDatabaseManager.h" +#include "mozilla/ipc/InputStreamUtils.h" +#include "mozilla/ipc/IPCStreamUtils.h" +#include "mozilla/ipc/PBackgroundChild.h" +#include "mozilla/ipc/PBackgroundParent.h" +#include "mozilla/ipc/PFileDescriptorSetParent.h" +#include "MultipartBlobImpl.h" +#include "nsDataHashtable.h" +#include "nsHashKeys.h" +#include "nsID.h" +#include "nsIFileStreams.h" +#include "nsIInputStream.h" +#include "nsIIPCSerializableInputStream.h" +#include "nsIMultiplexInputStream.h" +#include "nsIRemoteBlob.h" +#include "nsISeekableStream.h" +#include "nsIUUIDGenerator.h" +#include "nsNetCID.h" +#include "nsServiceManagerUtils.h" +#include "nsStringStream.h" +#include "nsThreadUtils.h" +#include "nsXULAppAPI.h" +#include "WorkerPrivate.h" +#include "WorkerRunnable.h" + +#ifdef DEBUG +#include "BackgroundChild.h" // BackgroundChild::GetForCurrentThread(). +#endif + +#ifdef OS_POSIX +#include "chrome/common/file_descriptor_set_posix.h" +#endif + +#define DISABLE_ASSERTS_FOR_FUZZING 0 + +#if DISABLE_ASSERTS_FOR_FUZZING +#define ASSERT_UNLESS_FUZZING(...) do { } while (0) +#else +#define ASSERT_UNLESS_FUZZING(...) MOZ_ASSERT(false, __VA_ARGS__) +#endif + +#define PRIVATE_REMOTE_INPUT_STREAM_IID \ + {0x30c7699f, 0x51d2, 0x48c8, {0xad, 0x56, 0xc0, 0x16, 0xd7, 0x6f, 0x71, 0x27}} + +namespace mozilla { +namespace dom { + +using namespace mozilla::ipc; +using namespace mozilla::dom::indexedDB; +using namespace mozilla::dom::workers; + +namespace { + +const char kUUIDGeneratorContractId[] = "@mozilla.org/uuid-generator;1"; + +const uint32_t kMaxFileDescriptorsPerMessage = 250; + +#ifdef OS_POSIX +// Keep this in sync with other platforms. +static_assert(FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE == 250, + "MAX_DESCRIPTORS_PER_MESSAGE mismatch!"); +#endif + +StaticRefPtr gUUIDGenerator; + +GeckoProcessType gProcessType = GeckoProcessType_Invalid; + +void +CommonStartup() +{ + MOZ_ASSERT(NS_IsMainThread()); + + gProcessType = XRE_GetProcessType(); + MOZ_ASSERT(gProcessType != GeckoProcessType_Invalid); + + nsCOMPtr uuidGen = do_GetService(kUUIDGeneratorContractId); + MOZ_RELEASE_ASSERT(uuidGen); + + gUUIDGenerator = uuidGen; + ClearOnShutdown(&gUUIDGenerator); +} + +template +struct ConcreteManagerTypeTraits; + +template <> +struct ConcreteManagerTypeTraits +{ + typedef ContentChild Type; +}; + +template <> +struct ConcreteManagerTypeTraits +{ + typedef PBackgroundChild Type; +}; + +template <> +struct ConcreteManagerTypeTraits +{ + typedef ContentParent Type; +}; + +template <> +struct ConcreteManagerTypeTraits +{ + typedef PBackgroundParent Type; +}; + +void +AssertCorrectThreadForManager(nsIContentChild* aManager) +{ + MOZ_ASSERT(NS_IsMainThread()); +} + +void +AssertCorrectThreadForManager(nsIContentParent* aManager) +{ + MOZ_ASSERT(gProcessType == GeckoProcessType_Default); + MOZ_ASSERT(NS_IsMainThread()); +} + +void +AssertCorrectThreadForManager(PBackgroundChild* aManager) +{ +#ifdef DEBUG + if (aManager) { + PBackgroundChild* backgroundChild = BackgroundChild::GetForCurrentThread(); + MOZ_ASSERT(backgroundChild); + MOZ_ASSERT(backgroundChild == aManager); + } +#endif +} + +void +AssertCorrectThreadForManager(PBackgroundParent* aManager) +{ + MOZ_ASSERT(gProcessType == GeckoProcessType_Default); + AssertIsOnBackgroundThread(); +} + +intptr_t +ActorManagerProcessID(nsIContentParent* aManager) +{ + AssertCorrectThreadForManager(aManager); + MOZ_ASSERT(aManager); + + return reinterpret_cast(aManager); +} + +intptr_t +ActorManagerProcessID(PBackgroundParent* aManager) +{ + AssertCorrectThreadForManager(aManager); + MOZ_ASSERT(aManager); + + return BackgroundParent::GetRawContentParentForComparison(aManager); +} + +bool +ActorManagerIsSameProcess(nsIContentParent* aManager) +{ + AssertCorrectThreadForManager(aManager); + MOZ_ASSERT(aManager); + + return false; +} + +bool +ActorManagerIsSameProcess(PBackgroundParent* aManager) +{ + AssertCorrectThreadForManager(aManager); + MOZ_ASSERT(aManager); + + return !BackgroundParent::IsOtherProcessActor(aManager); +} + +bool +EventTargetIsOnCurrentThread(nsIEventTarget* aEventTarget) +{ + if (!aEventTarget) { + return NS_IsMainThread(); + } + + bool current; + + // If this fails, we are probably shutting down. + if (NS_WARN_IF(NS_FAILED(aEventTarget->IsOnCurrentThread(¤t)))) { + return true; + } + + return current; +} + +class CancelableRunnableWrapper final + : public CancelableRunnable +{ + nsCOMPtr mRunnable; +#ifdef DEBUG + nsCOMPtr mDEBUGEventTarget; +#endif + +public: + CancelableRunnableWrapper(nsIRunnable* aRunnable, + nsIEventTarget* aEventTarget) + : mRunnable(aRunnable) +#ifdef DEBUG + , mDEBUGEventTarget(aEventTarget) +#endif + { + MOZ_ASSERT(aRunnable); + MOZ_ASSERT(aEventTarget); + } + + NS_DECL_ISUPPORTS_INHERITED + +private: + ~CancelableRunnableWrapper() + { } + + NS_DECL_NSIRUNNABLE + nsresult Cancel() override; +}; + +NS_IMPL_ISUPPORTS_INHERITED0(CancelableRunnableWrapper, CancelableRunnable) + +NS_IMETHODIMP +CancelableRunnableWrapper::Run() +{ + DebugOnly onTarget; + MOZ_ASSERT(mDEBUGEventTarget); + MOZ_ASSERT(NS_SUCCEEDED(mDEBUGEventTarget->IsOnCurrentThread(&onTarget))); + MOZ_ASSERT(onTarget); + + nsCOMPtr runnable; + mRunnable.swap(runnable); + + if (runnable) { + return runnable->Run(); + } + + return NS_OK; +} + +nsresult +CancelableRunnableWrapper::Cancel() +{ + DebugOnly onTarget; + MOZ_ASSERT(mDEBUGEventTarget); + MOZ_ASSERT(NS_SUCCEEDED(mDEBUGEventTarget->IsOnCurrentThread(&onTarget))); + MOZ_ASSERT(onTarget); + + if (NS_WARN_IF(!mRunnable)) { + return NS_ERROR_UNEXPECTED; + } + + Unused << Run(); + MOZ_ASSERT(!mRunnable); + + return NS_OK; +} + +// Ensure that a nsCOMPtr/nsRefPtr is released on the target thread. +template