2012-12-22 05:56:21 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et 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/net/RemoteOpenFileParent.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
|
|
|
|
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
|
|
|
|
#include <fcntl.h>
|
2012-12-26 07:16:42 -08:00
|
|
|
#include <unistd.h>
|
2012-12-22 05:56:21 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
bool
|
2013-02-07 05:06:58 -08:00
|
|
|
RemoteOpenFileParent::OpenSendCloseDelete()
|
2012-12-22 05:56:21 -08:00
|
|
|
{
|
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
|
2013-02-07 05:06:58 -08:00
|
|
|
MOZ_NOT_REACHED("OS X and Windows shouldn't be doing IPDL here");
|
2012-12-22 05:56:21 -08:00
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: make this async!
|
|
|
|
|
2013-02-07 05:06:58 -08:00
|
|
|
FileDescriptor fileDescriptor;
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
nsAutoCString path;
|
|
|
|
nsresult rv = mURI->GetFilePath(path);
|
2013-02-07 05:06:58 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!");
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
NS_UnescapeURL(path);
|
2013-02-07 05:06:58 -08:00
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
int fd = open(path.get(), O_RDONLY);
|
2013-02-07 05:06:58 -08:00
|
|
|
if (fd == -1) {
|
|
|
|
printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
|
|
|
|
path.get());
|
|
|
|
} else {
|
|
|
|
fileDescriptor = FileDescriptor(fd);
|
2012-12-22 05:56:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 05:06:58 -08:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
#endif // OS_TYPE
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|