mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 21:18:35 +00:00
Bug 965724 - Use IPC for NS_OpenAnonymousTemporaryFile if in content process. r=roc
This commit is contained in:
parent
c8a84e4eda
commit
12f969befb
@ -71,6 +71,7 @@
|
||||
#include "nsLayoutStylesheetCache.h"
|
||||
#include "nsIJSRuntimeService.h"
|
||||
#include "nsThreadManager.h"
|
||||
#include "nsAnonymousTemporaryFile.h"
|
||||
|
||||
#include "IHistory.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -646,6 +646,8 @@ parent:
|
||||
*/
|
||||
BackUpXResources(FileDescriptor aXSocketFd);
|
||||
|
||||
sync OpenAnonymousTemporaryFile() returns (FileDescriptor aFD);
|
||||
|
||||
both:
|
||||
AsyncMessage(nsString aMessage, ClonedMessageData aData,
|
||||
CpowEntry[] aCpows, Principal aPrincipal);
|
||||
|
@ -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<bool> 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<nsIFile> tmpFile;
|
||||
rv = GetTempDir(getter_AddRefs(tmpFile));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user