| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/string_split.h" | |
| 18 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 20 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" | 19 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
| 21 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 22 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 24 | 23 |
| 25 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 26 #include "ui/views/win/hwnd_util.h" | 25 #include "ui/views/win/hwnd_util.h" |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace extensions { | 28 namespace extensions { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 #if defined(OS_WIN) | |
| 34 // Name of the command line switch used to pass handle of the native view to | |
| 35 // the native messaging host. | |
| 36 const char kParentWindowSwitchName[] = "parent-window"; | |
| 37 #endif // defined(OS_WIN) | |
| 38 | |
| 39 // Default implementation on NativeProcessLauncher interface. | 32 // Default implementation on NativeProcessLauncher interface. |
| 40 class NativeProcessLauncherImpl : public NativeProcessLauncher { | 33 class NativeProcessLauncherImpl : public NativeProcessLauncher { |
| 41 public: | 34 public: |
| 42 NativeProcessLauncherImpl(bool allow_user_level_hosts, | 35 NativeProcessLauncherImpl(bool allow_user_level_hosts, |
| 43 intptr_t native_window); | 36 intptr_t native_window); |
| 44 ~NativeProcessLauncherImpl() override; | 37 ~NativeProcessLauncherImpl() override; |
| 45 | 38 |
| 46 void Launch(const GURL& origin, | 39 void Launch(const GURL& origin, |
| 47 const std::string& native_host_name, | 40 const std::string& native_host_name, |
| 48 const LaunchedCallback& callback) const override; | 41 const LaunchedCallback& callback) const override; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if (!base::PathExists(host_path)) { | 176 if (!base::PathExists(host_path)) { |
| 184 LOG(ERROR) | 177 LOG(ERROR) |
| 185 << "Found manifest, but not the binary for native messaging host " | 178 << "Found manifest, but not the binary for native messaging host " |
| 186 << native_host_name << ". Host path specified in the manifest: " | 179 << native_host_name << ". Host path specified in the manifest: " |
| 187 << host_path.AsUTF8Unsafe(); | 180 << host_path.AsUTF8Unsafe(); |
| 188 PostErrorResult(callback, RESULT_NOT_FOUND); | 181 PostErrorResult(callback, RESULT_NOT_FOUND); |
| 189 return; | 182 return; |
| 190 } | 183 } |
| 191 | 184 |
| 192 base::CommandLine command_line(host_path); | 185 base::CommandLine command_line(host_path); |
| 186 // Note: The origin must be the first argument, so do not use AppendSwitch* |
| 187 // hereafter because CommandLine inserts these switches before the other |
| 188 // arguments. |
| 193 command_line.AppendArg(origin.spec()); | 189 command_line.AppendArg(origin.spec()); |
| 194 | 190 |
| 195 // Pass handle of the native view window to the native messaging host. This | 191 // Pass handle of the native view window to the native messaging host. This |
| 196 // way the host will be able to create properly focused UI windows. | 192 // way the host will be able to create properly focused UI windows. |
| 197 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
| 198 command_line.AppendSwitchASCII(kParentWindowSwitchName, | 194 command_line.AppendArg( |
| 199 base::Int64ToString(window_handle_)); | 195 base::StringPrintf("--parent-window=%d", window_handle_)); |
| 200 #endif // !defined(OS_WIN) | 196 #endif // !defined(OS_WIN) |
| 201 | 197 |
| 202 base::Process process; | 198 base::Process process; |
| 203 base::File read_file; | 199 base::File read_file; |
| 204 base::File write_file; | 200 base::File write_file; |
| 205 if (NativeProcessLauncher::LaunchNativeProcess( | 201 if (NativeProcessLauncher::LaunchNativeProcess( |
| 206 command_line, &process, &read_file, &write_file)) { | 202 command_line, &process, &read_file, &write_file)) { |
| 207 PostResult(callback, std::move(process), std::move(read_file), | 203 PostResult(callback, std::move(process), std::move(read_file), |
| 208 std::move(write_file)); | 204 std::move(write_file)); |
| 209 } else { | 205 } else { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 intptr_t window_handle = 0; | 268 intptr_t window_handle = 0; |
| 273 #if defined(OS_WIN) | 269 #if defined(OS_WIN) |
| 274 window_handle = reinterpret_cast<intptr_t>( | 270 window_handle = reinterpret_cast<intptr_t>( |
| 275 views::HWNDForNativeView(native_view)); | 271 views::HWNDForNativeView(native_view)); |
| 276 #endif | 272 #endif |
| 277 return std::unique_ptr<NativeProcessLauncher>( | 273 return std::unique_ptr<NativeProcessLauncher>( |
| 278 new NativeProcessLauncherImpl(allow_user_level_hosts, window_handle)); | 274 new NativeProcessLauncherImpl(allow_user_level_hosts, window_handle)); |
| 279 } | 275 } |
| 280 | 276 |
| 281 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |