1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/ipc/RemoteOpenFileParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set sw=2 ts=8 et tw=80 : */ 1.6 + 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "mozilla/net/RemoteOpenFileParent.h" 1.12 +#include "mozilla/unused.h" 1.13 +#include "nsEscape.h" 1.14 + 1.15 +#if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA) 1.16 +#include <fcntl.h> 1.17 +#include <unistd.h> 1.18 +#endif 1.19 + 1.20 +namespace mozilla { 1.21 +namespace net { 1.22 + 1.23 +bool 1.24 +RemoteOpenFileParent::OpenSendCloseDelete() 1.25 +{ 1.26 +#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA) 1.27 + MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here"); 1.28 +#else 1.29 + 1.30 + // TODO: make this async! 1.31 + 1.32 + FileDescriptor fileDescriptor; 1.33 + 1.34 + nsAutoCString path; 1.35 + nsresult rv = mURI->GetFilePath(path); 1.36 + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!"); 1.37 + 1.38 + NS_UnescapeURL(path); 1.39 + 1.40 + if (NS_SUCCEEDED(rv)) { 1.41 + int fd = open(path.get(), O_RDONLY); 1.42 + if (fd == -1) { 1.43 + printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n", 1.44 + path.get()); 1.45 + } else { 1.46 + fileDescriptor = FileDescriptor(fd); 1.47 + } 1.48 + } 1.49 + 1.50 + // Sending a potentially invalid file descriptor is just fine. 1.51 + unused << Send__delete__(this, fileDescriptor); 1.52 + 1.53 + if (fileDescriptor.IsValid()) { 1.54 + // close file now that other process has it open, else we'll leak fds in the 1.55 + // parent process. 1.56 + close(fileDescriptor.PlatformHandle()); 1.57 + } 1.58 + 1.59 +#endif // OS_TYPE 1.60 + 1.61 + return true; 1.62 +} 1.63 + 1.64 +} // namespace net 1.65 +} // namespace mozilla