diff --git a/dom/base/MessageManagerGlobal.cpp b/dom/base/MessageManagerGlobal.cpp new file mode 100644 index 000000000000..160ab477669e --- /dev/null +++ b/dom/base/MessageManagerGlobal.cpp @@ -0,0 +1,66 @@ +/* -*- 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 "mozilla/dom/MessageManagerGlobal.h" +#include "mozilla/IntentionalCrash.h" +#include "mozilla/dom/DOMPrefs.h" +#include "nsContentUtils.h" + +#ifdef ANDROID +#include +#endif +#ifdef XP_WIN +#include +#endif + +namespace mozilla { +namespace dom { + +void +MessageManagerGlobal::Dump(const nsAString& aStr) +{ + if (!DOMPrefs::DumpEnabled()) { + return; + } + +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", NS_ConvertUTF16toUTF8(aStr).get()); +#endif +#ifdef XP_WIN + if (IsDebuggerPresent()) { + OutputDebugStringW(PromiseFlatString(aStr).get()); + } +#endif + fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout); + fflush(stdout); +} + +void +MessageManagerGlobal::PrivateNoteIntentionalCrash(ErrorResult& aError) +{ + if (XRE_IsContentProcess()) { + NoteIntentionalCrash("tab"); + return; + } + aError.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + +void +MessageManagerGlobal::Atob(const nsAString& aAsciiString, nsAString& aBase64Data, + ErrorResult& aError) +{ + aError = nsContentUtils::Atob(aAsciiString, aBase64Data); +} + +void +MessageManagerGlobal::Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, + ErrorResult& aError) +{ + aError = nsContentUtils::Btoa(aBase64Data, aAsciiString); +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/base/MessageManagerGlobal.h b/dom/base/MessageManagerGlobal.h index 00d9a1ae64a0..fa9fd3f88ced 100644 --- a/dom/base/MessageManagerGlobal.h +++ b/dom/base/MessageManagerGlobal.h @@ -127,40 +127,10 @@ public: } // MessageManagerGlobal - void Dump(const nsAString& aStr, ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Dump(aStr); - } - void PrivateNoteIntentionalCrash(ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->PrivateNoteIntentionalCrash(); - } - void Atob(const nsAString& aAsciiString, nsAString& aBase64Data, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Atob(aAsciiString, aBase64Data); - } - void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Btoa(aBase64Data, aAsciiString); - } + void Dump(const nsAString& aStr); + void PrivateNoteIntentionalCrash(ErrorResult& aError); + void Atob(const nsAString& aAsciiString, nsAString& aBase64Data, ErrorResult& aError); + void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, ErrorResult& aError); bool MarkForCC() { diff --git a/dom/base/ProcessGlobal.cpp b/dom/base/ProcessGlobal.cpp index 8549bc4be4c8..66f45d8d6088 100644 --- a/dom/base/ProcessGlobal.cpp +++ b/dom/base/ProcessGlobal.cpp @@ -96,7 +96,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ProcessGlobal) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessageManagerGlobal) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISyncMessageSender) NS_INTERFACE_MAP_ENTRY(nsIMessageListenerManager) NS_INTERFACE_MAP_ENTRY(nsIMessageSender) NS_INTERFACE_MAP_ENTRY(nsISyncMessageSender) diff --git a/dom/base/ProcessGlobal.h b/dom/base/ProcessGlobal.h index 71391c3c23bf..ed6d0fc27948 100644 --- a/dom/base/ProcessGlobal.h +++ b/dom/base/ProcessGlobal.h @@ -26,7 +26,7 @@ namespace mozilla { namespace dom { class ProcessGlobal : - public nsIMessageManagerGlobal, + public nsISyncMessageSender, public nsMessageManagerScriptExecutor, public nsIGlobalObject, public nsIScriptObjectPrincipal, @@ -52,7 +52,7 @@ public: static ProcessGlobal* Get(); NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ProcessGlobal, nsIMessageManagerGlobal) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ProcessGlobal, nsISyncMessageSender) virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override @@ -72,10 +72,6 @@ public: using MessageManagerGlobal::GetRemoteType; using MessageManagerGlobal::SendSyncMessage; using MessageManagerGlobal::SendRpcMessage; - using MessageManagerGlobal::Dump; - using MessageManagerGlobal::PrivateNoteIntentionalCrash; - using MessageManagerGlobal::Atob; - using MessageManagerGlobal::Btoa; // ContentProcessMessageManager void GetInitialProcessData(JSContext* aCx, @@ -92,7 +88,6 @@ public: NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) NS_FORWARD_SAFE_NSISYNCMESSAGESENDER(mMessageManager) - NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager) virtual void LoadScript(const nsAString& aURL); diff --git a/dom/base/moz.build b/dom/base/moz.build index 496ebe5aa61d..796b8be5f228 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -278,6 +278,7 @@ UNIFIED_SOURCES += [ 'Link.cpp', 'Location.cpp', 'MessageListenerManager.cpp', + 'MessageManagerGlobal.cpp', 'MessageSender.cpp', 'Navigator.cpp', 'NodeInfo.cpp', diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 0ceeac68a1e4..1b599fcadfcf 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -30,11 +30,9 @@ #include "nsIScriptSecurityManager.h" #include "xpcpublic.h" #include "mozilla/CycleCollectedJSContext.h" -#include "mozilla/IntentionalCrash.h" #include "mozilla/Preferences.h" #include "mozilla/ScriptPreloader.h" #include "mozilla/Telemetry.h" -#include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/ChildProcessMessageManager.h" #include "mozilla/dom/ChromeMessageBroadcaster.h" #include "mozilla/dom/ChromeMessageSender.h" @@ -58,11 +56,7 @@ #include #include "chrome/common/ipc_channel.h" // for IPC::Channel::kMaximumMessageSize -#ifdef ANDROID -#include -#endif #ifdef XP_WIN -#include # if defined(SendMessage) # undef SendMessage # endif @@ -871,52 +865,6 @@ nsFrameMessageManager::ReleaseCachedProcesses() return NS_OK; } -// nsIContentFrameMessageManager - -NS_IMETHODIMP -nsFrameMessageManager::Dump(const nsAString& aStr) -{ - if (!DOMPrefs::DumpEnabled()) { - return NS_OK; - } - -#ifdef ANDROID - __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", NS_ConvertUTF16toUTF8(aStr).get()); -#endif -#ifdef XP_WIN - if (IsDebuggerPresent()) { - OutputDebugStringW(PromiseFlatString(aStr).get()); - } -#endif - fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout); - fflush(stdout); - return NS_OK; -} - -NS_IMETHODIMP -nsFrameMessageManager::PrivateNoteIntentionalCrash() -{ - if (XRE_IsContentProcess()) { - mozilla::NoteIntentionalCrash("tab"); - return NS_OK; - } - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsFrameMessageManager::Btoa(const nsAString& aBinaryData, - nsAString& aAsciiBase64String) -{ - return nsContentUtils::Btoa(aBinaryData, aAsciiBase64String); -} - -NS_IMETHODIMP -nsFrameMessageManager::Atob(const nsAString& aAsciiString, - nsAString& aBinaryData) -{ - return nsContentUtils::Atob(aAsciiString, aBinaryData); -} - class MMListenerRemover { public: diff --git a/dom/base/nsFrameMessageManager.h b/dom/base/nsFrameMessageManager.h index c581658e0fcc..78b806a24ed2 100644 --- a/dom/base/nsFrameMessageManager.h +++ b/dom/base/nsFrameMessageManager.h @@ -254,7 +254,6 @@ public: NS_DECL_NSIMESSAGESENDER NS_DECL_NSIMESSAGEBROADCASTER NS_DECL_NSISYNCMESSAGESENDER - NS_DECL_NSIMESSAGEMANAGERGLOBAL NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER static mozilla::dom::ChromeMessageSender* diff --git a/dom/base/nsIMessageManager.idl b/dom/base/nsIMessageManager.idl index 3d51189c0f01..d605c0f29041 100644 --- a/dom/base/nsIMessageManager.idl +++ b/dom/base/nsIMessageManager.idl @@ -376,29 +376,8 @@ interface nsISyncMessageSender : nsIMessageSender [optional] in nsIPrincipal principal); }; -[uuid(13f3555f-769e-44ea-b607-5239230c3162)] -interface nsIMessageManagerGlobal : nsISyncMessageSender -{ - /** - * Print a string to stdout. - */ - void dump(in DOMString aStr); - - /** - * If leak detection is enabled, print a note to the leak log that this - * process will intentionally crash. - */ - void privateNoteIntentionalCrash(); - - /** - * Ascii base64 data to binary data and vice versa - */ - DOMString atob(in DOMString aAsciiString); - DOMString btoa(in DOMString aBase64Data); -}; - [uuid(694e367c-aa25-4446-8499-2c527c4bd838)] -interface nsIContentFrameMessageManager : nsIMessageManagerGlobal +interface nsIContentFrameMessageManager : nsISyncMessageSender { }; diff --git a/dom/base/nsInProcessTabChildGlobal.h b/dom/base/nsInProcessTabChildGlobal.h index 4143dc3d1fb0..4eefffe23254 100644 --- a/dom/base/nsInProcessTabChildGlobal.h +++ b/dom/base/nsInProcessTabChildGlobal.h @@ -69,7 +69,6 @@ public: NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) NS_FORWARD_SAFE_NSISYNCMESSAGESENDER(mMessageManager); - NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager) NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER diff --git a/dom/chrome-webidl/MessageManager.webidl b/dom/chrome-webidl/MessageManager.webidl index c8c4003ab975..f0a5ce1400b9 100644 --- a/dom/chrome-webidl/MessageManager.webidl +++ b/dom/chrome-webidl/MessageManager.webidl @@ -200,7 +200,6 @@ interface MessageManagerGlobal : SyncMessageSender /** * Print a string to stdout. */ - [Throws] void dump(DOMString str); /** diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index bd825aeff881..11545d41d274 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -107,7 +107,6 @@ public: NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) NS_FORWARD_SAFE_NSISYNCMESSAGESENDER(mMessageManager); - NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager) NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER nsresult