diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index d0ece243f75..e01be71c85d 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -71,6 +71,7 @@ #include "nsLayoutStylesheetCache.h" #include "nsIJSRuntimeService.h" #include "nsThreadManager.h" +#include "nsAnonymousTemporaryFile.h" #include "IHistory.h" #include "nsNetUtil.h" diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 1ae706eef64..acdc155e1af 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -66,6 +66,7 @@ #include "mozilla/Services.h" #include "mozilla/StaticPtr.h" #include "mozilla/unused.h" +#include "nsAnonymousTemporaryFile.h" #include "nsAppRunner.h" #include "nsAutoPtr.h" #include "nsCDefaultURIFixup.h" @@ -118,6 +119,8 @@ #include "nsIDocShell.h" #include "mozilla/net/NeckoMessageUtils.h" #include "gfxPrefs.h" +#include "prio.h" +#include "private/pprio.h" #if defined(ANDROID) || defined(LINUX) #include "nsSystemInfo.h" @@ -3655,6 +3658,21 @@ ContentParent::RecvBackUpXResources(const FileDescriptor& aXSocketFd) return true; } +bool +ContentParent::RecvOpenAnonymousTemporaryFile(FileDescriptor *aFD) +{ + PRFileDesc *prfd; + nsresult rv = NS_OpenAnonymousTemporaryFile(&prfd); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + *aFD = FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd)); + // The FileDescriptor object owns a duplicate of the file handle; we + // must close the original (and clean up the NSPR descriptor). + PR_Close(prfd); + return true; +} + PFileDescriptorSetParent* ContentParent::AllocPFileDescriptorSetParent(const FileDescriptor& aFD) { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index be8034d0cd0..6c08a5787b6 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -610,6 +610,9 @@ private: virtual bool RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE; + virtual bool + RecvOpenAnonymousTemporaryFile(FileDescriptor* aFD) MOZ_OVERRIDE; + virtual PFileDescriptorSetParent* AllocPFileDescriptorSetParent(const mozilla::ipc::FileDescriptor&) MOZ_OVERRIDE; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 4dc5fe71432..5be7469ec58 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -646,6 +646,8 @@ parent: */ BackUpXResources(FileDescriptor aXSocketFd); + sync OpenAnonymousTemporaryFile() returns (FileDescriptor aFD); + both: AsyncMessage(nsString aMessage, ClonedMessageData aData, CpowEntry[] aCpows, Principal aPrincipal); diff --git a/xpcom/io/nsAnonymousTemporaryFile.cpp b/xpcom/io/nsAnonymousTemporaryFile.cpp index b71a6e7aad8..b76962e40da 100644 --- a/xpcom/io/nsAnonymousTemporaryFile.cpp +++ b/xpcom/io/nsAnonymousTemporaryFile.cpp @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/dom/ContentChild.h" #include "nsAnonymousTemporaryFile.h" #include "nsDirectoryServiceUtils.h" #include "nsDirectoryServiceDefs.h" @@ -11,6 +12,8 @@ #include "nsCOMPtr.h" #include "nsString.h" #include "nsAppDirectoryServiceDefs.h" +#include "prio.h" +#include "private/pprio.h" #ifdef XP_WIN #include "nsIObserver.h" @@ -23,9 +26,9 @@ #include "nsITimer.h" #include "nsCRT.h" -using namespace mozilla; #endif +using namespace mozilla; // We store the temp files in the system temp dir. // @@ -84,8 +87,18 @@ NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc) if (NS_WARN_IF(!aOutFileDesc)) { return NS_ERROR_INVALID_ARG; } - nsresult rv; + if (dom::ContentChild* child = dom::ContentChild::GetSingleton()) { + ipc::FileDescriptor fd; + DebugOnly succeeded = child->SendOpenAnonymousTemporaryFile(&fd); + // The child process should already have been terminated if the + // IPC had failed. + MOZ_ASSERT(succeeded); + *aOutFileDesc = PR_ImportFile(PROsfd(fd.PlatformHandle())); + return NS_OK; + } + + nsresult rv; nsCOMPtr tmpFile; rv = GetTempDir(getter_AddRefs(tmpFile)); if (NS_WARN_IF(NS_FAILED(rv))) {