michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/net/RemoteOpenFileParent.h" michael@0: #include "mozilla/unused.h" michael@0: #include "nsEscape.h" michael@0: michael@0: #if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA) michael@0: #include michael@0: #include michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: bool michael@0: RemoteOpenFileParent::OpenSendCloseDelete() michael@0: { michael@0: #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA) michael@0: MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here"); michael@0: #else michael@0: michael@0: // TODO: make this async! michael@0: michael@0: FileDescriptor fileDescriptor; michael@0: michael@0: nsAutoCString path; michael@0: nsresult rv = mURI->GetFilePath(path); michael@0: NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!"); michael@0: michael@0: NS_UnescapeURL(path); michael@0: michael@0: if (NS_SUCCEEDED(rv)) { michael@0: int fd = open(path.get(), O_RDONLY); michael@0: if (fd == -1) { michael@0: printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n", michael@0: path.get()); michael@0: } else { michael@0: fileDescriptor = FileDescriptor(fd); michael@0: } michael@0: } michael@0: michael@0: // Sending a potentially invalid file descriptor is just fine. michael@0: unused << Send__delete__(this, fileDescriptor); michael@0: michael@0: if (fileDescriptor.IsValid()) { michael@0: // close file now that other process has it open, else we'll leak fds in the michael@0: // parent process. michael@0: close(fileDescriptor.PlatformHandle()); michael@0: } michael@0: michael@0: #endif // OS_TYPE michael@0: michael@0: return true; michael@0: } michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla