Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6083)

Unified Diff: chrome/browser/extensions/api/messaging/native_process_launcher_win.cc

Issue 10918255: The Windows portion of Native Messagaing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_messaging_apitest_posix.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
diff --git a/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc b/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
index 7d1fe69a283923f37908ef7cf7f1899e88c8c50b..cb787893bbe579210d3a845cc30ca109f002e5fa 100644
--- a/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
+++ b/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
@@ -6,10 +6,18 @@
#include <windows.h>
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
+#include "base/utf_string_conversions.h"
+
+namespace {
+
+int pipe_counter = 0;
+
+} // namespace
namespace extensions {
@@ -18,8 +26,90 @@ bool NativeProcessLauncher::LaunchNativeProcess(
base::ProcessHandle* native_process_handle,
NativeMessageProcessHost::FileHandle* read_file,
NativeMessageProcessHost::FileHandle* write_file) const {
- NOTREACHED();
- return false;
+ SECURITY_ATTRIBUTES sa_attr;
+ // Set the bInheritHandle flag so pipe handles are inherited.
+ sa_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ sa_attr.bInheritHandle = TRUE;
+ sa_attr.lpSecurityDescriptor = NULL;
+
+ DWORD pipe_open_mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED;
+ DWORD pipe_mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE;
+ DWORD max_instances = 1;
+ DWORD buffer_size = NativeMessageProcessHost::kMaxMessageDataLength;
+ DWORD timeout = NativeMessageProcessHost::kExitTimeoutMS;
+
+ string16 out_pipe_name = ASCIIToWide(base::StringPrintf(
+ "\\\\.\\pipe\\chrome.nativeMessage.out.%d", ++pipe_counter));
+ string16 in_pipe_name = ASCIIToWide(base::StringPrintf(
+ "\\\\.\\pipe\\chrome.nativeMessage.in.%d", ++pipe_counter));
+
+ HANDLE stdin_parent_pipe = NULL;
+ HANDLE stdout_parent_pipe = NULL;
+
+ HANDLE stdin_child_pipe = NULL;
+ HANDLE stdout_child_pipe = NULL;
+
+ // Create the pipes to read and write from.
+ stdout_parent_pipe = CreateNamedPipeW(out_pipe_name.c_str(), pipe_open_mode,
+ pipe_mode, max_instances, buffer_size,
+ buffer_size, timeout, &sa_attr);
+ if (stdout_parent_pipe == INVALID_HANDLE_VALUE) {
+ DPLOG(ERROR) << "Failed to create pipe";
+ return false;
+ }
+
+ DWORD desired_access = GENERIC_READ | GENERIC_WRITE;
+ DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+
+ stdout_child_pipe = CreateFileW(out_pipe_name.c_str(), desired_access,
+ share_mode, &sa_attr, OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED, NULL);
+ if (stdout_child_pipe == INVALID_HANDLE_VALUE) {
+ DPLOG(ERROR) << "Failed to create pipe";
+ return false;
+ }
+
+ stdin_parent_pipe = CreateNamedPipeW(in_pipe_name.c_str(), pipe_open_mode,
+ pipe_mode, max_instances, buffer_size,
+ buffer_size, timeout, &sa_attr);
+ if (stdin_parent_pipe == INVALID_HANDLE_VALUE) {
+ DPLOG(ERROR) << "Failed to create pipe";
+ return false;
+ }
+
+ stdin_child_pipe = CreateFileW(in_pipe_name.c_str(), desired_access,
+ share_mode, &sa_attr, OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED, NULL);
+ if (stdin_child_pipe == INVALID_HANDLE_VALUE) {
+ DPLOG(ERROR) << "Failed to create pipe";
+ return false;
+ }
+
+ // Don't inherit the parents'
+ if (!SetHandleInformation(stdin_parent_pipe, HANDLE_FLAG_INHERIT, 0) ||
+ !SetHandleInformation(stdout_parent_pipe, HANDLE_FLAG_INHERIT, 0)) {
+ DPLOG(ERROR) << "Failed to enable pipe inheritance";
+ return false;
+ }
+
+ CommandLine line(path);
+ base::LaunchOptions options;
+ // Need to inherit the file handles.
+ options.inherit_handles = true;
+ options.stdin_handle = stdin_child_pipe;
+ options.stdout_handle = stdout_child_pipe;
+ options.start_hidden = true;
+
+ if (!base::LaunchProcess(line.GetCommandLineString(), options,
+ native_process_handle)) {
+ LOG(ERROR) << "Error launching process";
+ return false;
+ }
+
+ *read_file = stdout_parent_pipe;
+ *write_file = stdin_parent_pipe;
+
+ return true;
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_messaging_apitest_posix.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698