Backed out changeset 84db7473edfb (bug 835575)

This commit is contained in:
Ed Morley
2013-02-07 12:52:50 +00:00
parent 6c1f2bf4b9
commit a0c0c987df
8 changed files with 89 additions and 60 deletions

View File

@@ -17,42 +17,51 @@
namespace mozilla {
namespace net {
RemoteOpenFileParent::RemoteOpenFileParent(nsIFileURL *aURI)
: mURI(aURI)
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
, mFd(-1)
#endif
{}
RemoteOpenFileParent::~RemoteOpenFileParent()
{
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
if (mFd != -1) {
// close file handle now that other process has it open, else we'll leak
// file handles in parent process
close(mFd);
}
#endif
}
bool
RemoteOpenFileParent::OpenSendCloseDelete()
RemoteOpenFileParent::RecvAsyncOpenFile()
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
MOZ_NOTREACHED("OS X and Windows shouldn't be doing IPDL here");
NS_NOTREACHED("osX and Windows shouldn't be doing IPDL here");
#else
// TODO: make this async!
FileDescriptor fileDescriptor;
nsAutoCString path;
nsresult rv = mURI->GetFilePath(path);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!");
NS_UnescapeURL(path);
if (NS_SUCCEEDED(rv)) {
int fd = open(path.get(), O_RDONLY);
if (fd == -1) {
printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
path.get());
} else {
fileDescriptor = FileDescriptor(fd);
if (fd != -1) {
unused << SendFileOpened(FileDescriptor(fd));
// file handle needs to stay open until it's shared with child (and IPDL
// is async, so hasn't happened yet). Close in destructor.
mFd = fd;
return true;
}
}
// Sending a potentially invalid file descriptor is just fine.
unused << Send__delete__(this, fileDescriptor);
if (fileDescriptor.IsValid()) {
// close file now that other process has it open, else we'll leak fds in the
// parent process.
close(fileDescriptor.PlatformHandle());
}
// Note: sending an invalid file descriptor currently kills the child process:
// but that's ok for our use case (failing to open application.jar).
printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n", path.get());
unused << SendFileDidNotOpen();
#endif // OS_TYPE
return true;