Chromium Code Reviews| Index: chrome/browser/extensions/api/messaging/native_process_launcher.cc |
| diff --git a/chrome/browser/extensions/api/messaging/native_process_launcher.cc b/chrome/browser/extensions/api/messaging/native_process_launcher.cc |
| index 2186e1e1c0083661b28b8ed2e418c8dd1ec7bcf6..caf34b4b396f97a68a5a3adfbeaf8efedac1cc74 100644 |
| --- a/chrome/browser/extensions/api/messaging/native_process_launcher.cc |
| +++ b/chrome/browser/extensions/api/messaging/native_process_launcher.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/path_service.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest.h" |
| @@ -24,6 +25,7 @@ namespace extensions { |
| namespace { |
| const char kNativeHostsDirectoryName[] = "native_hosts"; |
|
Sergey Ulanov
2013/08/08 18:22:37
This is not used anywhere. Can you please remove i
alexeypa (please no reviews)
2013/08/08 23:57:41
Done.
|
| +const char kNativeViewSwitchName[] = "native_view"; |
|
Sergey Ulanov
2013/08/08 18:22:37
Maybe call it "parent-hwnd" or something like that
alexeypa (please no reviews)
2013/08/08 23:57:41
Done. --parent-window
|
| base::FilePath GetHostManifestPathFromCommandLine( |
| const std::string& native_host_name) { |
| @@ -51,7 +53,7 @@ base::FilePath GetHostManifestPathFromCommandLine( |
| // Default implementation on NativeProcessLauncher interface. |
| class NativeProcessLauncherImpl : public NativeProcessLauncher { |
| public: |
| - NativeProcessLauncherImpl(); |
| + explicit NativeProcessLauncherImpl(gfx::NativeView native_view); |
| virtual ~NativeProcessLauncherImpl(); |
| virtual void Launch(const GURL& origin, |
| @@ -61,7 +63,7 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher { |
| private: |
| class Core : public base::RefCountedThreadSafe<Core> { |
| public: |
| - Core(); |
| + explicit Core(gfx::NativeView native_view); |
| void Launch(const GURL& origin, |
| const std::string& native_host_name, |
| LaunchedCallback callback); |
| @@ -85,6 +87,9 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher { |
| bool detached_; |
| + // Handle of the native view corrsponding to the extension. |
| + gfx::NativeView native_view_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(Core); |
| }; |
| @@ -93,8 +98,9 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher { |
| DISALLOW_COPY_AND_ASSIGN(NativeProcessLauncherImpl); |
| }; |
| -NativeProcessLauncherImpl::Core::Core() |
| - : detached_(false) { |
| +NativeProcessLauncherImpl::Core::Core(gfx::NativeView native_view) |
| + : detached_(false), |
| + native_view_(native_view) { |
| } |
| NativeProcessLauncherImpl::Core::~Core() { |
| @@ -182,6 +188,14 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool( |
| CommandLine command_line(host_path); |
| command_line.AppendArg(origin.spec()); |
| + // Pass handle of the native view window to the native messaging host. This |
| + // way the host will be able to create properly focused UI windows. |
| +#if defined(OS_WIN) |
| + int64 window_handle = reinterpret_cast<intptr_t>(native_view_); |
| + command_line.AppendSwitchASCII(kNativeViewSwitchName, |
| + base::Int64ToString(window_handle)); |
| +#endif // !defined(OS_WIN) |
| + |
| base::PlatformFile read_file; |
| base::PlatformFile write_file; |
| if (NativeProcessLauncher::LaunchNativeProcess( |
| @@ -230,8 +244,9 @@ void NativeProcessLauncherImpl::Core::PostResult( |
| this, callback, RESULT_SUCCESS, read_file, write_file)); |
| } |
| -NativeProcessLauncherImpl::NativeProcessLauncherImpl() |
| - : core_(new Core()) { |
| +NativeProcessLauncherImpl::NativeProcessLauncherImpl( |
| + gfx::NativeView native_view) |
| + : core_(new Core(native_view)) { |
| } |
| NativeProcessLauncherImpl::~NativeProcessLauncherImpl() { |
| @@ -247,8 +262,10 @@ void NativeProcessLauncherImpl::Launch(const GURL& origin, |
| } // namespace |
| // static |
| -scoped_ptr<NativeProcessLauncher> NativeProcessLauncher::CreateDefault() { |
| - return scoped_ptr<NativeProcessLauncher>(new NativeProcessLauncherImpl()); |
| +scoped_ptr<NativeProcessLauncher> NativeProcessLauncher::CreateDefault( |
| + gfx::NativeView native_view) { |
| + return scoped_ptr<NativeProcessLauncher>( |
| + new NativeProcessLauncherImpl(native_view)); |
| } |
| } // namespace extensions |