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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_process_launcher_win.cc

Issue 12406002: Pass ID of the calling extension to the native messaging host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 " is not registered"; 57 " is not registered";
58 return scoped_ptr<NativeMessagingHostManifest>(); 58 return scoped_ptr<NativeMessagingHostManifest>();
59 } 59 }
60 60
61 return NativeMessagingHostManifest::Load( 61 return NativeMessagingHostManifest::Load(
62 base::FilePath(manifest_path), error_message); 62 base::FilePath(manifest_path), error_message);
63 } 63 }
64 64
65 // static 65 // static
66 bool NativeProcessLauncher::LaunchNativeProcess( 66 bool NativeProcessLauncher::LaunchNativeProcess(
67 const base::FilePath& path, 67 const CommandLine& command_line,
68 base::PlatformFile* read_file, 68 base::PlatformFile* read_file,
69 base::PlatformFile* write_file) { 69 base::PlatformFile* write_file) {
70 // Timeout for the IO pipes. 70 // Timeout for the IO pipes.
71 const DWORD kTimeoutMs = 5000; 71 const DWORD kTimeoutMs = 5000;
72 72
73 // Windows will use default buffer size when 0 is passed to 73 // Windows will use default buffer size when 0 is passed to
74 // CreateNamedPipeW(). 74 // CreateNamedPipeW().
75 const DWORD kBufferSize = 0; 75 const DWORD kBufferSize = 0;
76 76
77 if (!path.IsAbsolute()) { 77 if (!path.IsAbsolute()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 DWORD comspec_length = ::GetEnvironmentVariable(L"COMSPEC", NULL, 0); 112 DWORD comspec_length = ::GetEnvironmentVariable(L"COMSPEC", NULL, 0);
113 if (comspec_length == 0) { 113 if (comspec_length == 0) {
114 LOG(ERROR) << "COMSPEC is not set"; 114 LOG(ERROR) << "COMSPEC is not set";
115 return false; 115 return false;
116 } 116 }
117 scoped_ptr<wchar_t[]> comspec(new wchar_t[comspec_length]); 117 scoped_ptr<wchar_t[]> comspec(new wchar_t[comspec_length]);
118 ::GetEnvironmentVariable(L"COMSPEC", comspec.get(), comspec_length); 118 ::GetEnvironmentVariable(L"COMSPEC", comspec.get(), comspec_length);
119 119
120 string16 command_line_string = command_line.GetCommandLineString();
121
120 // 'start' command has a moronic syntax: if first argument is quoted then it 122 // 'start' command has a moronic syntax: if first argument is quoted then it
121 // interprets it as a command title. Host path must always be in quotes, so 123 // interprets it as a command title. Host path must always be in quotes, so
122 // we always need to specify the title as the first argument. 124 // we always need to specify the title as the first argument.
123 string16 command = base::StringPrintf( 125 string16 command = base::StringPrintf(
124 L"%ls /c start \"Chrome Native Messaging Host\" /b " 126 L"%ls /c start \"Chrome Native Messaging Host\" /b "
125 L"\"%ls\" < %ls > %ls", 127 L"%ls < %ls > %ls",
126 comspec.get(), path.value().c_str(), 128 comspec.get(), command_line_string.c_str(),
127 in_pipe_name.c_str(), out_pipe_name.c_str()); 129 in_pipe_name.c_str(), out_pipe_name.c_str());
128 130
129 base::LaunchOptions options; 131 base::LaunchOptions options;
130 options.start_hidden = true; 132 options.start_hidden = true;
131 base::ProcessHandle cmd_handle; 133 base::ProcessHandle cmd_handle;
132 if (!base::LaunchProcess(command.c_str(), options, &cmd_handle)) { 134 if (!base::LaunchProcess(command.c_str(), options, &cmd_handle)) {
133 LOG(ERROR) << "Error launching process " << path.MaybeAsASCII(); 135 LOG(ERROR) << "Error launching process " << path.MaybeAsASCII();
134 return false; 136 return false;
135 } 137 }
136 138
(...skipping 24 matching lines...) Expand all
161 163
162 base::CloseProcessHandle(cmd_handle); 164 base::CloseProcessHandle(cmd_handle);
163 165
164 *read_file = stdout_pipe.Take(); 166 *read_file = stdout_pipe.Take();
165 *write_file = stdin_pipe.Take(); 167 *write_file = stdin_pipe.Take();
166 168
167 return true; 169 return true;
168 } 170 }
169 171
170 } // namespace extensions 172 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698