netwerk/ipc/RemoteOpenFileParent.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 bool
    21 RemoteOpenFileParent::OpenSendCloseDelete()
    22 {
    23 #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
    24   MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here");
    25 #else
    27   // TODO: make this async!
    29   FileDescriptor fileDescriptor;
    31   nsAutoCString path;
    32   nsresult rv = mURI->GetFilePath(path);
    33   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!");
    35   NS_UnescapeURL(path);
    37   if (NS_SUCCEEDED(rv)) {
    38     int fd = open(path.get(), O_RDONLY);
    39     if (fd == -1) {
    40       printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
    41                     path.get());
    42     } else {
    43       fileDescriptor = FileDescriptor(fd);
    44     }
    45   }
    47   // Sending a potentially invalid file descriptor is just fine.
    48   unused << Send__delete__(this, fileDescriptor);
    50   if (fileDescriptor.IsValid()) {
    51     // close file now that other process has it open, else we'll leak fds in the
    52     // parent process.
    53     close(fileDescriptor.PlatformHandle());
    54   }
    56 #endif // OS_TYPE
    58   return true;
    59 }
    61 } // namespace net
    62 } // namespace mozilla

mercurial