| OLD | NEW |
| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 friend class base::RefCountedThreadSafe<Core>; | 57 friend class base::RefCountedThreadSafe<Core>; |
| 58 virtual ~Core(); | 58 virtual ~Core(); |
| 59 | 59 |
| 60 void DoLaunchOnThreadPool(const GURL& origin, | 60 void DoLaunchOnThreadPool(const GURL& origin, |
| 61 const std::string& native_host_name, | 61 const std::string& native_host_name, |
| 62 LaunchedCallback callback); | 62 LaunchedCallback callback); |
| 63 void PostErrorResult(const LaunchedCallback& callback, LaunchResult error); | 63 void PostErrorResult(const LaunchedCallback& callback, LaunchResult error); |
| 64 void PostResult(const LaunchedCallback& callback, | 64 void PostResult(const LaunchedCallback& callback, |
| 65 base::ProcessHandle process_handle, | 65 base::Process process, |
| 66 base::File read_file, | 66 base::File read_file, |
| 67 base::File write_file); | 67 base::File write_file); |
| 68 void CallCallbackOnIOThread(LaunchedCallback callback, | 68 void CallCallbackOnIOThread(LaunchedCallback callback, |
| 69 LaunchResult result, | 69 LaunchResult result, |
| 70 base::ProcessHandle process_handle, | 70 base::Process process, |
| 71 base::File read_file, | 71 base::File read_file, |
| 72 base::File write_file); | 72 base::File write_file); |
| 73 | 73 |
| 74 bool detached_; | 74 bool detached_; |
| 75 | 75 |
| 76 bool allow_user_level_hosts_; | 76 bool allow_user_level_hosts_; |
| 77 | 77 |
| 78 // Handle of the native window corresponding to the extension. | 78 // Handle of the native window corresponding to the extension. |
| 79 intptr_t window_handle_; | 79 intptr_t window_handle_; |
| 80 | 80 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 CommandLine command_line(host_path); | 185 CommandLine command_line(host_path); |
| 186 command_line.AppendArg(origin.spec()); | 186 command_line.AppendArg(origin.spec()); |
| 187 | 187 |
| 188 // Pass handle of the native view window to the native messaging host. This | 188 // Pass handle of the native view window to the native messaging host. This |
| 189 // way the host will be able to create properly focused UI windows. | 189 // way the host will be able to create properly focused UI windows. |
| 190 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
| 191 command_line.AppendSwitchASCII(kParentWindowSwitchName, | 191 command_line.AppendSwitchASCII(kParentWindowSwitchName, |
| 192 base::Int64ToString(window_handle_)); | 192 base::Int64ToString(window_handle_)); |
| 193 #endif // !defined(OS_WIN) | 193 #endif // !defined(OS_WIN) |
| 194 | 194 |
| 195 base::ProcessHandle process_handle; | 195 base::Process process; |
| 196 base::File read_file; | 196 base::File read_file; |
| 197 base::File write_file; | 197 base::File write_file; |
| 198 if (NativeProcessLauncher::LaunchNativeProcess( | 198 if (NativeProcessLauncher::LaunchNativeProcess( |
| 199 command_line, &process_handle, &read_file, &write_file)) { | 199 command_line, &process, &read_file, &write_file)) { |
| 200 PostResult(callback, process_handle, read_file.Pass(), write_file.Pass()); | 200 PostResult(callback, process.Pass(), read_file.Pass(), write_file.Pass()); |
| 201 } else { | 201 } else { |
| 202 PostErrorResult(callback, RESULT_FAILED_TO_START); | 202 PostErrorResult(callback, RESULT_FAILED_TO_START); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 void NativeProcessLauncherImpl::Core::CallCallbackOnIOThread( | 206 void NativeProcessLauncherImpl::Core::CallCallbackOnIOThread( |
| 207 LaunchedCallback callback, | 207 LaunchedCallback callback, |
| 208 LaunchResult result, | 208 LaunchResult result, |
| 209 base::ProcessHandle process_handle, | 209 base::Process process, |
| 210 base::File read_file, | 210 base::File read_file, |
| 211 base::File write_file) { | 211 base::File write_file) { |
| 212 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 212 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 213 if (detached_) | 213 if (detached_) |
| 214 return; | 214 return; |
| 215 | 215 |
| 216 callback.Run(result, process_handle, read_file.Pass(), write_file.Pass()); | 216 callback.Run(result, process.Pass(), read_file.Pass(), write_file.Pass()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void NativeProcessLauncherImpl::Core::PostErrorResult( | 219 void NativeProcessLauncherImpl::Core::PostErrorResult( |
| 220 const LaunchedCallback& callback, | 220 const LaunchedCallback& callback, |
| 221 LaunchResult error) { | 221 LaunchResult error) { |
| 222 content::BrowserThread::PostTask( | 222 content::BrowserThread::PostTask( |
| 223 content::BrowserThread::IO, FROM_HERE, | 223 content::BrowserThread::IO, FROM_HERE, |
| 224 base::Bind(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread, this, | 224 base::Bind(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread, this, |
| 225 callback, error, base::kNullProcessHandle, | 225 callback, error, Passed(base::Process()), |
| 226 Passed(base::File()), Passed(base::File()))); | 226 Passed(base::File()), Passed(base::File()))); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void NativeProcessLauncherImpl::Core::PostResult( | 229 void NativeProcessLauncherImpl::Core::PostResult( |
| 230 const LaunchedCallback& callback, | 230 const LaunchedCallback& callback, |
| 231 base::ProcessHandle process_handle, | 231 base::Process process, |
| 232 base::File read_file, | 232 base::File read_file, |
| 233 base::File write_file) { | 233 base::File write_file) { |
| 234 content::BrowserThread::PostTask( | 234 content::BrowserThread::PostTask( |
| 235 content::BrowserThread::IO, FROM_HERE, | 235 content::BrowserThread::IO, FROM_HERE, |
| 236 base::Bind(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread, this, | 236 base::Bind(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread, this, |
| 237 callback, RESULT_SUCCESS, process_handle, | 237 callback, RESULT_SUCCESS, Passed(&process), |
| 238 Passed(read_file.Pass()), Passed(write_file.Pass()))); | 238 Passed(&read_file), Passed(&write_file))); |
| 239 } | 239 } |
| 240 | 240 |
| 241 NativeProcessLauncherImpl::NativeProcessLauncherImpl( | 241 NativeProcessLauncherImpl::NativeProcessLauncherImpl( |
| 242 bool allow_user_level_hosts, | 242 bool allow_user_level_hosts, |
| 243 intptr_t window_handle) | 243 intptr_t window_handle) |
| 244 : core_(new Core(allow_user_level_hosts, window_handle)) { | 244 : core_(new Core(allow_user_level_hosts, window_handle)) { |
| 245 } | 245 } |
| 246 | 246 |
| 247 NativeProcessLauncherImpl::~NativeProcessLauncherImpl() { | 247 NativeProcessLauncherImpl::~NativeProcessLauncherImpl() { |
| 248 core_->Detach(); | 248 core_->Detach(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 263 intptr_t window_handle = 0; | 263 intptr_t window_handle = 0; |
| 264 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| 265 window_handle = reinterpret_cast<intptr_t>( | 265 window_handle = reinterpret_cast<intptr_t>( |
| 266 views::HWNDForNativeView(native_view)); | 266 views::HWNDForNativeView(native_view)); |
| 267 #endif | 267 #endif |
| 268 return scoped_ptr<NativeProcessLauncher>( | 268 return scoped_ptr<NativeProcessLauncher>( |
| 269 new NativeProcessLauncherImpl(allow_user_level_hosts, window_handle)); | 269 new NativeProcessLauncherImpl(allow_user_level_hosts, window_handle)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace extensions | 272 } // namespace extensions |
| OLD | NEW |