1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
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 #import <CoreFoundation/CoreFoundation.h>
9 #import <Foundation/Foundation.h>
11 #include <sys/param.h>
13 #include "MacAutoreleasePool.h"
14 #include "nsMacRemoteClient.h"
15 #include "RemoteUtils.h"
17 using namespace mozilla;
19 nsresult nsMacRemoteClient::Init() { return NS_OK; }
21 nsresult nsMacRemoteClient::SendCommandLine(const char* aProgram,
22 const char* aProfile, int32_t argc,
23 const char** argv, bool aRaise) {
24 mozilla::MacAutoreleasePool pool;
27 BuildClassName(aProgram, aProfile, className);
28 NSString* serverNameString = [NSString
29 stringWithCharacters:reinterpret_cast<const unichar*>(className.get())
30 length:className.Length()];
32 CFMessagePortRef messageServer =
33 CFMessagePortCreateRemote(0, (CFStringRef)serverNameString);
36 // Getting current process directory
37 char cwdPtr[MAXPATHLEN + 1];
38 getcwd(cwdPtr, MAXPATHLEN + 1);
40 NSMutableArray* argumentsArray = [NSMutableArray array];
41 for (int i = 0; i < argc; i++) {
42 NSString* argument = [NSString stringWithUTF8String:argv[i]];
43 [argumentsArray addObject:argument];
45 NSDictionary* dict = @{@"args" : argumentsArray, @"raise" : @(aRaise)};
47 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:dict];
49 CFMessagePortSendRequest(messageServer, 0, (CFDataRef)data, 10.0, 0.0, NULL,
52 CFMessagePortInvalidate(messageServer);
53 CFRelease(messageServer);
58 return NS_ERROR_NOT_AVAILABLE;