Bumping manifests a=b2g-bump
[gecko.git] / netwerk / ipc / RemoteOpenFileParent.cpp
blobe21562e52176a4e62acb18c3aada5de187f0cb52
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/net/RemoteOpenFileParent.h"
9 #include "mozilla/unused.h"
10 #include "nsEscape.h"
12 #if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
13 #include <fcntl.h>
14 #include <unistd.h>
15 #endif
17 namespace mozilla {
18 namespace net {
20 void
21 RemoteOpenFileParent::ActorDestroy(ActorDestroyReason aWhy)
23 // Implement me! Bug 1005186
26 bool
27 RemoteOpenFileParent::OpenSendCloseDelete()
29 #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
30 MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here");
31 #else
33 // TODO: make this async!
35 FileDescriptor fileDescriptor;
37 nsAutoCString path;
38 nsresult rv = mURI->GetFilePath(path);
39 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!");
41 NS_UnescapeURL(path);
43 if (NS_SUCCEEDED(rv)) {
44 int fd = open(path.get(), O_RDONLY);
45 if (fd == -1) {
46 printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
47 path.get());
48 } else {
49 fileDescriptor = FileDescriptor(fd);
50 // FileDescriptor does a dup() internally, so we need to close our fd
51 close(fd);
55 // Sending a potentially invalid file descriptor is just fine.
56 unused << Send__delete__(this, fileDescriptor);
58 // Current process's file descriptor is closed by FileDescriptor destructor.
59 #endif // OS_TYPE
61 return true;
64 } // namespace net
65 } // namespace mozilla