Bug 835698 - 'Pre-open() and send the fd for app process's application.zip'. r=jduell.
This commit is contained in:
@@ -17,51 +17,42 @@
|
||||
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::RecvAsyncOpenFile()
|
||||
RemoteOpenFileParent::OpenSendCloseDelete()
|
||||
{
|
||||
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
|
||||
NS_NOTREACHED("osX and Windows shouldn't be doing IPDL here");
|
||||
MOZ_NOT_REACHED("OS X 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) {
|
||||
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;
|
||||
if (fd == -1) {
|
||||
printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
|
||||
path.get());
|
||||
} else {
|
||||
fileDescriptor = FileDescriptor(fd);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
// 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());
|
||||
}
|
||||
|
||||
#endif // OS_TYPE
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user